@opendata-ai/openchart-core 6.5.1 → 6.6.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 CHANGED
@@ -895,6 +895,51 @@ interface LayerSpec {
895
895
  /** Animation configuration. */
896
896
  animation?: AnimationSpec;
897
897
  }
898
+ /** Node alignment strategy for sankey layout. */
899
+ type SankeyNodeAlign = 'left' | 'right' | 'center' | 'justify';
900
+ /** Link coloring strategy for sankey diagrams. */
901
+ type SankeyLinkColor = 'gradient' | 'source' | 'target' | 'neutral';
902
+ /** Encoding channels specific to sankey diagrams. */
903
+ interface SankeyEncoding {
904
+ /** Source node field (required, nominal). */
905
+ source: EncodingChannel;
906
+ /** Target node field (required, nominal). */
907
+ target: EncodingChannel;
908
+ /** Flow value field (required, quantitative). */
909
+ value: EncodingChannel;
910
+ /** Color encoding for nodes/links (optional, nominal). */
911
+ color?: EncodingChannel;
912
+ /** Tooltip encoding (optional). */
913
+ tooltip?: EncodingChannel | EncodingChannel[];
914
+ }
915
+ interface SankeySpec {
916
+ /** Discriminant: always "sankey". */
917
+ type: 'sankey';
918
+ /** Tabular flow data. Each row is a source-target-value link. */
919
+ data: DataRow[];
920
+ /** Encoding channels mapping data fields to visual properties. */
921
+ encoding: SankeyEncoding;
922
+ /** Width of node rectangles in pixels. Defaults to 12. */
923
+ nodeWidth?: number;
924
+ /** Vertical padding between nodes in pixels. Defaults to 16. */
925
+ nodePadding?: number;
926
+ /** Node alignment algorithm. Defaults to 'justify'. */
927
+ nodeAlign?: SankeyNodeAlign;
928
+ /** Number of layout relaxation iterations. Defaults to 6. */
929
+ iterations?: number;
930
+ /** Link coloring strategy. Defaults to 'gradient'. */
931
+ linkStyle?: SankeyLinkColor;
932
+ /** Editorial chrome (title, subtitle, source, byline, footer). */
933
+ chrome?: Chrome;
934
+ /** Legend display configuration. */
935
+ legend?: LegendConfig;
936
+ /** Theme configuration overrides. */
937
+ theme?: ThemeConfig;
938
+ /** Dark mode behavior. Defaults to "off". */
939
+ darkMode?: DarkMode;
940
+ /** Animation configuration for entrance animations. */
941
+ animation?: AnimationSpec;
942
+ }
898
943
  /**
899
944
  * Top-level visualization spec: union discriminated by structural shape.
900
945
  *
@@ -902,16 +947,19 @@ interface LayerSpec {
902
947
  * - LayerSpec: has `layer` field
903
948
  * - TableSpec: has `type: 'table'`
904
949
  * - GraphSpec: has `type: 'graph'`
950
+ * - SankeySpec: has `type: 'sankey'`
905
951
  */
906
- type VizSpec = ChartSpec | LayerSpec | TableSpec | GraphSpec;
952
+ type VizSpec = ChartSpec | LayerSpec | TableSpec | GraphSpec | SankeySpec;
907
953
  /** Chart spec without runtime data, for persistence/storage. */
908
954
  type ChartSpecWithoutData = Omit<ChartSpec, 'data'>;
909
955
  /** Table spec without runtime data and columns, for persistence/storage. Columns can be auto-generated via dataTable(). */
910
956
  type TableSpecWithoutData = Omit<TableSpec, 'data' | 'columns'>;
911
957
  /** Graph spec without runtime data, for persistence/storage. */
912
958
  type GraphSpecWithoutData = Omit<GraphSpec, 'nodes' | 'edges'>;
959
+ /** Sankey spec without runtime data, for persistence/storage. */
960
+ type SankeySpecWithoutData = Omit<SankeySpec, 'data'>;
913
961
  /** Union of data-stripped spec types for persistence/storage. */
914
- type StoredVizSpec = ChartSpecWithoutData | TableSpecWithoutData | GraphSpecWithoutData;
962
+ type StoredVizSpec = ChartSpecWithoutData | TableSpecWithoutData | GraphSpecWithoutData | SankeySpecWithoutData;
915
963
  /** Logical AND combinator for filter predicates. */
916
964
  interface LogicalAnd<T> {
917
965
  and: T[];
@@ -1053,6 +1101,8 @@ declare function isLayerSpec(spec: VizSpec | Record<string, unknown>): spec is L
1053
1101
  declare function isTableSpec(spec: VizSpec | Record<string, unknown>): spec is TableSpec;
1054
1102
  /** Check if a spec is a GraphSpec. */
1055
1103
  declare function isGraphSpec(spec: VizSpec | Record<string, unknown>): spec is GraphSpec;
1104
+ /** Check if a spec is a SankeySpec. */
1105
+ declare function isSankeySpec(spec: VizSpec | Record<string, unknown>): spec is SankeySpec;
1056
1106
  /** Check if an annotation is a TextAnnotation. */
1057
1107
  declare function isTextAnnotation(annotation: Annotation): annotation is TextAnnotation;
1058
1108
  /** Check if an annotation is a RangeAnnotation. */
@@ -1837,8 +1887,8 @@ interface ResolvedLabel {
1837
1887
  to: Point;
1838
1888
  /** Connector line color. */
1839
1889
  stroke: string;
1840
- /** Connector style: straight line, curved arrow, or directional caret. */
1841
- style: 'straight' | 'curve' | 'caret';
1890
+ /** Connector style: straight line or curved arrow. */
1891
+ style: 'straight' | 'curve';
1842
1892
  };
1843
1893
  /** Background color behind the label text. */
1844
1894
  background?: string;
@@ -2218,6 +2268,98 @@ interface GraphLayout {
2218
2268
  height: number;
2219
2269
  };
2220
2270
  }
2271
+ /** A resolved sankey node with computed position and visual properties. */
2272
+ interface SankeyNodeMark {
2273
+ type: 'sankeyNode';
2274
+ /** Left edge x position. */
2275
+ x: number;
2276
+ /** Top edge y position. */
2277
+ y: number;
2278
+ /** Node rectangle width. */
2279
+ width: number;
2280
+ /** Node rectangle height (proportional to throughput). */
2281
+ height: number;
2282
+ /** Fill color. */
2283
+ fill: string;
2284
+ /** Stroke color. */
2285
+ stroke?: string;
2286
+ /** Stroke width. */
2287
+ strokeWidth?: number;
2288
+ /** Corner radius for subtle rounding. */
2289
+ cornerRadius: number;
2290
+ /** Node label positioned outside the node. */
2291
+ label: ResolvedLabel;
2292
+ /** Node identifier (unique across the diagram). */
2293
+ nodeId: string;
2294
+ /** Total value flowing through this node. */
2295
+ value: number;
2296
+ /** Depth column (0 = leftmost). */
2297
+ depth: number;
2298
+ /** Original data associated with this node. */
2299
+ data: Record<string, unknown>;
2300
+ /** Accessibility attributes. */
2301
+ aria: MarkAria;
2302
+ /** Index for stagger animation ordering. */
2303
+ animationIndex?: number;
2304
+ }
2305
+ /** A resolved sankey link with computed path and visual properties. */
2306
+ interface SankeyLinkMark {
2307
+ type: 'sankeyLink';
2308
+ /** SVG path string for the curved ribbon. */
2309
+ path: string;
2310
+ /** Source node color (for gradient start). */
2311
+ sourceColor: string;
2312
+ /** Target node color (for gradient end). */
2313
+ targetColor: string;
2314
+ /** Fill opacity (0.35 default, increases on hover). */
2315
+ fillOpacity: number;
2316
+ /** Source node identifier. */
2317
+ sourceId: string;
2318
+ /** Target node identifier. */
2319
+ targetId: string;
2320
+ /** Link ribbon width at its thinnest point. */
2321
+ width: number;
2322
+ /** Flow value this link represents. */
2323
+ value: number;
2324
+ /** Original data row for this link. */
2325
+ data: Record<string, unknown>;
2326
+ /** Accessibility attributes. */
2327
+ aria: MarkAria;
2328
+ /** Index for stagger animation ordering. */
2329
+ animationIndex?: number;
2330
+ }
2331
+ /**
2332
+ * SankeyLayout: the complete engine output for sankey diagram visualizations.
2333
+ *
2334
+ * Contains everything an adapter needs to render the sankey: dimensions,
2335
+ * chrome, nodes, links, legend, tooltip descriptors, and accessibility metadata.
2336
+ * No axes (sankey has no traditional axis system).
2337
+ */
2338
+ interface SankeyLayout {
2339
+ /** The sankey drawing area (after chrome and legend are subtracted). */
2340
+ area: Rect;
2341
+ /** Resolved chrome text elements with positions and styles. */
2342
+ chrome: ResolvedChrome;
2343
+ /** Resolved sankey node marks with positions and colors. */
2344
+ nodes: SankeyNodeMark[];
2345
+ /** Resolved sankey link marks with paths and gradient colors. */
2346
+ links: SankeyLinkMark[];
2347
+ /** Legend layout (position, entries, bounds). */
2348
+ legend: LegendLayout;
2349
+ /** Tooltip descriptors keyed by node/link identifier. */
2350
+ tooltipDescriptors: Map<string, TooltipContent>;
2351
+ /** Accessibility metadata. */
2352
+ a11y: A11yMetadata;
2353
+ /** The resolved theme used for rendering. */
2354
+ theme: ResolvedTheme;
2355
+ /** Total SVG dimensions. */
2356
+ dimensions: {
2357
+ width: number;
2358
+ height: number;
2359
+ };
2360
+ /** Resolved animation config. Present only when animation is enabled. */
2361
+ animation?: ResolvedAnimation;
2362
+ }
2221
2363
  /** Function signature for text measurement provided by adapters. */
