@opendata-ai/openchart-engine 8.0.0-rc.25 → 8.0.0-rc.26

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.js CHANGED
@@ -8560,6 +8560,11 @@ function computePieLabels(marks, _chartArea, density = "auto", _textFill = "#333
8560
8560
  width: textWidth,
8561
8561
  height: textHeight,
8562
8562
  priority: "data",
8563
+ // Index into the ORIGINAL marks array, not `targetMarks`. Density
8564
+ // filtering drops slices and resolveCollisions re-sorts by priority, so
8565
+ // the returned labels line up with neither. Callers assign by this index
8566
+ // instead of zipping positionally.
8567
+ index: marks.indexOf(mark),
8563
8568
  style: {
8564
8569
  fontFamily: "system-ui, -apple-system, sans-serif",
8565
8570
  fontSize: LABEL_FONT_SIZE5,
@@ -8581,14 +8586,16 @@ function computePieLabels(marks, _chartArea, density = "auto", _textFill = "#333
8581
8586
  x: c.anchorX,
8582
8587
  y: c.anchorY,
8583
8588
  style: c.style,
8584
- visible: true
8589
+ visible: true,
8590
+ ...c.index !== void 0 ? { index: c.index } : {}
8585
8591
  }));
8586
8592
  } else {
8587
8593
  resolved = resolveCollisions5(candidates);
8588
8594
  }
8589
- for (let i = 0; i < resolved.length && i < targetMarks.length; i++) {
8595
+ for (let i = 0; i < resolved.length; i++) {
8590
8596
  const label = resolved[i];
8591
- const mark = targetMarks[i];
8597
+ const mark = label.index !== void 0 ? marks[label.index] : void 0;
8598
+ if (!mark) continue;
8592
8599
  if (label.visible) {
8593
8600
  label.connector = {
8594
8601
  from: { x: label.x, y: label.y },
@@ -8606,16 +8613,16 @@ function computePieLabels(marks, _chartArea, density = "auto", _textFill = "#333
8606
8613
  var pieRenderer = (spec, scales, chartArea, strategy, theme) => {
8607
8614
  const marks = computePieMarks(spec, scales, chartArea, strategy, false);
8608
8615
  const labels = computePieLabels(marks, chartArea, spec.labels.density, theme.colors.text);
8609
- for (let i = 0; i < marks.length && i < labels.length; i++) {
8610
- marks[i].label = labels[i];
8616
+ for (const label of labels) {
8617
+ if (label.index !== void 0 && marks[label.index]) marks[label.index].label = label;
8611
8618
  }
8612
8619
  return marks;
8613
8620
  };
8614
8621
  var donutRenderer = (spec, scales, chartArea, strategy, theme) => {
8615
8622
  const marks = computePieMarks(spec, scales, chartArea, strategy, true);
8616
8623
  const labels = computePieLabels(marks, chartArea, spec.labels.density, theme.colors.text);
8617
- for (let i = 0; i < marks.length && i < labels.length; i++) {
8618
- marks[i].label = labels[i];
8624
+ for (const label of labels) {
8625
+ if (label.index !== void 0 && marks[label.index]) marks[label.index].label = label;
8619
8626
  }
8620
8627
  return marks;
8621
8628
  };
@@ -13849,6 +13856,7 @@ var LEGEND_PADDING = 8;
13849
13856
  var LEGEND_RIGHT_WIDTH = 120;
13850
13857
  var RIGHT_LEGEND_MAX_HEIGHT_RATIO = 0.4;
13851
13858
  var TOP_LEGEND_MAX_ROWS = 2;
13859
+ var ARC_LABEL_CROWDING_LIMIT = 21;
13852
13860
  function hasLegendContent(content) {
13853
13861
  return content.entries.length > 0 || content.continuous != null;
13854
13862
  }
@@ -14006,6 +14014,12 @@ function computeLegendContent(spec, strategy, theme, availableWidth, availableHe
14006
14014
  }
14007
14015
  }
14008
14016
  }
14017
+ const density = spec.labels.density;
14018
+ const everySliceLabeled = density === "all" || density === "auto";
14019
+ const uncrowded = seriesCount > 0 && seriesCount <= ARC_LABEL_CROWDING_LIMIT;
14020
+ if (spec.markType === "arc" && everySliceLabeled && uncrowded && !spec.userExplicit?.legend) {
14021
+ entries = [];
14022
+ }
14009
14023
  const labelStyle = {
14010
14024
  fontFamily: theme.fonts.family,
14011
14025
  fontSize: theme.fonts.sizes.small,
@@ -16015,6 +16029,7 @@ function collectContrastWarnings(scales, markType, theme) {
16015
16029
 
16016
16030
  // src/compiler/mark-render-mode.ts
16017
16031
  var AUTO_CANVAS_THRESHOLD = 1e3;
16032
+ var AUTO_CANVAS_REFUSAL_WARN_THRESHOLD = 5e3;
16018
16033
  function resolveMarkRenderMode(args, warnings = []) {
16019
16034
  const { markType, pointCount, display, faceted, layered } = args;
16020
16035
  const requested = args.requested ?? "auto";
@@ -16025,6 +16040,10 @@ function resolveMarkRenderMode(args, warnings = []) {
16025
16040
  warnings.push(
16026
16041
  `Chart warning: renderer "canvas" is not supported ${refusal}; rendering marks as SVG instead.`
16027
16042
  );
16043
+ } else if (pointCount > AUTO_CANVAS_REFUSAL_WARN_THRESHOLD) {
16044
+ warnings.push(
16045
+ `[openchart] Rendering ${pointCount} point marks as SVG: the canvas mark layer is not supported ${refusal}. Expect slow paint and interaction. Reduce the point count, or restructure so the dense marks compile as a single unlayered, unfaceted point chart.`
16046
+ );
16028
16047
  }
16029
16048
  return "svg";
16030
16049
  }
@@ -24106,6 +24125,19 @@ function compileFaceted(chartSpec, renderSpec, facetChannel, facetDirection, opt
24106
24125
  chartSpec.data
24107
24126
  );
24108
24127
  assignAnimationIndices(allMarks, resolvedAnimation);
24128
+ const facetRenderModeWarnings = [];
24129
+ resolveMarkRenderMode(
24130
+ {
24131
+ requested: options.renderer,
24132
+ markType: chartSpec.markType,
24133
+ pointCount: allMarks.reduce((n, m) => m.type === "point" ? n + 1 : n, 0),
24134
+ display: chartSpec.display,
24135
+ faceted: true,
24136
+ layered: options.layered ?? false
24137
+ },
24138
+ facetRenderModeWarnings
24139
+ );
24140
+ emitSpecWarnings(facetRenderModeWarnings, options.onWarn);
24109
24141
  return {
24110
24142
  area: chartArea,
24111
24143
  chrome: allFootnotes.length > 0 ? { ...dims.chrome, footnotes: allFootnotes } : dims.chrome,