@opendata-ai/openchart-engine 6.25.4 → 6.27.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 +82 -4
- package/dist/index.js +1027 -76
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/__test-fixtures__/specs.ts +33 -0
- package/src/__tests__/__snapshots__/compile-snapshot.test.ts.snap +6 -0
- package/src/__tests__/compile-chart.test.ts +301 -0
- package/src/__tests__/compound-labels.test.ts +147 -0
- package/src/charts/line/area.ts +1 -1
- package/src/charts/line/compute.ts +7 -1
- package/src/compile.ts +222 -17
- package/src/compiler/normalize.ts +83 -1
- package/src/compiler/types.ts +41 -1
- package/src/compiler/validate.ts +124 -5
- package/src/index.ts +16 -1
- package/src/layout/axes/ticks.ts +34 -2
- package/src/layout/axes.ts +36 -3
- package/src/layout/dimensions.ts +98 -5
- package/src/legend/compute.ts +6 -1
- package/src/sankey/compile-sankey.ts +1 -1
- package/src/tilemap/__tests__/compile-tilemap.test.ts +322 -0
- package/src/tilemap/compile-tilemap.ts +383 -0
- package/src/tilemap/layout.ts +172 -0
- package/src/tilemap/types.ts +32 -0
- package/src/transforms/__tests__/filter-relative.test.ts +202 -0
- package/src/transforms/__tests__/window.test.ts +286 -0
- package/src/transforms/filter.ts +108 -3
- package/src/transforms/index.ts +5 -1
- package/src/transforms/predicates.ts +39 -9
- package/src/transforms/window.ts +185 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _opendata_ai_openchart_core from '@opendata-ai/openchart-core';
|
|
2
|
-
import { LegendLayout, ResolvedChrome, TooltipContent, A11yMetadata, ResolvedTheme, CompileOptions, ChartLayout, LayerSpec, CompileTableOptions, TableLayout, AnimationSpec, ResolvedAnimation, MarkType, MarkDef, DataRow, Encoding, ChromeText, Annotation, LabelConfig,
|
|
3
|
-
export { ChartLayout, ChartSpec, CompileOptions, CompileTableOptions, GraphLayout, GraphSpec, LayerSpec, SankeyLayout, SankeySpec, TableLayout, TableSpec, VizSpec } from '@opendata-ai/openchart-core';
|
|
2
|
+
import { LegendLayout, ResolvedChrome, TooltipContent, A11yMetadata, ResolvedTheme, CompileOptions, ChartLayout, LayerSpec, CompileTableOptions, TableLayout, AnimationSpec, ResolvedAnimation, TileMapEncoding, TileMapPalette, LegendConfig, ThemeConfig, DarkMode, MarkType, MarkDef, DataRow, Encoding, ChromeText, Annotation, LabelConfig, Display, ColumnConfig, GraphSpec, GraphEncoding, GraphLayoutConfig, NodeOverride, SankeyEncoding, SankeyNodeAlign, SankeyLinkColor, VizSpec, ScaleType, EncodingChannel, Rect, LayoutStrategy, Mark, BinTransform, CalculateTransform, ConditionalValueDef, FilterPredicate, TimeUnitTransform, Transform } from '@opendata-ai/openchart-core';
|
|
3
|
+
export { ChartLayout, ChartSpec, CompileOptions, CompileTableOptions, GraphLayout, GraphSpec, LayerSpec, SankeyLayout, SankeySpec, TableLayout, TableSpec, TileMapLayout, TileMapSpec, VizSpec } from '@opendata-ai/openchart-core';
|
|
4
4
|
import { ScaleLinear, ScaleTime, ScaleLogarithmic, ScalePower, ScaleSymLog, ScaleBand, ScalePoint, ScaleOrdinal, ScaleQuantile, ScaleQuantize, ScaleThreshold } from 'd3-scale';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -169,6 +169,19 @@ declare function compileGraph(spec: unknown, options: CompileOptions): GraphComp
|
|
|
169
169
|
* @throws Error if spec is invalid or not a sankey type.
|
|
170
170
|
*/
|
|
171
171
|
declare function compileSankey(spec: unknown, options: CompileOptions): _opendata_ai_openchart_core.SankeyLayout;
|
|
172
|
+
/**
|
|
173
|
+
* Compile a tilemap spec into a TileMapLayout.
|
|
174
|
+
*
|
|
175
|
+
* Takes a raw tilemap spec, validates, normalizes, resolves theme and chrome,
|
|
176
|
+
* computes tile positions, builds tile marks with colors and labels, and
|
|
177
|
+
* returns a TileMapLayout ready for rendering.
|
|
178
|
+
*
|
|
179
|
+
* @param spec - Raw tilemap spec (validated and normalized internally).
|
|
180
|
+
* @param options - Compile options (width, height, theme, darkMode).
|
|
181
|
+
* @returns TileMapLayout with computed positions and visual properties.
|
|
182
|
+
* @throws Error if spec is invalid or not a tilemap type.
|
|
183
|
+
*/
|
|
184
|
+
declare function compileTileMap(spec: unknown, options: CompileOptions): _opendata_ai_openchart_core.TileMapLayout;
|
|
172
185
|
|
|
173
186
|
/**
|
|
174
187
|
* Animation resolver: normalizes AnimationSpec into fully resolved config.
|
|
@@ -189,6 +202,28 @@ declare function resolveAnimation(spec: AnimationSpec | undefined): ResolvedAnim
|
|
|
189
202
|
*/
|
|
190
203
|
declare function clampStaggerDelay(delay: number, elementCount: number): number;
|
|
191
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Internal normalized tilemap spec type used by the compilation pipeline.
|
|
207
|
+
*
|
|
208
|
+
* This mirrors NormalizedSankeySpec: all optional fields have been filled
|
|
209
|
+
* with sensible defaults. It's an engine implementation detail, not a public contract.
|
|
210
|
+
*/
|
|
211
|
+
|
|
212
|
+
/** A TileMapSpec with all optional fields filled with defaults. */
|
|
213
|
+
interface NormalizedTileMapSpec {
|
|
214
|
+
type: 'tilemap';
|
|
215
|
+
data: Record<string, unknown>[];
|
|
216
|
+
encoding: TileMapEncoding;
|
|
217
|
+
palette: TileMapPalette;
|
|
218
|
+
chrome: NormalizedChrome;
|
|
219
|
+
legend?: LegendConfig;
|
|
220
|
+
theme: ThemeConfig;
|
|
221
|
+
darkMode: DarkMode;
|
|
222
|
+
watermark: boolean;
|
|
223
|
+
animation?: AnimationSpec;
|
|
224
|
+
valueFormat?: string;
|
|
225
|
+
}
|
|
226
|
+
|
|
192
227
|
/** Chrome with all string values normalized to ChromeText objects. */
|
|
193
228
|
interface NormalizedChrome {
|
|
194
229
|
title?: ChromeText;
|
|
@@ -197,6 +232,34 @@ interface NormalizedChrome {
|
|
|
197
232
|
byline?: ChromeText;
|
|
198
233
|
footer?: ChromeText;
|
|
199
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Tracks which top-level fields the user explicitly set in their input spec.
|
|
237
|
+
*
|
|
238
|
+
* Built from the raw expandedSpec (post-breakpoint-merge, pre-normalize) so
|
|
239
|
+
* that "user wrote chrome.title" vs "user wrote nothing" is distinguishable
|
|
240
|
+
* after normalization fills in defaults.
|
|
241
|
+
*
|
|
242
|
+
* Used by sparkline display mode to decide whether to suppress chrome/axes/
|
|
243
|
+
* legend/etc. by default vs. respecting an explicit user opt-in.
|
|
244
|
+
*/
|
|
245
|
+
interface UserExplicit {
|
|
246
|
+
/** True if user wrote `chrome` (any non-empty chrome). */
|
|
247
|
+
chrome: boolean;
|
|
248
|
+
/** True if user wrote `legend`. */
|
|
249
|
+
legend: boolean;
|
|
250
|
+
/** True if user wrote `encoding.x.axis`. */
|
|
251
|
+
xAxis: boolean;
|
|
252
|
+
/** True if user wrote `encoding.y.axis`. */
|
|
253
|
+
yAxis: boolean;
|
|
254
|
+
/** True if user wrote `labels`. */
|
|
255
|
+
labels: boolean;
|
|
256
|
+
/** True if user wrote `animation`. */
|
|
257
|
+
animation: boolean;
|
|
258
|
+
/** True if user wrote `watermark`. */
|
|
259
|
+
watermark: boolean;
|
|
260
|
+
/** True if user wrote `crosshair`. */
|
|
261
|
+
crosshair: boolean;
|
|
262
|
+
}
|
|
200
263
|
/** A ChartSpec with all optional fields filled with sensible defaults. */
|
|
201
264
|
interface NormalizedChartSpec {
|
|
202
265
|
/** Resolved mark type string (extracted from spec.mark). */
|
|
@@ -220,6 +283,14 @@ interface NormalizedChartSpec {
|
|
|
220
283
|
hiddenSeries: string[];
|
|
221
284
|
/** Per-series visual style overrides. */
|
|
222
285
|
seriesStyles: Record<string, _opendata_ai_openchart_core.SeriesStyle>;
|
|
286
|
+
/** Display mode controlling chrome/axes/legend stripping. Defaults to `'full'`. */
|
|
287
|
+
display: Display;
|
|
288
|
+
/**
|
|
289
|
+
* Which top-level fields the user explicitly set. Populated by compileChart
|
|
290
|
+
* from the raw expanded spec before normalization. NormalizeChartSpec runs
|
|
291
|
+
* with a default-empty descriptor; compileChart overwrites it post-normalize.
|
|
292
|
+
*/
|
|
293
|
+
userExplicit: UserExplicit;
|
|
223
294
|
}
|
|
224
295
|
/** A TableSpec with all optional fields filled with sensible defaults. */
|
|
225
296
|
interface NormalizedTableSpec {
|
|
@@ -255,7 +326,7 @@ interface NormalizedGraphSpec {
|
|
|
255
326
|
watermark: boolean;
|
|
256
327
|
}
|
|
257
328
|
/** Discriminated union of all normalized spec types. */
|
|
258
|
-
type NormalizedSpec = NormalizedChartSpec | NormalizedTableSpec | NormalizedGraphSpec | NormalizedSankeySpec;
|
|
329
|
+
type NormalizedSpec = NormalizedChartSpec | NormalizedTableSpec | NormalizedGraphSpec | NormalizedSankeySpec | NormalizedTileMapSpec;
|
|
259
330
|
/** Machine-readable error code for programmatic handling. */
|
|
260
331
|
type ValidationErrorCode = 'MISSING_FIELD' | 'INVALID_TYPE' | 'INVALID_VALUE' | 'ENCODING_MISMATCH' | 'DATA_FIELD_MISSING' | 'EMPTY_DATA';
|
|
261
332
|
/** A single validation error with context. */
|
|
@@ -499,11 +570,18 @@ declare function isConditionalValueDef(def: unknown): def is ConditionalValueDef
|
|
|
499
570
|
|
|
500
571
|
/**
|
|
501
572
|
* Filter transform: removes rows that don't match a predicate.
|
|
573
|
+
*
|
|
574
|
+
* Supports RelativeTimeRef values on comparison properties (lt, lte, gt, gte, range).
|
|
575
|
+
* These are resolved against the data extent before filtering.
|
|
502
576
|
*/
|
|
503
577
|
|
|
504
578
|
/**
|
|
505
579
|
* Filter data rows by a predicate.
|
|
506
580
|
*
|
|
581
|
+
* If the predicate contains RelativeTimeRef values, they are resolved
|
|
582
|
+
* against the data extent first, then the standard evaluatePredicate
|
|
583
|
+
* logic runs per-row.
|
|
584
|
+
*
|
|
507
585
|
* @param data - Input rows.
|
|
508
586
|
* @param predicate - Filter predicate to evaluate per row.
|
|
509
587
|
* @returns Rows that pass the predicate.
|
|
@@ -564,4 +642,4 @@ declare function runTimeUnit(data: DataRow[], transform: TimeUnitTransform): Dat
|
|
|
564
642
|
*/
|
|
565
643
|
declare function runTransforms(data: DataRow[], transforms: Transform[]): DataRow[];
|
|
566
644
|
|
|
567
|
-
export { type ChartRenderer, type CompileResult, type CompiledGraphEdge, type CompiledGraphNode, type GraphCompilation, type NormalizedChartSpec, type NormalizedChrome, type NormalizedGraphSpec, type NormalizedSankeySpec, type NormalizedSpec, type NormalizedTableSpec, type SimulationConfig, type ValidationError, type ValidationErrorCode, type ValidationResult, clampStaggerDelay, clearRenderers, compile, compileChart, compileGraph, compileLayer, compileSankey, compileTable, evaluatePredicate, getChartRenderer, isConditionalValueDef, normalizeSpec, registerChartRenderer, resolveAnimation, resolveConditionalValue, runBin, runCalculate, runFilter, runTimeUnit, runTransforms, validateSpec };
|
|
645
|
+
export { type ChartRenderer, type CompileResult, type CompiledGraphEdge, type CompiledGraphNode, type GraphCompilation, type NormalizedChartSpec, type NormalizedChrome, type NormalizedGraphSpec, type NormalizedSankeySpec, type NormalizedSpec, type NormalizedTableSpec, type NormalizedTileMapSpec, type SimulationConfig, type ValidationError, type ValidationErrorCode, type ValidationResult, clampStaggerDelay, clearRenderers, compile, compileChart, compileGraph, compileLayer, compileSankey, compileTable, compileTileMap, evaluatePredicate, getChartRenderer, isConditionalValueDef, normalizeSpec, registerChartRenderer, resolveAnimation, resolveConditionalValue, runBin, runCalculate, runFilter, runTimeUnit, runTransforms, validateSpec };
|