Log inGet started
▣
module · drop-in viewer
asset⌬ modulemoduleprimary: init.luau·part ofmodule widget.module·originates fromworld 07158574-5…

_axes

Shared tick generation + axes + gridline drawing helpers for canvas-hosted charts. Used by `Z.plot` for axes/gridlines/ticks and by `Z.graph` for the optional axis labels + gridlines. Single source of truth for the nice-tick algorithm so both widgets render identical- looking tic…

byzero-proxy @ DESKTOP-DB3UJOJ·posted 2mo ago
What it does

_axes

Shared tick generation + axes + gridline drawing helpers for canvas-hosted charts. Used by Z.plot for axes/gridlines/ticks and by Z.graph for the optional axis labels + gridlines. Single source of truth for the nice-tick algorithm so both widgets render identical- looking tick scales. Underscore prefix marks it as a package-internal helper — not exported from zui.widget and not part of the Z.* surface.

Exports

  • M.computeTicks(minV: number, maxV: number, nTicks: number?, customFormat: TickFormatter?) -> TickResult — D3-style nice ticks. Snaps step to {1, 2, 5} × 10^n. nTicks default 5.
  • M.axisCommands(viewport: Viewport, bounds: Bounds, opts: AxesOpts?) -> { CanvasCommand } — axes + tick marks + tick labels.
  • M.gridCommands(viewport: Viewport, bounds: Bounds, opts: AxesOpts?) -> { CanvasCommand } — gridlines, one per major tick.

Types:

  • Viewport = { x: number, y: number, width: number, height: number } — canvas-local pixel rect.
  • Bounds = { xMin: number, xMax: number, yMin: number, yMax: number } — data-space range.
  • TickResult = { ticks: { number }, labels: { string } }
  • TickFormatter = (number) -> string — custom label formatter.
  • AxesOpts — visibility + styling (showXAxis, axisColor, labelSize, tickLength, xTickFormat, etc.).
  • CanvasCommand = { [string]: any } — opaque canvas-renderer command.

Usage

local Axes = require("@builtin::modules.zui.widget._axes")

local viewport = { x = 0,  y = 0,  width = 200, height = 120 }
local bounds   = { xMin = 0, xMax = 100, yMin = 0, yMax = 1 }

local axisCmds = Axes.axisCommands(viewport, bounds, {})
local gridCmds = Axes.gridCommands(viewport, bounds, { gridY = false })

local r = Axes.computeTicks(0, 100)      -- nice ticks: {0, 20, 40, ...}

-- Custom formatter:
Axes.axisCommands(viewport, bounds, {
    xTickFormat = function(v) return "$" .. v end,
})

Notes

  • Coordinate convention matches canvas: origin top-left, +y down. Y values from bounds are flipped at render time so yMax is drawn at the top of the viewport, matching plot conventions.
  • mergedOpts overlays caller opts on DEFAULTS and passes unknown keys through — additive opts (xTickFormat, yTickFormat, future ones) don't need bookkeeping in DEFAULTS.
  • computeTicks caps iteration at 64 ticks to avoid pathological loops on degenerate input.
  • Out-of-range ticks (after the data → pixel mapping) are filtered silently so neither labels nor lines bleed past the viewport.

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

conforms to

zero/source-extract/v2

ZuiAxes Module Shared tick generation + axes + gridline drawing helpers for canvas-hosted charts. Used by `Z.plot` for axes/gridlines/ticks and by `Z.graph` for the optional axis labels + gridlines. Single source of truth for the nice-tick algorithm so both widgets render identical- looking tick scales. Coordinate convention (matches canvas): origin top-left, +y down. Y values from `bounds` are flipped at render time so that yMax is drawn at the top of the viewport, matching plot conventions. Underscore prefix marks it as a package-internal helper. Consumers: local Axes = require("modules.deprecated.zui.widget._axes") local r = Axes.computeTicks(0, 100) -- nice ticks local cmds = Axes.axisCommands(rect, bounds, opts) -- axes + ticks local grid = Axes.gridCommands(rect, bounds, opts) -- gridlines

computeTicks(minV: number, maxV: number, nTicks: number?, customFormat: TickFormatter?) → TickResult

D3-style nice ticks: snaps the step to {1, 2, 5} × 10^n so the tick values are human-readable. Returns parallel arrays of numeric tick values and their formatted label strings. `nTicks` is a target count (default 5); the algorithm returns a count close to but not exactly `nTicks`. Label formatting uses an integer format when the step is >= 1 and a `%.Nf` format with appropriate digit count for fractional steps. Pass `customFormat` to override the default formatter (e.g. currency or time-series).

argtypedescription
minVnumberLower bound of the value range.
maxVnumberUpper bound of the value range.
nTicksnumber?Target tick count (default 5).
customFormatTickFormatter?Optional `function(v: number) -> string` label formatter.

examples

local r = Axes.computeTicks(0, 100)              -- → { ticks = {0, 20, ...}, labels = {"0", "20", ...} }
local r = Axes.computeTicks(0, 1, 5, function(v) return string.format("%.1f", v) end)

xToPixel(x: number, viewport: Viewport, bounds: Bounds) → number

Internal: data→viewport-local-pixel mapping for a single axis.

argtypedescription
xnumber
viewportViewport
boundsBounds

yToPixel(y: number, viewport: Viewport, bounds: Bounds) → number

argtypedescription
ynumber
viewportViewport
boundsBounds

mergedOpts(opts: AxesOpts?) → AxesOptsResolved

axisCommands Internal: overlay caller opts on DEFAULTS so unknown keys pass through (e.g. xTickFormat / yTickFormat).

argtypedescription
optsAxesOpts?

axisCommands(viewport: Viewport, bounds: Bounds, opts: AxesOpts?) →

Build canvas commands for X + Y axes — axis lines, tick marks, and tick labels. X axis at the bottom of `viewport`, Y axis at the left. Tick positions come from `computeTicks` and are clipped to the viewport's pixel bounds.

argtypedescription
viewportViewport`{ x, y, width, height }` in canvas-local pixels.
boundsBounds`{ xMin, xMax, yMin, yMax }` in data units.
optsAxesOpts?Visibility + styling (see `AxesOpts`).

examples

local cmds = Axes.axisCommands({x=0,y=0,width=200,height=120}, {xMin=0,xMax=100,yMin=0,yMax=1}, {})

gridCommands(viewport: Viewport, bounds: Bounds, opts: AxesOpts?) →

Build canvas line commands for vertical and horizontal gridlines — one per major tick. Visibility is per-axis via `opts.gridX` / `opts.gridY` (default both true). Gridlines are clipped to the viewport's pixel bounds.

argtypedescription
viewportViewport`{ x, y, width, height }` in canvas-local pixels.
boundsBounds`{ xMin, xMax, yMin, yMax }` in data units.
optsAxesOpts?Visibility + styling (see `AxesOpts`).

examples

local grid = Axes.gridCommands(viewport, bounds, { gridX = true, gridY = false })
⌬ Types
Viewport = { x: number, y: number, width: number, height: number }Bounds = { xMin: number, xMax: number, yMin: number, yMax: number }TickResult = { ticks: { number }, labels: { string } }TickFormatter = (number) -> stringCanvasCommand = { [string]: any }AxesOpts = {

Sub-parts

Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.

3items
·
other · born here
▤file
▲ 0↑ born
backing path · modules/deprecated/zui.module/widget.module/_axes.module

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported. This asset, its contents, and its direct deps are clean as of the latest commit.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.