scale
Mojo module 🡭
scale
LinearScale maps a continuous data domain onto a pixel range and picks “nice” tick positions within that domain for axis labeling. scale()/translate() compute the slope/intercept canvas.geometry.Transform2D’s affine map takes, so Plot builds a Transform2D from an x-scale and a y-scale (the y-scale’s range reversed, since pixel y increases downward).
ticks() implements Paul Heckbert’s “nice numbers for graph labels”
(Graphics Gems, 1990): round the
ideal step for a target tick count up to the nearest 1, 2, 5, or 10
times a power of ten, so labels read as 0.2/0.4/0.6 rather than
0.1934/0.3868/0.5802.
Structs
MinMax: A column’s minimum and maximum, the starting point for every domain this package computes:Plot._data_extentpads it for spatial axes;ColorScale/size encoding use it as-is, so a legend’s extremes are exactly the data’s.TickFormat: HowTheme.x_tick_format/y_tick_formatrender a tick label,Theme.show_data_labels’s value label, or a continuous legend’s endpoint labels – everywhereTicks.labels()/_format_tick()are the formatter. Same small-struct-with-comptime- constants-and-__eq__pattern asMark/OutputFormat, exceptFIXED()is a@staticmethodrather than a fixed comptime instance, since it carries a caller-chosen decimal count.Ticks:LinearScale.ticks()’s result: the tick positions plus how many decimal places they need for display, both from the same_nice_stepcomputation.LinearScale: A linear map from the domain endpoints to the range endpoints.range_min/range_maxare the pixel positionsdomain_min/domain_maxland on, not necessarily increasing: a y-axis scale passes range_min=plot_bottom_pixel and range_max=plot_top_pixel, and the map comes out with a negative slope.