@opendata-ai/openchart-engine 6.16.0 → 6.18.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 CHANGED
@@ -305,6 +305,7 @@ interface NormalizedSankeySpec {
305
305
  iterations: number;
306
306
  linkStyle: SankeyLinkColor;
307
307
  nodeLabelAlign: 'auto' | 'left' | 'right';
308
+ nodeSort?: string[];
308
309
  chrome: NormalizedChrome;
309
310
  legend?: LegendConfig;
310
311
  theme: ThemeConfig;
package/dist/index.js CHANGED
@@ -6530,6 +6530,7 @@ function normalizeSankeySpec(spec, _warnings) {
6530
6530
  iterations: spec.iterations ?? 6,
6531
6531
  linkStyle: spec.linkStyle ?? "gradient",
6532
6532
  nodeLabelAlign: spec.nodeLabelAlign ?? "auto",
6533
+ nodeSort: spec.nodeSort,
6533
6534
  chrome: normalizeChrome(spec.chrome),
6534
6535
  legend: spec.legend,
6535
6536
  theme: spec.theme ?? {},
@@ -7776,9 +7777,9 @@ import {
7776
7777
  formatNumber as formatNumber6
7777
7778
  } from "@opendata-ai/openchart-core";
7778
7779
  var TICK_COUNTS = {
7779
- full: 10,
7780
- reduced: 7,
7781
- minimal: 3
7780
+ full: 12,
7781
+ reduced: 8,
7782
+ minimal: 4
7782
7783
  };
7783
7784
  var HEIGHT_MINIMAL_THRESHOLD = 120;
7784
7785
  var HEIGHT_REDUCED_THRESHOLD = 200;
@@ -8804,6 +8805,20 @@ function computeLegend(spec, strategy, theme, chartArea, watermark = true) {
8804
8805
  };
8805
8806
  }
8806
8807
  let entries = extractColorEntries(spec, theme);
8808
+ const isLineOrArea = spec.markType === "line" || spec.markType === "area";
8809
+ const hasLabels = spec.labels.density !== "none";
8810
+ const labelsWillRender = strategy.labelMode !== "none";
8811
+ const hasColorEncoding = spec.encoding.color != null;
8812
+ const legendNotForced = spec.legend?.show !== true;
8813
+ if (isLineOrArea && hasLabels && labelsWillRender && hasColorEncoding && legendNotForced) {
8814
+ const isArea = spec.markType === "area";
8815
+ const quantChannel = spec.encoding.y?.type === "quantitative" ? spec.encoding.y : spec.encoding.x;
8816
+ const stackValue2 = quantChannel?.stack;
8817
+ const isStacked = stackValue2 !== null && stackValue2 !== false;
8818
+ if (!isArea || !isStacked) {
8819
+ entries = [];
8820
+ }
8821
+ }
8807
8822
  const labelStyle = {
8808
8823
  fontFamily: theme.fonts.family,
8809
8824
  fontSize: theme.fonts.sizes.small,
@@ -9331,7 +9346,7 @@ var ALIGN_MAP = {
9331
9346
  right,
9332
9347
  center
9333
9348
  };
9334
- function computeSankeyLayout(data, sourceField, targetField, valueField, area, nodeWidth, nodePadding, nodeAlign, iterations) {
9349
+ function computeSankeyLayout(data, sourceField, targetField, valueField, area, nodeWidth, nodePadding, nodeAlign, iterations, nodeSort) {
9335
9350
  const nodeSet = /* @__PURE__ */ new Set();
9336
9351
  for (const row of data) {
9337
9352
  nodeSet.add(String(row[sourceField]));
@@ -9352,6 +9367,13 @@ function computeSankeyLayout(data, sourceField, targetField, valueField, area, n
9352
9367
  [area.x, area.y],
9353
9368
  [area.x + area.width, area.y + area.height]
9354
9369
  ]).iterations(iterations);
9370
+ if (nodeSort && nodeSort.length > 0) {
9371
+ const orderMap = new Map(nodeSort.map((id, i) => [id, i]));
9372
+ const fallback = nodeSort.length;
9373
+ generator.nodeSort(
9374
+ (a, b) => (orderMap.get(a.id) ?? fallback) - (orderMap.get(b.id) ?? fallback)
9375
+ );
9376
+ }
9355
9377
  const graph = generator({
9356
9378
  nodes,
9357
9379
  links
@@ -9567,7 +9589,8 @@ function compileSankey(spec, options) {
9567
9589
  sankeySpec.nodeWidth,
9568
9590
  sankeySpec.nodePadding,
9569
9591
  sankeySpec.nodeAlign,
9570
- sankeySpec.iterations
9592
+ sankeySpec.iterations,
9593
+ sankeySpec.nodeSort
9571
9594
  );
9572
9595
  const nodeLabelAlign = sankeySpec.nodeLabelAlign ?? "auto";
9573
9596
  const maxDepthFirst = nodes.reduce((max4, n) => Math.max(max4, n.depth ?? 0), 0);
@@ -9600,7 +9623,8 @@ function compileSankey(spec, options) {
9600
9623
  sankeySpec.nodeWidth,
9601
9624
  sankeySpec.nodePadding,
9602
9625
  sankeySpec.nodeAlign,
9603
- sankeySpec.iterations
9626
+ sankeySpec.iterations,
9627
+ sankeySpec.nodeSort
9604
9628
  ));
9605
9629
  }
9606
9630
  const nodeColorMap = buildNodeColorMap(
@@ -9935,12 +9959,16 @@ function computeCategoryColors(data, column, theme, darkMode) {
9935
9959
  }
9936
9960
  bg = explicitMap[key];
9937
9961
  isExplicit = true;
9938
- } else if (autoAssigned.has(key)) {
9939
- bg = autoAssigned.get(key);
9962
+ } else if (column.autoAssign) {
9963
+ if (autoAssigned.has(key)) {
9964
+ bg = autoAssigned.get(key);
9965
+ } else {
9966
+ bg = categoricalPalette[nextPaletteIndex % categoricalPalette.length];
9967
+ nextPaletteIndex++;
9968
+ autoAssigned.set(key, bg);
9969
+ }
9940
9970
  } else {
9941
- bg = categoricalPalette[nextPaletteIndex % categoricalPalette.length];
9942
- nextPaletteIndex++;
9943
- autoAssigned.set(key, bg);
9971
+ continue;
9944
9972
  }
9945
9973
  if (darkMode && !isExplicit) {
9946
9974
  bg = adaptColorForDarkMode(bg, lightBg, darkBg);