@opendata-ai/openchart-core 6.25.3 → 6.26.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/src/types/spec.ts CHANGED
@@ -240,6 +240,8 @@ export interface AxisConfig {
240
240
  labelPadding?: number;
241
241
  /** Color override for axis tick labels and title. Useful in dual-axis charts to match axis color to its series. */
242
242
  labelColor?: string;
243
+ /** Secondary data field to display alongside each tick label. Renders in lighter weight/color. Only effective on categorical y-axis labels (horizontal bar charts). */
244
+ labelField?: string;
243
245
  }
244
246
 
245
247
  /** Scale configuration for an encoding channel. */
@@ -705,6 +707,9 @@ export interface LabelConfig {
705
707
  offsets?: Record<string, AnnotationOffset>;
706
708
  }
707
709
 
710
+ /** Shorthand: `false` disables all labels, `true` uses defaults, or pass a full config object. */
711
+ export type LabelSpec = boolean | LabelConfig;
712
+
708
713
  // ---------------------------------------------------------------------------
709
714
  // Legend configuration
710
715
  // ---------------------------------------------------------------------------
@@ -813,7 +818,7 @@ export interface ChartSpecOverride {
813
818
  /** Override editorial chrome at this breakpoint. */
814
819
  chrome?: Chrome;
815
820
  /** Override label configuration at this breakpoint. */
816
- labels?: LabelConfig;
821
+ labels?: LabelSpec;
817
822
  /** Override legend configuration at this breakpoint. */
818
823
  legend?: LegendConfig;
819
824
  /** Override annotations at this breakpoint. */
@@ -846,8 +851,8 @@ export interface ChartSpec {
846
851
  chrome?: Chrome;
847
852
  /** Data annotations (text callouts, highlighted ranges, reference lines). */
848
853
  annotations?: Annotation[];
849
- /** Label display configuration (density, format). */
850
- labels?: LabelConfig;
854
+ /** Label display configuration. `false` disables all labels, `true` uses defaults. */
855
+ labels?: LabelSpec;
851
856
  /** Legend display configuration (position override). */
852
857
  legend?: LegendConfig;
853
858
  /** Whether the chart adapts to container width. Defaults to true. */
@@ -875,6 +880,12 @@ export interface ChartSpec {
875
880
  * - AnimationConfig: full control via enter/update/exit phases
876
881
  */
877
882
  animation?: AnimationSpec;
883
+ /**
884
+ * Show a vertical crosshair line that tracks the nearest data point on
885
+ * line and area charts. Only active when a voronoi overlay is present.
886
+ * Defaults to false.
887
+ */
888
+ crosshair?: boolean;
878
889
  /**
879
890
  * Render order within a LayerSpec. Higher values render on top.
880
891
  * When omitted, layers render in array order (later layers paint on top).
@@ -1019,8 +1030,8 @@ export interface LayerSpec {
1019
1030
  chrome?: Chrome;
1020
1031
  /** Annotations on the layered view. */
1021
1032
  annotations?: Annotation[];
1022
- /** Label display configuration. */
1023
- labels?: LabelConfig;
1033
+ /** Label display configuration. `false` disables all labels, `true` uses defaults. */
1034
+ labels?: LabelSpec;
1024
1035
  /** Legend display configuration. */
1025
1036
  legend?: LegendConfig;
1026
1037
  /** Whether the chart adapts to container width. Defaults to true. */
@@ -1117,6 +1128,58 @@ export interface SankeySpec {
1117
1128
  valueFormat?: string;
1118
1129
  }
1119
1130
 
1131
+ // ---------------------------------------------------------------------------
1132
+ // TileMap spec (US state tile grid map)
1133
+ // ---------------------------------------------------------------------------
1134
+
1135
+ /** Encoding channels specific to tile map visualizations. */
1136
+ export interface TileMapEncoding {
1137
+ /** State code field (required, nominal). Maps to US state abbreviations. */
1138
+ state: EncodingChannel;
1139
+ /** Value field (required, quantitative). Maps to the sequential color scale. */
1140
+ value: EncodingChannel;
1141
+ /** Tooltip encoding (optional). */
1142
+ tooltip?: EncodingChannel | EncodingChannel[];
1143
+ }
1144
+
1145
+ /** Sequential color palette names available for tile maps. */
1146
+ export type TileMapPalette = 'blue' | 'green' | 'orange' | 'purple';
1147
+
1148
+ export interface TileMapSpec {
1149
+ /** Discriminant: always "tilemap". */
1150
+ type: 'tilemap';
1151
+ /**
1152
+ * Data for the tile map. Accepts either:
1153
+ * - A record mapping state codes to numeric values: `{ "CA": 12000, "TX": 8500 }`
1154
+ * - Tabular data rows with state and value fields (requires encoding)
1155
+ */
1156
+ data: Record<string, number | null> | DataRow[];
1157
+ /**
1158
+ * Encoding channels mapping data fields to visual properties.
1159
+ * Required when data is DataRow[]. Auto-generated when data is a record map.
1160
+ */
1161
+ encoding?: TileMapEncoding;
1162
+ /** Sequential color palette. Defaults to 'blue'. */
1163
+ palette?: TileMapPalette;
1164
+ /** Editorial chrome (title, subtitle, source, byline, footer). */
1165
+ chrome?: Chrome;
1166
+ /** Legend display configuration. */
1167
+ legend?: LegendConfig;
1168
+ /** Theme configuration overrides. */
1169
+ theme?: ThemeConfig;
1170
+ /** Dark mode behavior. Defaults to "off". */
1171
+ darkMode?: DarkMode;
1172
+ /** Whether to show the tryOpenData.ai watermark. Defaults to true. */
1173
+ watermark?: boolean;
1174
+ /** Animation configuration for entrance animations. */
1175
+ animation?: AnimationSpec;
1176
+ /**
1177
+ * d3-format string applied to tile values, legend labels, and tooltips.
1178
+ * Examples: ".1f" for one decimal, "$,.0f" for currency, "~s" for SI.
1179
+ */
1180
+ valueFormat?: string;
1181
+ }
1182
+
1120
1183
  /**
1121
1184
  * Top-level visualization spec: union discriminated by structural shape.
1122
1185
  *
@@ -1125,8 +1188,9 @@ export interface SankeySpec {
1125
1188
  * - TableSpec: has `type: 'table'`
1126
1189
  * - GraphSpec: has `type: 'graph'`
1127
1190
  * - SankeySpec: has `type: 'sankey'`
1191
+ * - TileMapSpec: has `type: 'tilemap'`
1128
1192
  */
1129
- export type VizSpec = ChartSpec | LayerSpec | TableSpec | GraphSpec | SankeySpec;
1193
+ export type VizSpec = ChartSpec | LayerSpec | TableSpec | GraphSpec | SankeySpec | TileMapSpec;
1130
1194
 
1131
1195
  /** Chart spec without runtime data, for persistence/storage. */
1132
1196
  export type ChartSpecWithoutData = Omit<ChartSpec, 'data'>;
@@ -1136,12 +1200,15 @@ export type TableSpecWithoutData = Omit<TableSpec, 'data' | 'columns'>;
1136
1200
  export type GraphSpecWithoutData = Omit<GraphSpec, 'nodes' | 'edges'>;
1137
1201
  /** Sankey spec without runtime data, for persistence/storage. */
1138
1202
  export type SankeySpecWithoutData = Omit<SankeySpec, 'data'>;
1203
+ /** TileMap spec without runtime data, for persistence/storage. */
1204
+ export type TileMapSpecWithoutData = Omit<TileMapSpec, 'data'>;
1139
1205
  /** Union of data-stripped spec types for persistence/storage. */
1140
1206
  export type StoredVizSpec =
1141
1207
  | ChartSpecWithoutData
1142
1208
  | TableSpecWithoutData
1143
1209
  | GraphSpecWithoutData
1144
- | SankeySpecWithoutData;
1210
+ | SankeySpecWithoutData
1211
+ | TileMapSpecWithoutData;
1145
1212
 
1146
1213
  // ---------------------------------------------------------------------------
1147
1214
  // Transforms (Vega-Lite aligned)
@@ -1162,6 +1229,13 @@ export interface LogicalNot<T> {
1162
1229
  not: T;
1163
1230
  }
1164
1231
 
1232
+ /** A relative-time reference that resolves against the data extent. */
1233
+ export interface RelativeTimeRef {
1234
+ anchor: 'max' | 'min';
1235
+ offset: number;
1236
+ unit: 'day' | 'week' | 'month' | 'quarter' | 'year';
1237
+ }
1238
+
1165
1239
  /** A predicate that tests a field value against a condition. */
1166
1240
  export interface FieldPredicate {
1167
1241
  /** Data field to test. */
@@ -1169,15 +1243,15 @@ export interface FieldPredicate {
1169
1243
  /** Equals comparison. */
1170
1244
  equal?: unknown;
1171
1245
  /** Less than. */
1172
- lt?: number;
1246
+ lt?: number | RelativeTimeRef;
1173
1247
  /** Less than or equal. */
1174
- lte?: number;
1248
+ lte?: number | RelativeTimeRef;
1175
1249
  /** Greater than. */
1176
- gt?: number;
1250
+ gt?: number | RelativeTimeRef;
1177
1251
  /** Greater than or equal. */
1178
- gte?: number;
1252
+ gte?: number | RelativeTimeRef;
1179
1253
  /** Inclusive range [min, max]. */
1180
- range?: [number, number];
1254
+ range?: [number | RelativeTimeRef, number | RelativeTimeRef];
1181
1255
  /** Value is one of these. */
1182
1256
  oneOf?: unknown[];
1183
1257
  /** Whether the value is valid (non-null, non-undefined, non-NaN). */
@@ -1283,6 +1357,33 @@ export interface FoldTransform {
1283
1357
  as?: [string, string];
1284
1358
  }
1285
1359
 
1360
+ /** Window operation types for computing values relative to other rows. */
1361
+ export type WindowOp = 'lag' | 'lead' | 'diff' | 'pct_change' | 'cumsum' | 'rank' | 'first_value';
1362
+
1363
+ /** Sort field definition for window transforms. */
1364
+ export interface WindowSortField {
1365
+ field: string;
1366
+ order?: 'ascending' | 'descending';
1367
+ }
1368
+
1369
+ /** Window field definition specifying which operation to compute. */
1370
+ export interface WindowFieldDef {
1371
+ op: WindowOp;
1372
+ field: string;
1373
+ /** Row offset for lag/lead/diff/pct_change. Defaults to 1. */
1374
+ offset?: number;
1375
+ as: string;
1376
+ }
1377
+
1378
+ /** Window transform: computes values relative to other rows in sort order within a partition. */
1379
+ export interface WindowTransform {
1380
+ window: WindowFieldDef[];
1381
+ /** Fields to sort by within each partition. */
1382
+ sort: WindowSortField[];
1383
+ /** Fields to partition (group) by. Each group is windowed independently. */
1384
+ groupby?: string[];
1385
+ }
1386
+
1286
1387
  /** Discriminated union of all transform types. */
1287
1388
  export type Transform =
1288
1389
  | FilterTransform
@@ -1290,7 +1391,8 @@ export type Transform =
1290
1391
  | CalculateTransform
1291
1392
  | TimeUnitTransform
1292
1393
  | AggregateTransform
1293
- | FoldTransform;
1394
+ | FoldTransform
1395
+ | WindowTransform;
1294
1396
 
1295
1397
  // ---------------------------------------------------------------------------
1296
1398
  // Conditional encoding (Vega-Lite aligned)
@@ -1409,6 +1511,11 @@ export function isSankeySpec(spec: VizSpec | Record<string, unknown>): spec is S
1409
1511
  return 'type' in spec && (spec as Record<string, unknown>).type === 'sankey';
1410
1512
  }
1411
1513
 
1514
+ /** Check if a spec is a TileMapSpec. */
1515
+ export function isTileMapSpec(spec: VizSpec | Record<string, unknown>): spec is TileMapSpec {
1516
+ return 'type' in spec && (spec as Record<string, unknown>).type === 'tilemap';
1517
+ }
1518
+
1412
1519
  // ---------------------------------------------------------------------------
1413
1520
  // Annotation type guards
1414
1521
  // ---------------------------------------------------------------------------