Break out draw function

This commit is contained in:
Colin Megill
2018-07-05 16:38:43 -04:00
parent e383e52320
commit d1895ecb05
+29 -21
View File
@@ -47,6 +47,20 @@ class Graph extends React.Component {
mode: "brush" mode: "brush"
}; };
} }
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()
});
}
componentDidMount() { componentDidMount() {
// setup canvas and camera // setup canvas and camera
const camera = _camera(this.reglCanvas, { scale: true, rotate: false }); const camera = _camera(this.reglCanvas, { scale: true, rotate: false });
@@ -59,23 +73,15 @@ class Graph 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,
size: sizeBuffer, camera
distance: camera.distance, );
color: colorBuffer,
position: pointBuffer,
count: this.count,
view: camera.view(),
scale: viewportHeight / viewportWidth
});
this.setState({ camera });
camera.tick(); camera.tick();
}); });
@@ -83,10 +89,11 @@ class Graph extends React.Component {
regl, regl,
pointBuffer, pointBuffer,
colorBuffer, colorBuffer,
sizeBuffer sizeBuffer,
camera,
reglRender
}); });
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (this.state.regl && nextProps.crossfilter) { if (this.state.regl && nextProps.crossfilter) {
/* update the regl state */ /* update the regl state */
@@ -164,7 +171,8 @@ class Graph extends React.Component {
nextProps.responsive.width !== this.props.responsive.width nextProps.responsive.width !== this.props.responsive.width
) { ) {
/* clear out whatever was on the div, even if nothing, but usually the brushes etc */ /* clear out whatever was on the div, even if nothing, but usually the brushes etc */
d3.select("#graphAttachPoint") d3
.select("#graphAttachPoint")
.selectAll("*") .selectAll("*")
.remove(); .remove();
const { svg, brush, brushContainer } = setupSVGandBrushElements( const { svg, brush, brushContainer } = setupSVGandBrushElements(
@@ -200,7 +208,7 @@ class Graph extends React.Component {
// transform screen coordinates -> cell coordinates // transform screen coordinates -> cell coordinates
const invert = pin => { const invert = pin => {
const x = const x =
(2 * pin[0]) / (this.props.responsive.height - this.graphPaddingTop) - 2 * pin[0] / (this.props.responsive.height - this.graphPaddingTop) -
1; 1;
const y = const y =
2 * 2 *