Last active
June 2, 2017 13:10
-
-
Save amitkaps/6453bb21d275128840739f05e0d014f0 to your computer and use it in GitHub Desktop.
Render 100000 points with Vega-lite & WebGL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <meta charset="utf-8"> | |
| <script src="https://d3js.org/d3.v4.min.js"></script> | |
| <script src="https://unpkg.com/vega/build/vega.min.js" charset="utf-8"></script> | |
| <script src="https://unpkg.com/vega-webgl-renderer/build/vega-webgl-renderer.js" charset="utf-8"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/vega-lite/2.0.0-beta.3/vega-lite.js"></script> | |
| <div id="vis"></div> | |
| <script> | |
| var numPoints = 100000; | |
| var pointWidth = 4; | |
| var width = 800; | |
| var height = 800; | |
| // create initial set of points | |
| var rng = d3.randomNormal(0, 0.15); | |
| var dataPoints = d3.range(numPoints).map(i => ({ | |
| x: (rng() * width) + (width / 2), | |
| y: (rng() * height) + (height / 2), | |
| c: Math.random(), | |
| })); | |
| console.log(dataPoints.length); | |
| var scatterJson = { | |
| "width" : 500, | |
| "height": 500, | |
| "data": { | |
| "values": dataPoints | |
| }, | |
| "mark": "circle", | |
| "encoding": { | |
| "x": {"field": "x", "type": "Q", "axis": null}, | |
| "y": {"field": "y", "type": "Q", "axis": null}, | |
| "color": {"field": "c", "type": "Q", "legend": null}, | |
| }, | |
| "config": { | |
| "background": "black", | |
| } | |
| } | |
| var vgSpec = vl.compile(scatterJson).spec; | |
| var view = new vega.View(vega.parse(vgSpec)) | |
| .initialize(document.querySelector('#vis')) | |
| .renderer('webgl') | |
| .run(); | |
| </script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment