@open-tomato/charts 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +283 -2
  2. package/dist/engine/BarChart/BarChart.d.ts +4 -0
  3. package/dist/engine/BarChart/BarChart.option.d.ts +4 -0
  4. package/dist/engine/BarChart/index.d.ts +2 -0
  5. package/dist/engine/BoxPlot/BoxPlot.d.ts +4 -0
  6. package/dist/engine/BoxPlot/BoxPlot.option.d.ts +4 -0
  7. package/dist/engine/BoxPlot/index.d.ts +2 -0
  8. package/dist/engine/Bullet/Bullet.d.ts +4 -0
  9. package/dist/engine/Bullet/Bullet.option.d.ts +4 -0
  10. package/dist/engine/Bullet/index.d.ts +2 -0
  11. package/dist/engine/Donut/Donut.d.ts +4 -0
  12. package/dist/engine/Donut/Donut.option.d.ts +4 -0
  13. package/dist/engine/Donut/index.d.ts +2 -0
  14. package/dist/engine/Gauge/Gauge.d.ts +4 -0
  15. package/dist/engine/Gauge/Gauge.option.d.ts +4 -0
  16. package/dist/engine/Gauge/index.d.ts +2 -0
  17. package/dist/engine/HeatmapGrid/HeatmapGrid.d.ts +4 -0
  18. package/dist/engine/HeatmapGrid/HeatmapGrid.option.d.ts +4 -0
  19. package/dist/engine/HeatmapGrid/index.d.ts +2 -0
  20. package/dist/engine/Histogram/Histogram.d.ts +4 -0
  21. package/dist/engine/Histogram/Histogram.option.d.ts +4 -0
  22. package/dist/engine/Histogram/index.d.ts +2 -0
  23. package/dist/engine/LineChart/LineChart.d.ts +19 -0
  24. package/dist/engine/LineChart/LineChart.option.d.ts +4 -0
  25. package/dist/engine/LineChart/index.d.ts +2 -0
  26. package/dist/engine/NetworkGraph/NetworkGraph.d.ts +4 -0
  27. package/dist/engine/NetworkGraph/NetworkGraph.option.d.ts +8 -0
  28. package/dist/engine/NetworkGraph/index.d.ts +2 -0
  29. package/dist/engine/Nightingale/Nightingale.d.ts +4 -0
  30. package/dist/engine/Nightingale/Nightingale.option.d.ts +4 -0
  31. package/dist/engine/Nightingale/index.d.ts +2 -0
  32. package/dist/engine/Radar/Radar.d.ts +4 -0
  33. package/dist/engine/Radar/Radar.option.d.ts +4 -0
  34. package/dist/engine/Radar/index.d.ts +2 -0
  35. package/dist/engine/Sankey/Sankey.d.ts +4 -0
  36. package/dist/engine/Sankey/Sankey.option.d.ts +6 -0
  37. package/dist/engine/Sankey/index.d.ts +2 -0
  38. package/dist/engine/ScatterChart/ScatterChart.d.ts +4 -0
  39. package/dist/engine/ScatterChart/ScatterChart.option.d.ts +6 -0
  40. package/dist/engine/ScatterChart/index.d.ts +2 -0
  41. package/dist/engine/Sunburst/Sunburst.d.ts +4 -0
  42. package/dist/engine/Sunburst/Sunburst.option.d.ts +19 -0
  43. package/dist/engine/Sunburst/index.d.ts +2 -0
  44. package/dist/engine/Treemap/Treemap.d.ts +4 -0
  45. package/dist/engine/Treemap/Treemap.option.d.ts +4 -0
  46. package/dist/engine/Treemap/index.d.ts +2 -0
  47. package/dist/engine/chrome.d.ts +90 -0
  48. package/dist/engine/core.d.ts +58 -0
  49. package/dist/engine/echartsEngine.d.ts +3 -0
  50. package/dist/engine/fixtures.d.ts +61 -0
  51. package/dist/engine/headless/headless.d.ts +86 -0
  52. package/dist/engine/headless/index.d.ts +10 -0
  53. package/dist/engine/headless/index.js +142 -0
  54. package/dist/engine/index.d.ts +1 -0
  55. package/dist/engine/shared.d.ts +59 -0
  56. package/dist/engine/shared.variants.d.ts +40 -0
  57. package/dist/index-4bxmxw89.js +1786 -0
  58. package/dist/index-85mb21rn.js +69 -0
  59. package/dist/index.d.ts +11 -0
  60. package/dist/index.js +618 -0
  61. package/dist/lib/cn.d.ts +7 -0
  62. package/dist/lib/index.d.ts +2 -0
  63. package/dist/seam/ChartEngineProvider.d.ts +12 -0
  64. package/dist/seam/FormatProvider.d.ts +25 -0
  65. package/dist/seam/format.d.ts +171 -0
  66. package/dist/seam/format.schema.d.ts +14 -0
  67. package/dist/seam/height.d.ts +15 -0
  68. package/dist/seam/index.d.ts +12 -0
  69. package/dist/seam/tones.d.ts +49 -0
  70. package/dist/seam/types.d.ts +322 -0
  71. package/dist/seam/useResolvedTokens.d.ts +7 -0
  72. package/dist/theme/index.d.ts +3 -0
  73. package/dist/theme/index.js +30 -0
  74. package/dist/theme/tokens.d.ts +40 -0
  75. package/package.json +82 -4
@@ -0,0 +1,90 @@
1
+ /**
2
+ * The chrome every primitive shares: the plot grid, the axes, the reference
3
+ * line and the hover readout. Each is a pure function of the resolved tokens.
4
+ */
5
+ import type { TooltipComponentFormatterCallbackParams, XAXisComponentOption, YAXisComponentOption } from 'echarts';
6
+ import type { GridComponentOption, MarkLineComponentOption, TooltipComponentOption } from 'echarts/components';
7
+ import { type ResolvedTokens } from './core.js';
8
+ import { type TooltipKeyShape } from './shared.variants.js';
9
+ /** The params an ECharts tooltip formatter receives. */
10
+ export type TooltipParams = TooltipComponentFormatterCallbackParams;
11
+ /** An axis that fits either side of the plot. */
12
+ export type PlotAxis = XAXisComponentOption & YAXisComponentOption;
13
+ /** Room around the plot rect, in px; each side defaults to a small gutter. */
14
+ export interface PlotRoom {
15
+ readonly top?: number;
16
+ readonly right?: number;
17
+ readonly bottom?: number;
18
+ readonly left?: number;
19
+ }
20
+ /** The plot rect, shrunk so axis labels stay inside the canvas. */
21
+ export declare function plotGrid(room?: PlotRoom): GridComponentOption;
22
+ /** Bounds of a value axis; `max` may be a function of the data extent. */
23
+ export interface ValueBounds {
24
+ readonly min?: number;
25
+ readonly max?: number | ((extent: {
26
+ max: number;
27
+ }) => number);
28
+ }
29
+ /** The value axis: hairline solid grid in `grid`, no axis line, compact ticks in `muted`. */
30
+ export declare function valueAxis(tokens: ResolvedTokens, format: (value: number) => string, bounds?: ValueBounds): PlotAxis;
31
+ /** Options of a category axis. */
32
+ export interface CategoryExtra {
33
+ readonly interval?: number;
34
+ readonly inverse?: boolean;
35
+ readonly showLine?: boolean;
36
+ /** false hides the tick labels (a band axis whose edges a second axis labels). */
37
+ readonly showLabels?: boolean;
38
+ /** false puts the ticks on the band edges instead of between them. */
39
+ readonly boundaryGap?: boolean;
40
+ readonly position?: 'top' | 'bottom';
41
+ }
42
+ export declare function categoryAxis(tokens: ResolvedTokens, data: readonly string[], extra?: CategoryExtra): PlotAxis;
43
+ /** The tick step a time axis may be pinned to; the axis picks its own otherwise. */
44
+ export type TimeStep = 'week';
45
+ /** How a time axis's ticks are pinned: the step and the span of the data, in epoch ms. */
46
+ export interface TimeTicks {
47
+ readonly step: TimeStep;
48
+ readonly from: number;
49
+ readonly to: number;
50
+ }
51
+ /** The Monday 00:00 UTC on or before the epoch `ms`. */
52
+ export declare function startOfWeekUtc(ms: number): number;
53
+ /** Every Monday 00:00 UTC from the week of `from` to `to`, inclusive. */
54
+ export declare function weekStartsUtc(from: number, to: number): number[];
55
+ /**
56
+ * A time axis: the axis line in `baseline`, labels through `xFormat`,
57
+ * spread so they never overlap. With `ticks` of step `week` the axis
58
+ * starts on the Monday of its first point and its labels sit on the
59
+ * Mondays of the span (ECharts' `customValues`), so a weekly label
60
+ * ("w/c 3 Nov") lands on a week's first day rather than wherever the
61
+ * time scale's own interval falls.
62
+ */
63
+ export declare function timeAxis(tokens: ResolvedTokens, xFormat: (date: Date) => string, ticks?: TimeTicks): PlotAxis;
64
+ /** A reference line (baseline, limit, target): 1px `ink-2`, its label in `ink-2` at the end. */
65
+ export declare function referenceLine(tokens: ResolvedTokens, axis: 'xAxis' | 'yAxis', value: number, label: string, labelAt?: 'start' | 'end'): MarkLineComponentOption;
66
+ /** Room on the right of the plot for a horizontal reference line's end label. */
67
+ export declare function referenceLabelRoom(label: string): number;
68
+ /**
69
+ * The ECharts tooltip container made invisible: the readout itself is the
70
+ * element the formatter returns, built from text nodes.
71
+ */
72
+ export declare function tooltipChrome(trigger: 'item' | 'axis'): TooltipComponentOption;
73
+ /** The axis tooltip's crosshair: a vertical hairline in `grid`. */
74
+ export declare function crosshair(tokens: ResolvedTokens): TooltipComponentOption['axisPointer'];
75
+ /** One row of the hover readout. */
76
+ export interface TooltipRow {
77
+ readonly value: string;
78
+ readonly label: string;
79
+ /** The key's colour; omitted for a plain row. */
80
+ readonly colour?: string;
81
+ readonly key?: TooltipKeyShape;
82
+ }
83
+ /** The hover readout: an optional heading in `ink-2`, then rows of value (strong, `ink`) and label (`ink-2`). */
84
+ export declare function tooltipNode(heading: string | undefined, rows: readonly TooltipRow[]): HTMLElement;
85
+ /** The first hovered item, whether ECharts passed one or a list. */
86
+ export declare function firstParam(params: TooltipParams): ReturnType<typeof paramList>[number] | undefined;
87
+ /** Every hovered item as a list. */
88
+ export declare function paramList(params: TooltipParams): Exclude<TooltipParams, unknown[]>[];
89
+ /** The numeric value of a `[x, y]` or plain data value. */
90
+ export declare function numericAt(value: unknown, index: number): number;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The engine's core, with no React and no DOM: the tree-shaken registration
3
+ * of the series and components every primitive uses, the option type, and
4
+ * the colour bridge (tokens resolved to colour strings). The React adapter
5
+ * (`shared.tsx`) adds the canvas renderer and the chart root; the headless
6
+ * engine (`headless/`) adds the SVG renderer.
7
+ *
8
+ * ECharts cannot read CSS variables, so every option is a pure function
9
+ * `(props, tokens) => option` over concrete colour strings.
10
+ */
11
+ import type { ResolvedTokens } from '../seam/tones.js';
12
+ import type { ChartTone } from '../seam/types.js';
13
+ import { type BarSeriesOption, type BoxplotSeriesOption, type CustomSeriesOption, type GaugeSeriesOption, type GraphSeriesOption, type HeatmapSeriesOption, type LineSeriesOption, type PieSeriesOption, type RadarSeriesOption, type SankeySeriesOption, type ScatterSeriesOption, type SunburstSeriesOption, type TreemapSeriesOption } from 'echarts/charts';
14
+ import { type DataZoomComponentOption, type GraphicComponentOption, type GridComponentOption, type MarkLineComponentOption, type RadarComponentOption, type TooltipComponentOption, type VisualMapComponentOption } from 'echarts/components';
15
+ import { type ComposeOption } from 'echarts/core';
16
+ /** The option shape of exactly the modules registered above. */
17
+ export type ChartOption = ComposeOption<BarSeriesOption | BoxplotSeriesOption | CustomSeriesOption | GaugeSeriesOption | GraphSeriesOption | HeatmapSeriesOption | LineSeriesOption | PieSeriesOption | RadarSeriesOption | SankeySeriesOption | ScatterSeriesOption | SunburstSeriesOption | TreemapSeriesOption | DataZoomComponentOption | GraphicComponentOption | GridComponentOption | MarkLineComponentOption | RadarComponentOption | TooltipComponentOption | VisualMapComponentOption>;
18
+ export type { ResolvedTokens };
19
+ /** Plot height in px when a chart is given none (the seam's `DEFAULT_CHART_HEIGHT`). */
20
+ export declare const DEFAULT_HEIGHT: number;
21
+ /** Bars and columns never grow thicker than this. */
22
+ export declare const BAR_MAX_WIDTH = 24;
23
+ /** Data-end corner radius of bars and columns. */
24
+ export declare const BAR_RADIUS = 4;
25
+ /** What the other marks fade to while one is hovered. */
26
+ export declare const BLUR_OPACITY = 0.85;
27
+ export declare const TICK_FONT_SIZE = 11;
28
+ /** Hover lift for marks: the hovered one stays, the others fade slightly. */
29
+ export interface MarkHover {
30
+ readonly emphasis: {
31
+ readonly focus: 'self';
32
+ };
33
+ readonly blur: {
34
+ readonly itemStyle: {
35
+ readonly opacity: number;
36
+ };
37
+ };
38
+ }
39
+ export declare const markHover: MarkHover;
40
+ /** A tone's colour, or a chrome token's, as a concrete string. */
41
+ export declare function paint(tokens: ResolvedTokens, toneOrToken: ChartTone | string): string;
42
+ /** The same colour at an alpha, for fills the canvas cannot wash with `opacity`. */
43
+ export declare function withAlpha(colour: string, alpha: number): string;
44
+ /** The colour `share` of the way from `from` to `to` (0 is `from`, 1 is `to`). */
45
+ export declare function mix(from: string, to: string, share: number): string;
46
+ /** Whichever of `ink` and `surface` reads better on `background`, by luminance. */
47
+ export declare function readableOn(tokens: ResolvedTokens, background: string): string;
48
+ /** The font stack when the page names none, or there is no page (the headless engine). */
49
+ export declare const FALLBACK_FONT_FAMILY = "sans-serif";
50
+ /** The page font stack from `--font-sans`, for canvas text and text measuring; the fallback with no DOM. */
51
+ export declare function readFontFamily(): string;
52
+ /**
53
+ * Lays the options every chart shares under a primitive's own: UTC time
54
+ * axes, so ECharts places a tick at midnight UTC where `formatDay` labels
55
+ * it; the mount animation (on unless `animate` is false); and the page
56
+ * font on canvas text.
57
+ */
58
+ export declare function finishOption(option: ChartOption, animate: boolean | undefined): ChartOption;
@@ -0,0 +1,3 @@
1
+ import type { ChartPrimitives } from '../seam/types.js';
2
+ /** Apache ECharts 6, tree-shaken, painted on canvas from the resolved tokens. */
3
+ export declare const echartsEngine: ChartPrimitives;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Fixed data for the engine's stories and tests: small, seeded, no clock.
3
+ * Every date derives from {@link LAST_DAY}, so a story draws the same picture
4
+ * on every run.
5
+ */
6
+ import type { ChartOption } from './core.js';
7
+ import type { BarSeries, BoxGroup, DonutSlice, GraphLink, GraphNode, HistogramBin, LineSeries, RadarAxis, RadarPole, RadarSeries, RoseSlice, ScatterPoint, SunburstNode, TimePoint, TreemapNode, ChartTone } from '../seam/types.js';
8
+ import { type ResolvedTokens } from '../seam/tones.js';
9
+ /** A seeded stream of numbers in [0, 1): the same seed gives the same stream. */
10
+ export declare function seeded(seed: number): () => number;
11
+ /** A value between `min` and `max` from a seeded stream. */
12
+ export declare function between(random: () => number, min: number, max: number): number;
13
+ /** The last day of every time series. */
14
+ export declare const LAST_DAY: Date;
15
+ /** Twenty-eight days ending on {@link LAST_DAY}. */
16
+ export declare const DAY_DATES: readonly Date[];
17
+ /** One fixed, distinct colour per token name, so a test can tell which token a mark was painted with. */
18
+ export declare const FIXED_TOKENS: ResolvedTokens;
19
+ /** A series as a test reads it: the fields are checked one by one, so they stay loose. */
20
+ export interface SeriesReading {
21
+ readonly id?: string;
22
+ readonly type?: string;
23
+ readonly name?: string;
24
+ readonly data?: readonly unknown[];
25
+ readonly [field: string]: unknown;
26
+ }
27
+ /** The option's series as a list, whether it holds one or many. */
28
+ export declare function seriesOf(option: ChartOption): readonly SeriesReading[];
29
+ export declare const BAR_CATEGORIES: readonly string[];
30
+ export declare const BAR_SERIES: readonly BarSeries[];
31
+ export declare const LINE_SERIES: readonly LineSeries[];
32
+ /** One series, for the area variant. */
33
+ export declare const AREA_SERIES: readonly LineSeries[];
34
+ export declare const SCATTER_POINTS: readonly ScatterPoint[];
35
+ /** A three-point moving average of the scatter points. */
36
+ export declare const SCATTER_TREND: readonly TimePoint[];
37
+ export declare const HISTOGRAM_BINS: readonly HistogramBin[];
38
+ export declare const BOX_GROUPS: readonly BoxGroup[];
39
+ export declare const DONUT_SLICES: readonly DonutSlice[];
40
+ /** The previous period, same ids and tones. */
41
+ export declare const DONUT_PREVIOUS: readonly DonutSlice[];
42
+ export declare const TREEMAP_NODES: readonly TreemapNode[];
43
+ export declare const TREEMAP_TONES: Readonly<Record<string, ChartTone>>;
44
+ export declare const HEAT_ROWS: readonly string[];
45
+ export declare const HEAT_COLS: readonly string[];
46
+ /** Halts per weekday and week: busy weekdays, quiet weekends. */
47
+ export declare const HEAT_CELLS: readonly (readonly number[])[];
48
+ /** The layers of a small workspace, left to right. */
49
+ export declare const LAYER_ORDER: readonly string[];
50
+ export declare const LAYER_TONES: Readonly<Record<string, ChartTone>>;
51
+ export declare const GRAPH_NODES: readonly GraphNode[];
52
+ /** Dependency to dependent: the direction code flows. */
53
+ export declare const GRAPH_LINKS: readonly GraphLink[];
54
+ export declare const ROSE_SLICES: readonly RoseSlice[];
55
+ /** Inner ring: the packages; outer ring: what each one is made of. */
56
+ export declare const SUNBURST_NODES: readonly SunburstNode[];
57
+ export declare const SUNBURST_TONES: Readonly<Record<string, ChartTone>>;
58
+ export declare const RADAR_POLES: readonly RadarPole[];
59
+ export declare const RADAR_AXES: readonly RadarAxis[];
60
+ /** This week over its twelve-week median on each axis. */
61
+ export declare const RADAR_SERIES: readonly RadarSeries[];
@@ -0,0 +1,86 @@
1
+ /**
2
+ * The headless engine: every primitive's pure option builder, and
3
+ * `renderToSvg`, which draws one primitive to an SVG string with ECharts'
4
+ * server-side mode. No React and no DOM, so a CLI, a server or a test can
5
+ * draw a chart: it registers the SVG renderer over the same `echarts/core`
6
+ * registration the React adapter uses (`../core.ts`).
7
+ *
8
+ * A headless caller has no CSS variables to read, so it passes a full
9
+ * `ResolvedTokens` map, which `tokensFrom` builds from the token values.
10
+ */
11
+ import type { BarChartProps, BoxPlotProps, BulletProps, DonutProps, GaugeProps, HeatmapGridProps, HistogramProps, LineChartProps, NightingaleProps, RadarProps, ScatterChartProps, SunburstProps, TreemapProps } from '../../seam/types.js';
12
+ import type { NetworkOptionProps } from '../NetworkGraph/NetworkGraph.option.js';
13
+ import type { SankeyOptionProps } from '../Sankey/Sankey.option.js';
14
+ import { type ChartOption, type ResolvedTokens } from '../core.js';
15
+ export { finishOption } from '../core.js';
16
+ export type { ChartOption, ResolvedTokens } from '../core.js';
17
+ export { tokensFrom } from '../../seam/tones.js';
18
+ export { buildOption as buildBarChartOption } from '../BarChart/BarChart.option.js';
19
+ export { buildOption as buildBoxPlotOption } from '../BoxPlot/BoxPlot.option.js';
20
+ export { buildOption as buildBulletOption } from '../Bullet/Bullet.option.js';
21
+ export { buildOption as buildDonutOption } from '../Donut/Donut.option.js';
22
+ export { buildOption as buildGaugeOption } from '../Gauge/Gauge.option.js';
23
+ export { buildOption as buildHeatmapGridOption } from '../HeatmapGrid/HeatmapGrid.option.js';
24
+ export { buildOption as buildHistogramOption } from '../Histogram/Histogram.option.js';
25
+ export { buildOption as buildLineChartOption } from '../LineChart/LineChart.option.js';
26
+ export { buildOption as buildNetworkGraphOption } from '../NetworkGraph/NetworkGraph.option.js';
27
+ export type { NetworkOptionProps } from '../NetworkGraph/NetworkGraph.option.js';
28
+ export { buildOption as buildNightingaleOption } from '../Nightingale/Nightingale.option.js';
29
+ export { buildOption as buildRadarOption } from '../Radar/Radar.option.js';
30
+ export { buildOption as buildSankeyOption } from '../Sankey/Sankey.option.js';
31
+ export type { SankeyOptionProps } from '../Sankey/Sankey.option.js';
32
+ export { buildOption as buildScatterChartOption } from '../ScatterChart/ScatterChart.option.js';
33
+ export { buildOption as buildSunburstOption } from '../Sunburst/Sunburst.option.js';
34
+ export { buildOption as buildTreemapOption } from '../Treemap/Treemap.option.js';
35
+ export type { TokenName } from '../../theme/index.js';
36
+ export * from '../../seam/format.js';
37
+ export * from '../../seam/format.schema.js';
38
+ /** One builder per primitive: props and tokens in, the ECharts option out. */
39
+ export interface OptionBuilders {
40
+ readonly BarChart: (props: BarChartProps, tokens: ResolvedTokens) => ChartOption;
41
+ readonly BoxPlot: (props: BoxPlotProps, tokens: ResolvedTokens) => ChartOption;
42
+ readonly Bullet: (props: BulletProps, tokens: ResolvedTokens) => ChartOption;
43
+ readonly Donut: (props: DonutProps, tokens: ResolvedTokens) => ChartOption;
44
+ readonly Gauge: (props: GaugeProps, tokens: ResolvedTokens) => ChartOption;
45
+ readonly HeatmapGrid: (props: HeatmapGridProps, tokens: ResolvedTokens) => ChartOption;
46
+ readonly Histogram: (props: HistogramProps, tokens: ResolvedTokens) => ChartOption;
47
+ readonly LineChart: (props: LineChartProps, tokens: ResolvedTokens) => ChartOption;
48
+ readonly NetworkGraph: (props: NetworkOptionProps, tokens: ResolvedTokens) => ChartOption;
49
+ readonly Nightingale: (props: NightingaleProps, tokens: ResolvedTokens) => ChartOption;
50
+ readonly Radar: (props: RadarProps, tokens: ResolvedTokens) => ChartOption;
51
+ readonly Sankey: (props: SankeyOptionProps, tokens: ResolvedTokens) => ChartOption;
52
+ readonly ScatterChart: (props: ScatterChartProps, tokens: ResolvedTokens) => ChartOption;
53
+ /** `width` sizes the radial labels; `renderToSvg` passes the drawing's width. */
54
+ readonly Sunburst: (props: SunburstProps, tokens: ResolvedTokens, width?: number, measuredHeight?: number) => ChartOption;
55
+ readonly Treemap: (props: TreemapProps, tokens: ResolvedTokens) => ChartOption;
56
+ }
57
+ /** The fifteen builders, by primitive name. */
58
+ export declare const OPTION_BUILDERS: OptionBuilders;
59
+ /** A primitive's name, as `ChartPrimitives` and the React engine spell it. */
60
+ export type PrimitiveName = keyof OptionBuilders;
61
+ /** The props a primitive's builder reads. */
62
+ export type PrimitiveOptionProps<K extends PrimitiveName> = Parameters<OptionBuilders[K]>[0];
63
+ /** The size of the drawing, and what it may override. */
64
+ export interface SvgRenderOptions {
65
+ /** The drawing's width in px. */
66
+ readonly width: number;
67
+ /** The drawing's height in px. */
68
+ readonly height: number;
69
+ /** The font stack for every text; `sans-serif` when absent, as there is no page to read it from. */
70
+ readonly fontFamily?: string;
71
+ /**
72
+ * The prefix of the ids and classes inside the SVG. Two SVGs inlined in one
73
+ * page need different prefixes; absent, it is a hash of the drawing, so the
74
+ * same input gives the same string and two different drawings do not clash.
75
+ */
76
+ readonly idPrefix?: string;
77
+ }
78
+ /**
79
+ * Draws one primitive to an SVG string with ECharts' server-side renderer:
80
+ * the builder's option over `tokens`, finished as the React adapter
81
+ * finishes it but with animation off, set on an instance with no DOM, then
82
+ * disposed. The same input gives the same string. A chart whose `height`
83
+ * is `'fill'` fills the drawing: the builders that size a layout from the
84
+ * height (Sunburst) read the drawing's height as the measured one.
85
+ */
86
+ export declare function renderToSvg<K extends PrimitiveName>(primitive: K, props: PrimitiveOptionProps<K>, tokens: ResolvedTokens, options: SvgRenderOptions): string;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * `@open-tomato/charts/engine`: the headless engine. Every primitive's pure
3
+ * option builder, `renderToSvg` over ECharts' server-side SVG renderer, the
4
+ * token map they read, and the value format spec with its zod schemas. No
5
+ * React and no DOM.
6
+ *
7
+ * Only `export *` here: bun drops an entry's named re-exports when the
8
+ * package is `sideEffects: false`, so `headless.ts` holds the list.
9
+ */
10
+ export * from './headless.js';
@@ -0,0 +1,142 @@
1
+ import {
2
+ DATE_PATTERNS,
3
+ DEFAULT_FORMAT_CONTEXT,
4
+ DURATION_UNITS,
5
+ PERCENT_BASES,
6
+ UNIT_POSITIONS,
7
+ VALUE_FORMAT_KINDS,
8
+ buildOption,
9
+ buildOption1 as buildOption2,
10
+ buildOption10 as buildOption11,
11
+ buildOption11 as buildOption12,
12
+ buildOption12 as buildOption13,
13
+ buildOption13 as buildOption14,
14
+ buildOption14 as buildOption15,
15
+ buildOption2 as buildOption3,
16
+ buildOption3 as buildOption4,
17
+ buildOption4 as buildOption5,
18
+ buildOption5 as buildOption6,
19
+ buildOption6 as buildOption7,
20
+ buildOption7 as buildOption8,
21
+ buildOption8 as buildOption9,
22
+ buildOption9 as buildOption10,
23
+ finishOption,
24
+ formatCompact,
25
+ formatContextSchema,
26
+ formatDate,
27
+ formatDay,
28
+ formatElapsed,
29
+ formatMeasured,
30
+ formatMinutes,
31
+ formatPercent,
32
+ formatRelative,
33
+ formatWeek,
34
+ formatterFor,
35
+ resolveFormatContext,
36
+ tokensFrom,
37
+ valueFormatSchema
38
+ } from "../../index-4bxmxw89.js";
39
+ import"../../index-85mb21rn.js";
40
+
41
+ // src/engine/headless/headless.ts
42
+ import * as echarts from "echarts/core";
43
+ import { SVGRenderer } from "echarts/renderers";
44
+ echarts.use([SVGRenderer]);
45
+ var OPTION_BUILDERS = {
46
+ BarChart: buildOption,
47
+ BoxPlot: buildOption2,
48
+ Bullet: buildOption3,
49
+ Donut: buildOption4,
50
+ Gauge: buildOption5,
51
+ HeatmapGrid: buildOption6,
52
+ Histogram: buildOption7,
53
+ LineChart: buildOption8,
54
+ NetworkGraph: buildOption9,
55
+ Nightingale: buildOption10,
56
+ Radar: buildOption11,
57
+ Sankey: buildOption12,
58
+ ScatterChart: buildOption13,
59
+ Sunburst: buildOption14,
60
+ Treemap: buildOption15
61
+ };
62
+ var INSTANCE_ID = /zr\d+-(?=[a-z]+-?\d)/g;
63
+ var PLACEHOLDER_ID = /zr-(?=[a-z]+-?\d)/g;
64
+ var STYLE_CLASS = /zr\d+-cls-(\d+)/g;
65
+ var FNV_OFFSET = 2166136261;
66
+ var FNV_PRIME = 16777619;
67
+ var HEX = 16;
68
+ function hashOf(text) {
69
+ let hash = FNV_OFFSET;
70
+ for (let index = 0;index < text.length; index += 1) {
71
+ hash ^= text.charCodeAt(index);
72
+ hash = Math.imul(hash, FNV_PRIME) >>> 0;
73
+ }
74
+ return hash.toString(HEX).padStart(8, "0");
75
+ }
76
+ function stableIds(svg, prefix) {
77
+ const classes = new Map;
78
+ const renumbered = svg.replace(STYLE_CLASS, (_match, number) => {
79
+ const index = classes.get(number) ?? classes.size;
80
+ classes.set(number, index);
81
+ return `zr-cls-${index}`;
82
+ }).replace(INSTANCE_ID, "zr-");
83
+ const stable = prefix ?? `c${hashOf(renumbered)}`;
84
+ return renumbered.replace(PLACEHOLDER_ID, `${stable}-`);
85
+ }
86
+ function renderToSvg(primitive, props, tokens, options) {
87
+ const { width, height, fontFamily, idPrefix } = options;
88
+ const build = OPTION_BUILDERS[primitive];
89
+ const finished = finishOption(build(props, tokens, width, height), false);
90
+ const option = {
91
+ ...finished,
92
+ animation: false,
93
+ textStyle: fontFamily === undefined ? finished.textStyle : { fontFamily }
94
+ };
95
+ const chart = echarts.init(null, null, { renderer: "svg", ssr: true, width, height });
96
+ try {
97
+ chart.setOption(option);
98
+ return stableIds(chart.renderToSVGString(), idPrefix);
99
+ } finally {
100
+ chart.dispose();
101
+ }
102
+ }
103
+ export {
104
+ valueFormatSchema,
105
+ tokensFrom,
106
+ resolveFormatContext,
107
+ renderToSvg,
108
+ formatterFor,
109
+ formatWeek,
110
+ formatRelative,
111
+ formatPercent,
112
+ formatMinutes,
113
+ formatMeasured,
114
+ formatElapsed,
115
+ formatDay,
116
+ formatDate,
117
+ formatContextSchema,
118
+ formatCompact,
119
+ finishOption,
120
+ buildOption15 as buildTreemapOption,
121
+ buildOption14 as buildSunburstOption,
122
+ buildOption13 as buildScatterChartOption,
123
+ buildOption12 as buildSankeyOption,
124
+ buildOption11 as buildRadarOption,
125
+ buildOption10 as buildNightingaleOption,
126
+ buildOption9 as buildNetworkGraphOption,
127
+ buildOption8 as buildLineChartOption,
128
+ buildOption7 as buildHistogramOption,
129
+ buildOption6 as buildHeatmapGridOption,
130
+ buildOption5 as buildGaugeOption,
131
+ buildOption4 as buildDonutOption,
132
+ buildOption3 as buildBulletOption,
133
+ buildOption2 as buildBoxPlotOption,
134
+ buildOption as buildBarChartOption,
135
+ VALUE_FORMAT_KINDS,
136
+ UNIT_POSITIONS,
137
+ PERCENT_BASES,
138
+ OPTION_BUILDERS,
139
+ DURATION_UNITS,
140
+ DEFAULT_FORMAT_CONTEXT,
141
+ DATE_PATTERNS
142
+ };
@@ -0,0 +1 @@
1
+ export { echartsEngine } from './echartsEngine.js';
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The engine's React adapter: the canvas renderer, the hook that builds a
3
+ * primitive's option over the live tokens, and the chart root. The option
4
+ * side (registration, the option type, the colour bridge) is `core.ts`.
5
+ *
6
+ * Canvas cannot read CSS variables, so a primitive re-runs its pure
7
+ * `(props, tokens) => option` when the tokens change (a theme flip) and
8
+ * `EChart` sets it with `notMerge`, so a flip repaints fully.
9
+ */
10
+ import type { ChartHeight } from '../seam/height.js';
11
+ import type { ECharts } from 'echarts/core';
12
+ import { type ReactElement } from 'react';
13
+ import { type ChartOption, type ResolvedTokens } from './core.js';
14
+ import { type ChartCursor } from './shared.variants.js';
15
+ /**
16
+ * The option of one primitive: its pure `build(props, tokens)` over the
17
+ * resolved tokens, finished with the shared options. Rebuilt when the props
18
+ * or the tokens (a theme flip) change.
19
+ */
20
+ export declare function useBuiltOption<P extends {
21
+ readonly animate?: boolean;
22
+ }>(props: P, build: (props: P, tokens: ResolvedTokens) => ChartOption): ChartOption;
23
+ /** A handler for one ECharts event, bound by name on the instance. */
24
+ export type ChartEventHandler = (event: unknown, instance: ECharts) => void;
25
+ /** The props of {@link EChart}. */
26
+ export interface EChartProps {
27
+ readonly option: ChartOption;
28
+ readonly ariaLabel: string;
29
+ /** Px, or `'fill'` for the container's full height; 220px when absent. */
30
+ readonly height?: ChartHeight;
31
+ readonly className?: string;
32
+ /** `'default'` keeps the arrow over charts whose marks are not buttons. */
33
+ readonly cursor?: ChartCursor;
34
+ /** ECharts events by name (`click`, `mouseover`), bound on the instance. */
35
+ readonly onEvents?: Readonly<Record<string, ChartEventHandler>>;
36
+ /**
37
+ * Merge new options into the live chart instead of replacing it, replacing
38
+ * only these components by id. Interaction state the option does not carry
39
+ * (a data-zoom window) then survives a re-render. Every colour is explicit
40
+ * in each option, so a theme flip still repaints fully. Default: replace.
41
+ */
42
+ readonly replaceMerge?: readonly string[];
43
+ /**
44
+ * Adjusts the option against the live instance just before it is set (for
45
+ * state the instance holds and the option does not, such as a zoom window).
46
+ */
47
+ readonly transform?: (option: ChartOption, instance: ECharts) => ChartOption;
48
+ }
49
+ /**
50
+ * The chart root over `echarts/core` directly: init on mount, dispose on
51
+ * unmount, resize with the host, set each option with `notMerge` unless the
52
+ * primitive asks for a `replaceMerge`, and bind the events by name.
53
+ *
54
+ * The host's height is a pixel count from a prop, which no class can carry,
55
+ * so it is set on the element in the layout effect, ahead of `init`.
56
+ * `'fill'` sets `100%`, so the host takes its container's height and the
57
+ * resize observer below follows the container.
58
+ */
59
+ export declare function EChart({ option, ariaLabel, height, className, cursor, onEvents, replaceMerge, transform }: EChartProps): ReactElement;
@@ -0,0 +1,40 @@
1
+ /** Where the chart root's pointer cursor comes from. */
2
+ export type ChartCursor = 'auto' | 'default';
3
+ /** The variant props `chartRootVariants` takes. */
4
+ export interface ChartRootVariantProps {
5
+ readonly cursor?: ChartCursor | null;
6
+ }
7
+ /**
8
+ * The element a chart is drawn into: as wide as its container. `cursor:
9
+ * 'default'` is for charts whose marks are not buttons: zrender puts an
10
+ * inline pointer cursor on every hoverable mark, and this wins over it.
11
+ */
12
+ export declare const chartRootVariants: (props?: ChartRootVariantProps) => string;
13
+ /** The variant props `chartFrameVariants` takes. */
14
+ export interface ChartFrameVariantProps {
15
+ readonly fill?: boolean | null;
16
+ }
17
+ /**
18
+ * A box a primitive wraps its chart root in (to measure it): no box of
19
+ * its own unless the chart fills its container, when it passes the
20
+ * container's height down to the root.
21
+ */
22
+ export declare const chartFrameVariants: (props?: ChartFrameVariantProps) => string;
23
+ /** The hover readout every chart renders into: surface, hairline ring, small text. */
24
+ export declare const tooltipSurfaceVariants: () => string;
25
+ /** The readout's heading line. */
26
+ export declare const tooltipHeadingVariants: () => string;
27
+ /** One readout row: key, value, label. */
28
+ export declare const tooltipRowVariants: () => string;
29
+ /** A readout row's strong value. */
30
+ export declare const tooltipValueVariants: () => string;
31
+ /** A readout row's label. */
32
+ export declare const tooltipLabelVariants: () => string;
33
+ /** The shape of a readout row's colour key. */
34
+ export type TooltipKeyShape = 'line' | 'dot';
35
+ /** The variant props `tooltipKeyVariants` takes. */
36
+ export interface TooltipKeyVariantProps {
37
+ readonly shape?: TooltipKeyShape | null;
38
+ }
39
+ /** The colour key in front of a readout row: a short line for line marks, a dot for the rest. */
40
+ export declare const tooltipKeyVariants: (props?: TooltipKeyVariantProps) => string;