Skip to content

Instantly share code, notes, and snippets.

@nkhine
Created July 31, 2012 14:00
Show Gist options
  • Save nkhine/3217249 to your computer and use it in GitHub Desktop.
Save nkhine/3217249 to your computer and use it in GitHub Desktop.
cube in D3
/**
* cubeD3 Create a rotating cube with D3.js:
*
* @param id div id tag starting with #
* @param width width of the grid in pixels
* @param height height of the grid in pixels
* @param square
*/
function cubeD3(id, width, height)
{
var svg = d3.select(id);
// Add SVG canvas
svgcanvas = svg.append("svg:svg")
.attr("width", 325)
.attr("height", 250);
// Background dark gray rectangle
svgcanvas.append("svg:rect")
.attr("x",0)
.attr("y",0)
.attr("width",325)
.attr("height",250)
.style("fill", "rgb(125,125,125)");
}
<html>
<head>
<title>Cube using d3.js</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.v2.js"></script>
</head>
<body>
<div id="cube"></div>
<script type="text/javascript" src="cube.js"></script>
<script type="text/javascript">
cubeD3('#chart', 500, 500);
</script>
</body>
</html>
@crwgregory
Copy link

crwgregory commented Aug 11, 2016

In geometry, a cube is a three-dimensional solid object bounded by six square faces, facets or sides, with three meeting at each vertex.

This is a square.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment