@opendata-ai/openchart-vanilla 6.18.0 → 6.19.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendata-ai/openchart-vanilla",
3
- "version": "6.18.0",
3
+ "version": "6.19.1",
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.18.0",
54
- "@opendata-ai/openchart-engine": "6.18.0",
53
+ "@opendata-ai/openchart-core": "6.19.1",
54
+ "@opendata-ai/openchart-engine": "6.19.1",
55
55
  "d3-force": "^3.0.0",
56
56
  "d3-quadtree": "^3.0.1"
57
57
  },
@@ -85,7 +85,7 @@ function stampAnimationAttrs(
85
85
  function wrapText(text: string, fontSize: number, fontWeight: number, maxWidth: number): string[] {
86
86
  if (maxWidth <= 0) return [text];
87
87
 
88
- const AVG_CHAR_WIDTH = 0.55;
88
+ const AVG_CHAR_WIDTH = 0.57;
89
89
  const WEIGHT_FACTORS: Record<number, number> = {
90
90
  100: 0.9,
91
91
  200: 0.92,
@@ -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
- text.textContent = label.text;
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
  }
@@ -178,7 +178,7 @@ function wrapText(
178
178
  }
179
179
 
180
180
  // Heuristic character width matching text-measure.ts
181
- const AVG_CHAR_WIDTH = 0.55;
181
+ const AVG_CHAR_WIDTH = 0.57;
182
182
  const WEIGHT_FACTORS: Record<number, number> = {
183
183
  100: 0.9,
184
184
  200: 0.92,