d3 / d3-shape

Graphical primitives for visualization, such as lines and areas.
https://d3js.org/d3-shape
ISC License
2.48k stars 310 forks source link

curveStepAbove, curveStepBelow? #68

Open mbostock opened 8 years ago

mbostock commented 8 years ago

Useful for drawing a halo around an area that uses d3.curveStepAfter:

function curveStepOutside(context) {
  var y0, i;
  return {
    lineStart: function() { y0 = NaN, i = 0; },
    lineEnd: function() {},
    point: function(x, y) {
      x -= y0 > y ? +0.5 : -0.5, y -= 0.5;
      if (++i === 1) context.moveTo(x, y0 = y);
      else context.lineTo(x, y0), context.lineTo(x, y0 = y);
    }
  };
}

As seen in Mona Lisa Histogram.

mbostock commented 8 years ago

Probably want two versions for above (or top?) and below (bottom?):

function curveStepBelow(context) {
  var y0, i;
  return {
    lineStart: function() { y0 = NaN, i = 0; },
    lineEnd: function() {},
    point: function(x, y) {
      x -= y0 < y ? -0.5 : +0.5, y += 0.5;
      if (++i === 1) context.moveTo(x, y0 = y);
      else context.lineTo(x, y0), context.lineTo(x, y0 = y);
    }
  };
}
mbostock commented 8 years ago

And two more for left and right…