Skip to content

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

Closed

Description

@kraf

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/

Activity

  1. added this to the 3.5 milestone on Oct 14, 2014
  2. modified the milestones: Icebox, 3.5 on Oct 17, 2014
  3. mbostock commented on Oct 17, 2014

    @mbostock
    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.

  4. added
    bug
    and removed on Oct 17, 2014
  5. modified the milestones: 3.4.x, Icebox on Oct 17, 2014
  6. changed the title [-]Single points not being displayed in path[/-] [+]Empty line segments not displayed in d3.svg.line.[/+] on Oct 17, 2014
  7. jasondavies commented on Oct 17, 2014

    @jasondavies
    Contributor

    Sounds reasonable.

  8. modified the milestones: 3.4.x, 3.5.x on Nov 10, 2014
  9. modified the milestones: 3.5, 3.5.x on Nov 13, 2014
  10. mbostock commented on Nov 13, 2014

    @mbostock
    Member

    A workaround for the time-being:

    line.interpolate(function(points) { return points.length > 1 ? points.join("L") : points + "z"; });
  11. modified the milestones: 3.5.7, 3.5.x on Oct 22, 2015
  12. added a commit that references this issue on Nov 9, 2015
    cf038c0
  13. mbostock commented on Nov 9, 2015

    @mbostock
    Member

    Fix staged in #2591 for 3.5.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions