Skip to content

Commit 72de3f6

Browse files
committed
Remove axis unit
1 parent c3dd513 commit 72de3f6

9 files changed

Lines changed: 29 additions & 30 deletions

File tree

src/axes.typ

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
padding: 0,
8787
))
8888

89+
// Default Schoolbook Style
8990
#let default-style-schoolbook = util.merge-dictionary(default-style, (
9091
x: (stroke: auto, fill: none, mark: (start: none, end: "straight"),
9192
tick: (label: (anchor: "north"))),
@@ -223,14 +224,13 @@
223224
// - ticks (dictionary): Tick settings:
224225
// - step (number): Major tic step
225226
// - minor-step (number): Minor tic step
226-
// - unit (content): Tick label suffix
227227
// - decimals (int): Tick float decimal length
228228
// - label (content): Axis label
229229
// - mode (string): Axis scaling function. Takes `lin` or `log`
230230
// - base (number): Base for tick labels when logarithmically scaled.
231231
#let axis(min: -1, max: 1, label: none,
232232
ticks: (step: auto, minor-step: none,
233-
unit: none, decimals: 2, grid: false,
233+
decimals: 2, grid: false,
234234
format: "float"
235235
),
236236
mode: auto, base: auto) = (
@@ -260,9 +260,6 @@
260260
value = str(value)
261261
}
262262

263-
if tic-options.at("unit", default: none) != none {
264-
value += tic-options.unit
265-
}
266263
return value
267264
}
268265

src/chart/barchart.typ

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
/// width can be set to `auto`.
5555
/// - bar-style (style,function): Style or function (idx => style) to use for
5656
/// each bar, accepts a palette function.
57-
/// - x-unit (content,auto): Tick suffix added to each tick label
5857
/// - y-label (content,none): Y axis label
5958
/// - x-label (content,none): x axis label
6059
/// - labels (none,content): Legend labels per x value group
@@ -67,7 +66,7 @@
6766
size: (auto, 1),
6867
bar-style: palette.red,
6968
x-label: none,
70-
x-unit: auto,
69+
x-format: auto,
7170
y-label: none,
7271
labels: none,
7372
..plot-args
@@ -100,9 +99,9 @@
10099
(data.len() - i - 1, t.at(label-key))
101100
})
102101

103-
let x-unit = x-unit
104-
if x-unit == auto {
105-
x-unit = if mode == "stacked100" {[%]} else []
102+
let x-format = x-format
103+
if x-format == auto {
104+
x-format = if mode == "stacked100" {plot.formats.decimal.with(suffix: [%])} else {auto}
106105
}
107106

108107
data = data.enumerate().map(((i, d)) => {
@@ -119,6 +118,7 @@
119118
axis-style: "scientific-auto",
120119
x-label: x-label,
121120
x-grid: true,
121+
x-format: x-format,
122122
y-label: y-label,
123123
y-min: -y-inset,
124124
y-max: data.len() + y-inset - 1,

src/chart/columnchart.typ

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
/// width can be set to `auto`.
5555
/// - bar-style (style,function): Style or function (idx => style) to use for
5656
/// each bar, accepts a palette function.
57-
/// - y-unit (content,auto): Tick suffix added to each tick label
5857
/// - y-label (content,none): Y axis label
5958
/// - x-label (content,none): x axis label
6059
/// - labels (none,content): Legend labels per y value group
@@ -67,7 +66,7 @@
6766
size: (auto, 1),
6867
bar-style: palette.red,
6968
x-label: none,
70-
y-unit: auto,
69+
y-format: auto,
7170
y-label: none,
7271
labels: none,
7372
..plot-args
@@ -98,9 +97,9 @@
9897
(i, t.at(label-key))
9998
})
10099

101-
let y-unit = y-unit
102-
if y-unit == auto {
103-
y-unit = if mode == "stacked100" {[%]} else []
100+
let y-format = y-format
101+
if y-format == auto {
102+
y-format = if mode == "stacked100" {plot.formats.decimal.with(suffix: [%])} else {auto}
104103
}
105104

106105
data = data.enumerate().map(((i, d)) => {
@@ -117,6 +116,7 @@
117116
axis-style: "scientific-auto",
118117
y-grid: true,
119118
y-label: y-label,
119+
y-format: y-format,
120120
x-min: -x-inset,
121121
x-max: data.len() + x-inset - 1,
122122
x-tick-step: none,

src/plot.typ

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@
115115
/// Number of decimals digits to display for tick labels, if the format is set
116116
/// to `"float"`.
117117
/// ])
118-
/// #show-parameter-block("unit", ("none", "content"), default: "none", [
119-
/// Suffix to append to all tick labels.
120-
/// ])
121118
/// #show-parameter-block("mode", ("none", "string"), default: "none", [
122119
/// The scaling function of the axis. Takes `lin` (default) for linear scaling,
123120
/// and `log` for logarithmic scaling.])

src/plot/formats.typ

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,29 @@
8383
/// could be found, a real number with `digits` digits is used.
8484
/// - digits (int): Number of digits to use for rounding
8585
/// - eps (number): Epsilon used for comparison
86+
/// - prefix (content): Content to prefix
87+
/// - suffix (content): Content to append
8688
/// -> Content if a matching fraction could be found or none
87-
#let multiple-of(value, factor: calc.pi, symbol: $pi$, fraction: true, digits: 2, eps: 1e-6) = {
89+
#let multiple-of(value, factor: calc.pi, symbol: $pi$, fraction: true, digits: 2, eps: 1e-6, prefix: [], suffix: []) = {
8890
if _compare(value, 0, eps: eps) {
8991
return _block-eq($0$)
9092
}
9193

9294
let a = value / factor
9395
if _compare(a, 1, eps: eps) {
94-
return _block-eq(symbol)
96+
return _block-eq(prefix + symbol + suffix)
9597
} else if _compare(a, -1, eps: eps) {
96-
return _block-eq($-$ + symbol)
98+
return _block-eq(prefix + $-$ + symbol + suffix)
9799
}
98100

99101
if fraction != none {
100102
let frac = _find-fraction(a, denom: if fraction == true { auto } else { fraction })
101103
if frac != none {
102-
return _block-eq(frac + symbol)
104+
return _block-eq(prefix + frac + symbol + suffix)
103105
}
104106
}
105107

106-
return _block-eq($#calc.round(a, digits: digits)$ + symbol)
108+
return _block-eq(prefix + $#calc.round(a, digits: digits)$ + symbol + suffix)
107109
}
108110

109111
/// Scientific notation tick formatter
@@ -119,8 +121,10 @@
119121
///
120122
/// - value (number): Value to format
121123
/// - digits (int): Number of digits for rounding the factor
124+
/// - prefix (content): Content to prefix
125+
/// - suffix (content): Content to append
122126
/// -> Content
123-
#let sci(value, digits: 2) = {
127+
#let sci(value, digits: 2, prefix: [], suffix: []) = {
124128
let exponent = if value != 0 {
125129
calc.floor(calc.log(calc.abs(value), base: 10))
126130
} else {
@@ -136,10 +140,10 @@
136140

137141
value = calc.round(value, digits: digits)
138142
if exponent <= -1 or exponent >= 1 {
139-
return _block-eq($#value times 10^#exponent$)
143+
return _block-eq(prefix + $#value times 10^#exponent$ + suffix)
140144
}
141145

142-
return _block-eq($#value$)
146+
return _block-eq(prefix + $#value$ + suffix)
143147
}
144148

145149
/// Rounded decimal number formatter
@@ -155,7 +159,9 @@
155159
///
156160
/// - value (number): Value to format
157161
/// - digits (int): Number of digits to round to
162+
/// - prefix (content): Content to prefix
163+
/// - suffix (content): Content to append
158164
/// -> Content
159-
#let decimal(value, digits: 2) = {
160-
_block-eq($#calc.round(value, digits: digits)$)
165+
#let decimal(value, digits: 2, prefix: [], suffix: []) = {
166+
_block-eq(prefix + $#calc.round(value, digits: digits)$ + suffix)
161167
}

tests/axes/ref/1.png

-197 Bytes
Loading

tests/axes/test.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
draw-unset: false,
3737
top: none,
3838
bottom: axes.axis(min: -1, max: 1, ticks: (step: 1, minor-step: auto,
39-
grid: "both", unit: [ units])),
39+
grid: "both", format: plot.formats.decimal.with(prefix: $<-$, suffix: $->$))),
4040
left: axes.axis(min: -1, max: 1, ticks: (step: .5, minor-step: auto,
4141
grid: false)),
4242
right: axes.axis(min: -10, max: 10, ticks: (step: auto, minor-step: auto,

tests/chart/ref/1.png

7.93 KB
Loading

tests/plot/violin/test.typ

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
let default-colors = (palette.blue-colors.at(3), palette.pink-colors.at(3))
2323

2424
plot.plot(size: (9, 6),
25-
2625
y-label: [Age],
2726
y-min: -10, y-max: 20,
2827
y-tick-step: 10, y-minor-tick-step: 5,

0 commit comments

Comments
 (0)