Skip to content

Commit

Permalink
Render line segments with a single point.
Browse files Browse the repository at this point in the history
Fixes #2061. A line segment with a single point is now rendered as "M2,3Z"
rather than "M2,3", such that if there is an associated stroke-linecap, it is
displayed correctly.
  • Loading branch information
mbostock committed Nov 9, 2015
1 parent 7a46a88 commit cf038c0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
12 changes: 5 additions & 7 deletions d3.js
Expand Up @@ -7344,10 +7344,8 @@
}
function treemap(d) {
var nodes = stickies || hierarchy(d), root = nodes[0];
root.x = 0;
root.y = 0;
root.dx = size[0];
root.dy = size[1];
root.x = root.y = 0;
if (root.value) root.dx = size[0], root.dy = size[1]; else root.dx = root.dy = 0;
if (stickies) hierarchy.revalue(root);
scale([ root ], root.dx * root.dy / root.value);
(stickies ? stickify : squarify)(root);
Expand Down Expand Up @@ -8184,10 +8182,10 @@
value.closed = /-closed$/.test(key);
});
function d3_svg_lineLinear(points) {
return points.join("L");
return points.length > 1 ? points.join("L") : points + "Z";
}
function d3_svg_lineLinearClosed(points) {
return d3_svg_lineLinear(points) + "Z";
return points.join("L") + "Z";
}
function d3_svg_lineStep(points) {
var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
Expand All @@ -8209,7 +8207,7 @@
return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
}
function d3_svg_lineCardinalClosed(points, tension) {
return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
return points.length < 3 ? d3_svg_lineLinearClosed(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
}
function d3_svg_lineCardinal(points, tension) {
Expand Down
10 changes: 5 additions & 5 deletions d3.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/svg/line.js
Expand Up @@ -104,11 +104,11 @@ d3_svg_lineInterpolators.forEach(function(key, value) {

// Linear interpolation; generates "L" commands.
function d3_svg_lineLinear(points) {
return points.join("L");
return points.length > 1 ? points.join("L") : points + "Z";
}

function d3_svg_lineLinearClosed(points) {
return d3_svg_lineLinear(points) + "Z";
return points.join("L") + "Z";
}

// Step interpolation; generates "H" and "V" commands.
Expand Down Expand Up @@ -153,7 +153,7 @@ function d3_svg_lineCardinalOpen(points, tension) {
// Closed cardinal spline interpolation; generates "C" commands.
function d3_svg_lineCardinalClosed(points, tension) {
return points.length < 3
? d3_svg_lineLinear(points)
? d3_svg_lineLinearClosed(points)
: points[0] + d3_svg_lineHermite((points.push(points[0]), points),
d3_svg_lineCardinalTangents([points[points.length - 2]]
.concat(points, [points[1]]), tension));
Expand Down
2 changes: 1 addition & 1 deletion test/svg/line-test.js
Expand Up @@ -149,7 +149,7 @@ suite.addBatch({
},
"supports a single-element array": function(line) {
var l = line().interpolate("bundle").tension(1);
assert.pathEqual(l([[0, 0]]), "M0,0");
assert.pathEqual(l([[0, 0]]), "M0,0Z");
}
},

Expand Down

0 comments on commit cf038c0

Please sign in to comment.