apexsankey 1.1.0 → 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.
- package/apexsankey.es.min.js +48 -43
- package/apexsankey.min.js +2 -2
- package/demo/{demo3.html → basic-sankey.html} +2 -1
- package/demo/{demo2.html → sankey-custom-fonts.html} +6 -1
- package/demo/{demo4.html → sankey-edge-options.html} +2 -1
- package/demo/{demo1.html → sankey-node-customization.html} +5 -2
- package/lib/models/Graph.d.ts +1 -0
- package/lib/models/Node.d.ts +1 -1
- package/lib/models/svgUtils.d.ts +1 -1
- package/package.json +1 -1
package/apexsankey.es.min.js
CHANGED
|
@@ -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(
|
|
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]);
|
|
@@ -16677,19 +16678,19 @@ function drawRect({
|
|
|
16677
16678
|
rect.stroke({ color: borderColor, width: 1 });
|
|
16678
16679
|
return rect;
|
|
16679
16680
|
}
|
|
16680
|
-
function drawText(text = "", { x: x2, y: y2, fontColor = "#666767", textAnchor = "start" }) {
|
|
16681
|
+
function drawText(text = "", { x: x2, y: y2, fontColor = "#666767", textAnchor = "start", pointerEvents = "all" }) {
|
|
16681
16682
|
const textSvg = new Text();
|
|
16682
16683
|
textSvg.font({ fill: fontColor });
|
|
16683
16684
|
textSvg.tspan(text);
|
|
16684
16685
|
if (x2 !== void 0 && y2 !== void 0) {
|
|
16685
16686
|
textSvg.move(x2, y2);
|
|
16686
16687
|
}
|
|
16687
|
-
textSvg.attr({ "text-anchor": textAnchor });
|
|
16688
|
+
textSvg.attr({ "text-anchor": textAnchor, "pointer-events": pointerEvents });
|
|
16688
16689
|
return textSvg;
|
|
16689
16690
|
}
|
|
16690
|
-
function drawGroup(x2
|
|
16691
|
+
function drawGroup(x2, y2, id, parent) {
|
|
16691
16692
|
const group = new G();
|
|
16692
|
-
group.attr({ transform: `translate(${x2}, ${y2})
|
|
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 } = {}) {
|
|
@@ -16698,70 +16699,69 @@ function drawPath(pathString, { id = "", edgeColor, opacity = 1 } = {}) {
|
|
|
16698
16699
|
path.fill(edgeColor).opacity(opacity);
|
|
16699
16700
|
return path;
|
|
16700
16701
|
}
|
|
16701
|
-
const nodeTitle = (nodeData) =>
|
|
16702
|
-
|
|
16702
|
+
const nodeTitle = (nodeData, maxLength) => {
|
|
16703
|
+
const text = nodeData.title !== void 0 ? nodeData.title : nodeData.id;
|
|
16704
|
+
if (maxLength && text.length > maxLength) {
|
|
16705
|
+
return `${text.substr(0, 15)}...`;
|
|
16706
|
+
}
|
|
16707
|
+
return text;
|
|
16708
|
+
};
|
|
16709
|
+
function titlePosition(node, maxRank) {
|
|
16703
16710
|
let top = false;
|
|
16704
16711
|
let right = false;
|
|
16705
|
-
if (node.
|
|
16706
|
-
top = true;
|
|
16707
|
-
} else {
|
|
16708
|
-
top = false;
|
|
16709
|
-
}
|
|
16710
|
-
if (node.incoming.length === 0) {
|
|
16712
|
+
if (node.rank < maxRank / 2) {
|
|
16711
16713
|
right = true;
|
|
16712
16714
|
top = false;
|
|
16713
|
-
} else if (node.outgoing.length === 0) {
|
|
16714
|
-
right = false;
|
|
16715
|
-
top = false;
|
|
16716
16715
|
}
|
|
16717
16716
|
return { top, right };
|
|
16718
16717
|
}
|
|
16719
|
-
function textTransform(
|
|
16720
|
-
const y2 = position2.top ? -25 :
|
|
16718
|
+
function textTransform(node, position2, nodeWidth) {
|
|
16719
|
+
const y2 = position2.top ? -25 : node.dy / 2 - 10;
|
|
16721
16720
|
let x2;
|
|
16722
16721
|
if (position2.top) {
|
|
16723
16722
|
x2 = position2.right ? 4 : -4;
|
|
16724
16723
|
} else {
|
|
16725
|
-
x2 = position2.right ?
|
|
16724
|
+
x2 = position2.right ? 10 + nodeWidth / 2 : -10 + -nodeWidth / 2;
|
|
16726
16725
|
}
|
|
16727
|
-
return { x:
|
|
16726
|
+
return { x: node.x + x2, y: node.y + y2 };
|
|
16728
16727
|
}
|
|
16729
|
-
function renderNodeText(graphNode, fontColor) {
|
|
16728
|
+
function renderNodeText(graphNode, { fontColor, nodeWidth, maxRank }) {
|
|
16730
16729
|
const { data: data2 } = graphNode;
|
|
16731
|
-
const
|
|
16732
|
-
const { x: x2, y: y2 } = textTransform(graphNode,
|
|
16733
|
-
const text = drawText(nodeTitle(data2), {
|
|
16730
|
+
const position2 = titlePosition(graphNode, maxRank);
|
|
16731
|
+
const { x: x2, y: y2 } = textTransform(graphNode, position2, nodeWidth);
|
|
16732
|
+
const text = drawText(nodeTitle(data2, position2.top ? 25 : 15), {
|
|
16734
16733
|
x: x2,
|
|
16735
16734
|
y: y2,
|
|
16736
|
-
textAnchor:
|
|
16737
|
-
fontColor
|
|
16735
|
+
textAnchor: position2.top ? "middle" : position2.right ? "start" : "end",
|
|
16736
|
+
fontColor,
|
|
16737
|
+
pointerEvents: "none"
|
|
16738
16738
|
});
|
|
16739
16739
|
return text;
|
|
16740
16740
|
}
|
|
16741
|
-
function renderNode(graphNode, options) {
|
|
16741
|
+
function renderNode(graphNode, maxRank, options) {
|
|
16742
16742
|
var _a, _b;
|
|
16743
16743
|
const { x: x2, y: y2, dy: dy2 } = graphNode;
|
|
16744
16744
|
const { nodeWidth, nodeBorderWidth, nodeBorderColor, onNodeClick, fontColor } = options;
|
|
16745
16745
|
const group = new G({ class: "node" });
|
|
16746
|
-
const
|
|
16746
|
+
const nodeBody = drawRect({
|
|
16747
16747
|
x: x2 - nodeWidth / 2,
|
|
16748
16748
|
y: y2,
|
|
16749
16749
|
width: nodeWidth,
|
|
16750
16750
|
height: dy2
|
|
16751
16751
|
});
|
|
16752
|
-
|
|
16753
|
-
|
|
16752
|
+
nodeBody.fill((_a = graphNode.data) == null ? void 0 : _a.color);
|
|
16753
|
+
nodeBody.stroke({
|
|
16754
16754
|
width: nodeBorderWidth,
|
|
16755
16755
|
color: nodeBorderColor ?? ((_b = graphNode.data) == null ? void 0 : _b.color)
|
|
16756
16756
|
});
|
|
16757
|
-
|
|
16757
|
+
nodeBody.on("click", () => {
|
|
16758
16758
|
if (typeof onNodeClick === "function") {
|
|
16759
16759
|
onNodeClick(graphNode);
|
|
16760
16760
|
}
|
|
16761
16761
|
});
|
|
16762
|
-
group.add(
|
|
16762
|
+
group.add(nodeBody);
|
|
16763
16763
|
if (graphNode.data) {
|
|
16764
|
-
const text = renderNodeText(graphNode, fontColor);
|
|
16764
|
+
const text = renderNodeText(graphNode, { fontColor, nodeWidth, maxRank });
|
|
16765
16765
|
group.add(text);
|
|
16766
16766
|
}
|
|
16767
16767
|
return group;
|
|
@@ -16837,7 +16837,7 @@ class SankeyGraph extends Paper {
|
|
|
16837
16837
|
construct(data2) {
|
|
16838
16838
|
const { width: width2, height: height2, spacing, nodeWidth } = this.options;
|
|
16839
16839
|
const layout = sankey({ nodeWidth });
|
|
16840
|
-
layout.size([width2 -
|
|
16840
|
+
layout.size([width2 - nodeWidth, height2 - spacing]);
|
|
16841
16841
|
const updatedNodes = data2.nodes.map((node, index) => {
|
|
16842
16842
|
const colorIndex = index % DefaultPalette.length;
|
|
16843
16843
|
return {
|
|
@@ -16847,6 +16847,7 @@ class SankeyGraph extends Paper {
|
|
|
16847
16847
|
};
|
|
16848
16848
|
});
|
|
16849
16849
|
const graph2 = layout(data2.edges, updatedNodes, data2.options);
|
|
16850
|
+
this.maxRank = layout.order().length - 1;
|
|
16850
16851
|
this.graph = graph2;
|
|
16851
16852
|
}
|
|
16852
16853
|
renderEdge(edgeObj, group) {
|
|
@@ -16920,24 +16921,28 @@ class SankeyGraph extends Paper {
|
|
|
16920
16921
|
fontFamily,
|
|
16921
16922
|
color: fontColor
|
|
16922
16923
|
});
|
|
16923
|
-
const mainGroup = drawGroup(
|
|
16924
|
+
const mainGroup = drawGroup(nodeWidth / 2, 0);
|
|
16924
16925
|
mainGroup.attr("style", globalStyle);
|
|
16925
16926
|
const nodes = ((_a = this.graph) == null ? void 0 : _a.nodes()) || [];
|
|
16926
16927
|
const edges = ((_b = this.graph) == null ? void 0 : _b.edges()) || [];
|
|
16928
|
+
const edgesGroup = drawGroup();
|
|
16927
16929
|
edges.forEach((edgeObj) => {
|
|
16928
|
-
this.renderEdge(edgeObj,
|
|
16930
|
+
this.renderEdge(edgeObj, edgesGroup);
|
|
16929
16931
|
});
|
|
16932
|
+
mainGroup.add(edgesGroup);
|
|
16933
|
+
const nodesGroup = drawGroup();
|
|
16930
16934
|
nodes.forEach((nodeId) => {
|
|
16931
16935
|
const node = this.graph.node(nodeId);
|
|
16932
|
-
const nodeGroup = renderNode(node, {
|
|
16936
|
+
const nodeGroup = renderNode(node, this.maxRank, {
|
|
16933
16937
|
nodeWidth,
|
|
16934
16938
|
nodeBorderWidth,
|
|
16935
16939
|
nodeBorderColor,
|
|
16936
16940
|
onNodeClick,
|
|
16937
16941
|
fontColor
|
|
16938
16942
|
});
|
|
16939
|
-
|
|
16943
|
+
nodesGroup.add(nodeGroup);
|
|
16940
16944
|
});
|
|
16945
|
+
mainGroup.add(nodesGroup);
|
|
16941
16946
|
this.add(mainGroup);
|
|
16942
16947
|
if (keepOldPosition) {
|
|
16943
16948
|
this.updateViewBox(
|
|
@@ -16956,9 +16961,9 @@ class SankeyGraph extends Paper {
|
|
|
16956
16961
|
}
|
|
16957
16962
|
const DefaultOptions = {
|
|
16958
16963
|
width: 800,
|
|
16959
|
-
height:
|
|
16964
|
+
height: 650,
|
|
16960
16965
|
canvasStyle: "border: 1px solid #caced0",
|
|
16961
|
-
spacing:
|
|
16966
|
+
spacing: 20,
|
|
16962
16967
|
nodeWidth: 20,
|
|
16963
16968
|
nodeBorderWidth: 1,
|
|
16964
16969
|
nodeBorderColor: null,
|