Skip to content

Commit fdf5f93

Browse files
committed
cleaner formatting for step interpolation method
1 parent 0500aae commit fdf5f93

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/svg/line.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ function d3_svg_lineStepBefore(points) {
130130

131131
// Step interpolation; generates "H" and "V" commands.
132132
function d3_svg_lineStep(points) {
133-
var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
133+
var i = 0, n = points.length, p0, p1 = points[0], path = [ p1[0], ",", p1[1] ];
134134
while (++i < n) {
135-
var prev = points[i-1], p = points[i];
136-
path.push("H", (p[0] - prev[0])/2 + prev[0], "V", p[1], "H", p[0]);
135+
p0 = p1, p1 = points[i];
136+
path.push("H", (p0[0] + p1[0]) / 2, "V", p1[1], "H", p1[0]);
137137
}
138138
return path.join("");
139139
}

test/svg/line-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ suite.addBatch({
9393
assert.pathEqual(l([[0, 0], [1, 1]]), "M0,0V1H1");
9494
assert.pathEqual(l([[0, 0], [1, 1], [2, 0]]), "M0,0V1H1V0H2");
9595
},
96-
"supports step-middle interpolation": function(line) {
96+
"supports step interpolation": function(line) {
9797
var l = line().interpolate("step");
9898
assert.pathEqual(l([[0, 0]]), "M0,0");
9999
assert.pathEqual(l([[0, 0], [1, 1]]), "M0,0H0.5V1H1");

0 commit comments

Comments
 (0)