fixed scatterplot infinite render (#429)

* add more to state from componentDidMount

* always brush

* destructure

* move render to function

* fixed scatterplot infinite render

* remove logging
This commit is contained in:
Colin Megill
2018-11-09 20:28:22 -05:00
committed by GitHub
parent 47ce0cfc49
commit 9decf134e0
3 changed files with 68 additions and 41 deletions
@@ -215,7 +215,12 @@ class HistogramBrush extends React.Component {
d3.select(svgRef) d3.select(svgRef)
.append("g") .append("g")
.attr("class", "brush") .attr("class", "brush")
.call(d3.brushX().on("end", this.onBrush(field, x.invert).bind(this))); .call(
d3
.brushX()
.on("brush", this.onBrush(field, x.invert).bind(this))
.on("end", this.onBrush(field, x.invert).bind(this))
);
/* AXIS */ /* AXIS */
d3.select(svgRef) d3.select(svgRef)
@@ -38,14 +38,7 @@ export default function(regl) {
uniforms: { uniforms: {
distance: regl.prop("distance"), distance: regl.prop("distance"),
view: regl.prop("view"), view: regl.prop("view"),
projection: (context, props) => projection: () => mat4.perspective([], Math.PI / 2, 1, 0.01, 1000)
mat4.perspective(
[],
Math.PI / 2,
(context.viewportWidth * props.scale) / context.viewportHeight,
0.01,
1000
)
}, },
count: regl.prop("count"), count: regl.prop("count"),
@@ -82,12 +82,6 @@ class Scatterplot extends React.Component {
this.drawAxesSVG(scales.xScale, scales.yScale, svg); this.drawAxesSVG(scales.xScale, scales.yScale, svg);
} }
this.setState({
svg,
xScale: scales ? scales.xScale : null,
yScale: scales ? scales.yScale : null
});
const camera = _camera(this.reglCanvas, { scale: true, rotate: false }); const camera = _camera(this.reglCanvas, { scale: true, rotate: false });
const regl = _regl(this.reglCanvas); const regl = _regl(this.reglCanvas);
@@ -98,43 +92,35 @@ class Scatterplot extends React.Component {
const colorBuffer = regl.buffer(); const colorBuffer = regl.buffer();
const sizeBuffer = regl.buffer(); const sizeBuffer = regl.buffer();
regl.frame(({ viewportWidth, viewportHeight }) => { const reglRender = regl.frame(() => {
regl.clear({ this.reglDraw(
depth: 1, regl,
color: [1, 1, 1, 1] drawPoints,
}); sizeBuffer,
colorBuffer,
drawPoints({ pointBuffer,
distance: camera.distance, camera
color: colorBuffer, );
position: pointBuffer,
size: sizeBuffer,
count: this.count,
view: camera.view(),
scale: viewportHeight / viewportWidth
});
camera.tick(); camera.tick();
}); });
this.reglRenderState = "rendering";
this.setState({ this.setState({
regl, regl,
sizeBuffer, sizeBuffer,
pointBuffer, pointBuffer,
colorBuffer colorBuffer,
svg,
xScale: scales ? scales.xScale : null,
yScale: scales ? scales.yScale : null,
reglRender,
camera,
drawPoints
}); });
} }
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
const {
svg,
xScale,
yScale,
regl,
pointBuffer,
colorBuffer,
sizeBuffer
} = this.state;
const { const {
world, world,
crossfilter, crossfilter,
@@ -144,6 +130,18 @@ class Scatterplot extends React.Component {
expressionY, expressionY,
colorRGB colorRGB
} = this.props; } = this.props;
const {
reglRender,
xScale,
yScale,
regl,
pointBuffer,
colorBuffer,
sizeBuffer,
svg,
drawPoints,
camera
} = this.state;
if ( if (
world && world &&
@@ -159,6 +157,11 @@ class Scatterplot extends React.Component {
this.drawAxesSVG(xScale, yScale, svg); this.drawAxesSVG(xScale, yScale, svg);
} }
if (reglRender && this.reglRenderState === "rendering") {
reglRender.cancel();
this.reglRenderState = "paused";
}
if ( if (
world && world &&
regl && regl &&
@@ -198,6 +201,16 @@ class Scatterplot extends React.Component {
colorBuffer({ data: colorsBuf, dimension: 3 }); colorBuffer({ data: colorsBuf, dimension: 3 });
sizeBuffer({ data: sizesBuf, dimension: 1 }); sizeBuffer({ data: sizesBuf, dimension: 1 });
this.count = cellCount; this.count = cellCount;
regl._refresh();
this.reglDraw(
regl,
drawPoints,
sizeBuffer,
colorBuffer,
pointBuffer,
camera
);
} }
if ( if (
@@ -227,6 +240,22 @@ class Scatterplot extends React.Component {
}; };
} }
reglDraw(regl, drawPoints, sizeBuffer, colorBuffer, pointBuffer, camera) {
regl.clear({
depth: 1,
color: [1, 1, 1, 1]
});
drawPoints({
size: sizeBuffer,
distance: camera.distance,
color: colorBuffer,
position: pointBuffer,
count: this.count,
view: camera.view()
});
}
drawAxesSVG(xScale, yScale, svg) { drawAxesSVG(xScale, yScale, svg) {
const { scatterplotYYaccessor, scatterplotXXaccessor } = this.props; const { scatterplotYYaccessor, scatterplotXXaccessor } = this.props;
svg.selectAll("*").remove(); svg.selectAll("*").remove();