Skip to content

Commit

Permalink
scientific: Draw axis labels
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Dec 5, 2024
1 parent 5a3e705 commit 19def48
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/spine/scientific.typ
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,38 @@
}
})

// TODO: Draw labels
let label-config = (
("south", "north", 0deg),
("west", "south", 90deg),
("north", "south", 0deg),
("east", "north", 90deg),
)
for (i, (side, default-anchor, default-angle)) in label-config.enumerate() {
let (ax, dir, _, proj, style, mirror) = axes.at(i)
if ax.label != none and ax.label != [] {
let pos = proj((ax.max + ax.min) / 2)
let offset = vector.scale(dir, -style.label.offset)
let is-horizontal = calc.rem(i, 2) == 0
pos = if is-horizontal {
(pos, "|-", (rel: offset, to: "spine." + side))
} else {
(pos, "-|", (rel: offset, to: "spine." + side))
}

let angle = style.label.angle
if angle == auto {
angle = default-angle
}

let anchor = style.label.anchor
if anchor == auto {
anchor = default-anchor
}

draw.content(pos,
[#ax.label], anchor: anchor, angle: angle)
}
}
},
)
}
8 changes: 8 additions & 0 deletions src/style.typ
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
minor-stroke: black + .25pt,
),

label: (
angle: auto,
offset: .5em,
anchor: auto,
),

// Overrides
x: (
tick: (
Expand Down Expand Up @@ -136,6 +142,8 @@

style.tick.label.offset = resolve-number(style.tick.label.offset)

style.label.offset = resolve-number(style.label.offset)

return style
}

Expand Down

0 comments on commit 19def48

Please sign in to comment.