apexsankey 1.1.0 → 1.1.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.
@@ -16677,19 +16677,19 @@ function drawRect({
16677
16677
  rect.stroke({ color: borderColor, width: 1 });
16678
16678
  return rect;
16679
16679
  }
16680
- function drawText(text = "", { x: x2, y: y2, fontColor = "#666767", textAnchor = "start" }) {
16680
+ function drawText(text = "", { x: x2, y: y2, fontColor = "#666767", textAnchor = "start", pointerEvents = "all" }) {
16681
16681
  const textSvg = new Text();
16682
16682
  textSvg.font({ fill: fontColor });
16683
16683
  textSvg.tspan(text);
16684
16684
  if (x2 !== void 0 && y2 !== void 0) {
16685
16685
  textSvg.move(x2, y2);
16686
16686
  }
16687
- textSvg.attr({ "text-anchor": textAnchor });
16687
+ textSvg.attr({ "text-anchor": textAnchor, "pointer-events": pointerEvents });
16688
16688
  return textSvg;
16689
16689
  }
16690
- function drawGroup(x2 = 0, y2 = 0, id, parent) {
16690
+ function drawGroup(x2, y2, id, parent) {
16691
16691
  const group = new G();
16692
- group.attr({ transform: `translate(${x2}, ${y2})`, "data-self": id, "data-parent": parent });
16692
+ group.attr({ transform: x2 && y2 ? `translate(${x2}, ${y2})` : void 0, "data-self": id, "data-parent": parent });
16693
16693
  return group;
16694
16694
  }
16695
16695
  function drawPath(pathString, { id = "", edgeColor, opacity = 1 } = {}) {
@@ -16698,7 +16698,13 @@ function drawPath(pathString, { id = "", edgeColor, opacity = 1 } = {}) {
16698
16698
  path.fill(edgeColor).opacity(opacity);
16699
16699
  return path;
16700
16700
  }
16701
- const nodeTitle = (nodeData) => nodeData.title !== void 0 ? nodeData.title : nodeData.id;
16701
+ const nodeTitle = (nodeData, maxLength) => {
16702
+ const text = nodeData.title !== void 0 ? nodeData.title : nodeData.id;
16703
+ if (maxLength && text.length > maxLength) {
16704
+ return `${text.substr(0, 15)}...`;
16705
+ }
16706
+ return text;
16707
+ };
16702
16708
  function titlePosition(node) {
16703
16709
  let top = false;
16704
16710
  let right = false;
@@ -16716,25 +16722,26 @@ function titlePosition(node) {
16716
16722
  }
16717
16723
  return { top, right };
16718
16724
  }
16719
- function textTransform(d, position2) {
16720
- const y2 = position2.top ? -25 : d.dy / 2 - 10;
16725
+ function textTransform(node, position2, nodeWidth) {
16726
+ const y2 = position2.top ? -25 : node.dy / 2 - 10;
16721
16727
  let x2;
16722
16728
  if (position2.top) {
16723
16729
  x2 = position2.right ? 4 : -4;
16724
16730
  } else {
16725
- x2 = position2.right ? -10 : 10;
16731
+ x2 = position2.right ? nodeWidth : -nodeWidth;
16726
16732
  }
16727
- return { x: d.x + x2, y: d.y + y2 };
16733
+ return { x: node.x + x2, y: node.y + y2 };
16728
16734
  }
16729
- function renderNodeText(graphNode, fontColor) {
16735
+ function renderNodeText(graphNode, { fontColor, nodeWidth }) {
16730
16736
  const { data: data2 } = graphNode;
16731
- const titleLayoutData = titlePosition(graphNode);
16732
- const { x: x2, y: y2 } = textTransform(graphNode, titleLayoutData);
16733
- const text = drawText(nodeTitle(data2), {
16737
+ const position2 = titlePosition(graphNode);
16738
+ const { x: x2, y: y2 } = textTransform(graphNode, position2, nodeWidth);
16739
+ const text = drawText(nodeTitle(data2, position2.top ? 25 : 15), {
16734
16740
  x: x2,
16735
16741
  y: y2,
16736
- textAnchor: titleLayoutData.right ? "end" : "start",
16737
- fontColor
16742
+ textAnchor: !position2.top ? position2.right ? "start" : "end" : "middle",
16743
+ fontColor,
16744
+ pointerEvents: "none"
16738
16745
  });
16739
16746
  return text;
16740
16747
  }
@@ -16743,25 +16750,25 @@ function renderNode(graphNode, options) {
16743
16750
  const { x: x2, y: y2, dy: dy2 } = graphNode;
16744
16751
  const { nodeWidth, nodeBorderWidth, nodeBorderColor, onNodeClick, fontColor } = options;
16745
16752
  const group = new G({ class: "node" });
16746
- const body = drawRect({
16753
+ const nodeBody = drawRect({
16747
16754
  x: x2 - nodeWidth / 2,
16748
16755
  y: y2,
16749
16756
  width: nodeWidth,
16750
16757
  height: dy2
16751
16758
  });
16752
- body.fill((_a = graphNode.data) == null ? void 0 : _a.color);
16753
- body.stroke({
16759
+ nodeBody.fill((_a = graphNode.data) == null ? void 0 : _a.color);
16760
+ nodeBody.stroke({
16754
16761
  width: nodeBorderWidth,
16755
16762
  color: nodeBorderColor ?? ((_b = graphNode.data) == null ? void 0 : _b.color)
16756
16763
  });
16757
- body.on("click", () => {
16764
+ nodeBody.on("click", () => {
16758
16765
  if (typeof onNodeClick === "function") {
16759
16766
  onNodeClick(graphNode);
16760
16767
  }
16761
16768
  });
16762
- group.add(body);
16769
+ group.add(nodeBody);
16763
16770
  if (graphNode.data) {
16764
- const text = renderNodeText(graphNode, fontColor);
16771
+ const text = renderNodeText(graphNode, { fontColor, nodeWidth });
16765
16772
  group.add(text);
16766
16773
  }
16767
16774
  return group;
@@ -16924,9 +16931,12 @@ class SankeyGraph extends Paper {
16924
16931
  mainGroup.attr("style", globalStyle);
16925
16932
  const nodes = ((_a = this.graph) == null ? void 0 : _a.nodes()) || [];
16926
16933
  const edges = ((_b = this.graph) == null ? void 0 : _b.edges()) || [];
16934
+ const edgesGroup = drawGroup();
16927
16935
  edges.forEach((edgeObj) => {
16928
- this.renderEdge(edgeObj, mainGroup);
16936
+ this.renderEdge(edgeObj, edgesGroup);
16929
16937
  });
16938
+ mainGroup.add(edgesGroup);
16939
+ const nodesGroup = drawGroup();
16930
16940
  nodes.forEach((nodeId) => {
16931
16941
  const node = this.graph.node(nodeId);
16932
16942
  const nodeGroup = renderNode(node, {
@@ -16936,8 +16946,9 @@ class SankeyGraph extends Paper {
16936
16946
  onNodeClick,
16937
16947
  fontColor
16938
16948
  });
16939
- mainGroup.add(nodeGroup);
16949
+ nodesGroup.add(nodeGroup);
16940
16950
  });
16951
+ mainGroup.add(nodesGroup);
16941
16952
  this.add(mainGroup);
16942
16953
  if (keepOldPosition) {
16943
16954
  this.updateViewBox(