Skip to content

Commit cf038c0

Browse files
committed
Render line segments with a single point.
Fixes d3#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.
1 parent 7a46a88 commit cf038c0

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

d3.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7344,10 +7344,8 @@
73447344
}
73457345
function treemap(d) {
73467346
var nodes = stickies || hierarchy(d), root = nodes[0];
7347-
root.x = 0;
7348-
root.y = 0;
7349-
root.dx = size[0];
7350-
root.dy = size[1];
7347+
root.x = root.y = 0;
7348+
if (root.value) root.dx = size[0], root.dy = size[1]; else root.dx = root.dy = 0;
73517349
if (stickies) hierarchy.revalue(root);
73527350
scale([ root ], root.dx * root.dy / root.value);
73537351
(stickies ? stickify : squarify)(root);
@@ -8184,10 +8182,10 @@
81848182
value.closed = /-closed$/.test(key);
81858183
});
81868184
function d3_svg_lineLinear(points) {
8187-
return points.join("L");
8185+
return points.length > 1 ? points.join("L") : points + "Z";
81888186
}
81898187
function d3_svg_lineLinearClosed(points) {
8190-
return d3_svg_lineLinear(points) + "Z";
8188+
return points.join("L") + "Z";
81918189
}
81928190
function d3_svg_lineStep(points) {
81938191
var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
@@ -8209,7 +8207,7 @@
82098207
return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
82108208
}
82118209
function d3_svg_lineCardinalClosed(points, tension) {
8212-
return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
8210+
return points.length < 3 ? d3_svg_lineLinearClosed(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
82138211
points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
82148212
}
82158213
function d3_svg_lineCardinal(points, tension) {

d3.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/svg/line.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ d3_svg_lineInterpolators.forEach(function(key, value) {
104104

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

110110
function d3_svg_lineLinearClosed(points) {
111-
return d3_svg_lineLinear(points) + "Z";
111+
return points.join("L") + "Z";
112112
}
113113

114114
// Step interpolation; generates "H" and "V" commands.
@@ -153,7 +153,7 @@ function d3_svg_lineCardinalOpen(points, tension) {
153153
// Closed cardinal spline interpolation; generates "C" commands.
154154
function d3_svg_lineCardinalClosed(points, tension) {
155155
return points.length < 3
156-
? d3_svg_lineLinear(points)
156+
? d3_svg_lineLinearClosed(points)
157157
: points[0] + d3_svg_lineHermite((points.push(points[0]), points),
158158
d3_svg_lineCardinalTangents([points[points.length - 2]]
159159
.concat(points, [points[1]]), tension));

test/svg/line-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ suite.addBatch({
149149
},
150150
"supports a single-element array": function(line) {
151151
var l = line().interpolate("bundle").tension(1);
152-
assert.pathEqual(l([[0, 0]]), "M0,0");
152+
assert.pathEqual(l([[0, 0]]), "M0,0Z");
153153
}
154154
},
155155

0 commit comments

Comments
 (0)