|
| 1 | +#import "/src/ticks.typ" |
| 2 | +#import "/src/plot/util.typ" |
1 | 3 |
|
2 | 4 | /// Transform linear axis value to linear space (low, high)
|
3 | 5 | #let _transform-lin(ax, value, low, high) = {
|
4 | 6 | let range = high - low
|
5 | 7 |
|
6 |
| - return (value - ax.low) * (range / (ax.high - ax.low)) |
| 8 | + return low + (value - ax.min) * (range / (ax.max - ax.min)) |
7 | 9 | }
|
8 | 10 |
|
9 | 11 | /// Transform log axis value to linear space (low, high)
|
|
14 | 16 | calc.log(calc.max(x, util.float-epsilon), base: ax.base)
|
15 | 17 | }
|
16 | 18 |
|
17 |
| - return (value - f(ax.low)) * (range / (f(ax.high) - f(ax.low))) |
| 19 | + return low + (f(value) - f(ax.min)) * (range / (f(ax.max) - f(ax.min))) |
18 | 20 | }
|
19 | 21 |
|
20 |
| -#let linear(low, high) = ( |
21 |
| - low: low, high: high, transform: _transform-lin, |
| 22 | +/// Linear Axis Constructor |
| 23 | +#let linear(name, min, max) = ( |
| 24 | + label: [#name], |
| 25 | + name: name, min: min, max: max, base: 10, transform: _transform-lin, |
| 26 | + auto-domain: (none, none), |
| 27 | + ticks: (step: auto, minor-step: none, format: auto, list: none), |
| 28 | + grid: none, |
| 29 | + compute-ticks: ticks.compute-ticks.with("lin"), |
22 | 30 | )
|
23 | 31 |
|
24 |
| -#let logarithmic(low, high, base) = ( |
25 |
| - low: low, high: high, base: base, transform: _transform-log, |
| 32 | +/// Log Axis Constructor |
| 33 | +#let logarithmic(name, min, max, base) = ( |
| 34 | + label: [#name], |
| 35 | + name: name, min: min, max: max, base: base, transform: _transform-log, |
| 36 | + auto-domain: (none, none), |
| 37 | + ticks: (step: auto, minor-step: none, format: auto, list: none), |
| 38 | + grid: none, |
| 39 | + compute-ticks: ticks.compute-ticks.with("log"), |
26 | 40 | )
|
27 | 41 |
|
| 42 | +// Prepare axis |
| 43 | +#let prepare(ptx, ax) = { |
| 44 | + if ax.min == none { ax.min = ax.auto-domain.at(0) } |
| 45 | + if ax.max == none { ax.max = ax.auto-domain.at(1) } |
| 46 | + if "compute-ticks" in ax { ax.computed-ticks = (ax.compute-ticks)(ax) } |
| 47 | + return ax |
| 48 | +} |
| 49 | + |
28 | 50 | /// Transform an axis value to a linear value between low and high
|
29 | 51 | /// - ax (axis): Axis
|
30 | 52 | /// - value (number): Value to transform from axis space to linear space
|
|
0 commit comments