Skip to content

curveBump? #152

@mbostock

Description

@mbostock

As in for bump charts. Like d3.linkHorizontal, but as a curve. Maybe d3.curveLinkHorizontal is a better name? Or d3.curveSankeyHorizontal? Here’s an implementation that works for lines:

function curveBump(context) {
  let _point, _x, _y;
  return {
    lineStart() {
      _point = 0;
    },
    lineEnd() {
      _point = NaN;
    },
    point(x, y) {
      if (++_point === 1) context.moveTo(x, y);
      else _x = (_x + x) / 2, context.bezierCurveTo(_x, _y, _x, y, x, y);
      _x = x, _y = y;
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions