score:2

Accepted answer

Actually, I just realized that linear.clamp(true) does exactly what I wanted.

score:3

I think you are over complicating this.

I'm sure you are using a d3.line function, just cap the values in the y accessor:

var line = d3.line()
  .x(function(d) { return x(d.x); })
  .y(function(d) { 
    if (d.y > 150) return y(150);
    else if (d.y < 50) return y(50);
    else return y(d.y);
  });