Skip to content

Commit 3e3af57

Browse files
committed
Some ideas, some tests
1 parent 5c99ee6 commit 3e3af57

14 files changed

+892
-655
lines changed

src/axes.typ

-30
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,6 @@
11
#import "/src/cetz.typ": util, draw, vector, matrix, styles, process, drawable, path-util, process
22
#import "/src/plot/formats.typ"
33

4-
/// Default axis style
5-
///
6-
/// #show-parameter-block("tick-limit", "int", default: 100, [Upper major tick limit.])
7-
/// #show-parameter-block("minor-tick-limit", "int", default: 1000, [Upper minor tick limit.])
8-
/// #show-parameter-block("auto-tick-factors", "array", [List of tick factors used for automatic tick step determination.])
9-
/// #show-parameter-block("auto-tick-count", "int", [Number of ticks to generate by default.])
10-
/// #show-parameter-block("stroke", "stroke", [Axis stroke style.])
11-
/// #show-parameter-block("label.offset", "number", [Distance to move axis labels away from the axis.])
12-
/// #show-parameter-block("label.anchor", "anchor", [Anchor of the axis label to use for it's placement.])
13-
/// #show-parameter-block("label.angle", "angle", [Angle of the axis label.])
14-
/// #show-parameter-block("axis-layer", "float", [Layer to draw axes on (see @@on-layer() )])
15-
/// #show-parameter-block("grid-layer", "float", [Layer to draw the grid on (see @@on-layer() )])
16-
/// #show-parameter-block("background-layer", "float", [Layer to draw the background on (see @@on-layer() )])
17-
/// #show-parameter-block("padding", "number", [Extra distance between axes and plotting area. For schoolbook axes, this is the length of how much axes grow out of the plotting area.])
18-
/// #show-parameter-block("overshoot", "number", [School-book style axes only: Extra length to add to the end (right, top) of axes.])
19-
/// #show-parameter-block("tick.stroke", "stroke", [Major tick stroke style.])
20-
/// #show-parameter-block("tick.minor-stroke", "stroke", [Minor tick stroke style.])
21-
/// #show-parameter-block("tick.offset", ("number", "ratio"), [Major tick offset along the tick's direction, can be relative to the length.])
22-
/// #show-parameter-block("tick.minor-offset", ("number", "ratio"), [Minor tick offset along the tick's direction, can be relative to the length.])
23-
/// #show-parameter-block("tick.length", ("number"), [Major tick length.])
24-
/// #show-parameter-block("tick.minor-length", ("number", "ratio"), [Minor tick length, can be relative to the major tick length.])
25-
/// #show-parameter-block("tick.label.offset", ("number"), [Major tick label offset away from the tick.])
26-
/// #show-parameter-block("tick.label.angle", ("angle"), [Major tick label angle.])
27-
/// #show-parameter-block("tick.label.anchor", ("anchor"), [Anchor of major tick labels used for positioning.])
28-
/// #show-parameter-block("tick.label.show", ("auto", "bool"), default: auto, [Set visibility of tick labels. A value of `auto` shows tick labels for all but mirrored axes.])
29-
/// #show-parameter-block("grid.stroke", "stroke", [Major grid line stroke style.])
30-
/// #show-parameter-block("break-point.width", "number", [Axis break width along the axis.])
31-
/// #show-parameter-block("break-point.length", "number", [Axis break length.])
32-
/// #show-parameter-block("minor-grid.stroke", "stroke", [Minor grid line stroke style.])
33-
/// #show-parameter-block("shared-zero", ("bool", "content"), default: "$0$", [School-book style axes only: Content to display at the plots origin (0,0). If set to `false`, nothing is shown. Having this set, suppresses auto-generated ticks for $0$!])
344
#let default-style = (
355
tick-limit: 100,
366
minor-tick-limit: 1000,

src/axis.typ

+28-6
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

src/lib.typ

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#let version = version(0,1,0)
22

3-
#import "/src/axes.typ"
43
#import "/src/plot.typ"
54
#import "/src/chart.typ"

0 commit comments

Comments
 (0)