/** * Shared chrome for the two usage charts: the peak/average axis and the date * axis below the bars. Both charts draw 30 columns over the same window, so * they must not drift apart in scale, ticks, or labels. */ export interface UsageAxisTick { value: number; top: number; /** Stable identity for `data-*-gridline`, independent of which ticks render. */ gridline: 0 | 1 | 2; } /** Peak at the top, daily average as the reference line, zero as the baseline. */ export function usageAxisTicks(peak: number, average: number): UsageAxisTick[] { if (peak <= 0) return []; const meanTop = Math.min(100, (1 - average / peak) * 100); const ticks: UsageAxisTick[] = [{ value: peak, top: 0, gridline: 0 }]; // A mean hugging the peak would print two labels on top of each other. if (meanTop >= 12) ticks.push({ value: average, top: meanTop, gridline: 1 }); ticks.push({ value: 0, top: 100, gridline: 2 }); return ticks; } /** Horizontal center of the peak column, in percent of the plot width. */ export function usagePeakCenter(columns: number, peakIndex: number): number { return columns ? ((peakIndex + 0.5) / columns) * 100 : 0; } export function UsageAxis({ ticks, format, gridlineAttribute }: { ticks: UsageAxisTick[]; format: (value: number) => string; gridlineAttribute: "data-usage-gridline" | "data-model-usage-gridline"; }) { return (