[ Launch: Crowdfunding Stats ] 8827504 by DeBraid
-
-
Save DeBraid/8827504 to your computer and use it in GitHub Desktop.
grouped to stacked transition
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":"grouped to stacked transition","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"data.json":{"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":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/M3GfyRM.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
[ | |
{ | |
"Category ":"All", | |
"Success":55797, | |
"Under $1000":6033, | |
"$1000-$9999":35439, | |
"$10000-19999":7461, | |
"$20000-99999":5755, | |
"100K - $999999":1053, | |
"Over $1 Million":56 | |
}, | |
{ | |
"Category ":"Music", | |
"Success":14744, | |
"Under $1000":1434, | |
"$1000-$9999":10935, | |
"$10000-19999":1709, | |
"$20000-99999":634, | |
"100K - $999999":31, | |
"Over $1 Million":1 | |
}, | |
{ | |
"Category ":"Film & Video", | |
"Success":12796, | |
"Under $1000":1216, | |
"$1000-$9999":7748, | |
"$10000-19999":2008, | |
"$20000-99999":1668, | |
"100K - $999999":153, | |
"Over $1 Million":3 | |
}, | |
{ | |
"Category ":"Art", | |
"Success":5491, | |
"Under $1000":1035, | |
"$1000-$9999":3782, | |
"$10000-19999":457, | |
"$20000-99999":203, | |
"100K - $999999":14, | |
"Over $1 Million":0 | |
}, | |
{ | |
"Category ":"Publishing", | |
"Success":4985, | |
"Under $1000":763, | |
"$1000-$9999":3258, | |
"$10000-19999":588, | |
"$20000-99999":351, | |
"100K - $999999":25, | |
"Over $1 Million":0 | |
}, | |
{ | |
"Category ":"Theater", | |
"Success":3502, | |
"Under $1000":465, | |
"$1000-$9999":2634, | |
"$10000-19999":258, | |
"$20000-99999":137, | |
"100K - $999999":8, | |
"Over $1 Million":0 | |
}, | |
{ | |
"Category ":"Games", | |
"Success":2822, | |
"Under $1000":150, | |
"$1000-$9999":1091, | |
"$10000-19999":541, | |
"$20000-99999":763, | |
"100K - $999999":248, | |
"Over $1 Million":29 | |
}, | |
{ | |
"Category ":"Design", | |
"Success":2433, | |
"Under $1000":146, | |
"$1000-$9999":852, | |
"$10000-19999":458, | |
"$20000-99999":719, | |
"100K - $999999":249, | |
"Over $1 Million":9 | |
}, | |
{ | |
"Category ":"Food", | |
"Success":2042, | |
"Under $1000":93, | |
"$1000-$9999":1002, | |
"$10000-19999":528, | |
"$20000-99999":397, | |
"100K - $999999":22, | |
"Over $1 Million":0 | |
}, | |
{ | |
"Category ":"Comics", | |
"Success":1703, | |
"Under $1000":216, | |
"$1000-$9999":1024, | |
"$10000-19999":246, | |
"$20000-99999":187, | |
"100K - $999999":29, | |
"Over $1 Million":1 | |
}, | |
{ | |
"Category ":"Fashion", | |
"Success":1464, | |
"Under $1000":149, | |
"$1000-$9999":816, | |
"$10000-19999":229, | |
"$20000-99999":234, | |
"100K - $999999":35, | |
"Over $1 Million":1 | |
}, | |
{ | |
"Category ":"Photography", | |
"Success":1426, | |
"Under $1000":219, | |
"$1000-$9999":936, | |
"$10000-19999":182, | |
"$20000-99999":87, | |
"100K - $999999":1, | |
"Over $1 Million":1 | |
}, | |
{ | |
"Category ":"Technology", | |
"Success":1212, | |
"Under $1000":52, | |
"$1000-$9999":385, | |
"$10000-19999":173, | |
"$20000-99999":353, | |
"100K - $999999":238, | |
"Over $1 Million":11 | |
}, | |
{ | |
"Category ":"Dance", | |
"Success":1177, | |
"Under $1000":95, | |
"$1000-$9999":976, | |
"$10000-19999":84, | |
"$20000-99999":22, | |
"100K - $999999":0, | |
"Over $1 Million":0 | |
} | |
] |
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
// Stacked explaination https://groups.google.com/forum/#!topic/d3-js/B4K5gYU0WYs | |
// var data1 = tributary.data; | |
var mycsv = 'Category,Under $1000,$1000-$9999,$10000-19999,$20000-99999,100K - $999999,Over $1 Million\n' + | |
'Music,1434,10935,1709,634,31,1\n' + | |
'Film & Video,1216,7748,2008,1668,153,3\n' + | |
'Art,1035,3782,457,203,14,0\n' + | |
'Publishing,763,3258,588,351,25,0\n' + | |
'Theater,465,2634,258,137,8,0\n' + | |
'Games,150,1091,541,763,248,29\n' + | |
'Design,146,852,458,719,249,9\n' + | |
'Food,93,1002,528,397,22,0\n' + | |
'Comics,216,1024,246,187,29,1\n' + | |
'Fashion,149,816,229,234,35,1\n' + | |
'Photography,219,936,182,87,1,1\n' + | |
'Technology,52,385,173,353,238,11\n' + | |
'Dance,95,976,84,22,0,0\n'; | |
var headers = ["Under $1000","$1000-$9999","$10000-19999","$20000-99999","100K - $999999","Over $1 Million"]; | |
/* | |
var myData = function(mycsv){ | |
d3.layout.stack()(headers | |
.map(function(value){ | |
return mycsv.map(function(d) { | |
return {x: d.Category, y: +d[value]}; | |
}); | |
})) | |
}; | |
console.log(myData); | |
*/ | |
var n = 6, // number of layers | |
m = 12, // number of samples per layer | |
stack = d3.layout.stack(), | |
layers = stack(d3.range(n).map(function() { return bumpLayer(m, .1); })), | |
yGroupMax = d3.max(layers, function(layer) { return d3.max(layer, function(d) { return d.y; }); }), | |
yStackMax = d3.max(layers, function(layer) { return d3.max(layer, function(d) { return d.y0 + d.y; }); }); | |
console.log("check bumpLayer"); | |
console.log(bumpLayer(m, 0.1)) | |
console.log("check layers"); | |
console.log(layers); | |
console.log("check yGroupMax"); | |
console.log(yGroupMax); | |
console.log("check yStackMax"); | |
console.log(yStackMax); | |
console.log("check end"); | |
var margin = {top: 40, right: 10, bottom: 20, left: 10}, | |
width = 700 - margin.left - margin.right, | |
height = 500 - margin.top - margin.bottom; | |
var x = d3.scale.ordinal() | |
.domain(d3.range(m)) | |
.rangeRoundBands([0, width], .08); | |
var y = d3.scale.linear() | |
.domain([0, yStackMax]) | |
.range([height, 0]); | |
var color = d3.scale.ordinal() | |
.range(["#98ABC5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]); | |
var xAxis = d3.svg.axis() | |
.scale(x) | |
.tickSize(0) | |
.tickPadding(6) | |
.orient("bottom"); | |
var svg = d3.select("svg") | |
.attr("width", width + margin.left + margin.right) | |
.attr("height", height + margin.top + margin.bottom) | |
.append("g") | |
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
var layer = svg.selectAll(".layer") | |
.data(layers) | |
.enter().append("g") | |
.attr("class", "layer") | |
.style("fill", function(d, i) { return color(i); }); | |
var rect = layer.selectAll("rect") | |
.data(function(d) { return d; }) | |
.enter().append("rect") | |
.attr("x", function(d) { return x(d.x); }) | |
.attr("y", height) | |
.attr("width", x.rangeBand()) | |
.attr("height", 0); | |
rect.transition() | |
.delay(function(d, i) { return i * 10; }) | |
.attr("y", function(d) { return y(d.y0 + d.y); }) | |
.attr("height", function(d) { return y(d.y0) - y(d.y0 + d.y); }); | |
svg.append("g") | |
.attr("class", "x axis") | |
.attr("transform", "translate(0," + height + ")") | |
.call(xAxis); | |
d3.selectAll("input").on("change", change); | |
var timeout = setTimeout(function() { | |
d3.select("input[value=\"grouped\"]").property("checked", true).each(change); | |
}, 2000); | |
function change() { | |
clearTimeout(timeout); | |
if (this.value === "grouped") transitionGrouped(); | |
else transitionStacked(); | |
} | |
function transitionGrouped() { | |
y.domain([0, yGroupMax]); | |
rect.transition() | |
.duration(500) | |
.delay(function(d, i) { return i * 10; }) | |
.attr("x", function(d, i, j) { return x(d.x) + x.rangeBand() / n * j; }) | |
.attr("width", x.rangeBand() / n) | |
.transition() | |
.attr("y", function(d) { return y(d.y); }) | |
.attr("height", function(d) { return height - y(d.y); }); | |
} | |
function transitionStacked() { | |
y.domain([0, yStackMax]); | |
rect.transition() | |
.duration(500) | |
.delay(function(d, i) { return i * 10; }) | |
.attr("y", function(d) { return y(d.y0 + d.y); }) | |
.attr("height", function(d) { return y(d.y0) - y(d.y0 + d.y); }) | |
.transition() | |
.attr("x", function(d) { return x(d.x); }) | |
.attr("width", x.rangeBand()); | |
} | |
// Inspired by Lee Byron's test data generator. | |
function bumpLayer(n, o) { | |
function bump(a) { | |
var x = 1 / (.1 + Math.random()), | |
y = 2 * Math.random() - .5, | |
z = 10 / (.1 + Math.random()); | |
for (var i = 0; i < n; i++) { | |
var w = (i / n - y) * z; | |
a[i] += x * Math.exp(-w * w); | |
} | |
} | |
var a = [], i; | |
for (i = 0; i < n; ++i) a[i] = o + o * Math.random(); | |
for (i = 0; i < 5; ++i) bump(a); | |
return a.map(function(d, i) { return {x: i, y: Math.max(0, d)}; }); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment