Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty line segments not displayed in d3.svg.line. #2061

Closed
kraf opened this issue Oct 13, 2014 · 5 comments
Closed

Empty line segments not displayed in d3.svg.line. #2061

kraf opened this issue Oct 13, 2014 · 5 comments
Labels
bug Something isn’t working
Milestone

Comments

@kraf
Copy link

kraf commented Oct 13, 2014

I can't get a line chart to display single points. In SVG it get's rendered as a dot when I move the pen to a point and then do a line to with the same coordinates (at least with a linecap different than "butt"). I noticed that d3.svg.line just creates the moves of the pen. Is this intentional?
I provided an example: http://jsfiddle.net/ntdwa4dv/1/

@mbostock
Copy link
Member

This is probably a bug (and I don’t think we’d need a new API to fix it). One simple fix is to patch this code in svg/line.js:

function segment() {
  segments.push("M", interpolate(projection(points), tension) || "z");
}

This causes d3.svg.line to use "z" for empty segments, producing a zero-length line, rather than a bare "M" command which draws nothing. This is probably the right fix, although perhaps not the optimal one.

But this fix would still require you to use stroke-linecap: round or stroke-linecap: square, and the dots would still be pretty small (dependent on the stroke-width). You might consider rendering each data point explicitly, say as circles on top of the line, so that you have more control over how they are displayed.

@mbostock mbostock added bug Something isn’t working and removed req labels Oct 17, 2014
@mbostock mbostock modified the milestones: 3.4.x, Icebox Oct 17, 2014
@mbostock mbostock changed the title Single points not being displayed in path Empty line segments not displayed in d3.svg.line. Oct 17, 2014
@jasondavies
Copy link
Contributor

Sounds reasonable.

@mbostock mbostock modified the milestones: 3.4.x, 3.5.x Nov 10, 2014
@jasondavies jasondavies modified the milestones: 3.5, 3.5.x Nov 13, 2014
@mbostock
Copy link
Member

A workaround for the time-being:

line.interpolate(function(points) { return points.length > 1 ? points.join("L") : points + "z"; });

@mbostock mbostock modified the milestones: 3.5.7, 3.5.x Oct 22, 2015
mbostock added a commit that referenced this issue Nov 9, 2015
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.
@mbostock
Copy link
Member

mbostock commented Nov 9, 2015

Fix staged in #2591 for 3.5.7.

@mbostock mbostock closed this as completed Nov 9, 2015
@mbostock
Copy link
Member

mbostock commented Nov 9, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn’t working
Development

No branches or pull requests

3 participants