Skip to content

Commit 15047ee

Browse files
authored
fix: labs(alt:) fills in plot alt text (#57)
2 parents 421abb4 + 3fc0929 commit 15047ee

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- feat: `labs()` fields default to `auto`; pass `none` to suppress an axis or legend title and reclaim the space it reserved. (#12)
1313
- feat: `element-blank()` on a text surface (axis, plot, or legend title) collapses the space the text would reserve. (#12)
1414
- feat: `width`/`height` accept `auto` to fill the available space of a bounded container. (#10)
15+
- fix: `labs(alt:)` fills in the figure's accessibility alt text when `plot(alt:)` is unset, instead of being stored and ignored. (#57)
1516
- fix: `geom-qq()`/`geom-qq-line()` honour the `distribution` argument (`uniform`/`exponential`) instead of always plotting against the normal reference. (#56)
1617
- fix: the `font` set on `element-text`/`element-typst`/`element-geom` is applied to every text surface and to the text-drawing geoms, inheriting the base `text` font when unset. (#54)
1718
- fix: a `stage`/`after-scale` channel now trains its scale on the marker's source column, so the closure receives the channel's scale-resolved value as documented. (#52)

src/plot.typ

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
#import "render.typ": render-plot
22
#import "data.typ": _normalise-data
33

4+
// Effective alt text: an explicit `plot(alt:)` wins; otherwise a `labs(alt:)`
5+
// fills in (its `auto` default and `none` both count as unset), so the labs
6+
// field reaches `get-alt-text` instead of being dropped.
7+
#let _resolve-alt(alt, labs) = {
8+
if alt != none { return alt }
9+
if labs != none {
10+
let labs-alt = labs.at("alt", default: auto)
11+
if labs-alt != auto and labs-alt != none { return labs-alt }
12+
}
13+
none
14+
}
15+
416
/// Compose a layered plot from data, aesthetics, and geom layers.
517
///
618
/// `plot` is the entry point of the grammar: it resolves the dataset, wires up
@@ -104,6 +116,7 @@
104116
strict: false,
105117
defer: false,
106118
) = {
119+
let alt = _resolve-alt(alt, labs)
107120
// Deferred plots skip the context block because `context` returns
108121
// content; compose() resolves the active theme from its own context
109122
// before handing the spec to the renderer.

tests/unit/test-labs-alt.typ

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// `_resolve-alt`: plot(alt:) wins, else labs(alt:) fills in.
2+
3+
#import "../../src/plot.typ": _resolve-alt
4+
#import "../../src/labs.typ": labs
5+
6+
// --- explicit plot alt wins over a labs alt -------------------------------
7+
8+
#assert.eq(_resolve-alt("explicit", labs(alt: "from labs")), "explicit")
9+
10+
// --- labs alt fills in when plot alt is unset -----------------------------
11+
12+
#assert.eq(_resolve-alt(none, labs(alt: "from labs")), "from labs")
13+
14+
// --- both unset resolves to none ------------------------------------------
15+
// labs(alt:) defaults to `auto`, which counts as unset.
16+
17+
#assert.eq(_resolve-alt(none, labs(title: "t")), none)
18+
#assert.eq(_resolve-alt(none, none), none)
19+
20+
Labs alt tests passed.

0 commit comments

Comments
 (0)