Skip to content

Commit 73a5d2f

Browse files
committed
Some ideas, some tests
1 parent 5c99ee6 commit 73a5d2f

File tree

8 files changed

+855
-546
lines changed

8 files changed

+855
-546
lines changed

src/axis.typ

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
#import "/src/ticks.typ"
2+
#import "/src/plot/util.typ"
13

24
/// Transform linear axis value to linear space (low, high)
35
#let _transform-lin(ax, value, low, high) = {
46
let range = high - low
57

6-
return (value - ax.low) * (range / (ax.high - ax.low))
8+
return low + (value - ax.min) * (range / (ax.max - ax.min))
79
}
810

911
/// Transform log axis value to linear space (low, high)
@@ -14,17 +16,37 @@
1416
calc.log(calc.max(x, util.float-epsilon), base: ax.base)
1517
}
1618

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)))
1820
}
1921

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"),
2230
)
2331

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"),
2640
)
2741

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+
2850
/// Transform an axis value to a linear value between low and high
2951
/// - ax (axis): Axis
3052
/// - value (number): Value to transform from axis space to linear space

0 commit comments

Comments
 (0)