Last active
December 1, 2015 23:13
-
-
Save ericsoco/44efa8d033588324b337 to your computer and use it in GitHub Desktop.
interpolator in need of interpolation
This file contains 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
// use of interpolator: | |
selection.transition() | |
.attrTween('d', areaGenerator) | |
// interpolator: | |
areaGenerator = function (d) { | |
// do I need a d3.interpolate call here, sim. to https://gist.github.com/mbostock/5100636#file-index-html-L66 ? | |
return function (t) { | |
return d3.svg.area() | |
.x(d => xScale(d.x)) | |
.y0(innerHeight) | |
.y1(d => yScale(d.y)) | |
.interpolate((points) => { | |
console.log(t); // outputs values from 0 to 1, as expected, | |
// but there's no longer any interpolation -- | |
// the same points are passed into each function call | |
// symmetrical concave beziers | |
let roundness = 0.8, | |
steepness = 0.5, | |
x0 = points[0][0], | |
y0 = points[0][1], | |
x1 = points[1][0], | |
y1 = points[1][1], | |
x2 = points[2][0], | |
y2 = points[2][1]; | |
let path = points[0].join(' ') + // first anchor point | |
` C${x0 + steepness*(x1-x0)} ${y0},` + // first control point, inside curve | |
`${x0 + roundness*(x1-x0)} ${y1},` + // second control point, outside curve | |
points[1].join(' ') + // middle anchor point | |
` C${x1 + (1-roundness)*(x2-x1)} ${y1},` + // third control point, outside curve | |
`${x1 + (1-steepness)*(x2-x1)} ${y2},` + // fourth control point, inside curve | |
points[2].join(' '); // last anchor point | |
return path; | |
}) | |
(data); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment