app.scale
Scale bar calculation helpers for the phylogenetic tree viewer.
Contains pure functions for computing tick positions, formatting labels, and calculating human-friendly scale intervals. Used by viewer, tree, and metadata components.
calculate-scale-unit
(calculate-scale-unit max-x)Calculates a human-friendly tick interval for a scale bar.
Given a maximum value, returns a ‘nice’ unit size based on the order of magnitude. The algorithm picks the largest round number that produces a reasonable number of ticks: - ratio < 2 -> 10% of magnitude - ratio < 5 -> 50% of magnitude - otherwise -> full magnitude
For example, (calculate-scale-unit 0.37) returns 0.05.
format-label
(format-label origin max-depth tick)Formats a scale label with precision based on max-depth.
get-ticks
(get-ticks max-x unit)Generates a lazy sequence of tick positions from 0 to max-x in increments of unit. Used to render scale bar gridlines and labels.
Guards against non-positive unit to avoid a non-terminating sequence: - If max-x is <= 0, returns a single tick at 0. - If unit is <= 0 (and max-x is > 0), returns an empty sequence.
label-decimals
(label-decimals max-depth)Returns the number of decimals to show for scale labels.
label-value
(label-value origin max-depth tick)Returns the display value for a tick based on scale origin.
scale-ticks
(scale-ticks {:keys [max-depth x-scale min-label-px minor-count origin], :or {min-label-px 48, minor-count 4, origin :tips}})Computes major and minor ticks for scale bars.
Options: - :max-depth - maximum x-coordinate in the tree - :x-scale - horizontal scaling factor (pixels per branch-length unit) - :min-label-px - minimum pixel spacing between labeled ticks (default 48) - :minor-count - number of minor ticks between labeled ticks (default 4) - :origin - :tips or :root for tick placement
Returns {:major-ticks … :minor-ticks … :base-ticks … :unit n}.
tick-position
(tick-position origin max-depth label)Returns the x-position for a label tick based on scale origin.