Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/plot.typ
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,38 @@

// Adjust axis bounds for annotations
for a in annotations {
let sub-ctx = ctx

// Register a stub-resolver that just forwards coordinates
sub-ctx.resolve-coordinate.push((ctx, c) => {
if type(c) == dictionary and "plot" in c {
return c.plot
}
return c
})

let (x, y) = a.axes.map(name => axis-dict.at(name))
(x, y) = calc-annotation-domain(ctx, x, y, a)
(x, y) = calc-annotation-domain(sub-ctx, x, y, a)
axis-dict.at(a.axes.at(0)) = x
axis-dict.at(a.axes.at(1)) = y
}

// Set axis options
axis-dict = plot-util.setup-axes(ctx, axis-dict, options.named(), size)

// Register axis coordinate systems
let axis-coordinate-resolver(ctx, c) = {
if type(c) == dictionary and "plot" in c {
let pt = c.plot
let names = c.at("axes", default: ("x", "y"))
let (x, y) = names.map(name => axis-dict.at(name))

return axes.transform-vec(size, x, y, none, pt)
}
return c
}
draw.register-coordinate-resolver(axis-coordinate-resolver)

// Prepare styles
for i in range(data.len()) {
if "style" not in data.at(i) { continue }
Expand Down Expand Up @@ -369,8 +392,7 @@
let (x, y) = a.axes.map(name => axis-dict.at(name))
let plot-ctx = make-ctx(x, y, size)

data-viewport(a, x, y, size, {
draw.anchor("default", (0, 0))
draw.scope({
a.body
})
}
Expand Down Expand Up @@ -467,8 +489,7 @@
let (x, y) = a.axes.map(name => axis-dict.at(name))
let plot-ctx = make-ctx(x, y, size)

data-viewport(a, x, y, size, {
draw.anchor("default", (0, 0))
draw.scope({
a.body
})
}
Expand Down
8 changes: 4 additions & 4 deletions tests/axes/log-mode/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@
mark: "o"
)
plot.annotate({
rect((0, 1), (calc.pi, 10), fill: rgb(50,50,200,50))
content((2, 3), [Annotation])
rect((plot: (0, 1)), (plot: (calc.pi, 10)), fill: rgb(50,50,200,50), name: "r")
content("r.center", [Annotation])
})
plot.annotate({
rect((0, 1000), (calc.pi, 10000), fill: rgb(50,50,200,50))
content((2, 3000), [Annotation])
rect((plot: (0, 1000)), (plot: (calc.pi, 10000)), fill: rgb(50,50,200,50), name: "r")
content("r.center", [Annotation])
})
}
)
Expand Down
Loading