2222
2364
  type MeasureTextFn = (text: string, fontSize: number, fontWeight?: number) => {
2223
2365
  width: number;
@@ -2786,4 +2928,4 @@ declare function scatterChart(data: DataRow[], x: FieldRef, y: FieldRef, options
2786
2928
  */
2787
2929
  declare function dataTable(data: DataRow[], options?: TableBuilderOptions): TableSpec;
2788
2930
 
2789
- export { type A11yMetadata, type AggregateOp, type AnimationConfig, type AnimationEase, type AnimationPhaseConfig, type AnimationSpec, type AnimationStagger, type Annotation, type AnnotationAnchor, type AnnotationOffset, type AnnotationPosition, type ArcMark, type AreaMark, type AxisConfig, type AxisLabelDensity, type AxisLayout, type AxisTick, BRAND_FONT_SIZE, BRAND_MIN_WIDTH, BRAND_RESERVE_WIDTH, type BarColumnConfig, type BarTableCell, type BinParams, type BinTransform, type Breakpoint, CATEGORICAL_PALETTE, CHART_ENCODING_RULES, CHART_TYPES, type CalculateExpression, type CalculateTransform, type CategoricalPalette, type CategoryColorsConfig, type CategoryTableCell, type CellStyle, type ChannelRule, type ChartBuilderOptions, type ChartEventHandlers, type ChartLayout, type ChartSpec, type ChartSpecOverride, type ChartSpecWithoutData, type ChartType, type Chrome, type ChromeDefaults, type ChromeKey, type ChromeMode, type ChromeText, type ChromeTextStyle, type ColorBlindnessType, type ColumnConfig, type CompileOptions, type CompileTableOptions, type Condition, type ConditionalValueDef, DEFAULT_THEME, DIVERGING_PALETTES, type DarkMode, type DataRow, type DateGranularity, type DivergingPalette, EXTENDED_OFFSET_STRATEGIES, type ElementEdit, type ElementRef, type Encoding, type EncodingChannel, type EncodingRule, type FieldPredicate, type FieldRef, type FieldType, type FilterPredicate, type FilterTransform, type FlagTableCell, GRAPH_ENCODING_RULES, type GraphChannelRule, type GraphEdge, type GraphEdgeLayout, type GraphEncoding, type GraphEncodingChannel, type GraphLayout, type GraphLayoutConfig, type GraphNode, type GraphNodeLayout, type GraphSpec, type GraphSpecWithoutData, type Gridline, type HeatmapColumnConfig, type HeatmapTableCell, type HeightClass, type ImageColumnConfig, type ImageTableCell, type LabelCandidate, type LabelConfig, type LabelDensity, type LabelMode, type LabelPriority, type LayerSpec, type LayoutStrategy, type LegendConfig, type LegendEntry, type LegendLayout, type LegendPosition, type LineMark, type LogicalAnd, type LogicalNot, type LogicalOr, MARK_DISPLAY_NAMES, MARK_ENCODING_RULES, MARK_TYPES, type Margins, type Mark, type MarkAria, type MarkDef, type MarkEvent, type MarkType, type MeasureTextFn, type NodeOverride, OFFSET_STRATEGIES, type OffsetStrategy, type PaginationState, type Point, type PointMark, type RangeAnnotation, type Rect, type RectMark, type RefLineAnnotation, type ResolveConfig, type ResolveMode, type ResolvedAnimation, type ResolvedAnnotation, type ResolvedChrome, type ResolvedChromeElement, type ResolvedColumn, type ResolvedLabel, type ResolvedTheme, type RuleMarkLayout, SEQUENTIAL_PALETTES, type ScaleConfig, type ScaleType, type SequentialPalette, type SeriesStyle, type SortState, type SparklineColumnConfig, type SparklineData, type SparklineTableCell, type StoredVizSpec, type TableBuilderOptions, type TableCell, type TableCellBase, type TableLayout, type TableRow, type TableSpec, type TableSpecWithoutData, type TextAnnotation, type TextMarkLayout, type TextStyle, type TextTableCell, type Theme, type ThemeChromeDefaults, type ThemeColors, type ThemeConfig, type ThemeFontSizes, type ThemeFontWeights, type ThemeFonts, type ThemeSpacing, type TickMarkLayout, type TimeUnit, type TimeUnitTransform, type TooltipContent, type TooltipField, type Transform, type VizSpec, abbreviateNumber, adaptColorForDarkMode, adaptTheme, areaChart, barChart, buildD3Formatter, buildTemporalFormatter, checkPaletteDistinguishability, columnChart, computeChrome, computeLabelBounds, contrastRatio, dataTable, detectCollision, donutChart, dotChart, elementRef, estimateTextWidth, findAccessibleColor, formatDate, formatNumber, generateAltText, generateAriaLabels, generateDataTable, getBreakpoint, getHeightClass, getLayoutStrategy, inferFieldType, isChartSpec, isConditionalDef, isEncodingChannel, isGraphSpec, isLayerSpec, isRangeAnnotation, isRefLineAnnotation, isTableSpec, isTextAnnotation, lineChart, meetsAA, pieChart, resolveCollisions, resolveMarkDef, resolveMarkType, resolveTheme, scatterChart, simulateColorBlindness };
2931
+ export { type A11yMetadata, type AggregateOp, type AnimationConfig, type AnimationEase, type AnimationPhaseConfig, type AnimationSpec, type AnimationStagger, type Annotation, type AnnotationAnchor, type AnnotationOffset, type AnnotationPosition, type ArcMark, type AreaMark, type AxisConfig, type AxisLabelDensity, type AxisLayout, type AxisTick, BRAND_FONT_SIZE, BRAND_MIN_WIDTH, BRAND_RESERVE_WIDTH, type BarColumnConfig, type BarTableCell, type BinParams, type BinTransform, type Breakpoint, CATEGORICAL_PALETTE, CHART_ENCODING_RULES, CHART_TYPES, type CalculateExpression, type CalculateTransform, type CategoricalPalette, type CategoryColorsConfig, type CategoryTableCell, type CellStyle, type ChannelRule, type ChartBuilderOptions, type ChartEventHandlers, type ChartLayout, type ChartSpec, type ChartSpecOverride, type ChartSpecWithoutData, type ChartType, type Chrome, type ChromeDefaults, type ChromeKey, type ChromeMode, type ChromeText, type ChromeTextStyle, type ColorBlindnessType, type ColumnConfig, type CompileOptions, type CompileTableOptions, type Condition, type ConditionalValueDef, DEFAULT_THEME, DIVERGING_PALETTES, type DarkMode, type DataRow, type DateGranularity, type DivergingPalette, EXTENDED_OFFSET_STRATEGIES, type ElementEdit, type ElementRef, type Encoding, type EncodingChannel, type EncodingRule, type FieldPredicate, type FieldRef, type FieldType, type FilterPredicate, type FilterTransform, type FlagTableCell, GRAPH_ENCODING_RULES, type GraphChannelRule, type GraphEdge, type GraphEdgeLayout, type GraphEncoding, type GraphEncodingChannel, type GraphLayout, type GraphLayoutConfig, type GraphNode, type GraphNodeLayout, type GraphSpec, type GraphSpecWithoutData, type Gridline, type HeatmapColumnConfig, type HeatmapTableCell, type HeightClass, type ImageColumnConfig, type ImageTableCell, type LabelCandidate, type LabelConfig, type LabelDensity, type LabelMode, type LabelPriority, type LayerSpec, type LayoutStrategy, type LegendConfig, type LegendEntry, type LegendLayout, type LegendPosition, type LineMark, type LogicalAnd, type LogicalNot, type LogicalOr, MARK_DISPLAY_NAMES, MARK_ENCODING_RULES, MARK_TYPES, type Margins, type Mark, type MarkAria, type MarkDef, type MarkEvent, type MarkType, type MeasureTextFn, type NodeOverride, OFFSET_STRATEGIES, type OffsetStrategy, type PaginationState, type Point, type PointMark, type RangeAnnotation, type Rect, type RectMark, type RefLineAnnotation, type ResolveConfig, type ResolveMode, type ResolvedAnimation, type ResolvedAnnotation, type ResolvedChrome, type ResolvedChromeElement, type ResolvedColumn, type ResolvedLabel, type ResolvedTheme, type RuleMarkLayout, SEQUENTIAL_PALETTES, type SankeyEncoding, type SankeyLayout, type SankeyLinkColor, type SankeyLinkMark, type SankeyNodeAlign, type SankeyNodeMark, type SankeySpec, type SankeySpecWithoutData, type ScaleConfig, type ScaleType, type SequentialPalette, type SeriesStyle, type SortState, type SparklineColumnConfig, type SparklineData, type SparklineTableCell, type StoredVizSpec, type TableBuilderOptions, type TableCell, type TableCellBase, type TableLayout, type TableRow, type TableSpec, type TableSpecWithoutData, type TextAnnotation, type TextMarkLayout, type TextStyle, type TextTableCell, type Theme, type ThemeChromeDefaults, type ThemeColors, type ThemeConfig, type ThemeFontSizes, type ThemeFontWeights, type ThemeFonts, type ThemeSpacing, type TickMarkLayout, type TimeUnit, type TimeUnitTransform, type TooltipContent, type TooltipField, type Transform, type VizSpec, abbreviateNumber, adaptColorForDarkMode, adaptTheme, areaChart, barChart, buildD3Formatter, buildTemporalFormatter, checkPaletteDistinguishability, columnChart, computeChrome, computeLabelBounds, contrastRatio, dataTable, detectCollision, donutChart, dotChart, elementRef, estimateTextWidth, findAccessibleColor, formatDate, formatNumber, generateAltText, generateAriaLabels, generateDataTable, getBreakpoint, getHeightClass, getLayoutStrategy, inferFieldType, isChartSpec, isConditionalDef, isEncodingChannel, isGraphSpec, isLayerSpec, isRangeAnnotation, isRefLineAnnotation, isSankeySpec, isTableSpec, isTextAnnotation, lineChart, meetsAA, pieChart, resolveCollisions, resolveMarkDef, resolveMarkType, resolveTheme, scatterChart, simulateColorBlindness };
package/dist/index.js CHANGED
@@ -201,6 +201,9 @@ function isTableSpec(spec) {
201
201
  function isGraphSpec(spec) {
202
202
  return "type" in spec && spec.type === "graph";
203
203
  }
204
+ function isSankeySpec(spec) {
205
+ return "type" in spec && spec.type === "sankey";
206
+ }
204
207
  function isTextAnnotation(annotation) {
205
208
  return annotation.type === "text";
206
209
  }
@@ -2781,6 +2784,7 @@ export {
2781
2784
  isLayerSpec,
2782
2785
  isRangeAnnotation,
2783
2786
  isRefLineAnnotation,
2787
+ isSankeySpec,
2784
2788
  isTableSpec,
2785
2789
  isTextAnnotation,
2786
2790
  lineChart,