@opendata-ai/openchart-core 6.9.0 → 6.11.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 +76 -11
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/types/__tests__/gradient.test.ts +95 -0
- package/src/types/index.ts +6 -0
- package/src/types/layout.ts +9 -8
- package/src/types/spec.ts +89 -2
package/dist/index.d.ts
CHANGED
|
@@ -180,6 +180,65 @@ interface ColumnConfig {
|
|
|
180
180
|
type MarkType = 'bar' | 'line' | 'area' | 'point' | 'circle' | 'arc' | 'text' | 'rule' | 'tick' | 'rect' | 'lollipop';
|
|
181
181
|
/** @deprecated Use MarkType instead. Kept for internal migration references. */
|
|
182
182
|
type ChartType = MarkType;
|
|
183
|
+
/** A single color stop in a gradient definition. */
|
|
184
|
+
interface GradientStop {
|
|
185
|
+
/** Position along the gradient, 0 to 1. */
|
|
186
|
+
offset: number;
|
|
187
|
+
/** CSS color string at this stop. */
|
|
188
|
+
color: string;
|
|
189
|
+
/** Opacity at this stop, 0 to 1. Maps to SVG stop-opacity. */
|
|
190
|
+
opacity?: number;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Linear gradient definition.
|
|
194
|
+
* Coordinates are in [0,1] normalized space relative to the mark's bounding box
|
|
195
|
+
* (maps to SVG gradientUnits="objectBoundingBox").
|
|
196
|
+
*/
|
|
197
|
+
interface LinearGradient {
|
|
198
|
+
gradient: 'linear';
|
|
199
|
+
/** Color stops from start to end. */
|
|
200
|
+
stops: GradientStop[];
|
|
201
|
+
/** Start x coordinate (0-1). Default: 0. */
|
|
202
|
+
x1?: number;
|
|
203
|
+
/** Start y coordinate (0-1). Default: 0. */
|
|
204
|
+
y1?: number;
|
|
205
|
+
/** End x coordinate (0-1). Default: 0. */
|
|
206
|
+
x2?: number;
|
|
207
|
+
/** End y coordinate (0-1). Default: 1 (top-to-bottom). */
|
|
208
|
+
y2?: number;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Radial gradient definition.
|
|
212
|
+
* Coordinates are in [0,1] normalized space relative to the mark's bounding box.
|
|
213
|
+
*/
|
|
214
|
+
interface RadialGradient {
|
|
215
|
+
gradient: 'radial';
|
|
216
|
+
/** Color stops from inner to outer. */
|
|
217
|
+
stops: GradientStop[];
|
|
218
|
+
/** Inner circle center x (0-1). Default: 0.5. */
|
|
219
|
+
x1?: number;
|
|
220
|
+
/** Inner circle center y (0-1). Default: 0.5. */
|
|
221
|
+
y1?: number;
|
|
222
|
+
/** Inner circle radius (0-1). Default: 0. */
|
|
223
|
+
r1?: number;
|
|
224
|
+
/** Outer circle center x (0-1). Default: 0.5. */
|
|
225
|
+
x2?: number;
|
|
226
|
+
/** Outer circle center y (0-1). Default: 0.5. */
|
|
227
|
+
y2?: number;
|
|
228
|
+
/** Outer circle radius (0-1). Default: 0.5. */
|
|
229
|
+
r2?: number;
|
|
230
|
+
}
|
|
231
|
+
/** A gradient definition, either linear or radial. */
|
|
232
|
+
type GradientDef = LinearGradient | RadialGradient;
|
|
233
|
+
/** Type guard: check if a value is a GradientDef object. */
|
|
234
|
+
declare function isGradientDef(value: unknown): value is GradientDef;
|
|
235
|
+
/**
|
|
236
|
+
* Extract a single representative color from a fill value.
|
|
237
|
+
* Returns the fill directly if it's a string, or the last stop color
|
|
238
|
+
* if it's a gradient. Used by tooltips, labels, legends, and voronoi
|
|
239
|
+
* overlays that need a flat color.
|
|
240
|
+
*/
|
|
241
|
+
declare function getRepresentativeColor(fill: string | GradientDef): string;
|
|
183
242
|
/**
|
|
184
243
|
* Mark definition object with visual properties.
|
|
185
244
|
*
|
|
@@ -214,8 +273,8 @@ interface MarkDef {
|
|
|
214
273
|
filled?: boolean;
|
|
215
274
|
/** Default opacity (0-1). */
|
|
216
275
|
opacity?: number;
|
|
217
|
-
/** Default fill color. */
|
|
218
|
-
fill?: string;
|
|
276
|
+
/** Default fill color or gradient. */
|
|
277
|
+
fill?: string | GradientDef;
|
|
219
278
|
/** Default stroke color. */
|
|
220
279
|
stroke?: string;
|
|
221
280
|
/** Default stroke width. */
|
|
@@ -321,6 +380,12 @@ interface EncodingChannel {
|
|
|
321
380
|
axis?: AxisConfig;
|
|
322
381
|
/** Scale configuration. */
|
|
323
382
|
scale?: ScaleConfig;
|
|
383
|
+
/**
|
|
384
|
+
* Stacking behavior for quantitative channels (Vega-Lite aligned).
|
|
385
|
+
* - undefined | true | 'zero': stack (default, cumulative segments)
|
|
386
|
+
* - null | false: no stacking (grouped/dodged side-by-side)
|
|
387
|
+
*/
|
|
388
|
+
stack?: boolean | 'zero' | null;
|
|
324
389
|
}
|
|
325
390
|
/**
|
|
326
391
|
* Encoding object mapping visual channels to data fields.
|
|
@@ -1674,8 +1739,8 @@ interface AreaMark {
|
|
|
1674
1739
|
path: string;
|
|
1675
1740
|
/** SVG path string for just the top boundary (for stroking the data line only). */
|
|
1676
1741
|
topPath: string;
|
|
1677
|
-
/** Fill color. */
|
|
1678
|
-
fill: string;
|
|
1742
|
+
/** Fill color or gradient. */
|
|
1743
|
+
fill: string | GradientDef;
|
|
1679
1744
|
/** Fill opacity. */
|
|
1680
1745
|
fillOpacity: number;
|
|
1681
1746
|
/** Optional stroke for the top boundary. */
|
|
@@ -1715,8 +1780,8 @@ interface RectMark {
|
|
|
1715
1780
|
width: number;
|
|
1716
1781
|
/** Height. */
|
|
1717
1782
|
height: number;
|
|
1718
|
-
/** Fill color. */
|
|
1719
|
-
fill: string;
|
|
1783
|
+
/** Fill color or gradient. */
|
|
1784
|
+
fill: string | GradientDef;
|
|
1720
1785
|
/** Stroke color. */
|
|
1721
1786
|
stroke?: string;
|
|
1722
1787
|
/** Stroke width. */
|
|
@@ -1758,8 +1823,8 @@ interface ArcMark {
|
|
|
1758
1823
|
startAngle: number;
|
|
1759
1824
|
/** End angle in radians. */
|
|
1760
1825
|
endAngle: number;
|
|
1761
|
-
/** Fill color. */
|
|
1762
|
-
fill: string;
|
|
1826
|
+
/** Fill color or gradient. */
|
|
1827
|
+
fill: string | GradientDef;
|
|
1763
1828
|
/** Stroke color (usually white for slice separation). */
|
|
1764
1829
|
stroke: string;
|
|
1765
1830
|
/** Stroke width. */
|
|
@@ -1785,8 +1850,8 @@ interface PointMark {
|
|
|
1785
1850
|
cy: number;
|
|
1786
1851
|
/** Radius in pixels. */
|
|
1787
1852
|
r: number;
|
|
1788
|
-
/** Fill color. */
|
|
1789
|
-
fill: string;
|
|
1853
|
+
/** Fill color or gradient. */
|
|
1854
|
+
fill: string | GradientDef;
|
|
1790
1855
|
/** Stroke color. */
|
|
1791
1856
|
stroke: string;
|
|
1792
1857
|
/** Stroke width. */
|
|
@@ -2957,4 +3022,4 @@ declare function scatterChart(data: DataRow[], x: FieldRef, y: FieldRef, options
|
|
|
2957
3022
|
*/
|
|
2958
3023
|
declare function dataTable(data: DataRow[], options?: TableBuilderOptions): TableSpec;
|
|
2959
3024
|
|
|
2960
|
-
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 };
|
|
3025
|
+
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 GradientDef, type GradientStop, 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 LinearGradient, 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 RadialGradient, 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, getRepresentativeColor, inferFieldType, isChartSpec, isConditionalDef, isEncodingChannel, isGradientDef, isGraphSpec, isLayerSpec, isRangeAnnotation, isRefLineAnnotation, isSankeySpec, isTableSpec, isTextAnnotation, lineChart, meetsAA, pieChart, resolveCollisions, resolveMarkDef, resolveMarkType, resolveTheme, scatterChart, simulateColorBlindness };
|
package/dist/index.js
CHANGED
|
@@ -161,6 +161,14 @@ var elementRef = {
|
|
|
161
161
|
};
|
|
162
162
|
|
|
163
163
|
// src/types/spec.ts
|
|
164
|
+
function isGradientDef(value) {
|
|
165
|
+
return typeof value === "object" && value !== null && "gradient" in value && "stops" in value && (value.gradient === "linear" || value.gradient === "radial");
|
|
166
|
+
}
|
|
167
|
+
function getRepresentativeColor(fill) {
|
|
168
|
+
if (typeof fill === "string") return fill;
|
|
169
|
+
const stops = fill.stops;
|
|
170
|
+
return stops.length > 0 ? stops[stops.length - 1].color : "#000000";
|
|
171
|
+
}
|
|
164
172
|
function isEncodingChannel(def) {
|
|
165
173
|
if (!def) return false;
|
|
166
174
|
return "field" in def && !("condition" in def);
|
|
@@ -2782,10 +2790,12 @@ export {
|
|
|
2782
2790
|
getBreakpoint,
|
|
2783
2791
|
getHeightClass,
|
|
2784
2792
|
getLayoutStrategy,
|
|
2793
|
+
getRepresentativeColor,
|
|
2785
2794
|
inferFieldType,
|
|
2786
2795
|
isChartSpec,
|
|
2787
2796
|
isConditionalDef,
|
|
2788
2797
|
isEncodingChannel,
|
|
2798
|
+
isGradientDef,
|
|
2789
2799
|
isGraphSpec,
|
|
2790
2800
|
isLayerSpec,
|
|
2791
2801
|
isRangeAnnotation,
|