Skip to content

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_extent pads it for spatial axes; ColorScale/size encoding use it as-is, so a legend’s extremes are exactly the data’s.
  • TickFormat: How Theme.x_tick_format/y_tick_format render a tick label, Theme.show_data_labels’s value label, or a continuous legend’s endpoint labels – everywhere Ticks.labels()/ _format_tick() are the formatter. Same small-struct-with-comptime- constants-and-__eq__ pattern as Mark/OutputFormat, except FIXED() is a @staticmethod rather 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_step computation.
  • LinearScale: A linear map from the domain endpoints to the range endpoints. range_min/range_max are the pixel positions domain_min/ domain_max land 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.