@classic-homes/charts-core 0.4.0 → 0.4.2

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.cjs CHANGED
@@ -573,14 +573,39 @@ function generateDataTable(headers, rows) {
573
573
  }
574
574
 
575
575
  // src/utils/merge.ts
576
- var ALWAYS_REPLACE = ["series", "graphic"];
576
+ var ALWAYS_REPLACE = ["graphic"];
577
577
  function countComponents(value) {
578
578
  if (value == null || value === false) return 0;
579
579
  if (Array.isArray(value)) return value.filter((item) => item != null).length;
580
580
  return 1;
581
581
  }
582
+ function isRecord(value) {
583
+ return value !== null && typeof value === "object" && !Array.isArray(value);
584
+ }
585
+ function sameShape(a, b) {
586
+ if (!isRecord(a) || !isRecord(b)) return !isRecord(a) && !isRecord(b);
587
+ const keys = Object.keys(a).filter((key) => a[key] !== void 0);
588
+ const other = Object.keys(b).filter((key) => b[key] !== void 0);
589
+ if (keys.length !== other.length) return false;
590
+ return keys.every(
591
+ (key) => key in b && b[key] !== void 0 && (key === "type" || key === "id" ? a[key] === b[key] : sameShape(a[key], b[key]))
592
+ );
593
+ }
594
+ function asList(value) {
595
+ if (value == null || value === false) return [];
596
+ return Array.isArray(value) ? value : [value];
597
+ }
598
+ function sameSeriesShape(prev, next) {
599
+ const before = asList(prev);
600
+ const after = asList(next);
601
+ return before.length === after.length && before.every((item, i) => sameShape(item, after[i]));
602
+ }
582
603
  function getReplaceMerge(prev, next, isComponentType) {
583
604
  const types = new Set(ALWAYS_REPLACE);
605
+ const prior = prev;
606
+ if (!prior || !sameSeriesShape(prior.series, next.series)) {
607
+ types.add("series");
608
+ }
584
609
  if (prev) {
585
610
  const before = prev;
586
611
  const after = next;
@@ -1162,6 +1187,12 @@ function buildStackTotalSeries(categories, series, { stacked, position, format,
1162
1187
  }
1163
1188
  }));
1164
1189
  }
1190
+ function barCornerRadius(horizontal, stackIds, index, radius = 4) {
1191
+ const stack = stackIds[index];
1192
+ const outer = stack === void 0 || stackIds.lastIndexOf(stack) === index;
1193
+ if (!outer) return [0, 0, 0, 0];
1194
+ return horizontal ? [0, radius, radius, 0] : [radius, radius, 0, 0];
1195
+ }
1165
1196
  function withEndLabelInset(inset, labels) {
1166
1197
  const longest = Math.max(0, ...labels.map((label) => label.length));
1167
1198
  if (longest === 0) return inset;
@@ -1561,6 +1592,7 @@ exports.THEME_LIGHT = THEME_LIGHT;
1561
1592
  exports.abbreviateNumber = abbreviateNumber;
1562
1593
  exports.allSeriesEmpty = allSeriesEmpty;
1563
1594
  exports.anchorCenterGraphic = anchorCenterGraphic;
1595
+ exports.barCornerRadius = barCornerRadius;
1564
1596
  exports.binValues = binValues;
1565
1597
  exports.boxPlotTable = boxPlotTable;
1566
1598
  exports.boxplotStats = boxplotStats;
package/dist/index.d.cts CHANGED
@@ -125,8 +125,12 @@ declare function generateDataTable(headers: string[], rows: (string | number)[][
125
125
  * rebuilds every component, so legend selection, dataZoom ranges and other
126
126
  * interaction state reset on each data update. Instead this replaces only:
127
127
  *
128
- * - `series` and `graphic`, so removed series, mark lines and centre labels
129
- * disappear;
128
+ * - `graphic`, so removed centre labels disappear;
129
+ * - `series`, unless every series keeps its keys and type and only its
130
+ * values change. A replaced series is a new model, which ECharts animates
131
+ * in from scratch, so a data refresh with the same shape (often the same
132
+ * data) must merge to avoid re-animating the chart; a changed shape is
133
+ * replaced so removed series, mark lines and options disappear;
130
134
  * - any component type that `next` has fewer of than `prev` (a hidden legend
131
135
  * or tooltip, a dropped volume grid and its axes).
132
136
  *
@@ -370,6 +374,12 @@ declare function buildStackTotalSeries(categories: (string | number)[], series:
370
374
  data: (number | null)[];
371
375
  stack?: string;
372
376
  }[], { stacked, position, format, axisType }: StackTotalOptions): AnyObject[];
377
+ /**
378
+ * Corner radius for one bar series. The theme rounds the top of vertical
379
+ * bars; horizontal bars round their right end instead. In a stack only the
380
+ * last series (the segment at the bar's end) is rounded.
381
+ */
382
+ declare function barCornerRadius(horizontal: boolean, stackIds: (string | undefined)[], index: number, radius?: number): number[];
373
383
  /**
374
384
  * Widen the grid's right edge for labels drawn past the end of horizontal
375
385
  * bars, which `containLabel` does not reserve room for. Width is estimated
@@ -667,4 +677,4 @@ declare function downloadFile(content: string, filename: string, mimeType?: stri
667
677
  */
668
678
  declare function downloadCsv(table: ChartDataTable, filename: string): void;
669
679
 
670
- export { type Accessor, type Aggregate, type AutoHeightOptions, AxisConfig, BarChartData, type BinValuesOptions, BoxPlotStats, type BuildDataLabelOptions, type BuildLegendOptions, type BuildTooltipOptions, BulletItem, CandlestickData, CategoryChartData, CategorySeriesData, ChartDataTable, ChartFormatter, type ChartFormatterOptions, type ChartFormatters, ChartLegendConfig, type Delta, type FromRecordsOptions, HeatmapData, HistogramBin, HistogramBucket, LabelFormatterParams, LegendItem, LineChartData, PieSliceData, type PointLabelLookup, RadarChartData, RadarIndicator, ReferenceBand, ReferenceLine, type ReferenceMarkOptions, SankeyData, ScatterChartData, type StackTotalOptions, type ToSliceDataOptions, TooltipFormatterParams, TreemapNode, ValueFormat, type WaterfallBar, WaterfallStep, abbreviateNumber, allSeriesEmpty, anchorCenterGraphic, binValues, boxPlotTable, boxplotStats, buildAxis, buildDataLabel, buildDataZoom, buildLegend, buildMarkArea, buildMarkLine, buildStackTotalSeries, buildTooltip, bulletTable, candlestickTable, categoryTable, chartFilename, chartFormatters, computeDelta, createTooltipFormatter, downloadCsv, downloadFile, escapeHtml, formatCurrency, formatDate, formatNumber, formatPercent, formatTableCell, formatTooltipValue, formatValue, fromRecords, generateAreaChartDescription, generateBarChartDescription, generateBoxPlotDescription, generateBulletDescription, generateComboChartDescription, generateDataTable, generateDotPlotDescription, generateHistogramDescription, generateLineChartDescription, generatePieChartDescription, generateScatterChartDescription, generateWaterfallDescription, getLegendItems, getReplaceMerge, gridInset, hasPointLabels, heatmapTable, histogramTable, itemLabelLookup, legendCenter, mergeChartOption, nameLabelLookup, niceStep, pairWithCategories, pointLabel, quantile, radarTable, resolveChartHeight, resolveValueFormatter, sankeyTable, scatterTable, seriesLabelLookup, sliceTable, stackTotals, tableToCsv, toPercentStack, toSliceData, treemapTable, trendLine, valueAxisConfig, valueLabelFormatter, waterfallLayout, waterfallTable, withEndLabelInset, withPointLabels, withReferenceMarks, withZoomInset };
680
+ export { type Accessor, type Aggregate, type AutoHeightOptions, AxisConfig, BarChartData, type BinValuesOptions, BoxPlotStats, type BuildDataLabelOptions, type BuildLegendOptions, type BuildTooltipOptions, BulletItem, CandlestickData, CategoryChartData, CategorySeriesData, ChartDataTable, ChartFormatter, type ChartFormatterOptions, type ChartFormatters, ChartLegendConfig, type Delta, type FromRecordsOptions, HeatmapData, HistogramBin, HistogramBucket, LabelFormatterParams, LegendItem, LineChartData, PieSliceData, type PointLabelLookup, RadarChartData, RadarIndicator, ReferenceBand, ReferenceLine, type ReferenceMarkOptions, SankeyData, ScatterChartData, type StackTotalOptions, type ToSliceDataOptions, TooltipFormatterParams, TreemapNode, ValueFormat, type WaterfallBar, WaterfallStep, abbreviateNumber, allSeriesEmpty, anchorCenterGraphic, barCornerRadius, binValues, boxPlotTable, boxplotStats, buildAxis, buildDataLabel, buildDataZoom, buildLegend, buildMarkArea, buildMarkLine, buildStackTotalSeries, buildTooltip, bulletTable, candlestickTable, categoryTable, chartFilename, chartFormatters, computeDelta, createTooltipFormatter, downloadCsv, downloadFile, escapeHtml, formatCurrency, formatDate, formatNumber, formatPercent, formatTableCell, formatTooltipValue, formatValue, fromRecords, generateAreaChartDescription, generateBarChartDescription, generateBoxPlotDescription, generateBulletDescription, generateComboChartDescription, generateDataTable, generateDotPlotDescription, generateHistogramDescription, generateLineChartDescription, generatePieChartDescription, generateScatterChartDescription, generateWaterfallDescription, getLegendItems, getReplaceMerge, gridInset, hasPointLabels, heatmapTable, histogramTable, itemLabelLookup, legendCenter, mergeChartOption, nameLabelLookup, niceStep, pairWithCategories, pointLabel, quantile, radarTable, resolveChartHeight, resolveValueFormatter, sankeyTable, scatterTable, seriesLabelLookup, sliceTable, stackTotals, tableToCsv, toPercentStack, toSliceData, treemapTable, trendLine, valueAxisConfig, valueLabelFormatter, waterfallLayout, waterfallTable, withEndLabelInset, withPointLabels, withReferenceMarks, withZoomInset };
package/dist/index.d.ts CHANGED
@@ -125,8 +125,12 @@ declare function generateDataTable(headers: string[], rows: (string | number)[][
125
125
  * rebuilds every component, so legend selection, dataZoom ranges and other
126
126
  * interaction state reset on each data update. Instead this replaces only:
127
127
  *
128
- * - `series` and `graphic`, so removed series, mark lines and centre labels
129
- * disappear;
128
+ * - `graphic`, so removed centre labels disappear;
129
+ * - `series`, unless every series keeps its keys and type and only its
130
+ * values change. A replaced series is a new model, which ECharts animates
131
+ * in from scratch, so a data refresh with the same shape (often the same
132
+ * data) must merge to avoid re-animating the chart; a changed shape is
133
+ * replaced so removed series, mark lines and options disappear;
130
134
  * - any component type that `next` has fewer of than `prev` (a hidden legend
131
135
  * or tooltip, a dropped volume grid and its axes).
132
136
  *
@@ -370,6 +374,12 @@ declare function buildStackTotalSeries(categories: (string | number)[], series:
370
374
  data: (number | null)[];
371
375
  stack?: string;
372
376
  }[], { stacked, position, format, axisType }: StackTotalOptions): AnyObject[];
377
+ /**
378
+ * Corner radius for one bar series. The theme rounds the top of vertical
379
+ * bars; horizontal bars round their right end instead. In a stack only the
380
+ * last series (the segment at the bar's end) is rounded.
381
+ */
382
+ declare function barCornerRadius(horizontal: boolean, stackIds: (string | undefined)[], index: number, radius?: number): number[];
373
383
  /**
374
384
  * Widen the grid's right edge for labels drawn past the end of horizontal
375
385
  * bars, which `containLabel` does not reserve room for. Width is estimated
@@ -667,4 +677,4 @@ declare function downloadFile(content: string, filename: string, mimeType?: stri
667
677
  */
668
678
  declare function downloadCsv(table: ChartDataTable, filename: string): void;
669
679
 
670
- export { type Accessor, type Aggregate, type AutoHeightOptions, AxisConfig, BarChartData, type BinValuesOptions, BoxPlotStats, type BuildDataLabelOptions, type BuildLegendOptions, type BuildTooltipOptions, BulletItem, CandlestickData, CategoryChartData, CategorySeriesData, ChartDataTable, ChartFormatter, type ChartFormatterOptions, type ChartFormatters, ChartLegendConfig, type Delta, type FromRecordsOptions, HeatmapData, HistogramBin, HistogramBucket, LabelFormatterParams, LegendItem, LineChartData, PieSliceData, type PointLabelLookup, RadarChartData, RadarIndicator, ReferenceBand, ReferenceLine, type ReferenceMarkOptions, SankeyData, ScatterChartData, type StackTotalOptions, type ToSliceDataOptions, TooltipFormatterParams, TreemapNode, ValueFormat, type WaterfallBar, WaterfallStep, abbreviateNumber, allSeriesEmpty, anchorCenterGraphic, binValues, boxPlotTable, boxplotStats, buildAxis, buildDataLabel, buildDataZoom, buildLegend, buildMarkArea, buildMarkLine, buildStackTotalSeries, buildTooltip, bulletTable, candlestickTable, categoryTable, chartFilename, chartFormatters, computeDelta, createTooltipFormatter, downloadCsv, downloadFile, escapeHtml, formatCurrency, formatDate, formatNumber, formatPercent, formatTableCell, formatTooltipValue, formatValue, fromRecords, generateAreaChartDescription, generateBarChartDescription, generateBoxPlotDescription, generateBulletDescription, generateComboChartDescription, generateDataTable, generateDotPlotDescription, generateHistogramDescription, generateLineChartDescription, generatePieChartDescription, generateScatterChartDescription, generateWaterfallDescription, getLegendItems, getReplaceMerge, gridInset, hasPointLabels, heatmapTable, histogramTable, itemLabelLookup, legendCenter, mergeChartOption, nameLabelLookup, niceStep, pairWithCategories, pointLabel, quantile, radarTable, resolveChartHeight, resolveValueFormatter, sankeyTable, scatterTable, seriesLabelLookup, sliceTable, stackTotals, tableToCsv, toPercentStack, toSliceData, treemapTable, trendLine, valueAxisConfig, valueLabelFormatter, waterfallLayout, waterfallTable, withEndLabelInset, withPointLabels, withReferenceMarks, withZoomInset };
680
+ export { type Accessor, type Aggregate, type AutoHeightOptions, AxisConfig, BarChartData, type BinValuesOptions, BoxPlotStats, type BuildDataLabelOptions, type BuildLegendOptions, type BuildTooltipOptions, BulletItem, CandlestickData, CategoryChartData, CategorySeriesData, ChartDataTable, ChartFormatter, type ChartFormatterOptions, type ChartFormatters, ChartLegendConfig, type Delta, type FromRecordsOptions, HeatmapData, HistogramBin, HistogramBucket, LabelFormatterParams, LegendItem, LineChartData, PieSliceData, type PointLabelLookup, RadarChartData, RadarIndicator, ReferenceBand, ReferenceLine, type ReferenceMarkOptions, SankeyData, ScatterChartData, type StackTotalOptions, type ToSliceDataOptions, TooltipFormatterParams, TreemapNode, ValueFormat, type WaterfallBar, WaterfallStep, abbreviateNumber, allSeriesEmpty, anchorCenterGraphic, barCornerRadius, binValues, boxPlotTable, boxplotStats, buildAxis, buildDataLabel, buildDataZoom, buildLegend, buildMarkArea, buildMarkLine, buildStackTotalSeries, buildTooltip, bulletTable, candlestickTable, categoryTable, chartFilename, chartFormatters, computeDelta, createTooltipFormatter, downloadCsv, downloadFile, escapeHtml, formatCurrency, formatDate, formatNumber, formatPercent, formatTableCell, formatTooltipValue, formatValue, fromRecords, generateAreaChartDescription, generateBarChartDescription, generateBoxPlotDescription, generateBulletDescription, generateComboChartDescription, generateDataTable, generateDotPlotDescription, generateHistogramDescription, generateLineChartDescription, generatePieChartDescription, generateScatterChartDescription, generateWaterfallDescription, getLegendItems, getReplaceMerge, gridInset, hasPointLabels, heatmapTable, histogramTable, itemLabelLookup, legendCenter, mergeChartOption, nameLabelLookup, niceStep, pairWithCategories, pointLabel, quantile, radarTable, resolveChartHeight, resolveValueFormatter, sankeyTable, scatterTable, seriesLabelLookup, sliceTable, stackTotals, tableToCsv, toPercentStack, toSliceData, treemapTable, trendLine, valueAxisConfig, valueLabelFormatter, waterfallLayout, waterfallTable, withEndLabelInset, withPointLabels, withReferenceMarks, withZoomInset };
package/dist/index.js CHANGED
@@ -252,14 +252,39 @@ function generateDataTable(headers, rows) {
252
252
  }
253
253
 
254
254
  // src/utils/merge.ts
255
- var ALWAYS_REPLACE = ["series", "graphic"];
255
+ var ALWAYS_REPLACE = ["graphic"];
256
256
  function countComponents(value) {
257
257
  if (value == null || value === false) return 0;
258
258
  if (Array.isArray(value)) return value.filter((item) => item != null).length;
259
259
  return 1;
260
260
  }
261
+ function isRecord(value) {
262
+ return value !== null && typeof value === "object" && !Array.isArray(value);
263
+ }
264
+ function sameShape(a, b) {
265
+ if (!isRecord(a) || !isRecord(b)) return !isRecord(a) && !isRecord(b);
266
+ const keys = Object.keys(a).filter((key) => a[key] !== void 0);
267
+ const other = Object.keys(b).filter((key) => b[key] !== void 0);
268
+ if (keys.length !== other.length) return false;
269
+ return keys.every(
270
+ (key) => key in b && b[key] !== void 0 && (key === "type" || key === "id" ? a[key] === b[key] : sameShape(a[key], b[key]))
271
+ );
272
+ }
273
+ function asList(value) {
274
+ if (value == null || value === false) return [];
275
+ return Array.isArray(value) ? value : [value];
276
+ }
277
+ function sameSeriesShape(prev, next) {
278
+ const before = asList(prev);
279
+ const after = asList(next);
280
+ return before.length === after.length && before.every((item, i) => sameShape(item, after[i]));
281
+ }
261
282
  function getReplaceMerge(prev, next, isComponentType) {
262
283
  const types = new Set(ALWAYS_REPLACE);
284
+ const prior = prev;
285
+ if (!prior || !sameSeriesShape(prior.series, next.series)) {
286
+ types.add("series");
287
+ }
263
288
  if (prev) {
264
289
  const before = prev;
265
290
  const after = next;
@@ -841,6 +866,12 @@ function buildStackTotalSeries(categories, series, { stacked, position, format,
841
866
  }
842
867
  }));
843
868
  }
869
+ function barCornerRadius(horizontal, stackIds, index, radius = 4) {
870
+ const stack = stackIds[index];
871
+ const outer = stack === void 0 || stackIds.lastIndexOf(stack) === index;
872
+ if (!outer) return [0, 0, 0, 0];
873
+ return horizontal ? [0, radius, radius, 0] : [radius, radius, 0, 0];
874
+ }
844
875
  function withEndLabelInset(inset, labels) {
845
876
  const longest = Math.max(0, ...labels.map((label) => label.length));
846
877
  if (longest === 0) return inset;
@@ -1235,4 +1266,4 @@ function downloadCsv(table, filename) {
1235
1266
  );
1236
1267
  }
1237
1268
 
1238
- export { abbreviateNumber, allSeriesEmpty, anchorCenterGraphic, binValues, boxPlotTable, boxplotStats, buildAxis, buildDataLabel, buildDataZoom, buildLegend, buildMarkArea, buildMarkLine, buildStackTotalSeries, buildTooltip, bulletTable, candlestickTable, categoryTable, chartFilename, chartFormatters, computeDelta, createTooltipFormatter, downloadCsv, downloadFile, escapeHtml, formatCurrency, formatDate, formatNumber, formatPercent, formatTableCell, formatTooltipValue, formatValue, fromRecords, generateAreaChartDescription, generateBarChartDescription, generateBoxPlotDescription, generateBulletDescription, generateComboChartDescription, generateDataTable, generateDotPlotDescription, generateHistogramDescription, generateLineChartDescription, generatePieChartDescription, generateScatterChartDescription, generateWaterfallDescription, getLegendItems, getReplaceMerge, gridInset, hasPointLabels, heatmapTable, histogramTable, itemLabelLookup, legendCenter, mergeChartOption, nameLabelLookup, niceStep, pairWithCategories, pointLabel, quantile, radarTable, resolveChartHeight, resolveValueFormatter, sankeyTable, scatterTable, seriesLabelLookup, sliceTable, stackTotals, tableToCsv, toPercentStack, toSliceData, treemapTable, trendLine, valueAxisConfig, valueLabelFormatter, waterfallLayout, waterfallTable, withEndLabelInset, withPointLabels, withReferenceMarks, withZoomInset };
1269
+ export { abbreviateNumber, allSeriesEmpty, anchorCenterGraphic, barCornerRadius, binValues, boxPlotTable, boxplotStats, buildAxis, buildDataLabel, buildDataZoom, buildLegend, buildMarkArea, buildMarkLine, buildStackTotalSeries, buildTooltip, bulletTable, candlestickTable, categoryTable, chartFilename, chartFormatters, computeDelta, createTooltipFormatter, downloadCsv, downloadFile, escapeHtml, formatCurrency, formatDate, formatNumber, formatPercent, formatTableCell, formatTooltipValue, formatValue, fromRecords, generateAreaChartDescription, generateBarChartDescription, generateBoxPlotDescription, generateBulletDescription, generateComboChartDescription, generateDataTable, generateDotPlotDescription, generateHistogramDescription, generateLineChartDescription, generatePieChartDescription, generateScatterChartDescription, generateWaterfallDescription, getLegendItems, getReplaceMerge, gridInset, hasPointLabels, heatmapTable, histogramTable, itemLabelLookup, legendCenter, mergeChartOption, nameLabelLookup, niceStep, pairWithCategories, pointLabel, quantile, radarTable, resolveChartHeight, resolveValueFormatter, sankeyTable, scatterTable, seriesLabelLookup, sliceTable, stackTotals, tableToCsv, toPercentStack, toSliceData, treemapTable, trendLine, valueAxisConfig, valueLabelFormatter, waterfallLayout, waterfallTable, withEndLabelInset, withPointLabels, withReferenceMarks, withZoomInset };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/charts-core",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Core utilities and theme for Classic Theme charts",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",