Skip to content

Instantly share code, notes, and snippets.

@spsaaibi
Created April 18, 2013 15:14
Show Gist options
  • Save spsaaibi/5413526 to your computer and use it in GitHub Desktop.
Save spsaaibi/5413526 to your computer and use it in GitHub Desktop.
hello inlet
{"description":"hello inlet","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01}
var jsonRectangles = [
{ "x_axis": 10, "y_axis": 10, "height": 20, "width":20, "color" : "green" },
{ "x_axis": 160, "y_axis": 40, "height": 20, "width":20, "color" : "purple" },
{ "x_axis": 70, "y_axis": 70, "height": 20, "width":20, "color" : "red" }];
var max_x = 0;
var max_y = 0;
for (var i = 0; i < jsonRectangles.length; i++) {
var temp_x, temp_y;
var temp_x = jsonRectangles[i].x_axis + jsonRectangles[i].width;
var temp_y = jsonRectangles[i].y_axis + jsonRectangles[i].height;
if ( temp_x >= max_x ) { max_x = temp_x; }
if ( temp_y >= max_y ) { max_y = temp_y; }
}
var svgContainer = d3.select("body").append("svg")
.attr("width", max_x)
.attr("height", max_y)
var rectangles = svgContainer.selectAll("rect")
.data(jsonRectangles)
.enter()
.append("rect");
var rectangleAttributes = rectangles
.attr("x", function (d) { return d.x_axis; })
.attr("y", function (d) { return d.y_axis; })
.attr("height", function (d) { return d.height; })
.attr("width", function (d) { return d.width; })
.style("fill", function(d) { return d.color; });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment