apexsankey 1.1.1 → 1.1.2

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.
@@ -5767,13 +5767,13 @@ class Paper {
5767
5767
  this.width = width2;
5768
5768
  this.height = height2;
5769
5769
  this.spacing = spacing;
5770
- this.canvas = SVG().addTo(element).size(width2, height2).viewbox(`-${spacing} -${spacing} ${width2} ${height2}`).attr({ style: canvasStyle });
5770
+ this.canvas = SVG().addTo(element).size("100%", "100%").viewbox(`-${spacing} -${spacing} ${width2 + spacing * 2} ${height2 + spacing}`).attr({ style: canvasStyle, preserveAspectRatio: "xMinYMin meet" });
5771
5771
  }
5772
5772
  add(element) {
5773
5773
  this.canvas.add(element);
5774
5774
  }
5775
5775
  resetViewBox() {
5776
- this.canvas.viewbox(`-${this.spacing} -${this.spacing} ${this.width} ${this.height}`);
5776
+ this.canvas.viewbox(`-${this.spacing} -${this.spacing} ${this.width + this.spacing * 2} ${this.height + this.spacing}`);
5777
5777
  }
5778
5778
  updateViewBox(x2, y2, width2, height2) {
5779
5779
  this.canvas.viewbox(`${x2} ${y2} ${width2} ${height2}`);
@@ -5785,7 +5785,7 @@ class Paper {
5785
5785
  }
5786
5786
  }
5787
5787
  clear() {
5788
- this.canvas.clear().viewbox(`-${this.spacing} -${this.spacing} ${this.width} ${this.height}`);
5788
+ this.canvas.clear().viewbox(`-${this.spacing} -${this.spacing} ${this.width + this.spacing * 2} ${this.height + this.spacing}`);
5789
5789
  }
5790
5790
  }
5791
5791
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
@@ -16201,7 +16201,7 @@ function justifiedPositioning() {
16201
16201
  let y2 = 0;
16202
16202
  rank.forEach((band, j) => {
16203
16203
  const bandHeight = bandVals[j] / lodashExports.sumBy(bandVals) * size2[1];
16204
- const margin = whitespace2 * bandHeight / 5;
16204
+ const margin = y2 === 0 ? 0 : whitespace2 * bandHeight / 5;
16205
16205
  const height2 = bandHeight - 2 * margin;
16206
16206
  const total = lodashExports.sumBy(band, (u) => G2.node(u).dy);
16207
16207
  const gaps = band.map((u, i) => {
@@ -16543,6 +16543,7 @@ function sankey(options) {
16543
16543
  addDummyNodes(graph2);
16544
16544
  order = ordering(graph2);
16545
16545
  } else {
16546
+ assignRanks(graph2, data2.rankSets || []);
16546
16547
  order = data2.order;
16547
16548
  if (order.length > 0 && order[0].length > 0 && !lodashExports.isArray(order[0][0])) {
16548
16549
  order = order.map((rank) => [rank]);
@@ -16689,7 +16690,7 @@ function drawText(text = "", { x: x2, y: y2, fontColor = "#666767", textAnchor =
16689
16690
  }
16690
16691
  function drawGroup(x2, y2, id, parent) {
16691
16692
  const group = new G();
16692
- group.attr({ transform: x2 && y2 ? `translate(${x2}, ${y2})` : void 0, "data-self": id, "data-parent": parent });
16693
+ group.attr({ transform: x2 !== void 0 && y2 !== void 0 ? `translate(${x2}, ${y2})` : void 0, "data-self": id, "data-parent": parent });
16693
16694
  return group;
16694
16695
  }
16695
16696
  function drawPath(pathString, { id = "", edgeColor, opacity = 1 } = {}) {
@@ -16705,20 +16706,12 @@ const nodeTitle = (nodeData, maxLength) => {
16705
16706
  }
16706
16707
  return text;
16707
16708
  };
16708
- function titlePosition(node) {
16709
+ function titlePosition(node, maxRank) {
16709
16710
  let top = false;
16710
16711
  let right = false;
16711
- if (node.spaceAbove > 20 && node.style !== "type") {
16712
- top = true;
16713
- } else {
16714
- top = false;
16715
- }
16716
- if (node.incoming.length === 0) {
16712
+ if (node.rank < maxRank / 2) {
16717
16713
  right = true;
16718
16714
  top = false;
16719
- } else if (node.outgoing.length === 0) {
16720
- right = false;
16721
- top = false;
16722
16715
  }
16723
16716
  return { top, right };
16724
16717
  }
@@ -16728,24 +16721,24 @@ function textTransform(node, position2, nodeWidth) {
16728
16721
  if (position2.top) {
16729
16722
  x2 = position2.right ? 4 : -4;
16730
16723
  } else {
16731
- x2 = position2.right ? nodeWidth : -nodeWidth;
16724
+ x2 = position2.right ? 10 + nodeWidth / 2 : -10 + -nodeWidth / 2;
16732
16725
  }
16733
16726
  return { x: node.x + x2, y: node.y + y2 };
16734
16727
  }
16735
- function renderNodeText(graphNode, { fontColor, nodeWidth }) {
16728
+ function renderNodeText(graphNode, { fontColor, nodeWidth, maxRank }) {
16736
16729
  const { data: data2 } = graphNode;
16737
- const position2 = titlePosition(graphNode);
16730
+ const position2 = titlePosition(graphNode, maxRank);
16738
16731
  const { x: x2, y: y2 } = textTransform(graphNode, position2, nodeWidth);
16739
16732
  const text = drawText(nodeTitle(data2, position2.top ? 25 : 15), {
16740
16733
  x: x2,
16741
16734
  y: y2,
16742
- textAnchor: !position2.top ? position2.right ? "start" : "end" : "middle",
16735
+ textAnchor: position2.top ? "middle" : position2.right ? "start" : "end",
16743
16736
  fontColor,
16744
16737
  pointerEvents: "none"
16745
16738
  });
16746
16739
  return text;
16747
16740
  }
16748
- function renderNode(graphNode, options) {
16741
+ function renderNode(graphNode, maxRank, options) {
16749
16742
  var _a, _b;
16750
16743
  const { x: x2, y: y2, dy: dy2 } = graphNode;
16751
16744
  const { nodeWidth, nodeBorderWidth, nodeBorderColor, onNodeClick, fontColor } = options;
@@ -16768,7 +16761,7 @@ function renderNode(graphNode, options) {
16768
16761
  });
16769
16762
  group.add(nodeBody);
16770
16763
  if (graphNode.data) {
16771
- const text = renderNodeText(graphNode, { fontColor, nodeWidth });
16764
+ const text = renderNodeText(graphNode, { fontColor, nodeWidth, maxRank });
16772
16765
  group.add(text);
16773
16766
  }
16774
16767
  return group;
@@ -16844,7 +16837,7 @@ class SankeyGraph extends Paper {
16844
16837
  construct(data2) {
16845
16838
  const { width: width2, height: height2, spacing, nodeWidth } = this.options;
16846
16839
  const layout = sankey({ nodeWidth });
16847
- layout.size([width2 - spacing * 2, height2 - spacing * 2]);
16840
+ layout.size([width2 - nodeWidth, height2 - spacing]);
16848
16841
  const updatedNodes = data2.nodes.map((node, index) => {
16849
16842
  const colorIndex = index % DefaultPalette.length;
16850
16843
  return {
@@ -16854,6 +16847,7 @@ class SankeyGraph extends Paper {
16854
16847
  };
16855
16848
  });
16856
16849
  const graph2 = layout(data2.edges, updatedNodes, data2.options);
16850
+ this.maxRank = layout.order().length - 1;
16857
16851
  this.graph = graph2;
16858
16852
  }
16859
16853
  renderEdge(edgeObj, group) {
@@ -16927,7 +16921,7 @@ class SankeyGraph extends Paper {
16927
16921
  fontFamily,
16928
16922
  color: fontColor
16929
16923
  });
16930
- const mainGroup = drawGroup(0, 0);
16924
+ const mainGroup = drawGroup(nodeWidth / 2, 0);
16931
16925
  mainGroup.attr("style", globalStyle);
16932
16926
  const nodes = ((_a = this.graph) == null ? void 0 : _a.nodes()) || [];
16933
16927
  const edges = ((_b = this.graph) == null ? void 0 : _b.edges()) || [];
@@ -16939,7 +16933,7 @@ class SankeyGraph extends Paper {
16939
16933
  const nodesGroup = drawGroup();
16940
16934
  nodes.forEach((nodeId) => {
16941
16935
  const node = this.graph.node(nodeId);
16942
- const nodeGroup = renderNode(node, {
16936
+ const nodeGroup = renderNode(node, this.maxRank, {
16943
16937
  nodeWidth,
16944
16938
  nodeBorderWidth,
16945
16939
  nodeBorderColor,
@@ -16967,9 +16961,9 @@ class SankeyGraph extends Paper {
16967
16961
  }
16968
16962
  const DefaultOptions = {
16969
16963
  width: 800,
16970
- height: 800,
16964
+ height: 650,
16971
16965
  canvasStyle: "border: 1px solid #caced0",
16972
- spacing: 100,
16966
+ spacing: 20,
16973
16967
  nodeWidth: 20,
16974
16968
  nodeBorderWidth: 1,
16975
16969
  nodeBorderColor: null,