@opendata-ai/openchart-engine 6.17.0 → 6.19.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 +1 -0
- package/dist/index.js +37 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/compiler/normalize.ts +1 -0
- package/src/sankey/compile-sankey.ts +29 -1
- package/src/sankey/layout.ts +14 -0
- package/src/sankey/types.ts +1 -0
package/dist/index.d.ts
CHANGED
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
|
|
@@ -9448,7 +9456,7 @@ function getLinkColors(linkStyle, sourceColor, targetColor, neutralColor) {
|
|
|
9448
9456
|
return { sourceColor, targetColor };
|
|
9449
9457
|
}
|
|
9450
9458
|
}
|
|
9451
|
-
function computeNodeLabel(node, maxDepth, theme, nodeWidth, nodeLabelAlign = "auto") {
|
|
9459
|
+
function computeNodeLabel(node, maxDepth, theme, nodeWidth, nodeLabelAlign = "auto", containerWidth, padding) {
|
|
9452
9460
|
const depth = node.depth ?? 0;
|
|
9453
9461
|
let placeLeft;
|
|
9454
9462
|
if (nodeLabelAlign === "left") {
|
|
@@ -9470,13 +9478,24 @@ function computeNodeLabel(node, maxDepth, theme, nodeWidth, nodeLabelAlign = "au
|
|
|
9470
9478
|
const y0 = node.y0 ?? 0;
|
|
9471
9479
|
const y1 = node.y1 ?? 0;
|
|
9472
9480
|
const midY = (y0 + y1) / 2;
|
|
9481
|
+
const pad2 = padding ?? 0;
|
|
9482
|
+
let maxWidth;
|
|
9483
|
+
if (containerWidth !== void 0) {
|
|
9484
|
+
if (placeLeft) {
|
|
9485
|
+
maxWidth = x0 - LABEL_GAP - pad2;
|
|
9486
|
+
} else {
|
|
9487
|
+
maxWidth = containerWidth - pad2 - (x1 + LABEL_GAP);
|
|
9488
|
+
}
|
|
9489
|
+
if (maxWidth !== void 0 && maxWidth < 0) maxWidth = 0;
|
|
9490
|
+
}
|
|
9473
9491
|
if (placeLeft) {
|
|
9474
9492
|
return {
|
|
9475
9493
|
text: node.label ?? node.id,
|
|
9476
9494
|
x: x0 - LABEL_GAP,
|
|
9477
9495
|
y: midY,
|
|
9478
9496
|
style: { ...style, textAnchor: "end", dominantBaseline: "central" },
|
|
9479
|
-
visible: true
|
|
9497
|
+
visible: true,
|
|
9498
|
+
maxWidth
|
|
9480
9499
|
};
|
|
9481
9500
|
}
|
|
9482
9501
|
return {
|
|
@@ -9484,7 +9503,8 @@ function computeNodeLabel(node, maxDepth, theme, nodeWidth, nodeLabelAlign = "au
|
|
|
9484
9503
|
x: x1 + LABEL_GAP,
|
|
9485
9504
|
y: midY,
|
|
9486
9505
|
style: { ...style, textAnchor: "start", dominantBaseline: "central" },
|
|
9487
|
-
visible: true
|
|
9506
|
+
visible: true,
|
|
9507
|
+
maxWidth
|
|
9488
9508
|
};
|
|
9489
9509
|
}
|
|
9490
9510
|
function compileSankey(spec, options) {
|
|
@@ -9581,7 +9601,8 @@ function compileSankey(spec, options) {
|
|
|
9581
9601
|
sankeySpec.nodeWidth,
|
|
9582
9602
|
sankeySpec.nodePadding,
|
|
9583
9603
|
sankeySpec.nodeAlign,
|
|
9584
|
-
sankeySpec.iterations
|
|
9604
|
+
sankeySpec.iterations,
|
|
9605
|
+
sankeySpec.nodeSort
|
|
9585
9606
|
);
|
|
9586
9607
|
const nodeLabelAlign = sankeySpec.nodeLabelAlign ?? "auto";
|
|
9587
9608
|
const maxDepthFirst = nodes.reduce((max4, n) => Math.max(max4, n.depth ?? 0), 0);
|
|
@@ -9614,7 +9635,8 @@ function compileSankey(spec, options) {
|
|
|
9614
9635
|
sankeySpec.nodeWidth,
|
|
9615
9636
|
sankeySpec.nodePadding,
|
|
9616
9637
|
sankeySpec.nodeAlign,
|
|
9617
|
-
sankeySpec.iterations
|
|
9638
|
+
sankeySpec.iterations,
|
|
9639
|
+
sankeySpec.nodeSort
|
|
9618
9640
|
));
|
|
9619
9641
|
}
|
|
9620
9642
|
const nodeColorMap = buildNodeColorMap(
|
|
@@ -9637,7 +9659,15 @@ function compileSankey(spec, options) {
|
|
|
9637
9659
|
height: (node.y1 ?? 0) - (node.y0 ?? 0),
|
|
9638
9660
|
fill,
|
|
9639
9661
|
cornerRadius: NODE_CORNER_RADIUS,
|
|
9640
|
-
label: computeNodeLabel(
|
|
9662
|
+
label: computeNodeLabel(
|
|
9663
|
+
node,
|
|
9664
|
+
maxDepth,
|
|
9665
|
+
theme,
|
|
9666
|
+
sankeySpec.nodeWidth,
|
|
9667
|
+
nodeLabelAlign,
|
|
9668
|
+
options.width,
|
|
9669
|
+
padding
|
|
9670
|
+
),
|
|
9641
9671
|
nodeId: node.id,
|
|
9642
9672
|
value: node.value ?? 0,
|
|
9643
9673
|
depth,
|