Created
November 16, 2013 01:15
-
-
Save zackdever/7494543 to your computer and use it in GitHub Desktop.
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
function r() { | |
return Math.random() * 100; | |
} | |
var lineData = function() { | |
return [ | |
[0, r()], | |
[20, r()], | |
[40, r()], | |
[60, r()], | |
[80, r()], | |
[100, r()], | |
[120, r()] | |
]; | |
} | |
var svgContainer = d3.select('body').append('svg').attr({ width: '100%', height: '100%' }); | |
var lineFx = function (interpolate) { | |
return d3.svg.line() | |
.x(function(d) { return d[0] + 10; }) | |
.y(function(d) { return d[1] + 10; }) | |
.interpolate(interpolate); | |
}; | |
var path = svgContainer.append('path') | |
.attr({ stroke: 'blue', 'stroke-width': 2, fill: 'none' }); | |
function randomLine(interpolate) { | |
var data = lineData(); | |
svgContainer.selectAll('circle').remove(); | |
svgContainer.selectAll('circle').data(data).enter() | |
.append('circle') | |
.attr('cx', function(d) { return d[0] + 10; }) | |
.attr('cy', function(d) { return d[1] + 10; }) | |
.attr('r', 4); | |
path.attr('d', lineFx(interpolate)(data)); | |
} | |
var interpolateOptions = [ | |
'linear', 'step-before', 'step-after', 'basis', 'basis-open', 'basis-closed', | |
'bundle', 'cardinal', 'cardinal-open', 'cardinal-closed', 'monotone' | |
]; | |
f = function() { | |
randomLine(_.sample(interpolateOptions)); | |
}; | |
f(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment