Skip to content

Instantly share code, notes, and snippets.

@romsson
Last active November 15, 2016 12:42
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 romsson/08f50eb3f077d14ba585da8f4f28ee19 to your computer and use it in GitHub Desktop.
Save romsson/08f50eb3f077d14ba585da8f4f28ee19 to your computer and use it in GitHub Desktop.
Rectangles design space
license: mit
<!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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment