@opendata-ai/openchart-engine 1.2.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.
- package/dist/index.d.ts +366 -0
- package/dist/index.js +4227 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
- package/src/__test-fixtures__/specs.ts +124 -0
- package/src/__tests__/axes.test.ts +114 -0
- package/src/__tests__/compile-chart.test.ts +337 -0
- package/src/__tests__/dimensions.test.ts +151 -0
- package/src/__tests__/legend.test.ts +113 -0
- package/src/__tests__/scales.test.ts +109 -0
- package/src/annotations/__tests__/compute.test.ts +454 -0
- package/src/annotations/compute.ts +603 -0
- package/src/charts/__tests__/registry.test.ts +110 -0
- package/src/charts/bar/__tests__/compute.test.ts +294 -0
- package/src/charts/bar/__tests__/labels.test.ts +75 -0
- package/src/charts/bar/compute.ts +205 -0
- package/src/charts/bar/index.ts +33 -0
- package/src/charts/bar/labels.ts +132 -0
- package/src/charts/column/__tests__/compute.test.ts +277 -0
- package/src/charts/column/compute.ts +282 -0
- package/src/charts/column/index.ts +33 -0
- package/src/charts/column/labels.ts +108 -0
- package/src/charts/dot/__tests__/compute.test.ts +344 -0
- package/src/charts/dot/compute.ts +257 -0
- package/src/charts/dot/index.ts +46 -0
- package/src/charts/dot/labels.ts +97 -0
- package/src/charts/line/__tests__/compute.test.ts +437 -0
- package/src/charts/line/__tests__/labels.test.ts +93 -0
- package/src/charts/line/area.ts +288 -0
- package/src/charts/line/compute.ts +177 -0
- package/src/charts/line/index.ts +68 -0
- package/src/charts/line/labels.ts +144 -0
- package/src/charts/pie/__tests__/compute.test.ts +276 -0
- package/src/charts/pie/compute.ts +234 -0
- package/src/charts/pie/index.ts +49 -0
- package/src/charts/pie/labels.ts +142 -0
- package/src/charts/registry.ts +64 -0
- package/src/charts/scatter/__tests__/compute.test.ts +304 -0
- package/src/charts/scatter/__tests__/trendline.test.ts +191 -0
- package/src/charts/scatter/compute.ts +124 -0
- package/src/charts/scatter/index.ts +41 -0
- package/src/charts/scatter/trendline.ts +100 -0
- package/src/charts/utils.ts +120 -0
- package/src/compile.ts +368 -0
- package/src/compiler/__tests__/compile.test.ts +87 -0
- package/src/compiler/__tests__/normalize.test.ts +210 -0
- package/src/compiler/__tests__/validate.test.ts +440 -0
- package/src/compiler/index.ts +47 -0
- package/src/compiler/normalize.ts +269 -0
- package/src/compiler/types.ts +148 -0
- package/src/compiler/validate.ts +581 -0
- package/src/graphs/__tests__/community.test.ts +228 -0
- package/src/graphs/__tests__/compile-graph.test.ts +315 -0
- package/src/graphs/__tests__/encoding.test.ts +314 -0
- package/src/graphs/community.ts +92 -0
- package/src/graphs/compile-graph.ts +291 -0
- package/src/graphs/encoding.ts +302 -0
- package/src/graphs/types.ts +98 -0
- package/src/index.ts +74 -0
- package/src/layout/axes.ts +194 -0
- package/src/layout/dimensions.ts +199 -0
- package/src/layout/gridlines.ts +84 -0
- package/src/layout/scales.ts +426 -0
- package/src/legend/compute.ts +186 -0
- package/src/tables/__tests__/bar-column.test.ts +147 -0
- package/src/tables/__tests__/category-colors.test.ts +153 -0
- package/src/tables/__tests__/compile-table.test.ts +208 -0
- package/src/tables/__tests__/format-cells.test.ts +126 -0
- package/src/tables/__tests__/heatmap.test.ts +124 -0
- package/src/tables/__tests__/pagination.test.ts +78 -0
- package/src/tables/__tests__/search.test.ts +94 -0
- package/src/tables/__tests__/sort.test.ts +107 -0
- package/src/tables/__tests__/sparkline.test.ts +122 -0
- package/src/tables/bar-column.ts +94 -0
- package/src/tables/category-colors.ts +67 -0
- package/src/tables/compile-table.ts +420 -0
- package/src/tables/format-cells.ts +110 -0
- package/src/tables/heatmap.ts +121 -0
- package/src/tables/pagination.ts +46 -0
- package/src/tables/search.ts +66 -0
- package/src/tables/sort.ts +69 -0
- package/src/tables/sparkline.ts +113 -0
- package/src/tables/utils.ts +16 -0
- package/src/tooltips/__tests__/compute.test.ts +328 -0
- package/src/tooltips/compute.ts +231 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import * as _opendata_ai_openchart_core from '@opendata-ai/openchart-core';
|
|
2
|
+
import { LegendLayout, ResolvedChrome, TooltipContent, A11yMetadata, ResolvedTheme, CompileOptions, ChartLayout, CompileTableOptions, TableLayout, ChartType, DataRow, Encoding, ChromeText, Annotation, LabelConfig, LegendConfig, ThemeConfig, DarkMode, ColumnConfig, GraphSpec, GraphEncoding, GraphLayoutConfig, VizSpec, EncodingChannel, Rect, LayoutStrategy, Mark } from '@opendata-ai/openchart-core';
|
|
3
|
+
export { ChartLayout, ChartSpec, CompileOptions, CompileTableOptions, GraphLayout, GraphSpec, TableLayout, TableSpec, VizSpec } from '@opendata-ai/openchart-core';
|
|
4
|
+
import { ScaleLinear, ScaleTime, ScaleLogarithmic, ScaleBand, ScalePoint, ScaleOrdinal } from 'd3-scale';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Graph compilation types.
|
|
8
|
+
*
|
|
9
|
+
* These types represent the engine output for graph specs. Unlike GraphLayout
|
|
10
|
+
* (which includes x/y positions for adapter rendering), GraphCompilation
|
|
11
|
+
* contains resolved visual properties WITHOUT positional layout. The force
|
|
12
|
+
* simulation in the adapter sets node positions at runtime.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** A compiled graph node with resolved visual properties (no x/y position). */
|
|
16
|
+
interface CompiledGraphNode {
|
|
17
|
+
/** Node identifier from the spec. */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Computed radius from nodeSize encoding (3-20px range, default 5px). */
|
|
20
|
+
radius: number;
|
|
21
|
+
/** Computed fill color from nodeColor encoding or community assignment. */
|
|
22
|
+
fill: string;
|
|
23
|
+
/** Stroke color, slightly darker than fill. */
|
|
24
|
+
stroke: string;
|
|
25
|
+
/** Stroke width in pixels. Default 1. */
|
|
26
|
+
strokeWidth: number;
|
|
27
|
+
/** Label text from nodeLabel encoding or node id. */
|
|
28
|
+
label: string | undefined;
|
|
29
|
+
/** Label priority for level-of-detail rendering (0-1, degree/maxDegree). */
|
|
30
|
+
labelPriority: number;
|
|
31
|
+
/** Community/cluster assignment from the clustering field. */
|
|
32
|
+
community: string | undefined;
|
|
33
|
+
/** Original node data (all fields from the spec node). */
|
|
34
|
+
data: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
/** A compiled graph edge with resolved visual properties (no positional endpoints). */
|
|
37
|
+
interface CompiledGraphEdge {
|
|
38
|
+
/** Source node id. */
|
|
39
|
+
source: string;
|
|
40
|
+
/** Target node id. */
|
|
41
|
+
target: string;
|
|
42
|
+
/** Stroke color from edgeColor encoding or theme default. */
|
|
43
|
+
stroke: string;
|
|
44
|
+
/** Stroke width from edgeWidth encoding (0.5-4px range, default 1px). */
|
|
45
|
+
strokeWidth: number;
|
|
46
|
+
/** Line style. */
|
|
47
|
+
style: 'solid' | 'dashed' | 'dotted';
|
|
48
|
+
/** Original edge data (all fields from the spec edge). */
|
|
49
|
+
data: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
/** Configuration for the force simulation, derived from the spec layout. */
|
|
52
|
+
interface SimulationConfig {
|
|
53
|
+
/** Repulsion strength between nodes. Negative = repulsion. */
|
|
54
|
+
chargeStrength: number;
|
|
55
|
+
/** Target distance between linked nodes. */
|
|
56
|
+
linkDistance: number;
|
|
57
|
+
/** Clustering configuration, or null if no clustering. */
|
|
58
|
+
clustering: {
|
|
59
|
+
field: string;
|
|
60
|
+
strength: number;
|
|
61
|
+
} | null;
|
|
62
|
+
/** How quickly the simulation cools. Default 0.0228. */
|
|
63
|
+
alphaDecay: number;
|
|
64
|
+
/** Velocity damping. Default 0.4. */
|
|
65
|
+
velocityDecay: number;
|
|
66
|
+
/** Collision radius: max node radius + padding. */
|
|
67
|
+
collisionRadius: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The complete engine output for graph specs.
|
|
71
|
+
*
|
|
72
|
+
* Contains resolved visual properties for nodes and edges, but does NOT
|
|
73
|
+
* include x/y positions. The adapter's force simulation assigns positions
|
|
74
|
+
* at runtime using the simulationConfig.
|
|
75
|
+
*/
|
|
76
|
+
interface GraphCompilation {
|
|
77
|
+
/** Compiled nodes with visual properties. */
|
|
78
|
+
nodes: CompiledGraphNode[];
|
|
79
|
+
/** Compiled edges with visual properties. */
|
|
80
|
+
edges: CompiledGraphEdge[];
|
|
81
|
+
/** Legend layout (community colors or nodeColor categories). */
|
|
82
|
+
legend: LegendLayout;
|
|
83
|
+
/** Resolved chrome text elements. */
|
|
84
|
+
chrome: ResolvedChrome;
|
|
85
|
+
/** Tooltip descriptors keyed by node id. */
|
|
86
|
+
tooltipDescriptors: Map<string, TooltipContent>;
|
|
87
|
+
/** Accessibility metadata. */
|
|
88
|
+
a11y: A11yMetadata;
|
|
89
|
+
/** Resolved theme used for rendering. */
|
|
90
|
+
theme: ResolvedTheme;
|
|
91
|
+
/** Total available dimensions. */
|
|
92
|
+
dimensions: {
|
|
93
|
+
width: number;
|
|
94
|
+
height: number;
|
|
95
|
+
};
|
|
96
|
+
/** Force simulation configuration. */
|
|
97
|
+
simulationConfig: SimulationConfig;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Main compile API: the public entry points for the engine.
|
|
102
|
+
*
|
|
103
|
+
* Pipeline for charts:
|
|
104
|
+
* validate spec -> normalize -> resolve theme -> dark mode adapt ->
|
|
105
|
+
* compute legend -> compute dimensions (with legend space) ->
|
|
106
|
+
* compute scales -> compute axes -> compute gridlines ->
|
|
107
|
+
* get chart renderer -> compute marks -> compute a11y -> return ChartLayout
|
|
108
|
+
*
|
|
109
|
+
* Table compiler handles full data pipeline (sort, search, pagination, visual enhancements).
|
|
110
|
+
* Graph compiler is a stub for future implementation.
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Compile a chart spec into a ChartLayout.
|
|
115
|
+
*
|
|
116
|
+
* This is the main engine entry point. Takes a raw spec (any shape,
|
|
117
|
+
* validated at runtime) and compile options, produces a fully resolved
|
|
118
|
+
* ChartLayout with positions, colors, and marks ready for rendering.
|
|
119
|
+
*
|
|
120
|
+
* @param spec - Raw chart spec (validated and normalized internally).
|
|
121
|
+
* @param options - Compile options (width, height, theme, darkMode).
|
|
122
|
+
* @returns ChartLayout with all computed positions.
|
|
123
|
+
* @throws Error if spec is invalid or not a chart type.
|
|
124
|
+
*/
|
|
125
|
+
declare function compileChart(spec: unknown, options: CompileOptions): ChartLayout;
|
|
126
|
+
/**
|
|
127
|
+
* Compile a table spec into a TableLayout.
|
|
128
|
+
*
|
|
129
|
+
* Validates and normalizes the spec, resolves the theme, then delegates
|
|
130
|
+
* to compileTableLayout for the full pipeline: column resolution, search,
|
|
131
|
+
* sort, pagination, cell formatting, and visual enhancements.
|
|
132
|
+
*
|
|
133
|
+
* @param spec - Raw table spec.
|
|
134
|
+
* @param options - Compile options with sort, search, pagination state.
|
|
135
|
+
* @returns Fully resolved TableLayout.
|
|
136
|
+
*/
|
|
137
|
+
declare function compileTable(spec: unknown, options: CompileTableOptions): TableLayout;
|
|
138
|
+
/**
|
|
139
|
+
* Compile a graph spec into a GraphCompilation.
|
|
140
|
+
*
|
|
141
|
+
* The graph pipeline resolves visual properties (size, color, stroke) for
|
|
142
|
+
* nodes and edges, assigns communities, and builds legend/tooltip/a11y data.
|
|
143
|
+
* Unlike charts, the output does NOT include x/y positions since the force
|
|
144
|
+
* simulation in the adapter handles layout at runtime.
|
|
145
|
+
*
|
|
146
|
+
* @param spec - Raw graph spec (validated and normalized internally).
|
|
147
|
+
* @param options - Compile options (width, height, theme, darkMode).
|
|
148
|
+
* @returns GraphCompilation with resolved visual properties and simulation config.
|
|
149
|
+
* @throws Error if spec is invalid or not a graph type.
|
|
150
|
+
*/
|
|
151
|
+
declare function compileGraph(spec: unknown, options: CompileOptions): GraphCompilation;
|
|
152
|
+
|
|
153
|
+
/** Chrome with all string values normalized to ChromeText objects. */
|
|
154
|
+
interface NormalizedChrome {
|
|
155
|
+
title?: ChromeText;
|
|
156
|
+
subtitle?: ChromeText;
|
|
157
|
+
source?: ChromeText;
|
|
158
|
+
byline?: ChromeText;
|
|
159
|
+
footer?: ChromeText;
|
|
160
|
+
}
|
|
161
|
+
/** A ChartSpec with all optional fields filled with sensible defaults. */
|
|
162
|
+
interface NormalizedChartSpec {
|
|
163
|
+
type: ChartType;
|
|
164
|
+
data: DataRow[];
|
|
165
|
+
encoding: Encoding;
|
|
166
|
+
chrome: NormalizedChrome;
|
|
167
|
+
annotations: Annotation[];
|
|
168
|
+
/** Normalized label configuration with defaults applied. density and format are always set; offsets stays optional. */
|
|
169
|
+
labels: Required<Pick<LabelConfig, 'density' | 'format'>> & Pick<LabelConfig, 'offsets'>;
|
|
170
|
+
/** Legend configuration (position override). */
|
|
171
|
+
legend?: LegendConfig;
|
|
172
|
+
responsive: boolean;
|
|
173
|
+
theme: ThemeConfig;
|
|
174
|
+
darkMode: DarkMode;
|
|
175
|
+
}
|
|
176
|
+
/** A TableSpec with all optional fields filled with sensible defaults. */
|
|
177
|
+
interface NormalizedTableSpec {
|
|
178
|
+
type: 'table';
|
|
179
|
+
data: DataRow[];
|
|
180
|
+
columns: ColumnConfig[];
|
|
181
|
+
rowKey?: string;
|
|
182
|
+
chrome: NormalizedChrome;
|
|
183
|
+
theme: ThemeConfig;
|
|
184
|
+
darkMode: DarkMode;
|
|
185
|
+
search: boolean;
|
|
186
|
+
pagination: boolean | {
|
|
187
|
+
pageSize: number;
|
|
188
|
+
};
|
|
189
|
+
stickyFirstColumn: boolean;
|
|
190
|
+
compact: boolean;
|
|
191
|
+
responsive: boolean;
|
|
192
|
+
}
|
|
193
|
+
/** A GraphSpec with all optional fields filled with sensible defaults. */
|
|
194
|
+
interface NormalizedGraphSpec {
|
|
195
|
+
type: 'graph';
|
|
196
|
+
nodes: GraphSpec['nodes'];
|
|
197
|
+
edges: GraphSpec['edges'];
|
|
198
|
+
encoding: GraphEncoding;
|
|
199
|
+
layout: GraphLayoutConfig;
|
|
200
|
+
chrome: NormalizedChrome;
|
|
201
|
+
annotations: Annotation[];
|
|
202
|
+
theme: ThemeConfig;
|
|
203
|
+
darkMode: DarkMode;
|
|
204
|
+
}
|
|
205
|
+
/** Discriminated union of all normalized spec types. */
|
|
206
|
+
type NormalizedSpec = NormalizedChartSpec | NormalizedTableSpec | NormalizedGraphSpec;
|
|
207
|
+
/** Machine-readable error code for programmatic handling. */
|
|
208
|
+
type ValidationErrorCode = 'MISSING_FIELD' | 'INVALID_TYPE' | 'INVALID_VALUE' | 'ENCODING_MISMATCH' | 'DATA_FIELD_MISSING' | 'EMPTY_DATA';
|
|
209
|
+
/** A single validation error with context. */
|
|
210
|
+
interface ValidationError {
|
|
211
|
+
/** Error message describing what's wrong. */
|
|
212
|
+
message: string;
|
|
213
|
+
/** The path to the problematic value (e.g. "encoding.x.field"). */
|
|
214
|
+
path?: string;
|
|
215
|
+
/** Machine-readable error code for programmatic handling. */
|
|
216
|
+
code: ValidationErrorCode;
|
|
217
|
+
/** Actionable suggestion for fixing the error. */
|
|
218
|
+
suggestion: string;
|
|
219
|
+
}
|
|
220
|
+
/** Result of spec validation. */
|
|
221
|
+
interface ValidationResult {
|
|
222
|
+
/** Whether the spec is valid. */
|
|
223
|
+
valid: boolean;
|
|
224
|
+
/** Validation errors (empty if valid). */
|
|
225
|
+
errors: ValidationError[];
|
|
226
|
+
/** The validated spec cast to VizSpec, or null if invalid. */
|
|
227
|
+
normalized: _opendata_ai_openchart_core.VizSpec | null;
|
|
228
|
+
}
|
|
229
|
+
/** Result of the compile pipeline (validate + normalize). */
|
|
230
|
+
interface CompileResult {
|
|
231
|
+
/** The normalized spec with all defaults applied. */
|
|
232
|
+
spec: NormalizedSpec;
|
|
233
|
+
/** Non-fatal warnings (e.g. type mismatches that were auto-corrected). */
|
|
234
|
+
warnings: string[];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Spec normalization: fill in defaults and infer types.
|
|
239
|
+
*
|
|
240
|
+
* Takes a validated VizSpec and produces a NormalizedSpec where:
|
|
241
|
+
* - All optional fields have sensible defaults
|
|
242
|
+
* - Chrome strings are converted to ChromeText objects
|
|
243
|
+
* - Encoding types are inferred from data if not specified
|
|
244
|
+
* - Annotations have default styles
|
|
245
|
+
*/
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Normalize a validated VizSpec, filling in all defaults.
|
|
249
|
+
*
|
|
250
|
+
* @param spec - A validated VizSpec (must pass validateSpec first).
|
|
251
|
+
* @param warnings - Mutable array to collect non-fatal warnings.
|
|
252
|
+
* @returns A NormalizedSpec with all optionals filled.
|
|
253
|
+
*/
|
|
254
|
+
declare function normalizeSpec(spec: VizSpec, warnings?: string[]): NormalizedSpec;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Runtime spec validation.
|
|
258
|
+
*
|
|
259
|
+
* TypeScript catches compile-time errors for specs written in code.
|
|
260
|
+
* This module catches runtime errors for specs coming from JSON, APIs,
|
|
261
|
+
* or Claude-generated output where the TypeScript compiler can't help.
|
|
262
|
+
*
|
|
263
|
+
* Every error includes a machine-readable code and an actionable suggestion
|
|
264
|
+
* so consumers (and LLMs) can fix issues programmatically.
|
|
265
|
+
*/
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Validate a spec at runtime.
|
|
269
|
+
*
|
|
270
|
+
* Checks structure, required fields, encoding rules, data shape, and
|
|
271
|
+
* field type compatibility. Returns structured errors with machine-readable
|
|
272
|
+
* codes and actionable suggestions for each problem found.
|
|
273
|
+
*/
|
|
274
|
+
declare function validateSpec(spec: unknown): ValidationResult;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Spec compiler: validate -> normalize pipeline.
|
|
278
|
+
*
|
|
279
|
+
* This is the first stage of the engine: take raw user input (possibly JSON
|
|
280
|
+
* from an API or Claude), validate it, fill in defaults, and produce a
|
|
281
|
+
* NormalizedSpec that the rest of the engine can work with safely.
|
|
282
|
+
*/
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Compile a raw spec through the validate -> normalize pipeline.
|
|
286
|
+
*
|
|
287
|
+
* @param spec - Raw spec input (unknown type, could be anything).
|
|
288
|
+
* @returns CompileResult with the normalized spec and any warnings.
|
|
289
|
+
* @throws Error if the spec is invalid.
|
|
290
|
+
*/
|
|
291
|
+
declare function compile(spec: unknown): CompileResult;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Scale computation from encoding spec + data.
|
|
295
|
+
*
|
|
296
|
+
* Creates D3 scales that map data values to pixel positions.
|
|
297
|
+
* Temporal -> scaleTime(), quantitative -> scaleLinear(),
|
|
298
|
+
* nominal/ordinal -> scaleBand() or scaleOrdinal(), depending on context.
|
|
299
|
+
*/
|
|
300
|
+
|
|
301
|
+
/** Continuous D3 scales (linear, time, log) that support .ticks() and .nice(). */
|
|
302
|
+
type D3ContinuousScale = ScaleLinear<number, number> | ScaleTime<number, number> | ScaleLogarithmic<number, number>;
|
|
303
|
+
/** Categorical D3 scales (band, point, ordinal) that support .domain() as string[]. */
|
|
304
|
+
type D3CategoricalScale = ScaleBand<string> | ScalePoint<string> | ScaleOrdinal<string, string>;
|
|
305
|
+
/** Union of all D3 scale types used by the engine. */
|
|
306
|
+
type D3Scale = D3ContinuousScale | D3CategoricalScale;
|
|
307
|
+
/**
|
|
308
|
+
* A resolved scale wrapping a d3 scale with type metadata.
|
|
309
|
+
* We need to carry the scale type around so axes and marks know
|
|
310
|
+
* how to interpret the domain/range. Consumers use the `type` discriminant
|
|
311
|
+
* to determine which D3 methods are available on the scale.
|
|
312
|
+
*/
|
|
313
|
+
interface ResolvedScale {
|
|
314
|
+
/** The d3 scale function. Maps domain value -> pixel position or color. */
|
|
315
|
+
scale: D3Scale;
|
|
316
|
+
/** The scale type for downstream use. */
|
|
317
|
+
type: 'linear' | 'time' | 'band' | 'ordinal' | 'point' | 'log' | 'sequential';
|
|
318
|
+
/** The encoding channel this scale was derived from. */
|
|
319
|
+
channel: EncodingChannel;
|
|
320
|
+
}
|
|
321
|
+
/** All resolved scales for a chart. */
|
|
322
|
+
interface ResolvedScales {
|
|
323
|
+
x?: ResolvedScale;
|
|
324
|
+
y?: ResolvedScale;
|
|
325
|
+
color?: ResolvedScale;
|
|
326
|
+
size?: ResolvedScale;
|
|
327
|
+
/** Default color for single-series charts (first categorical palette color). */
|
|
328
|
+
defaultColor?: string;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Chart renderer registry.
|
|
333
|
+
*
|
|
334
|
+
* Each chart type (line, bar, column, scatter, pie, donut, dot) registers
|
|
335
|
+
* a renderer that produces marks from normalized specs and resolved scales.
|
|
336
|
+
* The registry pattern decouples chart-type logic from the compile pipeline.
|
|
337
|
+
*/
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* A chart renderer function.
|
|
341
|
+
*
|
|
342
|
+
* Takes a normalized spec, resolved scales, chart area, layout strategy,
|
|
343
|
+
* and the resolved theme for theme-aware styling (e.g. label colors).
|
|
344
|
+
* Returns an array of marks to render.
|
|
345
|
+
*/
|
|
346
|
+
type ChartRenderer = (spec: NormalizedChartSpec, scales: ResolvedScales, chartArea: Rect, strategy: LayoutStrategy, theme: ResolvedTheme) => Mark[];
|
|
347
|
+
/**
|
|
348
|
+
* Register a chart renderer for a specific chart type.
|
|
349
|
+
*
|
|
350
|
+
* @param type - Chart type string (e.g. "line", "bar").
|
|
351
|
+
* @param renderer - The renderer function.
|
|
352
|
+
*/
|
|
353
|
+
declare function registerChartRenderer(type: string, renderer: ChartRenderer): void;
|
|
354
|
+
/**
|
|
355
|
+
* Get the registered chart renderer for a type.
|
|
356
|
+
*
|
|
357
|
+
* @param type - Chart type string.
|
|
358
|
+
* @returns The renderer, or undefined if no renderer is registered.
|
|
359
|
+
*/
|
|
360
|
+
declare function getChartRenderer(type: string): ChartRenderer | undefined;
|
|
361
|
+
/**
|
|
362
|
+
* Clear all registered renderers. Useful for testing.
|
|
363
|
+
*/
|
|
364
|
+
declare function clearRenderers(): void;
|
|
365
|
+
|
|
366
|
+
export { type ChartRenderer, type CompileResult, type CompiledGraphEdge, type CompiledGraphNode, type GraphCompilation, type NormalizedChartSpec, type NormalizedChrome, type NormalizedGraphSpec, type NormalizedSpec, type NormalizedTableSpec, type SimulationConfig, type ValidationError, type ValidationErrorCode, type ValidationResult, clearRenderers, compile, compileChart, compileGraph, compileTable, getChartRenderer, normalizeSpec, registerChartRenderer, validateSpec };
|