Skip to content

Commit

Permalink
Some ideas, some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Nov 24, 2024
1 parent 5c99ee6 commit 3e3af57
Show file tree
Hide file tree
Showing 14 changed files with 892 additions and 655 deletions.
30 changes: 0 additions & 30 deletions src/axes.typ
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
#import "/src/cetz.typ": util, draw, vector, matrix, styles, process, drawable, path-util, process
#import "/src/plot/formats.typ"

/// Default axis style
///
/// #show-parameter-block("tick-limit", "int", default: 100, [Upper major tick limit.])
/// #show-parameter-block("minor-tick-limit", "int", default: 1000, [Upper minor tick limit.])
/// #show-parameter-block("auto-tick-factors", "array", [List of tick factors used for automatic tick step determination.])
/// #show-parameter-block("auto-tick-count", "int", [Number of ticks to generate by default.])
/// #show-parameter-block("stroke", "stroke", [Axis stroke style.])
/// #show-parameter-block("label.offset", "number", [Distance to move axis labels away from the axis.])
/// #show-parameter-block("label.anchor", "anchor", [Anchor of the axis label to use for it's placement.])
/// #show-parameter-block("label.angle", "angle", [Angle of the axis label.])
/// #show-parameter-block("axis-layer", "float", [Layer to draw axes on (see @@on-layer() )])
/// #show-parameter-block("grid-layer", "float", [Layer to draw the grid on (see @@on-layer() )])
/// #show-parameter-block("background-layer", "float", [Layer to draw the background on (see @@on-layer() )])
/// #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.])
/// #show-parameter-block("overshoot", "number", [School-book style axes only: Extra length to add to the end (right, top) of axes.])
/// #show-parameter-block("tick.stroke", "stroke", [Major tick stroke style.])
/// #show-parameter-block("tick.minor-stroke", "stroke", [Minor tick stroke style.])
/// #show-parameter-block("tick.offset", ("number", "ratio"), [Major tick offset along the tick's direction, can be relative to the length.])
/// #show-parameter-block("tick.minor-offset", ("number", "ratio"), [Minor tick offset along the tick's direction, can be relative to the length.])
/// #show-parameter-block("tick.length", ("number"), [Major tick length.])
/// #show-parameter-block("tick.minor-length", ("number", "ratio"), [Minor tick length, can be relative to the major tick length.])
/// #show-parameter-block("tick.label.offset", ("number"), [Major tick label offset away from the tick.])
/// #show-parameter-block("tick.label.angle", ("angle"), [Major tick label angle.])
/// #show-parameter-block("tick.label.anchor", ("anchor"), [Anchor of major tick labels used for positioning.])
/// #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.])
/// #show-parameter-block("grid.stroke", "stroke", [Major grid line stroke style.])
/// #show-parameter-block("break-point.width", "number", [Axis break width along the axis.])
/// #show-parameter-block("break-point.length", "number", [Axis break length.])
/// #show-parameter-block("minor-grid.stroke", "stroke", [Minor grid line stroke style.])
/// #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$!])
#let default-style = (
tick-limit: 100,
minor-tick-limit: 1000,
Expand Down
34 changes: 28 additions & 6 deletions src/axis.typ
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#import "/src/ticks.typ"
#import "/src/plot/util.typ"

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

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

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

return (value - f(ax.low)) * (range / (f(ax.high) - f(ax.low)))
return low + (f(value) - f(ax.min)) * (range / (f(ax.max) - f(ax.min)))
}

#let linear(low, high) = (
low: low, high: high, transform: _transform-lin,
/// Linear Axis Constructor
#let linear(name, min, max) = (
label: [#name],
name: name, min: min, max: max, base: 10, transform: _transform-lin,
auto-domain: (none, none),
ticks: (step: auto, minor-step: none, format: auto, list: none),
grid: none,
compute-ticks: ticks.compute-ticks.with("lin"),
)

#let logarithmic(low, high, base) = (
low: low, high: high, base: base, transform: _transform-log,
/// Log Axis Constructor
#let logarithmic(name, min, max, base) = (
label: [#name],
name: name, min: min, max: max, base: base, transform: _transform-log,
auto-domain: (none, none),
ticks: (step: auto, minor-step: none, format: auto, list: none),
grid: none,
compute-ticks: ticks.compute-ticks.with("log"),
)

// Prepare axis
#let prepare(ptx, ax) = {
if ax.min == none { ax.min = ax.auto-domain.at(0) }
if ax.max == none { ax.max = ax.auto-domain.at(1) }
if "compute-ticks" in ax { ax.computed-ticks = (ax.compute-ticks)(ax) }
return ax
}

/// Transform an axis value to a linear value between low and high
/// - ax (axis): Axis
/// - value (number): Value to transform from axis space to linear space
Expand Down
1 change: 0 additions & 1 deletion src/lib.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#let version = version(0,1,0)

#import "/src/axes.typ"
#import "/src/plot.typ"
#import "/src/chart.typ"
Loading

0 comments on commit 3e3af57

Please sign in to comment.