diff --git a/src/lib/plot/line.typ b/src/lib/plot/line.typ index e183feaad..4e493366e 100644 --- a/src/lib/plot/line.typ +++ b/src/lib/plot/line.typ @@ -264,8 +264,10 @@ assert(y.named().len() == 0) let prepare(self, ctx) = { - let (min, max) = (ctx.x.min, ctx.x.max) - self.lines = self.y.map(y => ((min, y), (max, y))) + let (x-min, x-max) = (ctx.x.min, ctx.x.max) + let (y-min, y-max) = (ctx.y.min, ctx.y.max) + self.lines = self.y.filter(y => y >= y-min and y <= y-max) + .map(y => ((x-min, y), (x-max, y))) return self } @@ -278,6 +280,7 @@ (( type: "hline", y: y.pos(), + y-domain: (calc.min(..y.pos()), calc.max(..y.pos())), axes: axes, style: style, plot-prepare: prepare, @@ -300,8 +303,10 @@ assert(x.named().len() == 0) let prepare(self, ctx) = { - let (min, max) = (ctx.y.min, ctx.y.max) - self.lines = self.x.map(x => ((x, min), (x, max))) + let (x-min, x-max) = (ctx.x.min, ctx.x.max) + let (y-min, y-max) = (ctx.y.min, ctx.y.max) + self.lines = self.x.filter(x => x >= x-min and x <= x-max) + .map(x => ((x, y-min), (x, y-max))) return self } @@ -314,6 +319,7 @@ (( type: "vline", x: x.pos(), + x-domain: (calc.min(..x.pos()), calc.max(..x.pos())), axes: axes, style: style, plot-prepare: prepare, diff --git a/tests/plot/hvline/ref.png b/tests/plot/hvline/ref.png index 1ea634afe..2097ddda9 100644 Binary files a/tests/plot/hvline/ref.png and b/tests/plot/hvline/ref.png differ diff --git a/tests/plot/hvline/test.typ b/tests/plot/hvline/test.typ index 348d6d274..a94ff06ed 100644 --- a/tests/plot/hvline/test.typ +++ b/tests/plot/hvline/test.typ @@ -42,3 +42,18 @@ plot.add(((-2, -2), (2,2))) }) })) + +/* Clipped h/v lines */ +#box(stroke: 2pt + red, canvas({ + import draw: * + + plot.plot(size: (4, 4), + x-tick-step: none, + y-tick-step: none, + x-min: 0, x-max: 2, + y-min: 0, y-max: 2, + { + plot.add-vline(-.1, 1, 3) + plot.add-hline(-.1, 1, 3) + }) +}))