import { nothing, TemplateResult } from 'lit'; import { BahtElement } from '../base.js'; /** * Shared chart vocabulary for the baht-*-chart primitives: series colors, * value formatters, scales, the floating tooltip and the table twin every * chart ships behind "View as table". * * Series colors come from the `--baht-chart-1 … --baht-chart-10` tokens so a * consumer can retheme every chart from CSS; `color` on a chart overrides the * first (or only) series. */ export interface ChartGroup { label: string; count: number; } /** One plotted series: a name, one value per category, optional fixed color. */ export interface ChartSeries { name: string; values: number[]; color?: string; } /** A reference line (budget, target, daily average) drawn over the marks. */ export interface ChartMarker { /** Category the marker belongs to; omit for a chart-wide line. */ category?: string; value: number; label?: string; } /** One dated observation for ``. */ export interface ChartDatePoint { /** ISO `YYYY-MM-DD`. */ date: string; value: number; } /** How a raw number is rendered as text. `percent` takes a fraction (0.18 → 18%). */ export type ChartFormat = 'number' | 'currency' | 'percent' | 'compact'; /** CSS color for series `i` — `override` wins for the first series only. */ export declare function chartColor(i: number, override?: string): string; /** Sequential ramp step `i` (0-based, light → dark in light mode). */ export declare function chartSeqColor(i: number, steps?: number): string; /** * Render a number as display text. * * - `number` — grouped integer (`4,200`) * - `currency` — narrow symbol, no decimals; THB renders `฿4,200` * - `percent` — the value is a fraction (`0.185` → `18.5%`) * - `compact` — `12.9K`, `4.2M` */ export declare function formatValue(value: number, format?: ChartFormat, currency?: string): string; /** * Axis ticks rounded to clean numbers: `0 … max` in 1 / 2 / 2.5 / 5 × 10ⁿ steps, * always including 0 and a top step at or above `max` (marks-and-anatomy.md). */ export declare function niceTicks(max: number, count?: number): number[]; /** `v → px` over a linear domain. Degenerate domains map to the range start. */ export declare function linearScale(domain: readonly [number, number], range: readonly [number, number]): (value: number) => number; /** * Fold the tail of a group list into a single grey "Other" bucket — never cycle * or generate a ninth hue (anti-patterns.md). */ export declare function foldOther(groups: ChartGroup[], max: number, label?: string): ChartGroup[]; /** * The table twin every chart ships: the same numbers as real text, behind a * `
` so it never competes with the marks. Cells are bound as text, so * untrusted series/category names can never inject markup. */ export declare function renderTableTwin(caption: string, columns: string[], rows: (string | number)[][], summary?: string): TemplateResult; /** * Base for every chart element: the empty/loading contract, the value * formatter, the table twin toggle and one floating tooltip per chart. * * `loading` holds the previous render at reduced opacity instead of flashing a * skeleton (interaction.md): the data snapshot the chart draws is frozen while * the attribute is set, and picks up the new props when it clears. */ export declare abstract class BahtChartBase extends BahtElement { /** Shown instead of the marks when there is nothing to plot. */ emptyMessage: string; /** Hold the previous render at reduced opacity while new data loads. */ loading: boolean; /** Render the "View as table" twin under the chart. */ showTable: boolean; /** How values are rendered in labels, ticks, tooltips and the table twin. */ format: ChartFormat; /** ISO currency code for `format="currency"` (THB renders `฿`). */ currency: string; private tipEl?; private held; /** Value → display text using this chart's `format` / `currency`. */ protected fmt(value: number): string; /** * The snapshot to draw. While `loading` is set the previous one is returned, * so a refetch dims the chart instead of emptying it. */ protected hold(next: T): T; /** Root class list: `baht-chart` plus the loading modifier. */ protected rootClass(extra: string): string; /** The single floating tooltip node; rendered by the template, never appended. */ protected renderTooltip(): TemplateResult; /** * Show `text` near the pointer (or, on keyboard focus, near the mark). * Content is assigned with `textContent`: category and series names are * untrusted data (interaction.md). */ protected showTip(event: Event, text: string): void; /** Hide the tooltip (pointerleave / blur). */ protected hideTip(): void; /** The empty placeholder, or `nothing` when there is data. */ protected renderEmpty(): TemplateResult; /** Legend rows — only ever rendered for 2+ series (marks-and-anatomy.md). */ protected renderLegend(entries: { label: string; color: string; value?: string; share?: string; }[], kind?: 'rect' | 'line'): TemplateResult | typeof nothing; }