Skip to content

Commit

Permalink
plot: Fix hline/vline domain an clipping
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Oct 21, 2023
1 parent 6483736 commit cd897a5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/lib/plot/line.typ
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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,
Expand All @@ -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
}

Expand All @@ -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,
Expand Down
Binary file modified tests/plot/hvline/ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions tests/plot/hvline/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}))

0 comments on commit cd897a5

Please sign in to comment.