/** * Sparkline (mini chart) data model and utilities. * * Sparklines are cell-sized charts stored in the worksheet extLst under * `x14:sparklineGroups`. Each group contains: * - display options (type, line weight, markers, axis settings, colors) * - one or more sparklines, each pairing a data reference with an anchor cell. * * Reference: ECMA-376 §18.18.92 + Office Open XML extension `x14` namespace. */ /** * Top-level sparkline group — matches `x14:sparklineGroup`. */ export interface SparklineGroup { /** Chart type: line | column | stacked (win-loss) */ type?: SparklineType; /** Line weight in points (0.25 - 2.25) */ lineWeight?: number; /** Display empty cells as: gap, zero, or span */ displayEmptyCellsAs?: "gap" | "zero" | "span"; /** Whether to display markers */ markers?: boolean; /** High point marker */ high?: boolean; /** Low point marker */ low?: boolean; /** First point marker */ first?: boolean; /** Last point marker */ last?: boolean; /** Negative point marker */ negative?: boolean; /** Display X axis */ displayXAxis?: boolean; /** Display hidden cells data */ displayHidden?: boolean; /** Min axis type: individual, group, custom */ minAxisType?: SparklineAxisType; /** Max axis type */ maxAxisType?: SparklineAxisType; /** Manual min (when minAxisType === "custom") */ manualMin?: number; /** Manual max (when maxAxisType === "custom") */ manualMax?: number; /** Right-to-left */ rightToLeft?: boolean; /** Color series */ colorSeries?: SparklineColor; /** Color negative */ colorNegative?: SparklineColor; /** Color axis */ colorAxis?: SparklineColor; /** Color markers */ colorMarkers?: SparklineColor; /** Color first */ colorFirst?: SparklineColor; /** Color last */ colorLast?: SparklineColor; /** Color high */ colorHigh?: SparklineColor; /** Color low */ colorLow?: SparklineColor; /** Date axis source (reference range of dates) */ dateAxis?: string; /** Sparklines in this group */ sparklines: Sparkline[]; } export type SparklineType = "line" | "column" | "stacked"; export type SparklineAxisType = "individual" | "group" | "custom"; /** * A single sparkline within a group. */ export interface Sparkline { /** Data reference (e.g. "Sheet1!B2:G2") */ dataRef: string; /** Anchor cell reference (e.g. "H2") */ cellRef: string; } /** * Sparkline color — theme reference or sRGB. */ export interface SparklineColor { /** Theme index (0-11) */ theme?: number; /** sRGB hex */ rgb?: string; /** Tint (-1 to 1) */ tint?: number; /** Auto color */ auto?: boolean; } /** * High-level options for creating a sparkline group. */ export interface AddSparklineGroupOptions { /** Chart type */ type: SparklineType; /** List of sparklines (data + anchor) */ sparklines: Sparkline[]; /** Line weight in points */ lineWeight?: number; /** Show markers (line type) */ markers?: boolean; /** Show high point */ high?: boolean; /** Show low point */ low?: boolean; /** Show first point */ first?: boolean; /** Show last point */ last?: boolean; /** Show negative points */ negative?: boolean; /** Line color */ lineColor?: string; /** Negative bar color */ negativeColor?: string; /** * Colour for the reference line drawn when {@link displayXAxis} is * enabled. Maps to `` — the horizontal rule that * separates positive from negative values on a sparkline. */ axisColor?: string; /** * Colour applied to ordinary marker dots (those that are neither * first/last/high/low/negative). Maps to ``. */ markerColor?: string; /** High marker color */ highColor?: string; /** Low marker color */ lowColor?: string; /** First marker color */ firstColor?: string; /** Last marker color */ lastColor?: string; /** Min axis type */ minAxisType?: SparklineAxisType; /** Max axis type */ maxAxisType?: SparklineAxisType; /** Manual min */ manualMin?: number; /** Manual max */ manualMax?: number; /** Show X axis */ displayXAxis?: boolean; /** Right-to-left */ rightToLeft?: boolean; /** Display empty cells as */ displayEmptyCellsAs?: "gap" | "zero" | "span"; /** Date axis source */ dateAxis?: string; } /** * Build a SparklineGroup from simplified options. */ export declare function buildSparklineGroup(opts: AddSparklineGroupOptions): SparklineGroup; /** * Render all sparkline groups on a worksheet to an x14:sparklineGroups * XML fragment. Returns a string (empty if no groups). */ export declare function renderSparklineGroups(groups: SparklineGroup[]): string; /** * Parse an x14:sparklineGroups XML fragment into structured groups. * Best-effort regex-based parser — sufficient for round-trip via rebuild. */ export declare function parseSparklineGroups(xml: string): SparklineGroup[]; /** * Options for {@link renderSparklineSvg}. */ export interface SparklineRenderOptions { /** Output width in px (default 120). */ width?: number; /** Output height in px (default 30). */ height?: number; /** Background fill colour. When absent, the SVG has a transparent background. */ background?: string; /** Inner padding in px so markers don't clip against the SVG edges. */ padding?: number; } /** * Render a sparkline group to a single SVG string given explicit data * values for each sparkline in the group. This is a preview-grade * renderer suitable for PDF/PNG embedding — Excel ultimately renders * sparklines natively from the formula references. * * Why take `values: number[][]` rather than walk the workbook: the * caller already has a worksheet in scope when it wants a preview, * and decoupling the renderer from the worksheet keeps this module * free of upstream dependencies. When no per-sparkline data is * supplied the SVG is rendered empty (just the background) so the * function never throws. * * Respects the group's `type` (`line` / `column` / `stacked`), * `displayXAxis`, `minAxisType` / `maxAxisType` / `manualMin` / * `manualMax`, markers (`markers`, `first`, `last`, `high`, `low`, * `negative`), `rightToLeft`, and all structural colours * (`colorSeries`, `colorNegative`, `colorAxis`, `colorMarkers`, * `colorHigh`, `colorLow`, `colorFirst`, `colorLast`). * * The individual sparkline's `cellRef` is not consulted — the caller * controls layout at a higher level and this function returns a * standalone SVG per sparkline when passed a group with a single * member, or a grid-stacked SVG when given multiple members. */ export declare function renderSparklineSvg(group: SparklineGroup, values: number[][], options?: SparklineRenderOptions): string;