Skip to content

Instantly share code, notes, and snippets.

@grahampullan
Last active January 10, 2018 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grahampullan/806086a83b8e2471a08576a009c38ba3 to your computer and use it in GitHub Desktop.
Save grahampullan/806086a83b8e2471a08576a009c38ba3 to your computer and use it in GitHub Desktop.
dbslice.d3ContourStruct2d
license: mit

A minimal dbslice.d3ContourStruct2d plot example.

The github repository for dbslice is here.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
<body>
<div id = "target" style = "width:500px"> </div>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/d3-contour.v1.min.js"></script>
<script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>
<script src="http://dbslice.org/dbslice.js"></script>
<script>
var n = 50;
var m = 50;
var xgrid = new Array(n * m);
var ygrid = new Array(n * m);
var zgrid = new Array(n * m);
var vgrid = new Array(n * m);
// Populate plot data
for (var j = 0., k = 0; j < m; ++j) {
for (var i = 0.; i < n; ++i, ++k) {
xgrid[ k ] = i/n;
ygrid[ k ] = j/m;
var h = 0.125 * Math.cos( i/n * 2 * Math.PI) * (1 - Math.cos( j/m * 2 * Math.PI) );
vgrid[ k ] = h;
}
}
var data = { surfaces: [ { x : xgrid, y : ygrid, v : vgrid, size : [m,n] } ] };
var layout = { height : 500 };
dbslice.d3ContourStruct2d.make( document.getElementById("target"), data, layout);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment