@c2n/chart 0.0.7

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 (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +81 -0
  3. package/dist/area-chart.js +29 -0
  4. package/dist/bar-chart.js +65 -0
  5. package/dist/chart-adapter.js +0 -0
  6. package/dist/chart-base-C4-1TyKq.js +666 -0
  7. package/dist/chart-base.js +2 -0
  8. package/dist/chart-data.js +286 -0
  9. package/dist/chart-series-BnpHO3lm.js +83 -0
  10. package/dist/chart-series.js +2 -0
  11. package/dist/chart-theme.js +151 -0
  12. package/dist/chart-types.js +8 -0
  13. package/dist/chart.js +13 -0
  14. package/dist/echarts-chart-base-LogCQN10.js +228 -0
  15. package/dist/echarts-chart-base.js +2 -0
  16. package/dist/line-chart.js +31 -0
  17. package/dist/pie-chart.js +100 -0
  18. package/dist/sparkline.js +79 -0
  19. package/dist/uplot-chart-base-BWr0zJE2.js +253 -0
  20. package/dist/uplot-chart-base.js +2 -0
  21. package/dist/uplot-paths-ChKohvIX.js +95 -0
  22. package/package.json +146 -0
  23. package/react.d.ts +34 -0
  24. package/react.js +3 -0
  25. package/types/src/area-chart.d.ts +36 -0
  26. package/types/src/area-chart.d.ts.map +1 -0
  27. package/types/src/bar-chart.d.ts +46 -0
  28. package/types/src/bar-chart.d.ts.map +1 -0
  29. package/types/src/chart-adapter.d.ts +67 -0
  30. package/types/src/chart-adapter.d.ts.map +1 -0
  31. package/types/src/chart-base.d.ts +265 -0
  32. package/types/src/chart-base.d.ts.map +1 -0
  33. package/types/src/chart-data.d.ts +43 -0
  34. package/types/src/chart-data.d.ts.map +1 -0
  35. package/types/src/chart-series.d.ts +51 -0
  36. package/types/src/chart-series.d.ts.map +1 -0
  37. package/types/src/chart-theme.d.ts +64 -0
  38. package/types/src/chart-theme.d.ts.map +1 -0
  39. package/types/src/chart-types.d.ts +162 -0
  40. package/types/src/chart-types.d.ts.map +1 -0
  41. package/types/src/chart.d.ts +27 -0
  42. package/types/src/chart.d.ts.map +1 -0
  43. package/types/src/echarts-chart-base.d.ts +28 -0
  44. package/types/src/echarts-chart-base.d.ts.map +1 -0
  45. package/types/src/engines/echarts-adapter.d.ts +17 -0
  46. package/types/src/engines/echarts-adapter.d.ts.map +1 -0
  47. package/types/src/engines/echarts-loader.d.ts +16 -0
  48. package/types/src/engines/echarts-loader.d.ts.map +1 -0
  49. package/types/src/engines/uplot-adapter.d.ts +4 -0
  50. package/types/src/engines/uplot-adapter.d.ts.map +1 -0
  51. package/types/src/engines/uplot-loader.d.ts +20 -0
  52. package/types/src/engines/uplot-loader.d.ts.map +1 -0
  53. package/types/src/engines/uplot-paths.d.ts +25 -0
  54. package/types/src/engines/uplot-paths.d.ts.map +1 -0
  55. package/types/src/line-chart.d.ts +40 -0
  56. package/types/src/line-chart.d.ts.map +1 -0
  57. package/types/src/pie-chart.d.ts +59 -0
  58. package/types/src/pie-chart.d.ts.map +1 -0
  59. package/types/src/sparkline.d.ts +56 -0
  60. package/types/src/sparkline.d.ts.map +1 -0
  61. package/types/src/uplot-chart-base.d.ts +50 -0
  62. package/types/src/uplot-chart-base.d.ts.map +1 -0
  63. package/vue.d.ts +134 -0
  64. package/vue.js +3 -0
@@ -0,0 +1,265 @@
1
+ import { LitElement, type CSSResultGroup, type PropertyValues, type TemplateResult } from 'lit';
2
+ import type { TypedAddEventListener, TypedRemoveEventListener } from '@c2n/core/event-helper.js';
3
+ import { ChartFrameBuilder, type NormalizeContext } from './chart-data.js';
4
+ import { ChartThemeController, type ChartTheme } from './chart-theme.js';
5
+ import type { ChartAdapter, ChartBuildContext } from './chart-adapter.js';
6
+ import { type ChartSeries } from './chart-series.js';
7
+ import type { ChartDataSource, ChartFrame, ChartInput, ChartPointEventDetail, ChartRangeEventDetail, ChartSeriesConfig, ChartSeriesToggleEventDetail, ChartTooltipContext } from './chart-types.js';
8
+ /** One row of the legend. `series` and `index` are what a custom `renderLegendItem` is handed. */
9
+ export interface ChartLegendItem {
10
+ label: string;
11
+ color: string;
12
+ visible: boolean;
13
+ toggle: () => void;
14
+ series: ChartSeriesConfig;
15
+ index: number;
16
+ }
17
+ /** Events fired by every chart, keyed for `addEventListener`. */
18
+ export interface ChartEventMap {
19
+ 'chart-ready': CustomEvent<{
20
+ engine: 'uplot' | 'echarts';
21
+ }>;
22
+ 'chart-error': CustomEvent<{
23
+ error: unknown;
24
+ }>;
25
+ 'point-click': CustomEvent<ChartPointEventDetail>;
26
+ 'point-hover': CustomEvent<ChartPointEventDetail | null>;
27
+ 'range-change': CustomEvent<ChartRangeEventDetail>;
28
+ 'series-toggle': CustomEvent<ChartSeriesToggleEventDetail>;
29
+ }
30
+ export interface ChartBase {
31
+ addEventListener: TypedAddEventListener<ChartBase, ChartEventMap>;
32
+ removeEventListener: TypedRemoveEventListener<ChartBase, ChartEventMap>;
33
+ }
34
+ /**
35
+ * Shared behaviour of every `c2-*-chart`: the chrome and its slots, the resize observer, theme
36
+ * resolution, data normalisation, and the routing that keeps a realtime update off the expensive path.
37
+ * It defines no tag and is never registered — the concrete charts extend it.
38
+ *
39
+ * **Why the data and presentation inputs are separate.** `data` and `revision` are the only properties on
40
+ * the data path; everything else is presentation. A change limited to the data path is pushed straight
41
+ * into the engine from `shouldUpdate`, which returns `false`, so Lit never renders or commits and the
42
+ * canvas container is not touched. Anything else rebuilds the engine options, which is allowed to be
43
+ * expensive. That is what makes a streaming tick cost one engine redraw and nothing more.
44
+ *
45
+ * **Sizing.** A canvas has no intrinsic size, so the host is sized by `--c2-chart--height` (320px by
46
+ * default) rather than by its content. Give the host a height — through the variable, a CSS rule, or a
47
+ * flex parent — or the plot area collapses.
48
+ *
49
+ * @slot default - The series definitions: `c2-chart-series` elements. They render nothing themselves.
50
+ * @slot legend - Replaces the built-in legend. The built-in one is still what `legend` positions.
51
+ * @slot tooltip - Replaces the built-in tooltip body. The hovered point is available through the `renderTooltip` property when a function is easier than markup.
52
+ * @slot actions - Controls pinned to the top-right of the plot area, for a range picker or an export button.
53
+ * @slot empty - Replaces the built-in "no data" message.
54
+ * @slot loading - Replaces the built-in message shown while `loading` is set.
55
+ * @slot error - Replaces the built-in message shown when `error` is set.
56
+ *
57
+ * @slotcomponent c2-chart-series
58
+ *
59
+ * @event {CustomEvent<{ engine: string }>} chart-ready - Fired after the engine has loaded and drawn for the first time. The host also gains `data-chart-ready`, which is what a test should wait on.
60
+ * @event {CustomEvent<{ error: unknown }>} chart-error - Fired when the engine fails to load or to draw. `detail.error` is the underlying failure.
61
+ * @event {CustomEvent<ChartPointEventDetail>} point-click - Fired when a datum is clicked. Does not bubble: several components fire point events, so a listener belongs on the element itself.
62
+ * @event {CustomEvent<ChartPointEventDetail>} point-hover - Fired as the pointer moves between data points, and with a `null` detail when it leaves the plot. Does not bubble.
63
+ * @event {CustomEvent<ChartRangeEventDetail>} range-change - Fired after the user zooms or brushes. `detail.min` and `detail.max` are the new x bounds. Does not bubble.
64
+ * @event {CustomEvent<ChartSeriesToggleEventDetail>} series-toggle - Fired when a legend entry is toggled. Does not bubble.
65
+ *
66
+ * @csspart frame - The outer flex column holding the legend and the plot area.
67
+ * @csspart plot-area - The positioned box the engine draws into.
68
+ * @csspart plot - The engine's container element. Carries no Lit bindings, so the canvas survives every update.
69
+ * @csspart overlay - The non-interactive layer above the canvas that holds the tooltip and the actions.
70
+ * @csspart tooltip - The tooltip bubble.
71
+ * @csspart actions - The container for the `actions` slot.
72
+ * @csspart state - The empty, loading or error message layer.
73
+ * @csspart legend - The legend container.
74
+ * @csspart legend-item - One legend entry, a toggle button.
75
+ * @csspart legend-marker - The colour swatch inside a legend entry.
76
+ *
77
+ * @cssproperty {length} [--c2-chart--width=100%] - Width of the host. The plot is absolutely positioned and has no intrinsic width, so a chart used as a flex item would otherwise collapse to its legend.
78
+ * @cssproperty {pixel} [--c2-chart--height=320px] - Height of the host. A canvas has no intrinsic size, so this is what gives the chart a box.
79
+ * @cssproperty {color} [--c2-chart--background=#ffffff] - Background of the chart surface.
80
+ * @cssproperty {color} [--c2-chart--color=#18181b] - Primary text colour.
81
+ * @cssproperty {font-family} [--c2-chart--font-family=inherit] - Font family used for the chart chrome and the labels the engine draws.
82
+ * @cssproperty {font-size} [--c2-chart--font-size=12px] - Base font size.
83
+ * @cssproperty {padding} [--c2-chart--padding=12px] - Padding around the whole chart.
84
+ *
85
+ * @cssproperty {border} [--c2-chart--border-top=1px solid #e4e4e7] - Top border.
86
+ * @cssproperty {border} [--c2-chart--border-right=1px solid #e4e4e7] - Right border.
87
+ * @cssproperty {border} [--c2-chart--border-bottom=1px solid #e4e4e7] - Bottom border.
88
+ * @cssproperty {border} [--c2-chart--border-left=1px solid #e4e4e7] - Left border.
89
+ * @cssproperty {border-radius} [--c2-chart--border-top-left-radius=8px] - Top-left corner radius.
90
+ * @cssproperty {border-radius} [--c2-chart--border-top-right-radius=8px] - Top-right corner radius.
91
+ * @cssproperty {border-radius} [--c2-chart--border-bottom-left-radius=8px] - Bottom-left corner radius.
92
+ * @cssproperty {border-radius} [--c2-chart--border-bottom-right-radius=8px] - Bottom-right corner radius.
93
+ *
94
+ * @cssproperty {color} [--c2-chart__series-1--color=#0265dc] - Colour of the first series.
95
+ * @cssproperty {color} [--c2-chart__series-2--color=#ea580c] - Colour of the second series.
96
+ * @cssproperty {color} [--c2-chart__series-3--color=#0f766e] - Colour of the third series.
97
+ * @cssproperty {color} [--c2-chart__series-4--color=#db2777] - Colour of the fourth series.
98
+ * @cssproperty {color} [--c2-chart__series-5--color=#a16207] - Colour of the fifth series.
99
+ * @cssproperty {color} [--c2-chart__series-6--color=#7c3aed] - Colour of the sixth series.
100
+ * @cssproperty {color} [--c2-chart__series-7--color=#0891b2] - Colour of the seventh series.
101
+ * @cssproperty {color} [--c2-chart__series-8--color=#52525b] - Colour of the eighth series. Series beyond the eighth reuse the palette from the start.
102
+ *
103
+ * @cssproperty {pixel} [--c2-chart__line--width=2px] - Stroke width of a line series.
104
+ * @cssproperty {pixel} [--c2-chart__point--radius=2.5px] - Radius of a data point marker.
105
+ * @cssproperty {opacity} [--c2-chart__area--opacity=0.15] - Opacity of the fill under an area series.
106
+ *
107
+ * @cssproperty {color} [--c2-chart__axis--color=#71717a] - Colour of the axis lines and tick labels.
108
+ * @cssproperty {font-size} [--c2-chart__axis--font-size=12px] - Font size of the tick labels.
109
+ * @cssproperty {color} [--c2-chart__grid--color=#e4e4e7] - Colour of the grid lines.
110
+ * @cssproperty {pixel} [--c2-chart__grid--width=1px] - Width of the grid lines.
111
+ * @cssproperty {color} [--c2-chart__crosshair--color=#a1a1aa] - Colour of the cursor crosshair.
112
+ * @cssproperty {pixel} [--c2-chart__crosshair--width=1px] - Width of the cursor crosshair.
113
+ *
114
+ * @cssproperty {color} [--c2-chart__surface--color=#ffffff] - Surface colour handed to the engine, for marker borders and label backdrops.
115
+ * @cssproperty {color} [--c2-chart__muted--color=#71717a] - Secondary text colour.
116
+ * @cssproperty {color} [--c2-chart__positive--color=#16a34a] - Colour for a rising value, used by the candlestick and gauge charts.
117
+ * @cssproperty {color} [--c2-chart__negative--color=#dc2626] - Colour for a falling value, used by the candlestick and gauge charts.
118
+ *
119
+ * @cssproperty {pixel} [--c2-chart__legend--gap=12px] - Gap between legend entries.
120
+ * @cssproperty {padding} [--c2-chart__legend--padding=8px 0 0] - Padding around the legend.
121
+ * @cssproperty {color} [--c2-chart__legend--color=#71717a] - Legend text colour.
122
+ * @cssproperty {font-size} [--c2-chart__legend--font-size=12px] - Legend font size.
123
+ * @cssproperty {opacity} [--c2-chart__legend__disabled--opacity=0.38] - Opacity of a legend entry whose series is hidden.
124
+ * @cssproperty {pixel} [--c2-chart__legend-marker--size=10px] - Size of the legend colour swatch.
125
+ * @cssproperty {border-radius} [--c2-chart__legend-marker--border-radius=999px] - Corner radius of the legend colour swatch.
126
+ *
127
+ * @cssproperty {color} [--c2-chart__tooltip--background-color=#18181b] - Tooltip background.
128
+ * @cssproperty {color} [--c2-chart__tooltip--color=#fafafa] - Tooltip text colour.
129
+ * @cssproperty {font-size} [--c2-chart__tooltip--font-size=12px] - Tooltip font size.
130
+ * @cssproperty {padding} [--c2-chart__tooltip--padding=8px 10px] - Tooltip padding.
131
+ * @cssproperty {border-radius} [--c2-chart__tooltip--border-radius=6px] - Tooltip corner radius.
132
+ * @cssproperty {box-shadow} [--c2-chart__tooltip--box-shadow=0 8px 24px rgba(24, 24, 27, 0.08)] - Tooltip shadow.
133
+ * @cssproperty {pixel} [--c2-chart__tooltip--gap=6px] - Gap between tooltip rows.
134
+ *
135
+ * @cssproperty {color} [--c2-chart__state--color=#71717a] - Colour of the empty, loading and error text.
136
+ * @cssproperty {font-size} [--c2-chart__state--font-size=14px] - Font size of the empty, loading and error text.
137
+ */
138
+ export declare abstract class ChartBase extends LitElement {
139
+ #private;
140
+ static styles: CSSResultGroup;
141
+ protected plotElement: HTMLElement | null;
142
+ private tooltipElement;
143
+ /**
144
+ * The data to plot. Row objects, a bare `number[]`, columnar `[xs, ys…]`, or an already-normalised
145
+ * frame. Compared by identity: replace the array, or bump `revision` after mutating it in place.
146
+ */
147
+ data?: ChartInput;
148
+ /** Bump after mutating `data` in place. The cheap escape hatch for a large buffer you own. */
149
+ revision: number;
150
+ /** Lazy or streaming source used instead of `data`. Property only. */
151
+ dataSource?: ChartDataSource;
152
+ /** Series definitions, as an alternative to `c2-chart-series` children. Children win when both are set. */
153
+ series?: ChartSeriesConfig[];
154
+ /** Row field holding the x value; may be a dotted path. Defaults to the row index. */
155
+ xField: string;
156
+ /** Row field holding the category label, for charts that name their slices. */
157
+ labelField: string;
158
+ /** How x values are interpreted, which decides the axis and the tooltip format. */
159
+ xType: 'time' | 'linear' | 'category';
160
+ /**
161
+ * Where the legend sits, or `none` to hide it. Shown by default: a chart with more than one series is
162
+ * unreadable without one, and a single-series chart simply renders a one-entry legend.
163
+ */
164
+ legend: 'none' | 'top' | 'bottom' | 'start' | 'end';
165
+ /** Whether the tooltip follows the whole x position or only the hovered datum. */
166
+ tooltip: 'none' | 'item' | 'axis';
167
+ /**
168
+ * Whether the engine animates entry and updates. `none` by default: a chart fed by a live source should
169
+ * not animate every tick. Named `animation` rather than `animate` because `HTMLElement.animate()` is a
170
+ * method every element already has, and shadowing it breaks the Web Animations API on the host.
171
+ */
172
+ animation: 'none' | 'auto';
173
+ /** BCP 47 locale for the axis and tooltip formatting. Defaults to the browser locale. */
174
+ locale?: string;
175
+ /** Shows the loading state instead of the plot. */
176
+ loading: boolean;
177
+ /** Shows an error message instead of the plot. */
178
+ error: string;
179
+ /** Replaces the built-in "no data" text. */
180
+ emptyMessage: string;
181
+ /** Caps how many points a streaming chart keeps; older points fall off the front. `0` keeps everything. */
182
+ maxPoints: number;
183
+ /** Defers loading the engine until the host first scrolls into view. */
184
+ lazyRender: boolean;
185
+ /** Renders the tooltip body from a function instead of the `tooltip` slot. Property only. */
186
+ renderTooltip?: (context: ChartTooltipContext) => unknown;
187
+ /** Renders one legend entry from a function instead of the `legend` slot. Property only. */
188
+ renderLegendItem?: (series: ChartSeriesConfig, index: number) => unknown;
189
+ protected seriesElements: ChartSeries[];
190
+ protected hiddenSeries: Set<number>;
191
+ protected hoverContext: ChartTooltipContext | null;
192
+ private engineFailed;
193
+ protected themeController: ChartThemeController;
194
+ protected frameBuilder: ChartFrameBuilder;
195
+ protected frame?: ChartFrame;
196
+ protected adapter?: ChartAdapter;
197
+ /** Which engine this chart draws with. */
198
+ protected abstract readonly engineName: 'uplot' | 'echarts';
199
+ /** Loads the engine and returns a fresh adapter. */
200
+ protected abstract createAdapter(): Promise<ChartAdapter>;
201
+ /** Builds the engine options from the theme and the resolved series. Never sees raw data. */
202
+ protected abstract buildOptions(context: ChartBuildContext): unknown;
203
+ /** Projects the normalised frame into the shape this engine consumes. */
204
+ protected abstract projectData(frame: ChartFrame, context: ChartBuildContext): unknown;
205
+ connectedCallback(): void;
206
+ disconnectedCallback(): void;
207
+ /**
208
+ * The fast path. A change confined to `data`/`revision` on a live chart is pushed into the engine here
209
+ * and `false` is returned, so Lit skips render and commit entirely and the canvas is never touched.
210
+ */
211
+ protected shouldUpdate(changed: PropertyValues): boolean;
212
+ protected willUpdate(changed: PropertyValues): void;
213
+ protected updated(changed: PropertyValues): void;
214
+ /**
215
+ * Replaces the data without going through the update queue. Equivalent to assigning `data`, but skips
216
+ * Lit's scheduling — worth it in a tight loop.
217
+ */
218
+ updateData(next: ChartInput): void;
219
+ /**
220
+ * Appends one point across every series at a shared x. The frame grows in place, so nothing is
221
+ * re-normalised and no Lit update is scheduled: a 10 Hz feed costs one engine redraw per tick.
222
+ */
223
+ appendPoint(x: number, values: readonly (number | null)[]): void;
224
+ /** Shows or hides one series, as the legend does. */
225
+ setSeriesVisible(index: number, visible: boolean): void;
226
+ /** The series in draw order: `c2-chart-series` children when present, otherwise the `series` property. */
227
+ get resolvedSeries(): ChartSeriesConfig[];
228
+ /**
229
+ * The series to draw when nothing was declared: every numeric field of the first row except the ones
230
+ * already spoken for by `x-field` and `label-field`.
231
+ *
232
+ * This reads `data` rather than the normalised frame on purpose. Deriving it from the frame would be
233
+ * circular — the frame is built *from* the series list — and naming the results positionally would be
234
+ * worse than circular: the next normalisation would look up a field that does not exist in the rows and
235
+ * quietly read every value as a gap.
236
+ */
237
+ protected inferredSeries(): ChartSeriesConfig[];
238
+ /** The colour a series draws with: its own `color`, else its palette slot. */
239
+ protected colorOf(series: ChartSeriesConfig, index: number, theme?: ChartTheme): string;
240
+ protected normalizeContext(): NormalizeContext;
241
+ protected buildContext(): ChartBuildContext;
242
+ private handleThemeChange;
243
+ /** Formats an x value for the tooltip. Time charts get a date, everything else a number. */
244
+ protected formatX(value: number): string;
245
+ /**
246
+ * How much time the chart currently covers, in milliseconds, or `0` when that is not a meaningful question.
247
+ * Axis labels are chosen from it: a day of five-minute samples and a year of daily ones want different ticks.
248
+ */
249
+ protected xSpan(): number;
250
+ /** Formats a y value for the tooltip and the built-in labels. */
251
+ protected formatValue(value: number): string;
252
+ protected render(): TemplateResult;
253
+ /** Named slot, then the renderer property, then the built-in rows — the library's three-layer fallback. */
254
+ private renderTooltipBody;
255
+ private defaultTooltip;
256
+ private renderState;
257
+ /**
258
+ * What the legend lists. One entry per series for every cartesian chart — but a chart whose data is one
259
+ * dimensional overrides this: a pie has a single series and many slices, and listing "Revenue" above a
260
+ * four-slice donut tells the reader nothing.
261
+ */
262
+ protected legendItems(): ChartLegendItem[];
263
+ private renderLegend;
264
+ }
265
+ //# sourceMappingURL=chart-base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chart-base.d.ts","sourceRoot":"","sources":["../../src/chart-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsC,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;AAGnI,OAAO,KAAK,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AAEhG,OAAO,EAAE,iBAAiB,EAAe,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACvF,OAAO,EAAE,oBAAoB,EAAgB,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACtF,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACzE,OAAO,EAAmC,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACrF,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EACV,UAAU,EACV,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,4BAA4B,EAC5B,mBAAmB,EAEpB,MAAM,kBAAkB,CAAA;AA+BzB,kGAAkG;AAClG,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,IAAI,CAAA;IAClB,MAAM,EAAE,iBAAiB,CAAA;IACzB,KAAK,EAAE,MAAM,CAAA;CACd;AAYD,iEAAiE;AACjE,MAAM,W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KzB,OAAO,CAAC,cAAc;IAetB,OAAO,CAAC,WAAW;IASnB;;;;OAIG;IACH,SAAS,CAAC,WAAW,IAAI,eAAe,EAAE;IAW1C,OAAO,CAAC,YAAY;CAqBrB"}
@@ -0,0 +1,43 @@
1
+ import { type ChartColumn, type ChartFrame, type ChartInput, type ChartSeriesConfig } from './chart-types.js';
2
+ /** What the builder needs to read rows; all of it derived from the element's presentation properties. */
3
+ export interface NormalizeContext {
4
+ /** Row field holding the x value. Empty means "use the row index". */
5
+ xField: string;
6
+ /** Row field holding the category label, for categorical charts. */
7
+ labelField: string;
8
+ /** The series, in draw order; only their `field` is read here. */
9
+ series: ChartSeriesConfig[];
10
+ /** Changing this forces a re-read of the same input array. */
11
+ signature: string;
12
+ }
13
+ /** Reads one value out of a column, normalising the two representations to `number | null`. */
14
+ export declare function columnValue(column: ChartColumn, index: number): number | null;
15
+ /**
16
+ * Builds and caches the normalised form of whatever a consumer assigned, and owns the projections each
17
+ * engine consumes. One instance per chart element.
18
+ */
19
+ export declare class ChartFrameBuilder {
20
+ #private;
21
+ /**
22
+ * Normalises `input` into a {@link ChartFrame}. Returns the *same* frame for the same input reference
23
+ * and signature, so this is safe to call on every update.
24
+ */
25
+ build(input: ChartInput | undefined, context: NormalizeContext): ChartFrame | undefined;
26
+ /**
27
+ * Appends one x and one value per series in place. Grows geometrically, and drops the oldest points once
28
+ * `maxPoints` is reached, so a streaming chart holds a bounded ring rather than an unbounded array.
29
+ */
30
+ push(frame: ChartFrame, x: number, values: readonly (number | null)[], maxPoints: number): void;
31
+ /**
32
+ * uPlot's view: `[xs, ys…]` sliced to `length`. A typed column becomes a `subarray`, which is a view
33
+ * over the same buffer and costs nothing.
34
+ */
35
+ uplotView(frame: ChartFrame): unknown[];
36
+ /**
37
+ * ECharts' view, one array per series. `pairs` is `[[x, y], …]` for the cartesian charts, `named` is
38
+ * `[{ name, value }, …]` for the ones whose marks are labelled rather than positioned (pie, gauge), and
39
+ * `values` is a bare value list.
40
+ */
41
+ echartsView(frame: ChartFrame, shape: 'pairs' | 'values' | 'named'): unknown[];
42
+ }
43
+ //# sourceMappingURL=chart-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chart-data.d.ts","sourceRoot":"","sources":["../../src/chart-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAgB,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAiB,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAE1I,yGAAyG;AACzG,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAA;IACd,oEAAoE;IACpE,UAAU,EAAE,MAAM,CAAA;IAClB,kEAAkE;IAClE,MAAM,EAAE,iBAAiB,EAAE,CAAA;IAC3B,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAA;CAClB;AA+CD,+FAA+F;AAC/F,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG7E;AAqBD;;;GAGG;AACH,qBAAa,iBAAiB;;IAQ5B;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,EAAE,OAAO,EAAE,gBAAgB,GAAG,UAAU,GAAG,SAAS;IAgFvF;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAiC/F;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,EAAE;IAQvC;;;;OAIG;IACH,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,EAAE;CAsB/E"}
@@ -0,0 +1,51 @@
1
+ import { LitElement, type PropertyValues } from 'lit';
2
+ import type { ChartSeriesConfig } from './chart-types.js';
3
+ /** Fired at the parent chart whenever a series definition changes. */
4
+ export declare const SERIES_CHANGE_EVENT = "c2-chart-series-change";
5
+ /** The tag, so a chart can match a definition by name rather than by class identity. */
6
+ export declare const SERIES_TAG = "c2-chart-series";
7
+ /**
8
+ * One series of a chart, declared as a light-DOM child. The element renders nothing: it is a definition
9
+ * the chart reads, the same way `c2-table` reads its `c2-table-column` children. Everything it exposes as
10
+ * an attribute can also be set as a property, and `format` is property-only.
11
+ *
12
+ * ```html
13
+ * <c2-line-chart x-field="month" data='[{ "month": 1, "revenue": 120, "cost": 80 }]'>
14
+ * <c2-chart-series field="revenue" label="Revenue"></c2-chart-series>
15
+ * <c2-chart-series field="cost" label="Cost" color="#ea580c"></c2-chart-series>
16
+ * </c2-line-chart>
17
+ * ```
18
+ *
19
+ * @tag c2-chart-series
20
+ */
21
+ export declare class ChartSeries extends LitElement implements ChartSeriesConfig {
22
+ #private;
23
+ static styles: import("lit").CSSResult;
24
+ /** Key of the value in the row object; may be a dotted path such as `stats.cpu`. */
25
+ field: string;
26
+ /** Legend and tooltip label. Falls back to the field name. */
27
+ label?: string;
28
+ /** Explicit colour. Falls back to this series' slot in the chart's palette. */
29
+ color?: string;
30
+ /** Stroke width in pixels. Falls back to `--c2-chart__line--width`. */
31
+ lineWidth?: number;
32
+ /** Which y axis the series is drawn against. */
33
+ axis: 'left' | 'right';
34
+ /** Joins across gaps instead of breaking the line. */
35
+ spanGaps: boolean;
36
+ /** Leaves the series out of the chart without removing the definition. */
37
+ hidden: boolean;
38
+ /** Formats this series' values for the tooltip. Property only. */
39
+ format?: (value: number) => string;
40
+ /** A plain snapshot of this definition, so the chart never holds a reference to the element. */
41
+ toConfig(): ChartSeriesConfig;
42
+ connectedCallback(): void;
43
+ disconnectedCallback(): void;
44
+ protected updated(_changed: PropertyValues): void;
45
+ }
46
+ declare global {
47
+ interface HTMLElementTagNameMap {
48
+ 'c2-chart-series': ChartSeries;
49
+ }
50
+ }
51
+ //# sourceMappingURL=chart-series.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chart-series.d.ts","sourceRoot":"","sources":["../../src/chart-series.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAO,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;AAG1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEzD,sEAAsE;AACtE,eAAO,MAAM,mBAAmB,2BAA2B,CAAA;AAE3D,wFAAwF;AACxF,eAAO,MAAM,UAAU,oBAAoB,CAAA;AAE3C;;;;;;;;;;;;;GAaG;AACH,qBACa,WAAY,SAAQ,UAAW,YAAW,iBAAiB;;IACtE,OAAgB,MAAM,0BAIrB;IAED,oFAAoF;IACxD,KAAK,SAAK;IAEtC,8DAA8D;IAClC,KAAK,CAAC,EAAE,MAAM,CAAA;IAE1C,+EAA+E;IACnD,KAAK,CAAC,EAAE,MAAM,CAAA;IAE1C,uEAAuE;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAEvE,gDAAgD;IACpB,IAAI,EAAE,MAAM,GAAG,OAAO,CAAS;IAE3D,sDAAsD;IACD,QAAQ,UAAQ;IAErE,0EAA0E;IACrB,MAAM,UAAQ;IAEnE,kEAAkE;IAClC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IAElE,gGAAgG;IAChG,QAAQ,IAAI,iBAAiB;IAapB,iBAAiB,IAAI,IAAI;IAKzB,oBAAoB,IAAI,IAAI;cAKlB,OAAO,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;CAQ3D;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,iBAAiB,EAAE,WAAW,CAAA;KAC/B;CACF"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Turns the element's own CSS custom properties into plain values a canvas engine can use.
3
+ *
4
+ * This is the one place the package has to work around the fact that a chart is not DOM: `::part()` and
5
+ * `var()` never reach a canvas, so the theme has to be *read* and handed over as strings and numbers.
6
+ *
7
+ * Colours are read through hidden probe elements rather than `getPropertyValue`, because a custom
8
+ * property whose value is a `var()` chain or a `color-mix()` comes back from `getPropertyValue` as the
9
+ * author's literal text — which no engine can parse. The computed `color` of a probe is always a resolved
10
+ * `rgb(…)`. The probes live in the shadow root under `display: none`, so they cost no layout.
11
+ */
12
+ import { type ReactiveController, type ReactiveControllerHost } from 'lit';
13
+ /** The slice of the host this controller needs: a reactive element with a shadow root to probe. */
14
+ type ThemeHost = ReactiveControllerHost & HTMLElement & {
15
+ readonly renderRoot?: ParentNode;
16
+ };
17
+ /** Number of series colours in the palette; matches `--c2-chart__series-1…8--color`. */
18
+ export declare const PALETTE_SIZE = 8;
19
+ /**
20
+ * The colours the probe block exposes, in DOM order. `chart.scss` emits one `i:nth-child(n)` rule per
21
+ * entry, so this list and that loop must stay in step.
22
+ */
23
+ export declare const PROBE_COLORS: readonly ["series-1", "series-2", "series-3", "series-4", "series-5", "series-6", "series-7", "series-8", "axis", "grid", "text", "muted", "tooltip-background", "tooltip-text", "crosshair", "positive", "negative", "surface"];
24
+ /** Resolved, engine-ready theme values. Every colour is a computed `rgb(…)`. */
25
+ export interface ChartTheme {
26
+ /** The categorical series palette, longest-lived of the chart tokens. */
27
+ palette: string[];
28
+ /** Primary text colour, used for labels the chart draws itself. */
29
+ color: string;
30
+ /** Secondary text colour, used for axis tick labels. */
31
+ mutedColor: string;
32
+ axisColor: string;
33
+ gridColor: string;
34
+ surface: string;
35
+ tooltipBackground: string;
36
+ tooltipColor: string;
37
+ crosshairColor: string;
38
+ /** Colours for charts with an inherent direction (candlestick, gauge thresholds). */
39
+ positive: string;
40
+ negative: string;
41
+ fontFamily: string;
42
+ fontSize: number;
43
+ lineWidth: number;
44
+ pointRadius: number;
45
+ }
46
+ /**
47
+ * Resolves and caches the host's chart theme, and invalidates it whenever the page's colour scheme moves.
48
+ *
49
+ * Three independent triggers, because an app may use any of them: the `data-theme` / `class` attribute on
50
+ * `<html>` (what a site toggle sets), the OS preference, and the `c2n-theme-change` event the docs site
51
+ * happens to fire. None of them is required for the component to work.
52
+ */
53
+ export declare class ChartThemeController implements ReactiveController {
54
+ #private;
55
+ constructor(host: ThemeHost, onChange: () => void);
56
+ /** The resolved theme, computed on first read after each invalidation. */
57
+ get theme(): ChartTheme;
58
+ /** Drops the cached theme and tells the host to rebuild its engine options. */
59
+ invalidate(): void;
60
+ hostConnected(): void;
61
+ hostDisconnected(): void;
62
+ }
63
+ export {};
64
+ //# sourceMappingURL=chart-theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chart-theme.d.ts","sourceRoot":"","sources":["../../src/chart-theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAY,KAAK,kBAAkB,EAAE,KAAK,sBAAsB,EAAE,MAAM,KAAK,CAAA;AAEpF,mGAAmG;AACnG,KAAK,SAAS,GAAG,sBAAsB,GAAG,WAAW,GAAG;IAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAA;CAAE,CAAA;AAE5F,wFAAwF;AACxF,eAAO,MAAM,YAAY,IAAI,CAAA;AAE7B;;;GAGG;AACH,eAAO,MAAM,YAAY,kOAmBf,CAAA;AAEV,gFAAgF;AAChF,MAAM,WAAW,UAAU;IACzB,yEAAyE;IACzE,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,mEAAmE;IACnE,KAAK,EAAE,MAAM,CAAA;IACb,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,iBAAiB,EAAE,MAAM,CAAA;IACzB,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB,qFAAqF;IACrF,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;CACpB;AAoBD;;;;;;GAMG;AACH,qBAAa,oBAAqB,YAAW,kBAAkB;;gBAOjD,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,IAAI;IAMjD,0EAA0E;IAC1E,IAAI,KAAK,IAAI,UAAU,CAGtB;IAED,+EAA+E;IAC/E,UAAU,IAAI,IAAI;IAKlB,aAAa,IAAI,IAAI;IAarB,gBAAgB,IAAI,IAAI;CAiDzB"}
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Public data and configuration types shared by every `c2-*-chart` element.
3
+ *
4
+ * The split this file encodes is the point of the whole package: a {@link ChartSeriesConfig} describes
5
+ * *presentation* (what a series looks like and which field it reads), while {@link ChartInput} and
6
+ * {@link ChartDataSource} carry *data*. Nothing in the data path knows about colours, and nothing in the
7
+ * presentation path knows about buffers, so a source can be reused unchanged across chart types.
8
+ */
9
+ /** A row is any plain object; values are read by `field`, which may be a dotted path (`stats.cpu`). */
10
+ export type ChartRow = Record<string, unknown>;
11
+ /**
12
+ * One column per axis: `[xs, ys1, ys2, …]`. This is the shape uPlot draws natively, so handing it in
13
+ * costs no conversion at all.
14
+ */
15
+ export type ChartColumnarInput = ArrayLike<number>[];
16
+ /**
17
+ * Everything a chart accepts as `data`:
18
+ *
19
+ * - `number[]` — one series against its own index, the convenient shape for a sparkline.
20
+ * - {@link ChartRow}`[]` — row objects read through `x-field` and each series' `field`.
21
+ * - {@link ChartColumnarInput} — already columnar.
22
+ * - {@link ChartFrame} — already normalised, handed straight through.
23
+ */
24
+ export type ChartInput = number[] | ChartRow[] | ChartColumnarInput | ChartFrame;
25
+ /**
26
+ * A column of y values. Dense numeric data is a `Float64Array` (the fast path: appending is O(1) and no
27
+ * engine has to convert it). A column that contains holes falls back to a plain array, because both
28
+ * engines detect a gap with `== null` and `NaN` inside a typed array would silently poison the scale
29
+ * range instead.
30
+ */
31
+ export type ChartColumn = Float64Array | (number | null)[];
32
+ /**
33
+ * The normalised form every chart works with internally, produced once per input by `ChartFrameBuilder`.
34
+ *
35
+ * The buffers are deliberately longer than `length`: appending a realtime point writes into the spare
36
+ * capacity and bumps {@link revision} instead of reallocating, which is what makes a streaming tick cost
37
+ * nothing but the engine redraw.
38
+ */
39
+ export interface ChartFrame {
40
+ /** X values, ascending. A time chart stores epoch **milliseconds**. */
41
+ x: ChartColumn;
42
+ /** One column per series, each at least `length` long. */
43
+ columns: ChartColumn[];
44
+ /** How many entries of `x` and each column are valid. */
45
+ length: number;
46
+ /** Allocated capacity of the buffers; `length` grows into it. */
47
+ capacity: number;
48
+ /** Bumped on every in-place mutation, so every derived projection cache invalidates at once. */
49
+ revision: number;
50
+ /** Category labels, when the x axis is categorical (`x-type="category"`, pie, gauge). */
51
+ labels?: string[];
52
+ }
53
+ /** Marks a value as a `ChartFrame` without an `instanceof` check surviving a bundler boundary. */
54
+ export declare function isChartFrame(value: unknown): value is ChartFrame;
55
+ /**
56
+ * One series: which field it reads and how it is drawn. Everything here is presentation except `field`,
57
+ * which is the single point where a series touches the data.
58
+ */
59
+ export interface ChartSeriesConfig {
60
+ /** Key of the value in the row object; may be a dotted path such as `stats.cpu`. */
61
+ field: string;
62
+ /** Legend and tooltip label. Falls back to the field name. */
63
+ label?: string;
64
+ /** Explicit colour. Falls back to the palette slot for this series' index. */
65
+ color?: string;
66
+ /** Stroke width in pixels; falls back to `--c2-chart__line--width`. */
67
+ lineWidth?: number;
68
+ /** Draws the series against the secondary (right-hand) axis. */
69
+ axis?: 'left' | 'right';
70
+ /** Joins across gaps instead of breaking the line. */
71
+ spanGaps?: boolean;
72
+ /** Leaves the series out without removing the definition. */
73
+ hidden?: boolean;
74
+ /** Formats a value for the tooltip and the axis. Property only — no attribute equivalent. */
75
+ format?: (value: number) => string;
76
+ }
77
+ /** What the chart asks a {@link ChartDataSource} for. */
78
+ export interface ChartWindowRequest {
79
+ /** Inclusive x domain the chart needs. Absent on the first load. */
80
+ xMin?: number;
81
+ xMax?: number;
82
+ /** Points the chart can usefully draw at its current width; a source may decimate to this server-side. */
83
+ maxPoints: number;
84
+ /** Aborted when the user keeps panning and this window is no longer wanted. */
85
+ signal: AbortSignal;
86
+ }
87
+ /** What a {@link ChartDataSource} returns. */
88
+ export interface ChartWindowResult {
89
+ data: ChartInput;
90
+ /** Full domain of the dataset, so the chart can size its x scale before it holds every point. */
91
+ domain?: {
92
+ min: number;
93
+ max: number;
94
+ };
95
+ }
96
+ /**
97
+ * Lazy point source — the chart's equivalent of `TableDataSource`, used instead of `data`.
98
+ *
99
+ * `getWindow` is the pull half (first load, zoom, pan). `subscribe` is the push half: a tick handed to
100
+ * the listener lands straight in the frame's spare capacity and redraws without a Lit update.
101
+ */
102
+ export interface ChartDataSource {
103
+ getWindow(request: ChartWindowRequest): Promise<ChartWindowResult>;
104
+ subscribe?(listener: (x: number, values: readonly (number | null)[]) => void): () => void;
105
+ }
106
+ /** Identifies one datum, shared by the hover and click event details. */
107
+ export interface ChartPointEventDetail {
108
+ /** Index of the point within the series. */
109
+ index: number;
110
+ /** Index of the series the point belongs to. */
111
+ seriesIndex: number;
112
+ /** The series definition. */
113
+ series: ChartSeriesConfig;
114
+ /** The x value; epoch milliseconds on a time chart. */
115
+ x: number;
116
+ /** The y value, or `null` at a gap. */
117
+ y: number | null;
118
+ /** The category label, when the chart is categorical. */
119
+ label?: string;
120
+ }
121
+ /** One row of the tooltip: a series and its value at the hovered index. */
122
+ export interface ChartTooltipEntry {
123
+ seriesIndex: number;
124
+ series: ChartSeriesConfig;
125
+ value: number | null;
126
+ /** `value` run through the series' `format`, or the chart's number formatter. */
127
+ formatted: string;
128
+ color: string;
129
+ }
130
+ /** What the tooltip slot and `renderTooltip` are handed. */
131
+ export interface ChartTooltipContext {
132
+ /** Index of the hovered point. */
133
+ index: number;
134
+ /** The hovered x value; epoch milliseconds on a time chart. */
135
+ x: number;
136
+ /** `x` formatted for display. */
137
+ formattedX: string;
138
+ /** Every visible series at this index, in draw order. */
139
+ entries: ChartTooltipEntry[];
140
+ /** Position within the plot area, in CSS pixels. */
141
+ px: number;
142
+ py: number;
143
+ }
144
+ /** Detail of the `range-change` event. */
145
+ export interface ChartRangeEventDetail {
146
+ /** New lower bound of the x scale. */
147
+ min: number;
148
+ /** New upper bound of the x scale. */
149
+ max: number;
150
+ }
151
+ /** Detail of the `series-toggle` event. */
152
+ export interface ChartSeriesToggleEventDetail {
153
+ seriesIndex: number;
154
+ series: ChartSeriesConfig;
155
+ /** Whether the series is visible after the toggle. */
156
+ visible: boolean;
157
+ /** Indices of every series now hidden. */
158
+ hidden: number[];
159
+ }
160
+ /** Reads a possibly dotted `field` path out of a row. Re-exported so the package keeps its own subpath. */
161
+ export { getFieldValue } from '@c2n/core/data-helper.js';
162
+ //# sourceMappingURL=chart-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chart-types.d.ts","sourceRoot":"","sources":["../../src/chart-types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,uGAAuG;AACvG,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE9C;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,SAAS,CAAC,MAAM,CAAC,EAAE,CAAA;AAEpD;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,EAAE,GAAG,QAAQ,EAAE,GAAG,kBAAkB,GAAG,UAAU,CAAA;AAEhF;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAA;AAE1D;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,uEAAuE;IACvE,CAAC,EAAE,WAAW,CAAA;IACd,0DAA0D;IAC1D,OAAO,EAAE,WAAW,EAAE,CAAA;IACtB,yDAAyD;IACzD,MAAM,EAA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4BAA4B;IAC3C,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,iBAAiB,CAAA;IACzB,sDAAsD;IACtD,OAAO,EAAE,OAAO,CAAA;IAChB,0CAA0C;IAC1C,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB;AAED,2GAA2G;AAC3G,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The package barrel: registers every chart tag and re-exports the public API.
3
+ *
4
+ * Importing a single chart (`@c2n/chart/line-chart.js`) registers only that tag and pulls in only that
5
+ * engine; this entry exists for an application that wants them all.
6
+ */
7
+ import './line-chart.js';
8
+ import './area-chart.js';
9
+ import './bar-chart.js';
10
+ import './sparkline.js';
11
+ import './pie-chart.js';
12
+ import './chart-series.js';
13
+ export { ChartBase, type ChartEventMap } from './chart-base.js';
14
+ export { UplotChartBase, type UplotSeriesStyle } from './uplot-chart-base.js';
15
+ export { EchartsChartBase } from './echarts-chart-base.js';
16
+ export { LineChart } from './line-chart.js';
17
+ export { AreaChart } from './area-chart.js';
18
+ export { BarChart } from './bar-chart.js';
19
+ export { Sparkline } from './sparkline.js';
20
+ export { PieChart } from './pie-chart.js';
21
+ export { ChartSeries, SERIES_CHANGE_EVENT } from './chart-series.js';
22
+ export { ChartFrameBuilder, columnValue, type NormalizeContext } from './chart-data.js';
23
+ export { ChartThemeController, PALETTE_SIZE, PROBE_COLORS, type ChartTheme } from './chart-theme.js';
24
+ export type { ChartAdapter, ChartAdapterEvents, ChartBuildContext } from './chart-adapter.js';
25
+ export type { ChartColumn, ChartColumnarInput, ChartDataSource, ChartFrame, ChartInput, ChartPointEventDetail, ChartRangeEventDetail, ChartRow, ChartSeriesConfig, ChartSeriesToggleEventDetail, ChartTooltipContext, ChartTooltipEntry, ChartWindowRequest, ChartWindowResult, } from './chart-types.js';
26
+ export { isChartFrame } from './chart-types.js';
27
+ //# sourceMappingURL=chart.d.ts.map