Skip to content

Instantly share code, notes, and snippets.

@ninestar09
Created February 26, 2016 23:26
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 ninestar09/e4f186537d7ee77885f8 to your computer and use it in GitHub Desktop.
Save ninestar09/e4f186537d7ee77885f8 to your computer and use it in GitHub Desktop.
transition
{"description":"transition","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"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,"ajax-caching":true}
var svg = d3.select("svg");
var data1 = [
{id:"weezy", value:100},
{id:"aeezy", value:42},
{id:"veezy", value:172},
{id:"ceezy", value:82},
{id:"qeezy", value:60},
{id:"zeezy", value:132}
];
var data2 = [
{id:"weezy", value:77},
{id:"aeezy", value:28},
{id:"veezy", value:68},
{id:"ceezy", value:147},
{id:"qeezy", value:75},
{id:"zeezy", value:42}];
var bars = svg.selectAll("rect")
.data(data1)
.enter()
.append("rect")
.attr({
width:40,
height: function(d, i){
return d.value;
},
transform: function(d,i){
var x = i*50+246;
var y = 138;
return "translate("+[x,y]+")";
}
})
.classed("bars", true)
var button = svg.append("rect")
.attr({
width:100,
height:30,
x:600,
y:400,
fill: "#e3e3e3",
stroke: "#000"
})
.on("click", function() {
svg.selectAll("rect.bars")
.data(data2, function(d) {return d.id})
.transition()
.attr({
height:function(d,i){
return d.value;
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment