@opendata-ai/openchart-engine 6.18.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 CHANGED
@@ -9456,7 +9456,7 @@ function getLinkColors(linkStyle, sourceColor, targetColor, neutralColor) {
9456
9456
  return { sourceColor, targetColor };
9457
9457
  }
9458
9458
  }
9459
- function computeNodeLabel(node, maxDepth, theme, nodeWidth, nodeLabelAlign = "auto") {
9459
+ function computeNodeLabel(node, maxDepth, theme, nodeWidth, nodeLabelAlign = "auto", containerWidth, padding) {
9460
9460
  const depth = node.depth ?? 0;
9461
9461
  let placeLeft;
9462
9462
  if (nodeLabelAlign === "left") {
@@ -9478,13 +9478,24 @@ function computeNodeLabel(node, maxDepth, theme, nodeWidth, nodeLabelAlign = "au
9478
9478
  const y0 = node.y0 ?? 0;
9479
9479
  const y1 = node.y1 ?? 0;
9480
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
+ }
9481
9491
  if (placeLeft) {
9482
9492
  return {
9483
9493
  text: node.label ?? node.id,
9484
9494
  x: x0 - LABEL_GAP,
9485
9495
  y: midY,
9486
9496
  style: { ...style, textAnchor: "end", dominantBaseline: "central" },
9487
- visible: true
9497
+ visible: true,
9498
+ maxWidth
9488
9499
  };
9489
9500
  }
9490
9501
  return {
@@ -9492,7 +9503,8 @@ function computeNodeLabel(node, maxDepth, theme, nodeWidth, nodeLabelAlign = "au
9492
9503
  x: x1 + LABEL_GAP,
9493
9504
  y: midY,
9494
9505
  style: { ...style, textAnchor: "start", dominantBaseline: "central" },
9495
- visible: true
9506
+ visible: true,
9507
+ maxWidth
9496
9508
  };
9497
9509
  }
9498
9510
  function compileSankey(spec, options) {
@@ -9647,7 +9659,15 @@ function compileSankey(spec, options) {
9647
9659
  height: (node.y1 ?? 0) - (node.y0 ?? 0),
9648
9660
  fill,
9649
9661
  cornerRadius: NODE_CORNER_RADIUS,
9650
- label: computeNodeLabel(node, maxDepth, theme, sankeySpec.nodeWidth, nodeLabelAlign),
9662
+ label: computeNodeLabel(
9663
+ node,
9664
+ maxDepth,
9665
+ theme,
9666
+ sankeySpec.nodeWidth,
9667
+ nodeLabelAlign,
9668
+ options.width,
9669
+ padding
9670
+ ),
9651
9671
  nodeId: node.id,
9652
9672
  value: node.value ?? 0,
9653
9673
  depth,