Functional Weave
Code in Rust

charts.axis@1.0.1

impl/python/band_axis.py

713 bytes · the Python implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

from typing import Sequence

from .charts_axis_axis_from_ticks import axis_from_ticks  ← axisFromTicks, another function of this group · built into the same file, even by a slim install
from .charts_axis_types import Axis, AxisOrient
from .charts_scale_band_scale import band_scale


def band_axis(
    domain: Sequence[str],
    range: Sequence[float],  # noqa: A002 - the manifest names it range
    padding_inner: float,
    padding_outer: float,
    orient: AxisOrient,
    position: float,
    tick_size: float,
) -> Axis:
    """A category axis: one tick at the centre of each band, labelled with the category."""
    positions = [band_scale(domain, range, v, padding_inner, padding_outer, 0.5).center for v in domain]
    return axis_from_ticks(positions, list(domain), range, orient, position, tick_size)