LanternUI.Charts.Geometry (LanternUI v0.3.3)

Copy Markdown View Source

Pure geometry helpers for LanternUI charts: linear scaling, "nice" axis ticks, and SVG path building.

No rendering and no Phoenix here — numbers in, strings/lists out — so this module is easy to unit-test and reuse.

Summary

Functions

Closed area path: the line dropped to baseline_y and closed back to the start.

Build an SVG path d from pixel points [{x, y}].

"Nice" axis tick values covering [min, max] with roughly count ticks.

Round a coordinate to one decimal, as a number.

Map v from domain {d0, d1} onto range {r0, r1}.

Functions

area_path(pts, baseline, smooth?)

@spec area_path([{number(), number()}], number(), boolean()) :: String.t()

Closed area path: the line dropped to baseline_y and closed back to the start.

line_path(pts, arg2)

@spec line_path([{number(), number()}], boolean()) :: String.t()

Build an SVG path d from pixel points [{x, y}].

With smooth? true the path is Catmull-Rom smoothed (good for sparse series); false draws straight segments (better at high density).

nice_ticks(min, max, count \\ 5)

@spec nice_ticks(number(), number(), pos_integer()) :: [float()]

"Nice" axis tick values covering [min, max] with roughly count ticks.

Returns an ascending list of floats; the first and last entries define the padded ("nice") domain the caller should scale against.

round1(v)

@spec round1(number()) :: float()

Round a coordinate to one decimal, as a number.

scale(d0, d1, r0, r1, v)

@spec scale(number(), number(), number(), number(), number()) :: float()

Map v from domain {d0, d1} onto range {r0, r1}.

A degenerate domain (d0 == d1) maps to the range midpoint instead of dividing by zero.