D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
romsson
Full window
Github gist
Rectangles design space
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v3.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } rect { fill: none; stroke: black; stroke-width: 1px; } </style> </head> <body> <script> // Feel free to change or delete any of the code you see in this editor! var svg = d3.select("body").append("svg") .attr("width", 960) .attr("height", 500); var marks = [{ "name": "Rectangle", "svg_mark": "rect", "properties": [ {"name": "Width", "style": "width"}, {"name": "Height", "style": "height"} ] }, { "name": "Circle", "svg_mark": "circle", "properties": [ {"name": "Radius", "attr": "r"} ] }]; var data = [0, 20, 50, 80, 100]; //var x = d3.scale.linear().range([0, 500]).domain([0, data.length]); //var y = d3.scale.linear().range([0, 100]).domain([0, d3.max(data)]); var g = svg.selectAll("g").data(marks) .enter() .append("g") .attr("transform", function(d, i) { return "translate(100, " + (i * 100) + ")"; }); g.append("text") .text(function(d) { return "TOTOTO"; }) .attr("x", 200) .attr("y", function(d, i) { return i * 20 + 100; }) .style("font-size", 12) .style("font-family", "monospace"); g.append(function() { return document.createElement('rect');}) // .text(function(d) { return "TOTOTO"; }) .attr("x", 200) .attr("y", function(d, i) { return i * 20 + 100; }) .style("width", 12) .style("height", 50); /* g.selectAll("rect").data(data).enter().append("rect") .attr("x", function(d, i) { return x(i); }) .attr("y", function(d) { return 170 - y(d); }) .attr("height", function(d) { return y(d); }) .attr("width", 500 / data.length); */ </script> </body>
https://d3js.org/d3.v3.min.js