From 02d46f14ce224c163b382f6e61ab3ed27d059a95 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Wed, 18 Apr 2018 02:07:54 -0700 Subject: [PATCH] second regl instance running --- src/components/scatterplot/scatterplot.js | 67 +++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/components/scatterplot/scatterplot.js b/src/components/scatterplot/scatterplot.js index a8b862a2..2483660a 100644 --- a/src/components/scatterplot/scatterplot.js +++ b/src/components/scatterplot/scatterplot.js @@ -27,6 +27,34 @@ import { createDimensions, } from "./util"; +const generatePoints = function (count) { + return Array(count).fill().map(function () { + return [ + Math.random() - 0.5, + Math.random() - 0.5 + ] + }) +} + +const generateColors = function (count) { + return Array(count).fill().map(function () { + return [ + Math.random(), + Math.random(), + Math.random() + ] + }) +} + +const generateSizes = function (count) { + return Array(count).fill().map(function () { + return Math.random() * 10 + }) +} + +// set constants +const count = 1993; + @connect((state) => { const ranges = state.cells.cells && state.cells.cells.data.ranges ? state.cells.cells.data.ranges : null; @@ -68,6 +96,44 @@ class Scatterplot extends React.Component { margin ); this.setState({svg, ctx}) + + const camera = _camera(this.reglCanvas, {scale: true, rotate: false}); + const regl = _regl(this.reglCanvas) + + const drawPoints = _drawPoints(regl) + + // preallocate buffers + const pointBuffer = regl.buffer(generatePoints(count)) + const colorBuffer = regl.buffer(generateColors(count)) + const sizeBuffer = regl.buffer(generateSizes(count)) + + + regl.frame(({viewportWidth, viewportHeight}) => { + + regl.clear({ + depth: 1, + color: [1, 1, 1, 1] + }) + + drawPoints({ + distance: camera.distance, + color: colorBuffer, + position: pointBuffer, + size: sizeBuffer, + count: count, + view: camera.view(), + scale: viewportHeight / viewportWidth + }) + + camera.tick() + }) + + this.setState({ + regl, + pointBuffer, + colorBuffer, + }) + } componentWillReceiveProps(nextProps) { this.maybeSetupScalesAndDrawAxes(nextProps); @@ -180,6 +246,7 @@ class Scatterplot extends React.Component { height: height + margin.top + margin.bottom + "px", }} > + { this.reglCanvas = canvas}}/> ) }