Skip to content

Instantly share code, notes, and snippets.

@radiodario
Created June 19, 2014 12:18
Show Gist options
  • Save radiodario/f4ef0a0f5243eb1efcbd to your computer and use it in GitHub Desktop.
Save radiodario/f4ef0a0f5243eb1efcbd to your computer and use it in GitHub Desktop.
updateTransition
{"description":"updateTransition","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"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}},"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,"tab":"edit","display_percent":0.7,"thumbnail":"http://i.imgur.com/GJbvjP5.gif","fullscreen":false,"ajax-caching":true,"inline-console":true}
var svg = d3.select("svg");
var height = tributary.sh;
var width = tributary.sw;
var data = [];
function refreshData() {
for (var i = 0; i < 25; i++) {
data.push(2 + 10*Math.random())
}
}
refreshData();
var xs = d3.scale.linear()
.domain([0, data.length-1])
.range([0, width]);
var ys = d3.scale.linear()
.domain([0, 12])
.range([height, 0]);
var line = d3.svg.area()
.x(function(d, i) {
return xs(i);
})
.y0(height)
.y1(function(d, i) {
return ys(d);
});
var paths = svg.selectAll('path')
.data([data]);
paths.enter()
.append('path')
.attr('stroke', 'lightblue')
.attr('fill', 'steelblue')
.attr('d', line);
function tick() {
data.push(2+10*Math.random());
paths
.attr('d', line)
.attr('transform', null)
.transition()
.duration(1000)
.ease("linear")
.attr('transform', 'translate(' + xs(-1) + ')')
.each('end', tick);
data.shift();
}
tick();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment