import * as React from "react"; /** * Category-axis sizing for the HORIZONTAL bar chart (gh#409 · 1). * * recharts reserves a fixed 60px for the category axis whatever the ticks say, so a Japanese * company name — 8–10 full-width glyphs, 100–125px — was painted OUTSIDE the chart box and the * SVG clip cut it from the START, removing exactly the identifying `株式会社` prefix. Latin text * degrades gracefully there; 全角 does not, and `docs/DESIGN-AUTHORITY.md` gives anything the user * READS to the Japanese standard. * * The mechanism: measure every tick in the real rendered typography, size the axis from the * WIDEST one, cap that at a token-owned fraction of the canvas so one long name can never eat * the bars, and truncate anything past the cap at its END — the start, which identifies the row, * always survives, and the full string stays reachable through the tick's `` and the * figure's screen-reader list. * * The two knobs are component tokens (`src/tokens/components/chart.css`). They are read back in * px from real CSS properties on the probe element, because a custom property's computed value * keeps whatever unit its author wrote. */ /** Axis knobs resolved from the probe's computed style. `gap` is px, `maxFraction` unitless. */ export type CategoryAxisKnobs = { /** Space between the tick text and the plot area. */ gap: number; /** Share of the canvas the category axis may take, 0..1. */ maxFraction: number; }; /** What the chart needs to draw the axis: its reserved width and the text of each tick. */ export type CategoryAxisMetrics = { /** `width` for recharts' `YAxis`, or `undefined` while nothing has been measured yet. */ width: number | undefined; /** Tick text to paint — the original label, or one truncated at its END. */ display: (label: string) => string; }; /** * Axis width from the measured tick widths: the widest tick, capped, plus the gap. * Pure — the browser measurement is injected, so the rule is testable without a layout engine. */ export declare function resolveCategoryAxisWidth(textWidths: readonly number[], available: number, { gap, maxFraction }: CategoryAxisKnobs): { width: number; textCap: number; }; /** * Cut `label` at its END until it fits `maxWidth`, appending an ellipsis. The first glyph is * always kept: a tick that reads `…` identifies nothing, and a tick cut from the front is the * bug this exists to fix. */ export declare function truncateToWidth(label: string, maxWidth: number, measure: (text: string) => number): string; /** * Measure the category ticks in the live document and keep the axis sized to them. * * Re-runs when the canvas resizes and once `document.fonts` settles, because a CJK web face * arriving after first paint changes every one of these widths. */ export declare function useCategoryAxisMetrics(canvasRef: React.RefObject<HTMLDivElement | null>, probeRef: React.RefObject<HTMLSpanElement | null>, labels: readonly string[], enabled: boolean): CategoryAxisMetrics;