@opendata-ai/openchart-engine 6.8.0 → 6.9.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 +15 -5
- 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 +22 -12
- package/src/sankey/types.ts +1 -0
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -6111,6 +6111,7 @@ function normalizeSankeySpec(spec, _warnings) {
|
|
|
6111
6111
|
nodeAlign: spec.nodeAlign ?? "justify",
|
|
6112
6112
|
iterations: spec.iterations ?? 6,
|
|
6113
6113
|
linkStyle: spec.linkStyle ?? "gradient",
|
|
6114
|
+
nodeLabelAlign: spec.nodeLabelAlign ?? "auto",
|
|
6114
6115
|
chrome: normalizeChrome(spec.chrome),
|
|
6115
6116
|
legend: spec.legend,
|
|
6116
6117
|
theme: spec.theme ?? {},
|
|
@@ -8924,9 +8925,16 @@ function getLinkColors(linkStyle, sourceColor, targetColor, neutralColor) {
|
|
|
8924
8925
|
return { sourceColor, targetColor };
|
|
8925
8926
|
}
|
|
8926
8927
|
}
|
|
8927
|
-
function computeNodeLabel(node, maxDepth, theme, nodeWidth) {
|
|
8928
|
+
function computeNodeLabel(node, maxDepth, theme, nodeWidth, nodeLabelAlign = "auto") {
|
|
8928
8929
|
const depth = node.depth ?? 0;
|
|
8929
|
-
|
|
8930
|
+
let placeLeft;
|
|
8931
|
+
if (nodeLabelAlign === "left") {
|
|
8932
|
+
placeLeft = true;
|
|
8933
|
+
} else if (nodeLabelAlign === "right") {
|
|
8934
|
+
placeLeft = false;
|
|
8935
|
+
} else {
|
|
8936
|
+
placeLeft = depth === maxDepth;
|
|
8937
|
+
}
|
|
8930
8938
|
const style = {
|
|
8931
8939
|
fontFamily: theme.fonts.family,
|
|
8932
8940
|
fontSize: theme.fonts.sizes.small,
|
|
@@ -8939,7 +8947,7 @@ function computeNodeLabel(node, maxDepth, theme, nodeWidth) {
|
|
|
8939
8947
|
const y0 = node.y0 ?? 0;
|
|
8940
8948
|
const y1 = node.y1 ?? 0;
|
|
8941
8949
|
const midY = (y0 + y1) / 2;
|
|
8942
|
-
if (
|
|
8950
|
+
if (placeLeft) {
|
|
8943
8951
|
return {
|
|
8944
8952
|
text: node.label ?? node.id,
|
|
8945
8953
|
x: x0 - LABEL_GAP,
|
|
@@ -9047,12 +9055,14 @@ function compileSankey(spec, options) {
|
|
|
9047
9055
|
sankeySpec.nodeAlign,
|
|
9048
9056
|
sankeySpec.iterations
|
|
9049
9057
|
);
|
|
9058
|
+
const nodeLabelAlign = sankeySpec.nodeLabelAlign ?? "auto";
|
|
9050
9059
|
const maxDepthFirst = nodes.reduce((max4, n) => Math.max(max4, n.depth ?? 0), 0);
|
|
9051
9060
|
const rightEdge = area.x + area.width;
|
|
9052
9061
|
let maxOverflow = 0;
|
|
9053
9062
|
for (const node of nodes) {
|
|
9054
9063
|
const depth = node.depth ?? 0;
|
|
9055
|
-
|
|
9064
|
+
const labelsLeft = nodeLabelAlign === "left" || nodeLabelAlign === "auto" && depth === maxDepthFirst;
|
|
9065
|
+
if (labelsLeft) continue;
|
|
9056
9066
|
const labelX = (node.x1 ?? nodeWidth) + LABEL_GAP;
|
|
9057
9067
|
const labelText = node.label ?? node.id;
|
|
9058
9068
|
const labelWidth = estimateTextWidth10(labelText, labelFontSize, labelFontWeight);
|
|
@@ -9099,7 +9109,7 @@ function compileSankey(spec, options) {
|
|
|
9099
9109
|
height: (node.y1 ?? 0) - (node.y0 ?? 0),
|
|
9100
9110
|
fill,
|
|
9101
9111
|
cornerRadius: NODE_CORNER_RADIUS,
|
|
9102
|
-
label: computeNodeLabel(node, maxDepth, theme, sankeySpec.nodeWidth),
|
|
9112
|
+
label: computeNodeLabel(node, maxDepth, theme, sankeySpec.nodeWidth, nodeLabelAlign),
|
|
9103
9113
|
nodeId: node.id,
|
|
9104
9114
|
value: node.value ?? 0,
|
|
9105
9115
|
depth,
|