@fluentui/react-charting 5.11.0 → 5.12.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/CHANGELOG.json +72 -1
- package/CHANGELOG.md +32 -2
- package/dist/react-charting.js +1 -1
- package/dist/react-charting.min.js +1 -1
- package/lib/TreeChart.d.ts +1 -0
- package/lib/TreeChart.js +2 -0
- package/lib/TreeChart.js.map +1 -0
- package/lib/Utilities.d.ts +1 -1
- package/lib/Utilities.js +4 -2
- package/lib/Utilities.js.map +1 -1
- package/lib/components/Legends/Legends.base.js +2 -1
- package/lib/components/Legends/Legends.base.js.map +1 -1
- package/lib/components/TreeChart/TreeChart.base.d.ts +18 -0
- package/lib/components/TreeChart/TreeChart.base.js +297 -0
- package/lib/components/TreeChart/TreeChart.base.js.map +1 -0
- package/lib/components/TreeChart/TreeChart.d.ts +3 -0
- package/lib/components/TreeChart/TreeChart.js +5 -0
- package/lib/components/TreeChart/TreeChart.js.map +1 -0
- package/lib/components/TreeChart/TreeChart.styles.d.ts +2 -0
- package/lib/components/TreeChart/TreeChart.styles.js +28 -0
- package/lib/components/TreeChart/TreeChart.styles.js.map +1 -0
- package/lib/components/TreeChart/TreeChart.types.d.ts +185 -0
- package/lib/components/TreeChart/TreeChart.types.js +23 -0
- package/lib/components/TreeChart/TreeChart.types.js.map +1 -0
- package/lib/components/TreeChart/index.d.ts +2 -0
- package/lib/components/TreeChart/index.js +3 -0
- package/lib/components/TreeChart/index.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/version.js +1 -1
- package/lib/version.js.map +1 -1
- package/lib-amd/TreeChart.d.ts +1 -0
- package/lib-amd/TreeChart.js +6 -0
- package/lib-amd/TreeChart.js.map +1 -0
- package/lib-amd/Utilities.d.ts +1 -1
- package/lib-amd/Utilities.js +3 -1
- package/lib-amd/Utilities.js.map +1 -1
- package/lib-amd/components/Legends/Legends.base.js +2 -1
- package/lib-amd/components/Legends/Legends.base.js.map +1 -1
- package/lib-amd/components/TreeChart/TreeChart.base.d.ts +18 -0
- package/lib-amd/components/TreeChart/TreeChart.base.js +296 -0
- package/lib-amd/components/TreeChart/TreeChart.base.js.map +1 -0
- package/lib-amd/components/TreeChart/TreeChart.d.ts +3 -0
- package/lib-amd/components/TreeChart/TreeChart.js +7 -0
- package/lib-amd/components/TreeChart/TreeChart.js.map +1 -0
- package/lib-amd/components/TreeChart/TreeChart.styles.d.ts +2 -0
- package/lib-amd/components/TreeChart/TreeChart.styles.js +33 -0
- package/lib-amd/components/TreeChart/TreeChart.styles.js.map +1 -0
- package/lib-amd/components/TreeChart/TreeChart.types.d.ts +185 -0
- package/lib-amd/components/TreeChart/TreeChart.types.js +28 -0
- package/lib-amd/components/TreeChart/TreeChart.types.js.map +1 -0
- package/lib-amd/components/TreeChart/index.d.ts +2 -0
- package/lib-amd/components/TreeChart/index.js +7 -0
- package/lib-amd/components/TreeChart/index.js.map +1 -0
- package/lib-amd/index.d.ts +1 -0
- package/lib-amd/index.js +2 -1
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/version.js +1 -1
- package/lib-amd/version.js.map +1 -1
- package/lib-commonjs/TreeChart.d.ts +1 -0
- package/lib-commonjs/TreeChart.js +5 -0
- package/lib-commonjs/TreeChart.js.map +1 -0
- package/lib-commonjs/Utilities.d.ts +1 -1
- package/lib-commonjs/Utilities.js +6 -4
- package/lib-commonjs/Utilities.js.map +1 -1
- package/lib-commonjs/components/Legends/Legends.base.js +2 -1
- package/lib-commonjs/components/Legends/Legends.base.js.map +1 -1
- package/lib-commonjs/components/TreeChart/TreeChart.base.d.ts +18 -0
- package/lib-commonjs/components/TreeChart/TreeChart.base.js +300 -0
- package/lib-commonjs/components/TreeChart/TreeChart.base.js.map +1 -0
- package/lib-commonjs/components/TreeChart/TreeChart.d.ts +3 -0
- package/lib-commonjs/components/TreeChart/TreeChart.js +8 -0
- package/lib-commonjs/components/TreeChart/TreeChart.js.map +1 -0
- package/lib-commonjs/components/TreeChart/TreeChart.styles.d.ts +2 -0
- package/lib-commonjs/components/TreeChart/TreeChart.styles.js +32 -0
- package/lib-commonjs/components/TreeChart/TreeChart.styles.js.map +1 -0
- package/lib-commonjs/components/TreeChart/TreeChart.types.d.ts +185 -0
- package/lib-commonjs/components/TreeChart/TreeChart.types.js +26 -0
- package/lib-commonjs/components/TreeChart/TreeChart.types.js.map +1 -0
- package/lib-commonjs/components/TreeChart/index.d.ts +2 -0
- package/lib-commonjs/components/TreeChart/index.js +6 -0
- package/lib-commonjs/components/TreeChart/index.js.map +1 -0
- package/lib-commonjs/index.d.ts +1 -0
- package/lib-commonjs/index.js +1 -0
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/version.js +1 -1
- package/lib-commonjs/version.js.map +1 -1
- package/package.json +6 -4
- package/src/components/TreeChart/TreeChart.types.ts +186 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TreeChartBase = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var React = require("react");
|
|
6
|
+
var d3_hierarchy_1 = require("d3-hierarchy");
|
|
7
|
+
var Utilities_1 = require("@fluentui/react/lib-commonjs/Utilities");
|
|
8
|
+
var d3_selection_1 = require("d3-selection");
|
|
9
|
+
var react_focus_1 = require("@fluentui/react-focus");
|
|
10
|
+
var getClassNames = Utilities_1.classNamesFunction();
|
|
11
|
+
// Create a parent class for common tree components
|
|
12
|
+
var StandardTree = /** @class */ (function () {
|
|
13
|
+
function StandardTree(treeData, styleClassNames, _nodeElements, _linkElements) {
|
|
14
|
+
if (_nodeElements === void 0) { _nodeElements = []; }
|
|
15
|
+
if (_linkElements === void 0) { _linkElements = []; }
|
|
16
|
+
this._nodeElements = [];
|
|
17
|
+
this._linkElements = [];
|
|
18
|
+
this.treeData = treeData;
|
|
19
|
+
this.styleClassNames = styleClassNames;
|
|
20
|
+
this._nodeElements = _nodeElements;
|
|
21
|
+
this._linkElements = _linkElements;
|
|
22
|
+
}
|
|
23
|
+
StandardTree.prototype.truncateText = function (text, rectangleWidth, padding, styleClass) {
|
|
24
|
+
var truncatedText = '';
|
|
25
|
+
var words = text.split(/\s+/).reverse();
|
|
26
|
+
var word = '';
|
|
27
|
+
var tspan = d3_selection_1.select('.svgTree').append('text').attr('class', 'tempText').append('tspan').text(null);
|
|
28
|
+
if (styleClass !== undefined) {
|
|
29
|
+
tspan.attr('class', styleClass);
|
|
30
|
+
}
|
|
31
|
+
var line = [];
|
|
32
|
+
while ((word = words.pop())) {
|
|
33
|
+
line.push(word);
|
|
34
|
+
tspan.text(line.join(' ') + ' ');
|
|
35
|
+
if (tspan.node() !== null) {
|
|
36
|
+
var w = tspan.node().getComputedTextLength();
|
|
37
|
+
if (w > rectangleWidth - padding) {
|
|
38
|
+
line.pop();
|
|
39
|
+
line.push('...');
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
truncatedText = line.join(' ') + ' ';
|
|
45
|
+
tspan.text(null);
|
|
46
|
+
d3_selection_1.selectAll('.tempText').remove();
|
|
47
|
+
return truncatedText;
|
|
48
|
+
};
|
|
49
|
+
// Append node elements
|
|
50
|
+
// nodeId to create unique key
|
|
51
|
+
StandardTree.prototype.addNodeShapetoSVG = function (name, subname, metricName, xCoordinate, yCoordinate, fillColor, rectangleWidth, rectangleHeight, nodeId, parentInfo) {
|
|
52
|
+
var ariaLabel = "nodeId: " + nodeId + " \nnodeMainText: " + name + "\nsubText " + subname + " " + parentInfo;
|
|
53
|
+
this._nodeElements.push(React.createElement("rect", { width: rectangleWidth, height: rectangleHeight, x: xCoordinate, y: yCoordinate, tabIndex: 0, role: 'text', "data-is-focusable": true, "aria-label": ariaLabel, className: this.styleClassNames.rectNode, stroke: fillColor, key: "" + nodeId + this.styleClassNames.rectNode }));
|
|
54
|
+
if (subname !== undefined) {
|
|
55
|
+
subname = this.truncateText(subname, rectangleWidth, rectangleWidth / 4, this.styleClassNames.rectSubText);
|
|
56
|
+
}
|
|
57
|
+
if (metricName !== undefined) {
|
|
58
|
+
metricName = this.truncateText(metricName, rectangleWidth, rectangleWidth / 4, this.styleClassNames.rectmetricText);
|
|
59
|
+
}
|
|
60
|
+
name = this.truncateText(name, rectangleWidth, rectangleWidth / 4, this.styleClassNames.rectText);
|
|
61
|
+
// Text position y = y + rectHeight/2, 2 is ratio for depth
|
|
62
|
+
// Text position x = x + rectWidth/2, 2 is ratio for length
|
|
63
|
+
// Sub-text position x = x + rectWidth/2, 2 is ratio for length
|
|
64
|
+
var subValue = metricName !== undefined ? (React.createElement("tspan", { className: this.styleClassNames.rectmetricText, dy: "1.4em", x: xCoordinate + rectangleWidth / 2 }, metricName)) : (React.createElement("tspan", { className: this.styleClassNames.rectSubText, dy: "1.4em", x: xCoordinate + rectangleWidth / 2 }, subname));
|
|
65
|
+
if (subname === undefined && metricName === undefined) {
|
|
66
|
+
this._nodeElements.push(React.createElement("text", { textAnchor: "middle", className: this.styleClassNames.rectmetricText, dy: yCoordinate + rectangleHeight / 1.6, x: xCoordinate + rectangleWidth / 2, key: "" + nodeId + this.styleClassNames.rectText }, name));
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this._nodeElements.push(React.createElement("text", { textAnchor: "middle", className: metricName !== undefined ? this.styleClassNames.rectSubText : this.styleClassNames.rectText, dy: metricName !== undefined ? yCoordinate + rectangleHeight / 2.5 : yCoordinate + rectangleHeight / 2, x: xCoordinate + rectangleWidth / 2, key: "" + nodeId + this.styleClassNames.rectText },
|
|
70
|
+
name,
|
|
71
|
+
subValue));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
// Create a rectangular path from parent to the child nodes
|
|
75
|
+
StandardTree.prototype.createPathLink = function (parentX, parentY, childX, childY, leaf, rectWidth, rectHeight, gap) {
|
|
76
|
+
// gap adds ratio for parent.y to child.y
|
|
77
|
+
var path = "M" + (childX + rectWidth / 2) + "," + (childY - gap) + " H" + (parentX + rectWidth / 2) + " V" + (parentY + rectHeight + gap / 2);
|
|
78
|
+
var leafpath = "M" + (parentX + rectWidth / 2) + "," + (parentY + rectHeight + gap / 2) + " V" + (parentY + gap * 5) + " H" + parentX + " H" + (parentX + rectWidth);
|
|
79
|
+
// based on the type of node return leafpath or path element
|
|
80
|
+
return leaf ? leafpath : path;
|
|
81
|
+
};
|
|
82
|
+
// Append path link element
|
|
83
|
+
StandardTree.prototype.addLinktoSVG = function (nodeId, parentX, parentY, childX, childY, leaf, rectWidth, rectHeight, gap) {
|
|
84
|
+
this._linkElements.push(React.createElement("path", { className: this.styleClassNames.link, d: this.createPathLink(parentX, parentY, childX, childY, leaf, rectWidth, rectHeight, gap), key: "" + nodeId + this.styleClassNames.link }));
|
|
85
|
+
};
|
|
86
|
+
return StandardTree;
|
|
87
|
+
}());
|
|
88
|
+
// Create child class to Add Tree component based on treeHeight
|
|
89
|
+
var LayeredTree = /** @class */ (function (_super) {
|
|
90
|
+
tslib_1.__extends(LayeredTree, _super);
|
|
91
|
+
function LayeredTree(treeData, composition, styleClassNames, _nodeElements, _linkElements, _treeTraversal) {
|
|
92
|
+
if (_nodeElements === void 0) { _nodeElements = []; }
|
|
93
|
+
if (_linkElements === void 0) { _linkElements = []; }
|
|
94
|
+
var _this = _super.call(this, treeData, styleClassNames, _nodeElements, _linkElements) || this;
|
|
95
|
+
_this.composition = composition;
|
|
96
|
+
_this._treeTraversal = _treeTraversal;
|
|
97
|
+
return _this;
|
|
98
|
+
}
|
|
99
|
+
LayeredTree.prototype.createTree = function (givenLayoutWidth, screenWidth) {
|
|
100
|
+
var _a, _b, _c, _d;
|
|
101
|
+
if (givenLayoutWidth !== undefined) {
|
|
102
|
+
if (givenLayoutWidth < 65) {
|
|
103
|
+
givenLayoutWidth = 65;
|
|
104
|
+
}
|
|
105
|
+
if (givenLayoutWidth > 90) {
|
|
106
|
+
givenLayoutWidth = 90;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
var layoutWidth = givenLayoutWidth || 75;
|
|
110
|
+
var root = d3_hierarchy_1.hierarchy(this.treeData, function (d) {
|
|
111
|
+
return d.children;
|
|
112
|
+
});
|
|
113
|
+
// Find tree Height
|
|
114
|
+
var treeHeight = (root === null || root === void 0 ? void 0 : root.height) + 1;
|
|
115
|
+
// Create tree layout, width: layoutWidth, height: layoutWidth/1.5 and add node separation
|
|
116
|
+
var treemap = d3_hierarchy_1.tree()
|
|
117
|
+
.nodeSize([layoutWidth, layoutWidth / 1.5])
|
|
118
|
+
.separation(function (a, b) {
|
|
119
|
+
return a.parent === root && b.parent === root ? 3.5 : 1;
|
|
120
|
+
});
|
|
121
|
+
// Assigns the x and y position for the nodes
|
|
122
|
+
var treeData = treemap(root);
|
|
123
|
+
// Compute the new tree layout.
|
|
124
|
+
var nodes = treeData.descendants();
|
|
125
|
+
// Normalize for fixed-depth and width
|
|
126
|
+
// Normalise y coordinate by depth of each node by a factor of 130
|
|
127
|
+
// Normalise x coordinate by start coordinate 0 with screenSize/3
|
|
128
|
+
nodes.forEach(function (d) {
|
|
129
|
+
d.y = d.depth === 0 ? 10 : d.depth * 130;
|
|
130
|
+
d.x += screenWidth / 3;
|
|
131
|
+
});
|
|
132
|
+
// <------------------ Traversal section ------------------>
|
|
133
|
+
// Create tree data structure
|
|
134
|
+
var treeDataStructure = [];
|
|
135
|
+
var TreeID = 0;
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
137
|
+
var createTreeDataStructure = function (d) {
|
|
138
|
+
var _a, _b;
|
|
139
|
+
d.id = TreeID;
|
|
140
|
+
treeDataStructure.push({
|
|
141
|
+
id: TreeID,
|
|
142
|
+
children: d.children,
|
|
143
|
+
dataName: d.data.name,
|
|
144
|
+
subName: d.data.subname,
|
|
145
|
+
metricName: (_a = d.data) === null || _a === void 0 ? void 0 : _a.metric,
|
|
146
|
+
fill: d.data.fill,
|
|
147
|
+
x: d.x,
|
|
148
|
+
y: d.y,
|
|
149
|
+
parentID: (_b = d.parent) === null || _b === void 0 ? void 0 : _b.id,
|
|
150
|
+
});
|
|
151
|
+
TreeID++;
|
|
152
|
+
};
|
|
153
|
+
this._treeTraversal === 0
|
|
154
|
+
? root.each(function (d) {
|
|
155
|
+
createTreeDataStructure(d);
|
|
156
|
+
})
|
|
157
|
+
: root.eachBefore(function (d) {
|
|
158
|
+
createTreeDataStructure(d);
|
|
159
|
+
});
|
|
160
|
+
var rectWidth = layoutWidth * 3;
|
|
161
|
+
var rectHeight = rectWidth / 3.45;
|
|
162
|
+
var gap = 20;
|
|
163
|
+
var parentSet = new Set();
|
|
164
|
+
for (var _i = 0, treeDataStructure_1 = treeDataStructure; _i < treeDataStructure_1.length; _i++) {
|
|
165
|
+
var d = treeDataStructure_1[_i];
|
|
166
|
+
var parentInfo = d.id === 0
|
|
167
|
+
? 'Root Node'
|
|
168
|
+
: "Parent info parentId: " + d.parentID + "\n " + treeDataStructure[d.parentID].dataName + "\n " + treeDataStructure[d.parentID].subName;
|
|
169
|
+
// check for leaf nodes
|
|
170
|
+
if (!d.children && !parentSet.has(d.parentID) && treeHeight === 3) {
|
|
171
|
+
var newWidth = (rectWidth - gap) / 2;
|
|
172
|
+
var newHeight = rectHeight;
|
|
173
|
+
parentSet.add(d.parentID);
|
|
174
|
+
// <------------------ Links section ------------------>
|
|
175
|
+
this.addLinktoSVG(d.id, treeDataStructure[d.parentID].x, treeDataStructure[d.parentID].y, treeDataStructure[d.id].x, treeDataStructure[d.id].y, true, rectWidth, rectHeight, gap);
|
|
176
|
+
// <------------------ Nodes section ------------------>
|
|
177
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
178
|
+
var children = (_a = treeDataStructure[d.parentID]) === null || _a === void 0 ? void 0 : _a.children;
|
|
179
|
+
var dx1 = (_b = treeDataStructure[d.parentID]) === null || _b === void 0 ? void 0 : _b.x;
|
|
180
|
+
var dx2 = ((_c = treeDataStructure[d.parentID]) === null || _c === void 0 ? void 0 : _c.x) + newWidth + gap;
|
|
181
|
+
var dy = (_d = children[0]) === null || _d === void 0 ? void 0 : _d.y;
|
|
182
|
+
for (var itr = 0; itr < children.length; ++itr) {
|
|
183
|
+
var child = children[itr];
|
|
184
|
+
// Given Composition
|
|
185
|
+
if (this.composition !== undefined) {
|
|
186
|
+
// For compact compostion
|
|
187
|
+
if (this.composition === 0) {
|
|
188
|
+
this.addNodeShapetoSVG(child.data.name, child.data.subname, child.data.metricName, itr % 2 === 0 ? dx1 : dx2, dy, child.data.fill, children.length === 1 ? rectWidth : newWidth, rectHeight, child.id, parentInfo);
|
|
189
|
+
if (itr % 2 === 1) {
|
|
190
|
+
dy += newHeight + gap;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// For long compostion
|
|
194
|
+
else {
|
|
195
|
+
this.addNodeShapetoSVG(child.data.name, child.data.subname, child.data.metricName, dx1, dy, child.data.fill, rectWidth, rectHeight, child.id, parentInfo);
|
|
196
|
+
dy += newHeight + gap;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// Automatic Node Composition
|
|
200
|
+
else {
|
|
201
|
+
if (children.length > 2) {
|
|
202
|
+
this.addNodeShapetoSVG(child.data.name, child.data.subname, child.data.metricName, itr % 2 === 0 ? dx1 : dx2, dy, child.data.fill, children.length === 1 ? rectWidth : newWidth, rectHeight, child.id, parentInfo);
|
|
203
|
+
if (itr % 2 === 1) {
|
|
204
|
+
dy += newHeight + gap;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
this.addNodeShapetoSVG(child.data.name, child.data.subname, child.data.metricName, dx1, dy, child.data.fill, rectWidth, rectHeight, child.id, parentInfo);
|
|
209
|
+
dy += newHeight + gap;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (d.children || treeHeight <= 2) {
|
|
215
|
+
// <------------------ Nodes section ------------------>
|
|
216
|
+
this.addNodeShapetoSVG(d.dataName, d.subName, d.metricName, d.x, d.y, d.fill, rectWidth, rectHeight, d.id, parentInfo);
|
|
217
|
+
// <------------------ Links section ------------------>
|
|
218
|
+
if (d.id !== 0) {
|
|
219
|
+
this.addLinktoSVG(d.id, treeDataStructure[d.parentID].x, treeDataStructure[d.parentID].y, treeDataStructure[d.id].x, treeDataStructure[d.id].y, false, rectWidth, rectHeight, gap);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
return LayeredTree;
|
|
225
|
+
}(StandardTree));
|
|
226
|
+
var TreeChartBase = /** @class */ (function (_super) {
|
|
227
|
+
tslib_1.__extends(TreeChartBase, _super);
|
|
228
|
+
function TreeChartBase(props) {
|
|
229
|
+
var _a;
|
|
230
|
+
var _this = _super.call(this, props) || this;
|
|
231
|
+
_this._nodeElements = [];
|
|
232
|
+
_this._linkElements = [];
|
|
233
|
+
_this._margin = { top: 30, right: 20, bottom: 30, left: 50 };
|
|
234
|
+
_this._width = _this.props.width || 1500;
|
|
235
|
+
_this._height = _this.props.height || 700;
|
|
236
|
+
_this._treeData = _this.props.treeData;
|
|
237
|
+
_this._composition = (_a = _this.props) === null || _a === void 0 ? void 0 : _a.composition;
|
|
238
|
+
_this._treeTraversal = _this.props.treeTraversal;
|
|
239
|
+
_this.state = {
|
|
240
|
+
_width: _this._width,
|
|
241
|
+
_height: _this._height,
|
|
242
|
+
};
|
|
243
|
+
return _this;
|
|
244
|
+
}
|
|
245
|
+
TreeChartBase.prototype.componentDidMount = function () {
|
|
246
|
+
var _a = this.props, theme = _a.theme, className = _a.className, styles = _a.styles;
|
|
247
|
+
// Get classNames to create component styling
|
|
248
|
+
this._classNames = getClassNames(styles, {
|
|
249
|
+
theme: theme,
|
|
250
|
+
className: className,
|
|
251
|
+
});
|
|
252
|
+
// Call createTreeChart function in componentDidMount
|
|
253
|
+
this.createTreeChart();
|
|
254
|
+
this.setState({
|
|
255
|
+
_width: this.props.width || 1500,
|
|
256
|
+
_height: this.props.height || 700,
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
TreeChartBase.prototype.componentDidUpdate = function (prevProps) {
|
|
260
|
+
if (prevProps.layoutWidth !== this.props.layoutWidth) {
|
|
261
|
+
var svgText = d3_selection_1.selectAll('text');
|
|
262
|
+
var svgRect = d3_selection_1.selectAll('rect');
|
|
263
|
+
var svgLink = d3_selection_1.selectAll('path');
|
|
264
|
+
if (this._nodeElements.length === 0 && this._linkElements.length === 0) {
|
|
265
|
+
svgText.remove();
|
|
266
|
+
svgRect.remove();
|
|
267
|
+
svgLink.remove();
|
|
268
|
+
}
|
|
269
|
+
this.createTreeChart();
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
TreeChartBase.prototype.createTreeChart = function () {
|
|
273
|
+
var nodeElements = [];
|
|
274
|
+
var linkElements = [];
|
|
275
|
+
// Create styleClass object to access it in parent class
|
|
276
|
+
var styleClassNames = {
|
|
277
|
+
link: this._classNames.link,
|
|
278
|
+
rectNode: this._classNames.rectNode,
|
|
279
|
+
rectText: this._classNames.rectText,
|
|
280
|
+
rectSubText: this._classNames.rectSubText,
|
|
281
|
+
rectmetricText: this._classNames.rectMetricText,
|
|
282
|
+
};
|
|
283
|
+
// Instantiate inherited class and call createTree function for the object
|
|
284
|
+
var treeObject = new LayeredTree(this._treeData, this._composition, styleClassNames, nodeElements, linkElements, this._treeTraversal);
|
|
285
|
+
treeObject.createTree(this.props.layoutWidth, this._width);
|
|
286
|
+
this._nodeElements = nodeElements;
|
|
287
|
+
this._linkElements = linkElements;
|
|
288
|
+
};
|
|
289
|
+
TreeChartBase.prototype.render = function () {
|
|
290
|
+
var _a;
|
|
291
|
+
return (React.createElement(react_focus_1.FocusZone, null,
|
|
292
|
+
React.createElement("div", { className: (_a = this._classNames) === null || _a === void 0 ? void 0 : _a.root },
|
|
293
|
+
React.createElement("svg", { className: "svgTree", width: this.state._width - this._margin.left - this._margin.right, height: this.state._height - this._margin.top - this._margin.bottom },
|
|
294
|
+
React.createElement("g", { className: "svgNode" }, this._nodeElements.map(function (element) { return element; })),
|
|
295
|
+
React.createElement("g", { className: "svgLink" }, this._linkElements.map(function (element) { return element; }))))));
|
|
296
|
+
};
|
|
297
|
+
return TreeChartBase;
|
|
298
|
+
}(React.Component));
|
|
299
|
+
exports.TreeChartBase = TreeChartBase;
|
|
300
|
+
//# sourceMappingURL=TreeChart.base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeChart.base.js","sourceRoot":"../src/","sources":["components/TreeChart/TreeChart.base.tsx"],"names":[],"mappings":";;;;AAAA,6BAA+B;AAC/B,6CAA+C;AAC/C,2DAAmE;AAEnE,6CAAiD;AACjD,qDAAkD;AAWlD,IAAM,aAAa,GAAG,8BAAkB,EAAgC,CAAC;AAEzE,mDAAmD;AACnD;IAYE,sBACE,QAA6B,EAC7B,eAAkH,EAClH,aAA0F,EAC1F,aAAyD;QADzD,8BAAA,EAAA,kBAA0F;QAC1F,8BAAA,EAAA,kBAAyD;QANnD,kBAAa,GAA2E,EAAE,CAAC;QAC3F,kBAAa,GAA0C,EAAE,CAAC;QAOhE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAEM,mCAAY,GAAnB,UAAoB,IAAY,EAAE,cAAsB,EAAE,OAAe,EAAE,UAA8B;QACvG,IAAI,aAAa,GAAG,EAAE,CAAC;QACvB,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;QAC1C,IAAI,IAAI,GAAW,EAAE,CAAC;QACtB,IAAM,KAAK,GAAG,qBAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,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AAK,CACnE,CACF,CACI,CACb,CAAC;IACJ,CAAC;IACH,oBAAC;AAAD,CAAC,AArGD,CAAmC,KAAK,CAAC,SAAS,GAqGjD;AArGY,sCAAa","sourcesContent":["import * as React from 'react';\nimport { hierarchy, tree } from 'd3-hierarchy';\nimport { classNamesFunction } from '@fluentui/react/lib/Utilities';\nimport { IProcessedStyleSet } from '@fluentui/react/lib/Styling';\nimport { select, selectAll } from 'd3-selection';\nimport { FocusZone } from '@fluentui/react-focus';\n\nimport {\n ITreeProps,\n ITreeState,\n ITreeDataStructure,\n ITreeChartDataPoint,\n ITreeStyleProps,\n ITreeStyles,\n} from '../../index';\n\nconst getClassNames = classNamesFunction<ITreeStyleProps, ITreeStyles>();\n\n// Create a parent class for common tree components\nclass StandardTree {\n public treeData: ITreeChartDataPoint;\n public styleClassNames: {\n rectmetricText: string | undefined;\n rectSubText: string | undefined;\n link: string;\n rectNode: string;\n rectText: string;\n };\n\n private _nodeElements: Array<React.SVGProps<SVGRectElement> | React.SVGProps<SVGTextElement>> = [];\n private _linkElements: Array<React.SVGProps<SVGPathElement>> = [];\n constructor(\n treeData: ITreeChartDataPoint,\n styleClassNames: { link: string; rectNode: string; rectText: string; rectSubText: string; rectmetricText: string },\n _nodeElements: Array<React.SVGProps<SVGRectElement> | React.SVGProps<SVGTextElement>> = [],\n _linkElements: Array<React.SVGProps<SVGPathElement>> = [],\n ) {\n this.treeData = treeData;\n this.styleClassNames = styleClassNames;\n this._nodeElements = _nodeElements;\n this._linkElements = _linkElements;\n }\n\n public truncateText(text: string, rectangleWidth: number, padding: number, styleClass: string | undefined) {\n let truncatedText = '';\n const words = text.split(/\\s+/).reverse();\n let word: string = '';\n const tspan = select('.svgTree').append('text').attr('class', 'tempText').append('tspan').text(null);\n\n if (styleClass !== undefined) {\n tspan.attr('class', styleClass);\n }\n\n const line: string[] = [];\n while ((word = words.pop()!)) {\n line.push(word);\n tspan.text(line.join(' ') + ' ');\n if (tspan.node() !== null) {\n const w = tspan.node()!.getComputedTextLength();\n if (w > rectangleWidth - padding) {\n line.pop();\n line.push('...');\n break;\n }\n }\n }\n\n truncatedText = line.join(' ') + ' ';\n tspan.text(null);\n selectAll('.tempText').remove();\n return truncatedText;\n }\n\n // Append node elements\n // nodeId to create unique key\n public addNodeShapetoSVG(\n name: string,\n subname: string | undefined,\n metricName: string | undefined,\n xCoordinate: number,\n yCoordinate: number,\n fillColor: string,\n rectangleWidth: number,\n rectangleHeight: number,\n nodeId: number,\n parentInfo: string,\n ) {\n const ariaLabel = `nodeId: ${nodeId} \\nnodeMainText: ${name}\\nsubText ${subname} ${parentInfo}`;\n this._nodeElements.push(\n <rect\n width={rectangleWidth}\n height={rectangleHeight}\n x={xCoordinate}\n y={yCoordinate}\n tabIndex={0}\n role={'text'}\n data-is-focusable={true}\n aria-label={ariaLabel}\n className={this.styleClassNames.rectNode}\n stroke={fillColor}\n key={`${nodeId}${this.styleClassNames.rectNode}`}\n />,\n );\n\n if (subname !== undefined) {\n subname = this.truncateText(subname, rectangleWidth, rectangleWidth / 4, this.styleClassNames.rectSubText);\n }\n if (metricName !== undefined) {\n metricName = this.truncateText(\n metricName,\n rectangleWidth,\n rectangleWidth / 4,\n this.styleClassNames.rectmetricText,\n );\n }\n name = this.truncateText(name, rectangleWidth, rectangleWidth / 4, this.styleClassNames.rectText);\n\n // Text position y = y + rectHeight/2, 2 is ratio for depth\n // Text position x = x + rectWidth/2, 2 is ratio for length\n // Sub-text position x = x + rectWidth/2, 2 is ratio for length\n\n const subValue =\n metricName !== undefined ? (\n <tspan className={this.styleClassNames.rectmetricText} dy=\"1.4em\" x={xCoordinate + rectangleWidth / 2}>\n {metricName}\n </tspan>\n ) : (\n <tspan className={this.styleClassNames.rectSubText} dy=\"1.4em\" x={xCoordinate + rectangleWidth / 2}>\n {subname}\n </tspan>\n );\n\n if (subname === undefined && metricName === undefined) {\n this._nodeElements.push(\n <text\n textAnchor=\"middle\"\n className={this.styleClassNames.rectmetricText}\n dy={yCoordinate + rectangleHeight / 1.6}\n x={xCoordinate + rectangleWidth / 2}\n key={`${nodeId}${this.styleClassNames.rectText}`}\n >\n {name}\n </text>,\n );\n } else {\n this._nodeElements.push(\n <text\n textAnchor=\"middle\"\n className={metricName !== undefined ? this.styleClassNames.rectSubText : this.styleClassNames.rectText}\n dy={metricName !== undefined ? yCoordinate + rectangleHeight / 2.5 : yCoordinate + rectangleHeight / 2}\n x={xCoordinate + rectangleWidth / 2}\n key={`${nodeId}${this.styleClassNames.rectText}`}\n >\n {name}\n {subValue}\n </text>,\n );\n }\n }\n // Create a rectangular path from parent to the child nodes\n public createPathLink(\n parentX: number,\n parentY: number,\n childX: number,\n childY: number,\n leaf: boolean,\n rectWidth: number,\n rectHeight: number,\n gap: number,\n ): string {\n // gap adds ratio for parent.y to child.y\n const path = `M${childX + rectWidth / 2},${childY - gap} H${parentX + rectWidth / 2} V${\n parentY + rectHeight + gap / 2\n }`;\n const leafpath = `M${parentX + rectWidth / 2},${parentY + rectHeight + gap / 2} V${\n parentY + gap * 5\n } H${parentX} H${parentX + rectWidth}`;\n\n // based on the type of node return leafpath or path element\n return leaf ? leafpath : path;\n }\n\n // Append path link element\n public addLinktoSVG(\n nodeId: number,\n parentX: number,\n parentY: number,\n childX: number,\n childY: number,\n leaf: boolean,\n rectWidth: number,\n rectHeight: number,\n gap: number,\n ) {\n this._linkElements.push(\n <path\n className={this.styleClassNames.link}\n d={this.createPathLink(parentX, parentY, childX, childY, leaf, rectWidth, rectHeight, gap)}\n key={`${nodeId}${this.styleClassNames.link}`}\n />,\n );\n }\n}\n\n// Create child class to Add Tree component based on treeHeight\nclass LayeredTree extends StandardTree {\n public composition: number | undefined;\n private _treeTraversal: number | undefined;\n constructor(\n treeData: ITreeChartDataPoint,\n composition: number | undefined,\n styleClassNames: { link: string; rectNode: string; rectText: string; rectSubText: string; rectmetricText: string },\n _nodeElements: Array<React.SVGProps<SVGRectElement> | React.SVGProps<SVGTextElement>> = [],\n _linkElements: Array<React.SVGProps<SVGPathElement>> = [],\n _treeTraversal: number | undefined,\n ) {\n super(treeData, styleClassNames, _nodeElements, _linkElements);\n this.composition = composition;\n this._treeTraversal = _treeTraversal;\n }\n public createTree(givenLayoutWidth: number | undefined, screenWidth: number) {\n if (givenLayoutWidth !== undefined) {\n if (givenLayoutWidth < 65) {\n givenLayoutWidth = 65;\n }\n if (givenLayoutWidth > 90) {\n givenLayoutWidth = 90;\n }\n }\n const layoutWidth = givenLayoutWidth || 75;\n const root = hierarchy(this.treeData, d => {\n return d.children;\n });\n\n // Find tree Height\n const treeHeight = root?.height + 1;\n\n // Create tree layout, width: layoutWidth, height: layoutWidth/1.5 and add node separation\n const treemap = tree()\n .nodeSize([layoutWidth, layoutWidth / 1.5])\n .separation((a, b) => {\n return a.parent === root && b.parent === root ? 3.5 : 1;\n });\n\n // Assigns the x and y position for the nodes\n const treeData = treemap(root);\n\n // Compute the new tree layout.\n const nodes = treeData.descendants();\n\n // Normalize for fixed-depth and width\n // Normalise y coordinate by depth of each node by a factor of 130\n // Normalise x coordinate by start coordinate 0 with screenSize/3\n nodes.forEach(d => {\n d.y = d.depth === 0 ? 10 : d.depth * 130;\n d.x += screenWidth / 3;\n });\n\n // <------------------ Traversal section ------------------>\n\n // Create tree data structure\n const treeDataStructure: Array<ITreeDataStructure> = [];\n let TreeID: number = 0;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const createTreeDataStructure = (d: any) => {\n d.id = TreeID;\n treeDataStructure.push({\n id: TreeID,\n children: d.children,\n dataName: d.data.name,\n subName: d.data.subname,\n metricName: d.data?.metric,\n fill: d.data.fill,\n x: d.x,\n y: d.y,\n parentID: d.parent?.id,\n });\n TreeID++;\n };\n\n this._treeTraversal === 0\n ? root.each(d => {\n createTreeDataStructure(d);\n })\n : root.eachBefore(d => {\n createTreeDataStructure(d);\n });\n\n const rectWidth = layoutWidth * 3;\n const rectHeight = rectWidth / 3.45;\n const gap: number = 20;\n const parentSet = new Set();\n\n for (const d of treeDataStructure) {\n const parentInfo =\n d.id === 0\n ? 'Root Node'\n : `Parent info parentId: ${d.parentID}\n ${treeDataStructure[d.parentID].dataName}\n ${treeDataStructure[d.parentID].subName}`;\n\n // check for leaf nodes\n if (!d.children && !parentSet.has(d.parentID) && treeHeight === 3) {\n const newWidth = (rectWidth - gap) / 2;\n const newHeight = rectHeight;\n parentSet.add(d.parentID);\n\n // <------------------ Links section ------------------>\n this.addLinktoSVG(\n d.id,\n treeDataStructure[d.parentID].x,\n treeDataStructure[d.parentID].y,\n treeDataStructure[d.id].x,\n treeDataStructure[d.id].y,\n true,\n rectWidth,\n rectHeight,\n gap,\n );\n\n // <------------------ Nodes section ------------------>\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const children: any = treeDataStructure[d.parentID]?.children;\n\n const dx1: number = treeDataStructure[d.parentID]?.x;\n const dx2: number = treeDataStructure[d.parentID]?.x + newWidth + gap;\n let dy: number = children[0]?.y;\n\n for (let itr = 0; itr < children.length; ++itr) {\n const child = children[itr];\n\n // Given Composition\n if (this.composition !== undefined) {\n // For compact compostion\n if (this.composition === 0) {\n this.addNodeShapetoSVG(\n child.data.name,\n child.data.subname,\n child.data.metricName,\n itr % 2 === 0 ? dx1 : dx2,\n dy,\n child.data.fill,\n children.length === 1 ? rectWidth : newWidth,\n rectHeight,\n child.id,\n parentInfo,\n );\n if (itr % 2 === 1) {\n dy += newHeight + gap;\n }\n }\n // For long compostion\n else {\n this.addNodeShapetoSVG(\n child.data.name,\n child.data.subname,\n child.data.metricName,\n dx1,\n dy,\n child.data.fill,\n rectWidth,\n rectHeight,\n child.id,\n parentInfo,\n );\n dy += newHeight + gap;\n }\n }\n\n // Automatic Node Composition\n else {\n if (children.length > 2) {\n this.addNodeShapetoSVG(\n child.data.name,\n child.data.subname,\n child.data.metricName,\n itr % 2 === 0 ? dx1 : dx2,\n dy,\n child.data.fill,\n children.length === 1 ? rectWidth : newWidth,\n rectHeight,\n child.id,\n parentInfo,\n );\n if (itr % 2 === 1) {\n dy += newHeight + gap;\n }\n } else {\n this.addNodeShapetoSVG(\n child.data.name,\n child.data.subname,\n child.data.metricName,\n dx1,\n dy,\n child.data.fill,\n rectWidth,\n rectHeight,\n child.id,\n parentInfo,\n );\n dy += newHeight + gap;\n }\n }\n }\n }\n\n if (d.children || treeHeight <= 2) {\n // <------------------ Nodes section ------------------>\n this.addNodeShapetoSVG(\n d.dataName,\n d.subName,\n d.metricName,\n d.x,\n d.y,\n d.fill,\n rectWidth,\n rectHeight,\n d.id,\n parentInfo,\n );\n\n // <------------------ Links section ------------------>\n if (d.id !== 0) {\n this.addLinktoSVG(\n d.id,\n treeDataStructure[d.parentID].x,\n treeDataStructure[d.parentID].y,\n treeDataStructure[d.id].x,\n treeDataStructure[d.id].y,\n false,\n rectWidth,\n rectHeight,\n gap,\n );\n }\n }\n }\n }\n}\n\nexport class TreeChartBase extends React.Component<ITreeProps, ITreeState> {\n private _treeData: ITreeChartDataPoint;\n private _width: number;\n private _height: number;\n private _composition: number | undefined;\n private _classNames: IProcessedStyleSet<ITreeStyles>;\n private _margin: { left: number; right: number; top: number; bottom: number };\n private _nodeElements: Array<React.SVGProps<SVGRectElement> | React.SVGProps<SVGTextElement>> = [];\n private _linkElements: Array<React.SVGProps<SVGPathElement>> = [];\n private _treeTraversal: number | undefined;\n\n constructor(props: ITreeProps) {\n super(props);\n this._margin = { top: 30, right: 20, bottom: 30, left: 50 };\n this._width = this.props.width || 1500;\n this._height = this.props.height || 700;\n this._treeData = this.props.treeData;\n this._composition = this.props?.composition;\n this._treeTraversal = this.props.treeTraversal;\n\n this.state = {\n _width: this._width,\n _height: this._height,\n };\n }\n\n public componentDidMount() {\n const { theme, className, styles } = this.props;\n\n // Get classNames to create component styling\n this._classNames = getClassNames(styles!, {\n theme: theme!,\n className,\n });\n\n // Call createTreeChart function in componentDidMount\n this.createTreeChart();\n\n this.setState({\n _width: this.props.width || 1500,\n _height: this.props.height || 700,\n });\n }\n\n public componentDidUpdate(prevProps: ITreeProps): void {\n if (prevProps.layoutWidth !== this.props.layoutWidth) {\n const svgText = selectAll('text');\n const svgRect = selectAll('rect');\n const svgLink = selectAll('path');\n\n if (this._nodeElements.length === 0 && this._linkElements.length === 0) {\n svgText.remove();\n svgRect.remove();\n svgLink.remove();\n }\n\n this.createTreeChart();\n }\n }\n public createTreeChart() {\n const nodeElements: Array<React.SVGProps<SVGRectElement> | React.SVGProps<SVGTextElement>> = [];\n const linkElements: Array<React.SVGProps<SVGPathElement>> = [];\n\n // Create styleClass object to access it in parent class\n const styleClassNames = {\n link: this._classNames.link,\n rectNode: this._classNames.rectNode,\n rectText: this._classNames.rectText,\n rectSubText: this._classNames.rectSubText,\n rectmetricText: this._classNames.rectMetricText,\n };\n // Instantiate inherited class and call createTree function for the object\n const treeObject = new LayeredTree(\n this._treeData,\n this._composition,\n styleClassNames,\n nodeElements,\n linkElements,\n this._treeTraversal,\n );\n treeObject.createTree(this.props.layoutWidth, this._width);\n this._nodeElements = nodeElements;\n this._linkElements = linkElements;\n }\n\n public render(): JSX.Element {\n return (\n <FocusZone>\n <div className={this._classNames?.root}>\n <svg\n className=\"svgTree\"\n width={this.state._width - this._margin.left - this._margin.right}\n height={this.state._height - this._margin.top - this._margin.bottom}\n >\n <g className=\"svgNode\">{this._nodeElements.map(element => element)}</g>\n <g className=\"svgLink\">{this._linkElements.map(element => element)}</g>\n </svg>\n </div>\n </FocusZone>\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TreeChart = void 0;
|
|
4
|
+
var Utilities_1 = require("@fluentui/react/lib-commonjs/Utilities");
|
|
5
|
+
var TreeChart_base_1 = require("./TreeChart.base");
|
|
6
|
+
var TreeChart_styles_1 = require("./TreeChart.styles");
|
|
7
|
+
exports.TreeChart = Utilities_1.styled(TreeChart_base_1.TreeChartBase, TreeChart_styles_1.getStyles);
|
|
8
|
+
//# sourceMappingURL=TreeChart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeChart.js","sourceRoot":"../src/","sources":["components/TreeChart/TreeChart.tsx"],"names":[],"mappings":";;;AACA,2DAAuD;AAEvD,mDAAiD;AACjD,uDAA+C;AAElC,QAAA,SAAS,GAAwC,kBAAM,CAClE,8BAAa,EACb,4BAAS,CACV,CAAC","sourcesContent":["import * as React from 'react';\nimport { styled } from '@fluentui/react/lib/Utilities';\nimport { ITreeStyles, ITreeProps, ITreeStyleProps } from './TreeChart.types';\nimport { TreeChartBase } from './TreeChart.base';\nimport { getStyles } from './TreeChart.styles';\n\nexport const TreeChart: React.FunctionComponent<ITreeProps> = styled<ITreeProps, ITreeStyleProps, ITreeStyles>(\n TreeChartBase,\n getStyles,\n);\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStyles = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var getStyles = function (props) {
|
|
6
|
+
return {
|
|
7
|
+
root: [
|
|
8
|
+
props.theme.spacing,
|
|
9
|
+
'ms-TreeChart',
|
|
10
|
+
props.className,
|
|
11
|
+
{
|
|
12
|
+
overflow: 'scroll',
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
link: {
|
|
16
|
+
fill: 'none',
|
|
17
|
+
stroke: '#A1A1A1',
|
|
18
|
+
strokeWidth: '2px',
|
|
19
|
+
},
|
|
20
|
+
rectNode: {
|
|
21
|
+
strokeWidth: '2px',
|
|
22
|
+
fill: 'white',
|
|
23
|
+
padding: '10px',
|
|
24
|
+
rx: '2px',
|
|
25
|
+
},
|
|
26
|
+
rectText: tslib_1.__assign({ fill: 'black' }, props.theme.fonts.large),
|
|
27
|
+
rectSubText: tslib_1.__assign({ fill: '#484644' }, props.theme.fonts.medium),
|
|
28
|
+
rectMetricText: tslib_1.__assign({ fill: '#000000' }, props.theme.fonts.xLarge),
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
exports.getStyles = getStyles;
|
|
32
|
+
//# sourceMappingURL=TreeChart.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeChart.styles.js","sourceRoot":"../src/","sources":["components/TreeChart/TreeChart.styles.ts"],"names":[],"mappings":";;;;AAEO,IAAM,SAAS,GAAG,UAAC,KAAsB;IAC9C,OAAO;QACL,IAAI,EAAE;YACJ,KAAK,CAAC,KAAK,CAAC,OAAO;YACnB,cAAc;YACd,KAAK,CAAC,SAAS;YACf;gBACE,QAAQ,EAAE,QAAQ;aACnB;SACF;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,SAAS;YACjB,WAAW,EAAE,KAAK;SACnB;QACD,QAAQ,EAAE;YACR,WAAW,EAAE,KAAK;YAClB,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,MAAM;YACf,EAAE,EAAE,KAAK;SACV;QACD,QAAQ,qBACN,IAAI,EAAE,OAAO,IACV,KAAK,CAAC,KAAM,CAAC,KAAK,CAAC,KAAK,CAC5B;QACD,WAAW,qBACT,IAAI,EAAE,SAAS,IACZ,KAAK,CAAC,KAAM,CAAC,KAAK,CAAC,MAAM,CAC7B;QACD,cAAc,qBACZ,IAAI,EAAE,SAAS,IACZ,KAAK,CAAC,KAAM,CAAC,KAAK,CAAC,MAAM,CAC7B;KACF,CAAC;AACJ,CAAC,CAAC;AAlCW,QAAA,SAAS,aAkCpB","sourcesContent":["import { ITreeStyleProps, ITreeStyles } from './TreeChart.types';\n\nexport const getStyles = (props: ITreeStyleProps): ITreeStyles => {\n return {\n root: [\n props.theme.spacing,\n 'ms-TreeChart',\n props.className,\n {\n overflow: 'scroll',\n },\n ],\n link: {\n fill: 'none',\n stroke: '#A1A1A1',\n strokeWidth: '2px',\n },\n rectNode: {\n strokeWidth: '2px',\n fill: 'white',\n padding: '10px',\n rx: '2px',\n },\n rectText: {\n fill: 'black',\n ...props.theme!.fonts.large,\n },\n rectSubText: {\n fill: '#484644',\n ...props.theme!.fonts.medium,\n },\n rectMetricText: {\n fill: '#000000',\n ...props.theme!.fonts.xLarge,\n },\n };\n};\n"]}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { IStyle, ITheme } from '@fluentui/react/lib/Styling';
|
|
2
|
+
import { IStyleFunctionOrObject } from '@fluentui/react/lib/Utilities';
|
|
3
|
+
export interface ITreeChartDataPoint {
|
|
4
|
+
/**
|
|
5
|
+
* Node main text
|
|
6
|
+
*/
|
|
7
|
+
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* Subtext value (optional)
|
|
10
|
+
*/
|
|
11
|
+
subname?: string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Metric text value (optional)
|
|
14
|
+
*/
|
|
15
|
+
metric?: string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Color of the rectangular box
|
|
18
|
+
*/
|
|
19
|
+
fill: string;
|
|
20
|
+
/**
|
|
21
|
+
* Recursive datastructure for child node object
|
|
22
|
+
*/
|
|
23
|
+
children?: Array<ITreeChartDataPoint>;
|
|
24
|
+
}
|
|
25
|
+
export declare enum NodesComposition {
|
|
26
|
+
/**
|
|
27
|
+
* NodeComposition enum val for long: number = 1
|
|
28
|
+
*/
|
|
29
|
+
long = 1,
|
|
30
|
+
/**
|
|
31
|
+
* NodeComposition enum val for compact: number = 0
|
|
32
|
+
*/
|
|
33
|
+
compact = 0
|
|
34
|
+
}
|
|
35
|
+
export declare enum TreeTraverse {
|
|
36
|
+
/**
|
|
37
|
+
* TreeTraverse enum val for preOrder: number = 1
|
|
38
|
+
*/
|
|
39
|
+
preOrder = 1,
|
|
40
|
+
/**
|
|
41
|
+
* TreeTraverse enum val for levelOrder: number = 0
|
|
42
|
+
*/
|
|
43
|
+
levelOrder = 0
|
|
44
|
+
}
|
|
45
|
+
export interface ITreeProps {
|
|
46
|
+
/**
|
|
47
|
+
* An object of chart data points for the Tree chart
|
|
48
|
+
*/
|
|
49
|
+
treeData: ITreeChartDataPoint;
|
|
50
|
+
/**
|
|
51
|
+
* compostion for three layer chart, long: composition = 1; compact: composition = 0
|
|
52
|
+
*/
|
|
53
|
+
composition?: NodesComposition.long | NodesComposition.compact | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Node Width Size for the Tree Layout
|
|
56
|
+
* * @default 75
|
|
57
|
+
*/
|
|
58
|
+
layoutWidth?: number | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* traversal order for tree chart, preOrder = 1, levelOrder = 0
|
|
61
|
+
*/
|
|
62
|
+
treeTraversal?: TreeTraverse.preOrder | TreeTraverse.levelOrder;
|
|
63
|
+
/**
|
|
64
|
+
* Width of SVG tree chart
|
|
65
|
+
* * @default 1500
|
|
66
|
+
*/
|
|
67
|
+
width?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Height of SVG tree chart
|
|
70
|
+
* * @default 700
|
|
71
|
+
*/
|
|
72
|
+
height?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Margin for the SVG tree chart
|
|
75
|
+
*/
|
|
76
|
+
marign?: {
|
|
77
|
+
left: number;
|
|
78
|
+
right: number;
|
|
79
|
+
top: number;
|
|
80
|
+
bottom: number;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Call to provide customized styling that will layer on top of the variant rules.
|
|
84
|
+
*/
|
|
85
|
+
styles?: IStyleFunctionOrObject<ITreeStyleProps, ITreeStyles>;
|
|
86
|
+
/**
|
|
87
|
+
* Additional CSS class(es) to apply to the TreeChart.
|
|
88
|
+
*/
|
|
89
|
+
className?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Theme (provided through customization.)
|
|
92
|
+
*/
|
|
93
|
+
theme?: ITheme;
|
|
94
|
+
}
|
|
95
|
+
export interface ITreeState {
|
|
96
|
+
/**
|
|
97
|
+
* Width of SVG tree chart
|
|
98
|
+
* * @default 1500
|
|
99
|
+
*/
|
|
100
|
+
_width: number;
|
|
101
|
+
/**
|
|
102
|
+
* Height of SVG tree chart
|
|
103
|
+
* * @default 700
|
|
104
|
+
*/
|
|
105
|
+
_height: number;
|
|
106
|
+
/**
|
|
107
|
+
* Layout Width of SVG tree chart
|
|
108
|
+
* * @default 75
|
|
109
|
+
*/
|
|
110
|
+
_layoutWidth?: number;
|
|
111
|
+
}
|
|
112
|
+
export interface ITreeDataStructure {
|
|
113
|
+
/**
|
|
114
|
+
* Node id of each node
|
|
115
|
+
*/
|
|
116
|
+
id: number;
|
|
117
|
+
/**
|
|
118
|
+
* Children node object
|
|
119
|
+
*/
|
|
120
|
+
children: unknown;
|
|
121
|
+
/**
|
|
122
|
+
* Node main text
|
|
123
|
+
*/
|
|
124
|
+
dataName: string;
|
|
125
|
+
/**
|
|
126
|
+
* Subtext value (optional)
|
|
127
|
+
*/
|
|
128
|
+
subName?: string | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* Metric text value (optional)
|
|
131
|
+
*/
|
|
132
|
+
metricName?: string | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* Color of the rectangular box
|
|
135
|
+
*/
|
|
136
|
+
fill: string;
|
|
137
|
+
/**
|
|
138
|
+
* X-coordindate of node
|
|
139
|
+
*/
|
|
140
|
+
x: number;
|
|
141
|
+
/**
|
|
142
|
+
* Y-coordindate of node
|
|
143
|
+
*/
|
|
144
|
+
y: number;
|
|
145
|
+
/**
|
|
146
|
+
* Node id of each node's parent
|
|
147
|
+
*/
|
|
148
|
+
parentID: number;
|
|
149
|
+
}
|
|
150
|
+
export interface ITreeStyleProps {
|
|
151
|
+
/**
|
|
152
|
+
* Theme (provided through customization.)
|
|
153
|
+
*/
|
|
154
|
+
theme: ITheme;
|
|
155
|
+
/**
|
|
156
|
+
* Additional CSS class(es) to apply to the TreeChart.
|
|
157
|
+
*/
|
|
158
|
+
className?: string;
|
|
159
|
+
}
|
|
160
|
+
export interface ITreeStyles {
|
|
161
|
+
/**
|
|
162
|
+
* Style for the root element.
|
|
163
|
+
*/
|
|
164
|
+
root: IStyle;
|
|
165
|
+
/**
|
|
166
|
+
* Style for the Link/Path element.
|
|
167
|
+
*/
|
|
168
|
+
link: IStyle;
|
|
169
|
+
/**
|
|
170
|
+
* Style for rectangular Node
|
|
171
|
+
*/
|
|
172
|
+
rectNode: IStyle;
|
|
173
|
+
/**
|
|
174
|
+
* Style for the node main Text
|
|
175
|
+
*/
|
|
176
|
+
rectText: IStyle;
|
|
177
|
+
/**
|
|
178
|
+
* Style for the node sub Text
|
|
179
|
+
*/
|
|
180
|
+
rectSubText: IStyle;
|
|
181
|
+
/**
|
|
182
|
+
* Style for the node metric value Text
|
|
183
|
+
*/
|
|
184
|
+
rectMetricText: IStyle;
|
|
185
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TreeTraverse = exports.NodesComposition = void 0;
|
|
4
|
+
var NodesComposition;
|
|
5
|
+
(function (NodesComposition) {
|
|
6
|
+
/**
|
|
7
|
+
* NodeComposition enum val for long: number = 1
|
|
8
|
+
*/
|
|
9
|
+
NodesComposition[NodesComposition["long"] = 1] = "long";
|
|
10
|
+
/**
|
|
11
|
+
* NodeComposition enum val for compact: number = 0
|
|
12
|
+
*/
|
|
13
|
+
NodesComposition[NodesComposition["compact"] = 0] = "compact";
|
|
14
|
+
})(NodesComposition = exports.NodesComposition || (exports.NodesComposition = {}));
|
|
15
|
+
var TreeTraverse;
|
|
16
|
+
(function (TreeTraverse) {
|
|
17
|
+
/**
|
|
18
|
+
* TreeTraverse enum val for preOrder: number = 1
|
|
19
|
+
*/
|
|
20
|
+
TreeTraverse[TreeTraverse["preOrder"] = 1] = "preOrder";
|
|
21
|
+
/**
|
|
22
|
+
* TreeTraverse enum val for levelOrder: number = 0
|
|
23
|
+
*/
|
|
24
|
+
TreeTraverse[TreeTraverse["levelOrder"] = 0] = "levelOrder";
|
|
25
|
+
})(TreeTraverse = exports.TreeTraverse || (exports.TreeTraverse = {}));
|
|
26
|
+
//# sourceMappingURL=TreeChart.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeChart.types.js","sourceRoot":"../src/","sources":["components/TreeChart/TreeChart.types.ts"],"names":[],"mappings":";;;AA0BA,IAAY,gBASX;AATD,WAAY,gBAAgB;IAC1B;;OAEG;IACH,uDAAQ,CAAA;IACR;;OAEG;IACH,6DAAW,CAAA;AACb,CAAC,EATW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAS3B;AAED,IAAY,YASX;AATD,WAAY,YAAY;IACtB;;OAEG;IACH,uDAAY,CAAA;IACZ;;OAEG;IACH,2DAAc,CAAA;AAChB,CAAC,EATW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QASvB","sourcesContent":["import { IStyle, ITheme } from '@fluentui/react/lib/Styling';\nimport { IStyleFunctionOrObject } from '@fluentui/react/lib/Utilities';\n\nexport interface ITreeChartDataPoint {\n /**\n * Node main text\n */\n name: string;\n /**\n * Subtext value (optional)\n */\n subname?: string | undefined;\n /**\n * Metric text value (optional)\n */\n metric?: string | undefined;\n /**\n * Color of the rectangular box\n */\n fill: string;\n /**\n * Recursive datastructure for child node object\n */\n children?: Array<ITreeChartDataPoint>;\n}\n\nexport enum NodesComposition {\n /**\n * NodeComposition enum val for long: number = 1\n */\n long = 1,\n /**\n * NodeComposition enum val for compact: number = 0\n */\n compact = 0,\n}\n\nexport enum TreeTraverse {\n /**\n * TreeTraverse enum val for preOrder: number = 1\n */\n preOrder = 1,\n /**\n * TreeTraverse enum val for levelOrder: number = 0\n */\n levelOrder = 0,\n}\n\nexport interface ITreeProps {\n /**\n * An object of chart data points for the Tree chart\n */\n treeData: ITreeChartDataPoint;\n /**\n * compostion for three layer chart, long: composition = 1; compact: composition = 0\n */\n composition?: NodesComposition.long | NodesComposition.compact | undefined;\n /**\n * Node Width Size for the Tree Layout\n * * @default 75\n */\n layoutWidth?: number | undefined;\n /**\n * traversal order for tree chart, preOrder = 1, levelOrder = 0\n */\n treeTraversal?: TreeTraverse.preOrder | TreeTraverse.levelOrder;\n /**\n * Width of SVG tree chart\n * * @default 1500\n */\n width?: number;\n /**\n * Height of SVG tree chart\n * * @default 700\n */\n height?: number;\n /**\n * Margin for the SVG tree chart\n */\n marign?: { left: number; right: number; top: number; bottom: number };\n /**\n * Call to provide customized styling that will layer on top of the variant rules.\n */\n styles?: IStyleFunctionOrObject<ITreeStyleProps, ITreeStyles>;\n /**\n * Additional CSS class(es) to apply to the TreeChart.\n */\n className?: string;\n /**\n * Theme (provided through customization.)\n */\n theme?: ITheme;\n}\nexport interface ITreeState {\n /**\n * Width of SVG tree chart\n * * @default 1500\n */\n _width: number;\n /**\n * Height of SVG tree chart\n * * @default 700\n */\n _height: number;\n /**\n * Layout Width of SVG tree chart\n * * @default 75\n */\n _layoutWidth?: number;\n}\n\nexport interface ITreeDataStructure {\n /**\n * Node id of each node\n */\n id: number;\n /**\n * Children node object\n */\n children: unknown;\n /**\n * Node main text\n */\n dataName: string;\n /**\n * Subtext value (optional)\n */\n subName?: string | undefined;\n /**\n * Metric text value (optional)\n */\n metricName?: string | undefined;\n /**\n * Color of the rectangular box\n */\n fill: string;\n /**\n * X-coordindate of node\n */\n x: number;\n /**\n * Y-coordindate of node\n */\n y: number;\n /**\n * Node id of each node's parent\n */\n parentID: number;\n}\n\nexport interface ITreeStyleProps {\n /**\n * Theme (provided through customization.)\n */\n theme: ITheme;\n /**\n * Additional CSS class(es) to apply to the TreeChart.\n */\n className?: string;\n}\nexport interface ITreeStyles {\n /**\n * Style for the root element.\n */\n root: IStyle;\n /**\n * Style for the Link/Path element.\n */\n link: IStyle;\n /**\n * Style for rectangular Node\n */\n rectNode: IStyle;\n /**\n * Style for the node main Text\n */\n rectText: IStyle;\n /**\n * Style for the node sub Text\n */\n rectSubText: IStyle;\n /**\n * Style for the node metric value Text\n */\n rectMetricText: IStyle;\n}\n"]}
|