@opendata-ai/openchart-core 6.3.0 → 6.4.1
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 +54 -3
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/types/events.ts +43 -3
- package/src/types/index.ts +2 -0
- package/src/types/layout.ts +2 -0
- package/src/types/spec.ts +2 -0
package/dist/index.d.ts
CHANGED
|
@@ -455,6 +455,8 @@ interface AnnotationOffset {
|
|
|
455
455
|
type AnnotationAnchor = 'top' | 'bottom' | 'left' | 'right' | 'auto';
|
|
456
456
|
/** Base properties shared by all annotation types. */
|
|
457
457
|
interface AnnotationBase {
|
|
458
|
+
/** Stable identifier for selection and edit callbacks. When provided, edit events include this ID for reliable element matching. */
|
|
459
|
+
id?: string;
|
|
458
460
|
/** Human-readable label for the annotation. */
|
|
459
461
|
label?: string;
|
|
460
462
|
/** Fill color for the annotation element. */
|
|
@@ -1083,9 +1085,42 @@ declare const GRAPH_ENCODING_RULES: Record<string, GraphChannelRule>;
|
|
|
1083
1085
|
|
|
1084
1086
|
/** Identifies a specific chrome text element (title, subtitle, source, byline, footer). */
|
|
1085
1087
|
type ChromeKey = 'title' | 'subtitle' | 'source' | 'byline' | 'footer';
|
|
1088
|
+
/**
|
|
1089
|
+
* Reference to an editable chart element.
|
|
1090
|
+
* Carries enough info to find the element in both the spec and the DOM.
|
|
1091
|
+
* The `annotation` variant uses two-tier identity: `id` (when the consumer provides one)
|
|
1092
|
+
* and `index` (always available, position in the spec's annotations array).
|
|
1093
|
+
*/
|
|
1094
|
+
type ElementRef = {
|
|
1095
|
+
type: 'annotation';
|
|
1096
|
+
index: number;
|
|
1097
|
+
id?: string;
|
|
1098
|
+
} | {
|
|
1099
|
+
type: 'chrome';
|
|
1100
|
+
key: ChromeKey;
|
|
1101
|
+
} | {
|
|
1102
|
+
type: 'series-label';
|
|
1103
|
+
series: string;
|
|
1104
|
+
} | {
|
|
1105
|
+
type: 'legend';
|
|
1106
|
+
} | {
|
|
1107
|
+
type: 'legend-entry';
|
|
1108
|
+
series: string;
|
|
1109
|
+
index: number;
|
|
1110
|
+
};
|
|
1111
|
+
/** Helper constructors for ergonomic ElementRef creation. */
|
|
1112
|
+
declare const elementRef: {
|
|
1113
|
+
readonly annotation: (index: number, id?: string) => ElementRef;
|
|
1114
|
+
readonly chrome: (key: ChromeKey) => ElementRef;
|
|
1115
|
+
readonly seriesLabel: (series: string) => ElementRef;
|
|
1116
|
+
readonly legend: () => ElementRef;
|
|
1117
|
+
readonly legendEntry: (series: string, index: number) => ElementRef;
|
|
1118
|
+
};
|
|
1086
1119
|
/**
|
|
1087
1120
|
* Discriminated union of all element edit events.
|
|
1088
|
-
* Fired by the `onEdit` callback when any editable chart element is
|
|
1121
|
+
* Fired by the `onEdit` callback when any editable chart element is modified.
|
|
1122
|
+
* Covers repositioning (drag), deletion (Delete key), and text editing (double-click).
|
|
1123
|
+
* Selection events (onSelect/onDeselect) are separate callbacks, not part of this union.
|
|
1089
1124
|
*/
|
|
1090
1125
|
type ElementEdit = {
|
|
1091
1126
|
type: 'annotation';
|
|
@@ -1120,6 +1155,14 @@ type ElementEdit = {
|
|
|
1120
1155
|
type: 'legend-toggle';
|
|
1121
1156
|
series: string;
|
|
1122
1157
|
hidden: boolean;
|
|
1158
|
+
} | {
|
|
1159
|
+
type: 'delete';
|
|
1160
|
+
element: ElementRef;
|
|
1161
|
+
} | {
|
|
1162
|
+
type: 'text-edit';
|
|
1163
|
+
element: ElementRef;
|
|
1164
|
+
oldText: string;
|
|
1165
|
+
newText: string;
|
|
1123
1166
|
};
|
|
1124
1167
|
/**
|
|
1125
1168
|
* Event fired when a user interacts with a data mark (bar, point, line segment, etc.).
|
|
@@ -1159,8 +1202,14 @@ interface ChartEventHandlers {
|
|
|
1159
1202
|
onAnnotationClick?: (annotation: Annotation, event: MouseEvent) => void;
|
|
1160
1203
|
/** Called when a text annotation label is dragged to a new position. */
|
|
1161
1204
|
onAnnotationEdit?: (annotation: TextAnnotation, updatedOffset: AnnotationOffset) => void;
|
|
1162
|
-
/** Unified edit callback. Fires for any
|
|
1205
|
+
/** Unified edit callback. Fires for any spec-modifying edit (repositioning, deletion, text editing). */
|
|
1163
1206
|
onEdit?: (edit: ElementEdit) => void;
|
|
1207
|
+
/** Fired when an element is selected via click or programmatic select(). */
|
|
1208
|
+
onSelect?: (element: ElementRef) => void;
|
|
1209
|
+
/** Fired when the current element is deselected (click empty, Escape, or new selection replaces old). */
|
|
1210
|
+
onDeselect?: (element: ElementRef) => void;
|
|
1211
|
+
/** Fired when inline text editing commits. Also flows through onEdit as a 'text-edit' event. */
|
|
1212
|
+
onTextEdit?: (element: ElementRef, oldText: string, newText: string) => void;
|
|
1164
1213
|
}
|
|
1165
1214
|
|
|
1166
1215
|
/**
|
|
@@ -1716,6 +1765,8 @@ interface ResolvedLabel {
|
|
|
1716
1765
|
interface ResolvedAnnotation {
|
|
1717
1766
|
/** Original annotation type. */
|
|
1718
1767
|
type: 'text' | 'range' | 'refline';
|
|
1768
|
+
/** Stable identifier from the spec annotation, for selection/edit callbacks. */
|
|
1769
|
+
id?: string;
|
|
1719
1770
|
/** Label text (if any). */
|
|
1720
1771
|
label?: ResolvedLabel;
|
|
1721
1772
|
/** For range: the highlighted rectangle in pixel coordinates. */
|
|
@@ -2634,4 +2685,4 @@ declare function scatterChart(data: DataRow[], x: FieldRef, y: FieldRef, options
|
|
|
2634
2685
|
*/
|
|
2635
2686
|
declare function dataTable(data: DataRow[], options?: TableBuilderOptions): TableSpec;
|
|
2636
2687
|
|
|
2637
|
-
export { type A11yMetadata, type AggregateOp, 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 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 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, 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 };
|
|
2688
|
+
export { type A11yMetadata, type AggregateOp, 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 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 };
|
package/dist/index.js
CHANGED
|
@@ -147,6 +147,19 @@ var GRAPH_ENCODING_RULES = {
|
|
|
147
147
|
nodeLabel: { required: false, allowedTypes: [] }
|
|
148
148
|
};
|
|
149
149
|
|
|
150
|
+
// src/types/events.ts
|
|
151
|
+
var elementRef = {
|
|
152
|
+
annotation: (index, id) => ({ type: "annotation", index, id }),
|
|
153
|
+
chrome: (key) => ({ type: "chrome", key }),
|
|
154
|
+
seriesLabel: (series) => ({ type: "series-label", series }),
|
|
155
|
+
legend: () => ({ type: "legend" }),
|
|
156
|
+
legendEntry: (series, index) => ({
|
|
157
|
+
type: "legend-entry",
|
|
158
|
+
series,
|
|
159
|
+
index
|
|
160
|
+
})
|
|
161
|
+
};
|
|
162
|
+
|
|
150
163
|
// src/types/spec.ts
|
|
151
164
|
function isEncodingChannel(def) {
|
|
152
165
|
if (!def) return false;
|
|
@@ -2749,6 +2762,7 @@ export {
|
|
|
2749
2762
|
detectCollision,
|
|
2750
2763
|
donutChart,
|
|
2751
2764
|
dotChart,
|
|
2765
|
+
elementRef,
|
|
2752
2766
|
estimateTextWidth,
|
|
2753
2767
|
findAccessibleColor,
|
|
2754
2768
|
formatDate,
|