adding step-middle as interpolation method
This commit is contained in:
Родитель
18105839c5
Коммит
2f82165d5f
|
@ -92,6 +92,7 @@ var d3_svg_lineInterpolators = d3.map({
|
|||
"linear": d3_svg_lineLinear,
|
||||
"linear-closed": d3_svg_lineLinearClosed,
|
||||
"step-before": d3_svg_lineStepBefore,
|
||||
"step-middle": d3_svg_lineStepMiddle,
|
||||
"step-after": d3_svg_lineStepAfter,
|
||||
"basis": d3_svg_lineBasis,
|
||||
"basis-open": d3_svg_lineBasisOpen,
|
||||
|
@ -127,6 +128,16 @@ function d3_svg_lineStepBefore(points) {
|
|||
return path.join("");
|
||||
}
|
||||
|
||||
// Step interpolation; generates "H" and "V" commands.
|
||||
function d3_svg_lineStepMiddle(points) {
|
||||
var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
|
||||
while (++i < n) {
|
||||
var prev = points[i-1], p = points[i];
|
||||
path.push("H", (p[0] - prev[0])/2 + prev[0], "V", p[1], "H", p[0]);
|
||||
}
|
||||
return path.join("");
|
||||
}
|
||||
|
||||
// Step interpolation; generates "H" and "V" commands.
|
||||
function d3_svg_lineStepAfter(points) {
|
||||
var i = 0,
|
||||
|
|
|
@ -93,6 +93,12 @@ suite.addBatch({
|
|||
assert.pathEqual(l([[0, 0], [1, 1]]), "M0,0V1H1");
|
||||
assert.pathEqual(l([[0, 0], [1, 1], [2, 0]]), "M0,0V1H1V0H2");
|
||||
},
|
||||
"supports step-middle interpolation": function(line) {
|
||||
var l = line().interpolate("step-middle");
|
||||
assert.pathEqual(l([[0, 0]]), "M0,0");
|
||||
assert.pathEqual(l([[0, 0], [1, 1]]), "M0,0H0.5V1H1");
|
||||
assert.pathEqual(l([[0, 0], [1, 1], [2, 0]]), "M0,0H0.5V1H1H1.5V0H2");
|
||||
},
|
||||
"supports step-after interpolation": function(line) {
|
||||
var l = line().interpolate("step-after");
|
||||
assert.pathEqual(l([[0, 0]]), "M0,0");
|
||||
|
|
Загрузка…
Ссылка в новой задаче