path-rite

scaleBandMap

Map a categorical value through a band scale, returning position, bandwidth, and step information.

scaleBandMap(config: BandScaleConfig, value: string): BandMapResult

config — Band scale configuration object:

interface BandScaleConfig {
  domain: string[];        // Categorical values (e.g. ["A", "B", "C"])
  range: [number, number]; // Output range in pixels (e.g. [0, 300])
  paddingInner?: number;   // Padding between bands, 0.0-1.0 (default: 0.1)
  paddingOuter?: number;   // Padding before first / after last band, 0.0-1.0 (default: 0.05)
}

value — The categorical value to look up.

Returns — A BandMapResult object:

interface BandMapResult {
  start: number | null;    // Left edge of the band (null if value not in domain)
  center: number | null;   // Center of the band (null if value not in domain)
  bandwidth: number;       // Width of each band (excluding padding)
  step: number;            // Width of one step (band + inner padding)
}
// Position bars in a bar chart
const config = {
  domain: ["Jan", "Feb", "Mar", "Apr"],
  range: [0, 400],
  paddingInner: 0.2,
  paddingOuter: 0.1
};

const bar = pathRite.scaleBandMap(config, "Feb");
// bar.start  — x position for the bar's left edge
// bar.center — x position for a centered label
// bar.bandwidth — width to draw the bar
// bar.step   — distance between consecutive bar starts

// Unknown values return null positions
const missing = pathRite.scaleBandMap(config, "Dec");
// missing.start === null, missing.center === null