[ Launch: [dot enter: 07] stacks ] 6286132 by jgautsch
-
-
Save jgautsch/6286132 to your computer and use it in GitHub Desktop.
[dot enter: 07] stacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"description":"[dot enter: 07] stacks","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"inlet.svg":{"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,"thumbnail":"http://i.imgur.com/s38yqXS.png"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var svg = d3.select("svg"); | |
var color = d3.scale.category20(); | |
var data = [ | |
[{y:21},{y:10},{y:10},{y:38},{y:20}], | |
[{y:14},{y:25},{y:21},{y:10},{y:10}], | |
[{y:15},{y:35},{y:21},{y:10},{y:4}] | |
]; | |
var stack = d3.layout.stack(); | |
stack(data); | |
var max = d3.max(data, function(d) { | |
return d3.max(d, function(v) { | |
return v.y + v.y0 | |
}) | |
}) | |
var ch = 361; | |
var yscale = d3.scale.linear() | |
.domain([0, max]) | |
.range([0, ch]); | |
var group = svg.append("g") | |
.attr("transform", "translate(" + [100, 100] + ")") | |
var layers = group.selectAll("g") | |
.data(data) | |
.enter() | |
.append("g") | |
.style({ | |
fill: function(d,i) { return color(i) } | |
}) | |
var stacks = layers.selectAll("rect") | |
.data(function(d) { return d }) | |
.enter() | |
.append("rect") | |
.attr({ | |
width: 30, | |
height: function(d,i) { | |
return yscale(d.y) | |
}, | |
x: function(d,i) { | |
return i * 40 | |
}, | |
y: function(d,i) { | |
return ch - yscale(d.y0 + d.y) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment