@opendata-ai/openchart-engine 6.17.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 ?? {},
@@ -9345,7 +9346,7 @@ var ALIGN_MAP = {
9345
9346
  right,
9346
9347
  center
9347
9348
  };
9348
- function computeSankeyLayout(data, sourceField, targetField, valueField, area, nodeWidth, nodePadding, nodeAlign, iterations) {
9349
+ function computeSankeyLayout(data, sourceField, targetField, valueField, area, nodeWidth, nodePadding, nodeAlign, iterations, nodeSort) {
9349
9350
  const nodeSet = /* @__PURE__ */ new Set();
9350
9351
  for (const row of data) {
9351
9352
  nodeSet.add(String(row[sourceField]));
@@ -9366,6 +9367,13 @@ function computeSankeyLayout(data, sourceField, targetField, valueField, area, n
9366
9367
  [area.x, area.y],
9367
9368
  [area.x + area.width, area.y + area.height]
9368
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
+ }
9369
9377
  const graph = generator({
9370
9378
  nodes,
9371
9379
  links
@@ -9581,7 +9589,8 @@ function compileSankey(spec, options) {
9581
9589
  sankeySpec.nodeWidth,
9582
9590
  sankeySpec.nodePadding,
9583
9591
  sankeySpec.nodeAlign,
9584
- sankeySpec.iterations
9592
+ sankeySpec.iterations,
9593
+ sankeySpec.nodeSort
9585
9594
  );
9586
9595
  const nodeLabelAlign = sankeySpec.nodeLabelAlign ?? "auto";
9587
9596
  const maxDepthFirst = nodes.reduce((max4, n) => Math.max(max4, n.depth ?? 0), 0);
@@ -9614,7 +9623,8 @@ function compileSankey(spec, options) {
9614
9623
  sankeySpec.nodeWidth,
9615
9624
  sankeySpec.nodePadding,
9616
9625
  sankeySpec.nodeAlign,
9617
- sankeySpec.iterations
9626
+ sankeySpec.iterations,
9627
+ sankeySpec.nodeSort
9618
9628
  ));
9619
9629
  }
9620
9630
  const nodeColorMap = buildNodeColorMap(