sparkline.ts

Pure geometry helpers behind Sparkline and ProjectActivityChart.

Computes polyline points, alpha-fade gradient stops, and the end-dot position for a series of values, so components stay thin and the math is testable and reusable outside Svelte.

view source

Declarations
#

5 declarations

sparkline_geometry
#

sparkline.ts view source

(values: number[], options: SparklineOptions): SparklineGeometry | null import {sparkline_geometry} from '@fuzdev/fuz_ui/sparkline.js';

Computes the rendering geometry for a sparkline of values.

Returns null when values has fewer than 2 points, which cannot form a line.

values

type number[]

options

returns

SparklineGeometry | null

SparklineGeometry
#

sparkline.ts view source

SparklineGeometry import type {SparklineGeometry} from '@fuzdev/fuz_ui/sparkline.js';

points

SVG polyline points string.

type string

stops

Alpha-fade gradient stops, thinned to runs' boundaries so long flat stretches (like all-zero history) cost a constant number of stops.

type SparklineStop[]

end_x

X coordinate of the final point.

type number

end_y

Y coordinate of the final point.

type number

end_alpha

Alpha of the final point.

type number

dot_radius

Radius for an end dot, equal to the stroke width.

type number

SparklineOptions
#

sparkline.ts view source

SparklineOptions import type {SparklineOptions} from '@fuzdev/fuz_ui/sparkline.js';

width

Width of the drawing area in px.

type number

height

Height of the drawing area in px.

type number

max?

The value rendered at full height and full alpha. Pass a shared max across sparklines for comparable scales. Defaults to the local max of the values.

type number

scale?

Vertical scale for the line's geometry. The alpha fade always tracks the linear ratio regardless of scale.

type SparklineScale

default 'linear'

stroke_width?

type number

default 2

alpha_floor?

Alpha at a value of 0, scaling linearly to 1 at the max.

type number

default 0.4

end_dot?

Reserve padding for an end dot of radius stroke_width at the final point.

type boolean

default false

SparklineScale
#

sparkline.ts view source

SparklineScale

type SparklineScale

import type {SparklineScale} from '@fuzdev/fuz_ui/sparkline.js';

Vertical scale for a sparkline's geometry. The nonlinear options compress the top of the range so small values stay legible under a large shared max — increasingly so from 'sqrt' to smaller power exponents (a number in (0, 1], where 1 is linear and 1 / 3 is cube root) to 'log'.

SparklineStop
#

sparkline.ts view source

SparklineStop import type {SparklineStop} from '@fuzdev/fuz_ui/sparkline.js';

A gradient stop for the per-point alpha fade.

offset

Gradient offset in [0, 1].

type number

opacity

Stop opacity in [alpha_floor, 1].

type number

Imported by
#