@opendata-ai/openchart-vanilla 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.js +21 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/sankey-renderer.ts +24 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opendata-ai/openchart-vanilla",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.19.0",
|
|
4
4
|
"description": "Vanilla JS renderer for openchart: SVG charts, HTML tables, force-directed graphs",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Riley Hilliard",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@floating-ui/dom": "^1.7.6",
|
|
53
|
-
"@opendata-ai/openchart-core": "6.
|
|
54
|
-
"@opendata-ai/openchart-engine": "6.
|
|
53
|
+
"@opendata-ai/openchart-core": "6.19.0",
|
|
54
|
+
"@opendata-ai/openchart-engine": "6.19.0",
|
|
55
55
|
"d3-force": "^3.0.0",
|
|
56
56
|
"d3-quadtree": "^3.0.1"
|
|
57
57
|
},
|
package/src/sankey-renderer.ts
CHANGED
|
@@ -524,7 +524,30 @@ function renderLabels(parent: SVGElement, nodes: SankeyNodeMark[]): void {
|
|
|
524
524
|
const text = createSVGElement('text');
|
|
525
525
|
setAttrs(text, { x: label.x, y: label.y });
|
|
526
526
|
applyTextStyle(text, label.style);
|
|
527
|
-
|
|
527
|
+
|
|
528
|
+
// Wrap label text when maxWidth is set and text would overflow
|
|
529
|
+
if (label.maxWidth !== undefined && label.maxWidth > 0) {
|
|
530
|
+
const fontSize = label.style.fontSize ?? 12;
|
|
531
|
+
const fontWeight = label.style.fontWeight ?? 400;
|
|
532
|
+
const lines = wrapText(label.text, fontSize, fontWeight, label.maxWidth);
|
|
533
|
+
if (lines.length > 1) {
|
|
534
|
+
const lineHeight = fontSize * (label.style.lineHeight ?? 1.3);
|
|
535
|
+
// Center the multi-line block vertically around the label y position
|
|
536
|
+
const totalHeight = (lines.length - 1) * lineHeight;
|
|
537
|
+
const startY = label.y - totalHeight / 2;
|
|
538
|
+
for (let i = 0; i < lines.length; i++) {
|
|
539
|
+
const tspan = createSVGElement('tspan');
|
|
540
|
+
tspan.setAttribute('x', String(label.x));
|
|
541
|
+
tspan.setAttribute('y', String(startY + i * lineHeight));
|
|
542
|
+
tspan.textContent = lines[i];
|
|
543
|
+
text.appendChild(tspan);
|
|
544
|
+
}
|
|
545
|
+
} else {
|
|
546
|
+
text.textContent = label.text;
|
|
547
|
+
}
|
|
548
|
+
} else {
|
|
549
|
+
text.textContent = label.text;
|
|
550
|
+
}
|
|
528
551
|
|
|
529
552
|
g.appendChild(text);
|
|
530
553
|
}
|