cleaner formatting for step interpolation method
This commit is contained in:
Родитель
0500aaea43
Коммит
fdf5f93797
|
@ -130,10 +130,10 @@ function d3_svg_lineStepBefore(points) {
|
||||||
|
|
||||||
// Step interpolation; generates "H" and "V" commands.
|
// Step interpolation; generates "H" and "V" commands.
|
||||||
function d3_svg_lineStep(points) {
|
function d3_svg_lineStep(points) {
|
||||||
var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
|
var i = 0, n = points.length, p0, p1 = points[0], path = [ p1[0], ",", p1[1] ];
|
||||||
while (++i < n) {
|
while (++i < n) {
|
||||||
var prev = points[i-1], p = points[i];
|
p0 = p1, p1 = points[i];
|
||||||
path.push("H", (p[0] - prev[0])/2 + prev[0], "V", p[1], "H", p[0]);
|
path.push("H", (p0[0] + p1[0]) / 2, "V", p1[1], "H", p1[0]);
|
||||||
}
|
}
|
||||||
return path.join("");
|
return path.join("");
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ suite.addBatch({
|
||||||
assert.pathEqual(l([[0, 0], [1, 1]]), "M0,0V1H1");
|
assert.pathEqual(l([[0, 0], [1, 1]]), "M0,0V1H1");
|
||||||
assert.pathEqual(l([[0, 0], [1, 1], [2, 0]]), "M0,0V1H1V0H2");
|
assert.pathEqual(l([[0, 0], [1, 1], [2, 0]]), "M0,0V1H1V0H2");
|
||||||
},
|
},
|
||||||
"supports step-middle interpolation": function(line) {
|
"supports step interpolation": function(line) {
|
||||||
var l = line().interpolate("step");
|
var l = line().interpolate("step");
|
||||||
assert.pathEqual(l([[0, 0]]), "M0,0");
|
assert.pathEqual(l([[0, 0]]), "M0,0");
|
||||||
assert.pathEqual(l([[0, 0], [1, 1]]), "M0,0H0.5V1H1");
|
assert.pathEqual(l([[0, 0], [1, 1]]), "M0,0H0.5V1H1");
|
||||||
|
|
Загрузка…
Ссылка в новой задаче