@opendata-ai/openchart-core 6.1.4 → 6.2.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 +10 -2
- package/dist/index.js +14 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/locale/__tests__/format.test.ts +79 -1
- package/src/locale/format.ts +21 -4
- package/src/locale/index.ts +7 -1
- package/src/types/spec.ts +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -363,12 +363,14 @@ interface Encoding {
|
|
|
363
363
|
/** Radial position for arc marks. */
|
|
364
364
|
radius?: EncodingChannel;
|
|
365
365
|
}
|
|
366
|
-
/** Encoding channel for graph nodes and edges.
|
|
366
|
+
/** Encoding channel for graph nodes and edges. */
|
|
367
367
|
interface GraphEncodingChannel {
|
|
368
368
|
/** Data field name on the node/edge object. */
|
|
369
369
|
field: string;
|
|
370
370
|
/** How to interpret the field values. */
|
|
371
371
|
type?: FieldType;
|
|
372
|
+
/** Scale configuration. Auto-derived from data if omitted. */
|
|
373
|
+
scale?: ScaleConfig;
|
|
372
374
|
}
|
|
373
375
|
/** Graph-specific encoding mapping visual properties to node/edge data fields. */
|
|
374
376
|
interface GraphEncoding {
|
|
@@ -2401,6 +2403,12 @@ type DateGranularity = 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' |
|
|
|
2401
2403
|
* @param granularity - Time granularity for format selection.
|
|
2402
2404
|
*/
|
|
2403
2405
|
declare function formatDate(value: Date | string | number, _locale?: string, granularity?: DateGranularity): string;
|
|
2406
|
+
/**
|
|
2407
|
+
* Build a formatter for temporal values using a d3-time-format string (e.g. "%Y", "%b %Y").
|
|
2408
|
+
* Returns a function that accepts a Date, string, or number and returns the formatted string.
|
|
2409
|
+
* Returns null if the format string is falsy.
|
|
2410
|
+
*/
|
|
2411
|
+
declare function buildTemporalFormatter(formatStr: string | undefined): ((value: Date | string | number) => string) | null;
|
|
2404
2412
|
|
|
2405
2413
|
/**
|
|
2406
2414
|
* Automatic alt text generation for chart accessibility.
|
|
@@ -2605,4 +2613,4 @@ declare function scatterChart(data: DataRow[], x: FieldRef, y: FieldRef, options
|
|
|
2605
2613
|
*/
|
|
2606
2614
|
declare function dataTable(data: DataRow[], options?: TableBuilderOptions): TableSpec;
|
|
2607
2615
|
|
|
2608
|
-
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, 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, 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, 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 };
|
|
2616
|
+
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, 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, 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 };
|
package/dist/index.js
CHANGED
|
@@ -2417,12 +2417,21 @@ function formatDate(value, _locale, granularity) {
|
|
|
2417
2417
|
}
|
|
2418
2418
|
return timeFormat(formatStr)(date);
|
|
2419
2419
|
}
|
|
2420
|
+
function buildTemporalFormatter(formatStr) {
|
|
2421
|
+
if (!formatStr) return null;
|
|
2422
|
+
const fmt = utcFormat(formatStr);
|
|
2423
|
+
return (value) => {
|
|
2424
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
2425
|
+
if (Number.isNaN(date.getTime())) return String(value);
|
|
2426
|
+
return fmt(date);
|
|
2427
|
+
};
|
|
2428
|
+
}
|
|
2420
2429
|
function inferGranularity(date) {
|
|
2421
|
-
if (date.
|
|
2422
|
-
return date.
|
|
2430
|
+
if (date.getUTCHours() !== 0 || date.getUTCMinutes() !== 0) {
|
|
2431
|
+
return date.getUTCMinutes() !== 0 ? "minute" : "hour";
|
|
2423
2432
|
}
|
|
2424
|
-
if (date.
|
|
2425
|
-
if (date.
|
|
2433
|
+
if (date.getUTCDate() !== 1) return "day";
|
|
2434
|
+
if (date.getUTCMonth() !== 0) return "month";
|
|
2426
2435
|
return "year";
|
|
2427
2436
|
}
|
|
2428
2437
|
|
|
@@ -2696,6 +2705,7 @@ export {
|
|
|
2696
2705
|
areaChart,
|
|
2697
2706
|
barChart,
|
|
2698
2707
|
buildD3Formatter,
|
|
2708
|
+
buildTemporalFormatter,
|
|
2699
2709
|
checkPaletteDistinguishability,
|
|
2700
2710
|
columnChart,
|
|
2701
2711
|
computeChrome,
|