@semcore/d3-chart 1.7.0 → 1.9.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/CHANGELOG.md +18 -0
- package/lib/cjs/Axis.js +33 -21
- package/lib/cjs/Axis.js.map +1 -1
- package/lib/cjs/Bar.js +3 -3
- package/lib/cjs/Bar.js.map +1 -1
- package/lib/cjs/Bubble.js +3 -24
- package/lib/cjs/Bubble.js.map +1 -1
- package/lib/cjs/ClipPath.js +2 -1
- package/lib/cjs/ClipPath.js.map +1 -1
- package/lib/cjs/Donut.js +1 -1
- package/lib/cjs/Donut.js.map +1 -1
- package/lib/cjs/Dots.js +1 -1
- package/lib/cjs/Dots.js.map +1 -1
- package/lib/cjs/GroupBar.js +8 -8
- package/lib/cjs/GroupBar.js.map +1 -1
- package/lib/cjs/HorizontalBar.js +3 -3
- package/lib/cjs/HorizontalBar.js.map +1 -1
- package/lib/cjs/Plot.js +16 -2
- package/lib/cjs/Plot.js.map +1 -1
- package/lib/cjs/RadialTree.js +691 -0
- package/lib/cjs/RadialTree.js.map +1 -0
- package/lib/cjs/ResponsiveContainer.js +2 -2
- package/lib/cjs/ResponsiveContainer.js.map +1 -1
- package/lib/cjs/StackBar.js +8 -8
- package/lib/cjs/StackBar.js.map +1 -1
- package/lib/cjs/StackedArea.js +8 -8
- package/lib/cjs/StackedArea.js.map +1 -1
- package/lib/cjs/Tooltip.js +6 -10
- package/lib/cjs/Tooltip.js.map +1 -1
- package/lib/cjs/Venn.js +2 -2
- package/lib/cjs/Venn.js.map +1 -1
- package/lib/cjs/createElement.js +3 -2
- package/lib/cjs/createElement.js.map +1 -1
- package/lib/cjs/index.js +8 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/style/axis.shadow.css +2 -4
- package/lib/cjs/style/plot.shadow.css +6 -0
- package/lib/cjs/style/radial-tree.shadow.css +23 -0
- package/lib/cjs/types/Area.d.ts +47 -0
- package/lib/cjs/types/Axis.d.ts +64 -0
- package/lib/cjs/types/Bar.d.ts +48 -0
- package/lib/cjs/types/Bubble.d.ts +27 -0
- package/lib/cjs/types/ClipPath.d.ts +26 -0
- package/lib/cjs/types/Donut.d.ts +42 -0
- package/lib/cjs/types/GroupBar.d.ts +20 -0
- package/lib/cjs/types/HorizontalBar.d.ts +29 -0
- package/lib/cjs/types/Hover.d.ts +15 -0
- package/lib/cjs/types/Line.d.ts +50 -0
- package/lib/cjs/types/Plot.d.ts +16 -0
- package/lib/cjs/types/ResponsiveContainer.d.ts +20 -0
- package/lib/cjs/types/ScatterPlot.d.ts +27 -0
- package/lib/cjs/types/StackBar.d.ts +26 -0
- package/lib/cjs/types/StackedArea.d.ts +26 -0
- package/lib/cjs/types/Tooltip.d.ts +31 -0
- package/lib/cjs/types/Venn.d.ts +45 -0
- package/lib/cjs/types/context.d.ts +6 -0
- package/lib/cjs/types/index.d.ts +53 -0
- package/lib/cjs/utils.js +120 -55
- package/lib/cjs/utils.js.map +1 -1
- package/lib/es6/Axis.js +33 -21
- package/lib/es6/Axis.js.map +1 -1
- package/lib/es6/Bar.js +3 -3
- package/lib/es6/Bar.js.map +1 -1
- package/lib/es6/Bubble.js +3 -24
- package/lib/es6/Bubble.js.map +1 -1
- package/lib/es6/ClipPath.js +2 -1
- package/lib/es6/ClipPath.js.map +1 -1
- package/lib/es6/Donut.js +1 -1
- package/lib/es6/Donut.js.map +1 -1
- package/lib/es6/Dots.js +1 -1
- package/lib/es6/Dots.js.map +1 -1
- package/lib/es6/GroupBar.js +8 -8
- package/lib/es6/GroupBar.js.map +1 -1
- package/lib/es6/HorizontalBar.js +3 -3
- package/lib/es6/HorizontalBar.js.map +1 -1
- package/lib/es6/Plot.js +18 -2
- package/lib/es6/Plot.js.map +1 -1
- package/lib/es6/RadialTree.js +679 -0
- package/lib/es6/RadialTree.js.map +1 -0
- package/lib/es6/ResponsiveContainer.js +2 -2
- package/lib/es6/ResponsiveContainer.js.map +1 -1
- package/lib/es6/StackBar.js +8 -8
- package/lib/es6/StackBar.js.map +1 -1
- package/lib/es6/StackedArea.js +8 -8
- package/lib/es6/StackedArea.js.map +1 -1
- package/lib/es6/Tooltip.js +6 -10
- package/lib/es6/Tooltip.js.map +1 -1
- package/lib/es6/Venn.js +2 -2
- package/lib/es6/Venn.js.map +1 -1
- package/lib/es6/createElement.js +3 -2
- package/lib/es6/createElement.js.map +1 -1
- package/lib/es6/index.js +1 -0
- package/lib/es6/index.js.map +1 -1
- package/lib/es6/style/axis.shadow.css +2 -4
- package/lib/es6/style/plot.shadow.css +6 -0
- package/lib/es6/style/radial-tree.shadow.css +23 -0
- package/lib/es6/types/Area.d.ts +47 -0
- package/lib/es6/types/Axis.d.ts +64 -0
- package/lib/es6/types/Bar.d.ts +48 -0
- package/lib/es6/types/Bubble.d.ts +27 -0
- package/lib/es6/types/ClipPath.d.ts +26 -0
- package/lib/es6/types/Donut.d.ts +42 -0
- package/lib/es6/types/GroupBar.d.ts +20 -0
- package/lib/es6/types/HorizontalBar.d.ts +29 -0
- package/lib/es6/types/Hover.d.ts +15 -0
- package/lib/es6/types/Line.d.ts +50 -0
- package/lib/es6/types/Plot.d.ts +16 -0
- package/lib/es6/types/ResponsiveContainer.d.ts +20 -0
- package/lib/es6/types/ScatterPlot.d.ts +27 -0
- package/lib/es6/types/StackBar.d.ts +26 -0
- package/lib/es6/types/StackedArea.d.ts +26 -0
- package/lib/es6/types/Tooltip.d.ts +31 -0
- package/lib/es6/types/Venn.d.ts +45 -0
- package/lib/es6/types/context.d.ts +6 -0
- package/lib/es6/types/index.d.ts +53 -0
- package/lib/es6/utils.js +95 -44
- package/lib/es6/utils.js.map +1 -1
- package/lib/types/RadialTree.d.ts +202 -0
- package/lib/types/index.d.ts +6 -0
- package/lib/types/utils.d.ts +27 -0
- package/package.json +17 -10
- package/src/Axis.jsx +11 -1
- package/src/Bubble.jsx +1 -21
- package/src/ClipPath.jsx +1 -0
- package/src/Donut.jsx +7 -9
- package/src/Plot.jsx +2 -0
- package/src/RadialTree.tsx +768 -0
- package/src/createElement.jsx +3 -1
- package/src/index.js +1 -0
- package/src/style/axis.shadow.css +2 -4
- package/src/style/plot.shadow.css +6 -0
- package/src/style/radial-tree.shadow.css +23 -0
- package/src/types/index.d.ts +6 -0
- package/src/utils.ts +227 -0
- package/src/utils.js +0 -147
|
@@ -0,0 +1,679 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
4
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
5
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
6
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
7
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
8
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
9
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
10
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
11
|
+
import { sstyled as _sstyled } from "@semcore/core";
|
|
12
|
+
var _excluded = ["data"];
|
|
13
|
+
|
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
+
|
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
+
|
|
18
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
19
|
+
|
|
20
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
21
|
+
|
|
22
|
+
import React from 'react';
|
|
23
|
+
import { Component, sstyled } from '@semcore/core'; // @ts-ignore
|
|
24
|
+
|
|
25
|
+
import createElement from './createElement';
|
|
26
|
+
import uniqueIDEnhancement from '@semcore/utils/lib/uniqueID';
|
|
27
|
+
import { transition } from 'd3-transition';
|
|
28
|
+
|
|
29
|
+
/*__reshadow-styles__:"./style/radial-tree.shadow.css"*/
|
|
30
|
+
var style = (
|
|
31
|
+
/*__reshadow_css_start__*/
|
|
32
|
+
_sstyled.insert(
|
|
33
|
+
/*__inner_css_start__*/
|
|
34
|
+
".___SRadian_1rr18_gg_{cursor:pointer}.___SCap_1rr18_gg_{transition:r .1s}.___SLabel_1rr18_gg_{fill:var(--color_qzvs85);cursor:var(--text-cursor_qzvs85);transform-origin:var(--transform-origin_qzvs85)}.___SRadian_1rr18_gg_:hover .___SLabel_1rr18_gg_{fill:var(--color-hovered_qzvs85)}@media (prefers-reduced-motion){.___SLineCap_1rr18_gg_{transition:none}}"
|
|
35
|
+
/*__inner_css_end__*/
|
|
36
|
+
, "qzvs85_gg_")
|
|
37
|
+
/*__reshadow_css_end__*/
|
|
38
|
+
, {
|
|
39
|
+
"__SRadian": "___SRadian_1rr18_gg_",
|
|
40
|
+
"__SCap": "___SCap_1rr18_gg_",
|
|
41
|
+
"__SLabel": "___SLabel_1rr18_gg_",
|
|
42
|
+
"--color": "--color_qzvs85",
|
|
43
|
+
"--text-cursor": "--text-cursor_qzvs85",
|
|
44
|
+
"--transform-origin": "--transform-origin_qzvs85",
|
|
45
|
+
"--color-hovered": "--color-hovered_qzvs85",
|
|
46
|
+
"__SLineCap": "___SLineCap_1rr18_gg_"
|
|
47
|
+
});
|
|
48
|
+
import { shade } from '@semcore/utils/lib/color';
|
|
49
|
+
import { measureText } from './utils';
|
|
50
|
+
import assignProps from '@semcore/utils/lib/assignProps';
|
|
51
|
+
import getOriginChildren from '@semcore/utils/lib/getOriginChildren';
|
|
52
|
+
var baseAngle = -Math.PI / 2; // The top vertical line
|
|
53
|
+
|
|
54
|
+
var RadialTreeBase = /*#__PURE__*/function (_Component) {
|
|
55
|
+
_inherits(RadialTreeBase, _Component);
|
|
56
|
+
|
|
57
|
+
var _super = _createSuper(RadialTreeBase);
|
|
58
|
+
|
|
59
|
+
function RadialTreeBase(props) {
|
|
60
|
+
var _this;
|
|
61
|
+
|
|
62
|
+
_classCallCheck(this, RadialTreeBase);
|
|
63
|
+
|
|
64
|
+
_this = _super.call(this, props);
|
|
65
|
+
|
|
66
|
+
_defineProperty(_assertThisInitialized(_this), "Element", void 0);
|
|
67
|
+
|
|
68
|
+
_this.handleRadianClick = _this.handleRadianClick.bind(_assertThisInitialized(_this));
|
|
69
|
+
return _this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
_createClass(RadialTreeBase, [{
|
|
73
|
+
key: "uncontrolledProps",
|
|
74
|
+
value: function uncontrolledProps() {
|
|
75
|
+
return {
|
|
76
|
+
activeKey: null
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
key: "runAppearAnimation",
|
|
81
|
+
value: function runAppearAnimation() {
|
|
82
|
+
var _this$asProps = this.asProps,
|
|
83
|
+
duration = _this$asProps.duration,
|
|
84
|
+
uid = _this$asProps.uid;
|
|
85
|
+
var preferReduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)')?.matches;
|
|
86
|
+
/** using `!(>)` instead of `<=` to get true on NaN and non numbers stuff */
|
|
87
|
+
|
|
88
|
+
if (!(duration > 0)) return;
|
|
89
|
+
if (preferReduceMotion) return;
|
|
90
|
+
var circlesAnimation = transition().selection().selectAll("[data-radial-animation=".concat(uid, "-cap-circle]"));
|
|
91
|
+
var iconsAnimation = transition().selection().selectAll("[data-radial-animation=".concat(uid, "-cap-icon]"));
|
|
92
|
+
var linesAnimation = transition().selection().selectAll("[data-radial-animation=".concat(uid, "-line]"));
|
|
93
|
+
var labelsAnimation = transition().selection().selectAll("[data-radial-animation=".concat(uid, "-label]"));
|
|
94
|
+
var circlesNodes = circlesAnimation.nodes();
|
|
95
|
+
var iconsNodes = iconsAnimation.nodes();
|
|
96
|
+
var linesNodes = linesAnimation.nodes();
|
|
97
|
+
var labelsNodes = linesAnimation.nodes();
|
|
98
|
+
|
|
99
|
+
if (circlesNodes.length > 0) {
|
|
100
|
+
var attrs = circlesNodes.map(function (node) {
|
|
101
|
+
var cx = node.cx?.baseVal?.value;
|
|
102
|
+
var cy = node.cy?.baseVal?.value;
|
|
103
|
+
var radianIndex = parseInt(node.dataset.radianIndex, 10);
|
|
104
|
+
var lineNode = linesNodes[radianIndex];
|
|
105
|
+
return {
|
|
106
|
+
from: {
|
|
107
|
+
cx: lineNode.x1?.baseVal?.value,
|
|
108
|
+
cy: lineNode.y1?.baseVal?.value
|
|
109
|
+
},
|
|
110
|
+
to: {
|
|
111
|
+
cx: cx,
|
|
112
|
+
cy: cy
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
circlesAnimation.attr('opacity', 0).attr('cx', function (_, index) {
|
|
117
|
+
return attrs[index].from?.cx;
|
|
118
|
+
}).attr('cy', function (_, index) {
|
|
119
|
+
return attrs[index].from?.cy;
|
|
120
|
+
});
|
|
121
|
+
circlesAnimation.transition().duration(duration).attr('opacity', 1).attr('cx', function (_, index) {
|
|
122
|
+
return attrs[index].to?.cx;
|
|
123
|
+
}).attr('cy', function (_, index) {
|
|
124
|
+
return attrs[index].to?.cy;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (iconsNodes.length > 0) {
|
|
129
|
+
var _attrs = iconsNodes.map(function (node) {
|
|
130
|
+
var x = node.x?.baseVal?.value;
|
|
131
|
+
var y = node.y?.baseVal?.value;
|
|
132
|
+
var width = node.width?.baseVal?.value;
|
|
133
|
+
var height = node.height?.baseVal?.value;
|
|
134
|
+
var radianIndex = parseInt(node.dataset.radianIndex, 10);
|
|
135
|
+
var lineNode = linesNodes[radianIndex];
|
|
136
|
+
return {
|
|
137
|
+
from: {
|
|
138
|
+
x: lineNode.x1?.baseVal?.value - width / 2,
|
|
139
|
+
y: lineNode.y1?.baseVal?.value - height / 2
|
|
140
|
+
},
|
|
141
|
+
to: {
|
|
142
|
+
x: x,
|
|
143
|
+
y: y
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
iconsAnimation.attr('opacity', 0).attr('x', function (_, index) {
|
|
149
|
+
return _attrs[index].from?.x;
|
|
150
|
+
}).attr('y', function (_, index) {
|
|
151
|
+
return _attrs[index].from?.y;
|
|
152
|
+
});
|
|
153
|
+
iconsAnimation.transition().duration(duration).attr('opacity', 1).attr('x', function (_, index) {
|
|
154
|
+
return _attrs[index].to?.x;
|
|
155
|
+
}).attr('y', function (_, index) {
|
|
156
|
+
return _attrs[index].to?.y;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (linesNodes.length > 0) {
|
|
161
|
+
var _attrs2 = linesNodes.map(function (node) {
|
|
162
|
+
var x2 = node.x2?.baseVal?.value;
|
|
163
|
+
var y2 = node.y2?.baseVal?.value;
|
|
164
|
+
return {
|
|
165
|
+
from: {
|
|
166
|
+
x2: node.x1?.baseVal?.value,
|
|
167
|
+
y2: node.y1?.baseVal?.value
|
|
168
|
+
},
|
|
169
|
+
to: {
|
|
170
|
+
x2: x2,
|
|
171
|
+
y2: y2
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
linesAnimation.attr('opacity', 0).attr('x2', function (_, index) {
|
|
177
|
+
return _attrs2[index].from?.x2;
|
|
178
|
+
}).attr('y2', function (_, index) {
|
|
179
|
+
return _attrs2[index].from?.y2;
|
|
180
|
+
});
|
|
181
|
+
linesAnimation.transition().duration(duration).attr('opacity', 1).attr('x2', function (_, index) {
|
|
182
|
+
return _attrs2[index].to?.x2;
|
|
183
|
+
}).attr('y2', function (_, index) {
|
|
184
|
+
return _attrs2[index].to?.y2;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (labelsNodes.length > 0) {
|
|
189
|
+
labelsAnimation.attr('opacity', 0);
|
|
190
|
+
labelsAnimation.transition().duration(duration).attr('opacity', 1);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}, {
|
|
194
|
+
key: "componentDidUpdate",
|
|
195
|
+
value: function componentDidUpdate(prevProps) {
|
|
196
|
+
if (prevProps.$rootProps.data?.length !== this.asProps.data?.length) {
|
|
197
|
+
this.runAppearAnimation();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}, {
|
|
201
|
+
key: "componentDidMount",
|
|
202
|
+
value: function componentDidMount() {
|
|
203
|
+
this.runAppearAnimation();
|
|
204
|
+
}
|
|
205
|
+
}, {
|
|
206
|
+
key: "handleRadianClick",
|
|
207
|
+
value: function handleRadianClick(key) {
|
|
208
|
+
var _this2 = this;
|
|
209
|
+
|
|
210
|
+
return function (event) {
|
|
211
|
+
var newKey = key !== _this2.asProps.activeKey ? key : null;
|
|
212
|
+
|
|
213
|
+
_this2.handlers.activeKey(newKey, event);
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}, {
|
|
217
|
+
key: "computeTextWidth",
|
|
218
|
+
value: function computeTextWidth() {
|
|
219
|
+
var _this$asProps2 = this.asProps,
|
|
220
|
+
data = _this$asProps2.data,
|
|
221
|
+
textSize = _this$asProps2.textSize;
|
|
222
|
+
var widths = data.map(function (_ref9) {
|
|
223
|
+
var label = _ref9.label;
|
|
224
|
+
return measureText(label, textSize);
|
|
225
|
+
});
|
|
226
|
+
return Math.max.apply(Math, _toConsumableArray(widths));
|
|
227
|
+
}
|
|
228
|
+
}, {
|
|
229
|
+
key: "getTitleProps",
|
|
230
|
+
value: function getTitleProps() {
|
|
231
|
+
var _this$asProps3 = this.asProps,
|
|
232
|
+
uid = _this$asProps3.uid,
|
|
233
|
+
size = _this$asProps3.size,
|
|
234
|
+
textSize = _this$asProps3.textSize;
|
|
235
|
+
|
|
236
|
+
var _size = _slicedToArray(size, 2),
|
|
237
|
+
width = _size[0],
|
|
238
|
+
height = _size[1];
|
|
239
|
+
|
|
240
|
+
var center = [width / 2, height / 2];
|
|
241
|
+
var x = center[0],
|
|
242
|
+
y = center[1];
|
|
243
|
+
return _defineProperty({
|
|
244
|
+
x: x,
|
|
245
|
+
y: y,
|
|
246
|
+
textSize: textSize * 1.5
|
|
247
|
+
}, 'data-radial-animation', "".concat(uid, "-label"));
|
|
248
|
+
}
|
|
249
|
+
}, {
|
|
250
|
+
key: "getRadianProps",
|
|
251
|
+
value: function getRadianProps() {
|
|
252
|
+
var _this$asProps4 = this.asProps,
|
|
253
|
+
data = _this$asProps4.data,
|
|
254
|
+
restRootProps = _objectWithoutProperties(_this$asProps4, _excluded);
|
|
255
|
+
|
|
256
|
+
var textWidth = this.computeTextWidth();
|
|
257
|
+
return _objectSpread(_objectSpread({}, restRootProps), {}, {
|
|
258
|
+
radiansCount: data.length,
|
|
259
|
+
data: data,
|
|
260
|
+
textWidth: textWidth,
|
|
261
|
+
onRadianClick: this.handleRadianClick
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}, {
|
|
265
|
+
key: "render",
|
|
266
|
+
value: function render() {
|
|
267
|
+
var _ref;
|
|
268
|
+
|
|
269
|
+
var SRadialTree = this.Element;
|
|
270
|
+
var Children = this.asProps.Children;
|
|
271
|
+
return _ref = sstyled(this.asProps.styles), /*#__PURE__*/React.createElement(SRadialTree, _ref.cn("SRadialTree", {
|
|
272
|
+
"render": "g"
|
|
273
|
+
}), /*#__PURE__*/React.createElement(Children, _ref.cn("Children", {})));
|
|
274
|
+
}
|
|
275
|
+
}]);
|
|
276
|
+
|
|
277
|
+
return RadialTreeBase;
|
|
278
|
+
}(Component);
|
|
279
|
+
|
|
280
|
+
_defineProperty(RadialTreeBase, "displayName", 'RadialTree');
|
|
281
|
+
|
|
282
|
+
_defineProperty(RadialTreeBase, "style", style);
|
|
283
|
+
|
|
284
|
+
_defineProperty(RadialTreeBase, "enhance", [uniqueIDEnhancement()]);
|
|
285
|
+
|
|
286
|
+
_defineProperty(RadialTreeBase, "defaultProps", {
|
|
287
|
+
angleOffset: 0,
|
|
288
|
+
duration: 300,
|
|
289
|
+
centralMargin: 50,
|
|
290
|
+
labelMargin: 2,
|
|
291
|
+
color: '#008FF8',
|
|
292
|
+
iconColor: '#fff',
|
|
293
|
+
capSize: 8,
|
|
294
|
+
iconSize: 8,
|
|
295
|
+
textSize: 14,
|
|
296
|
+
defaultActiveKey: null
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
var RadialTreeRadian = /*#__PURE__*/function (_Component2) {
|
|
300
|
+
_inherits(RadialTreeRadian, _Component2);
|
|
301
|
+
|
|
302
|
+
var _super2 = _createSuper(RadialTreeRadian);
|
|
303
|
+
|
|
304
|
+
function RadialTreeRadian(props) {
|
|
305
|
+
var _this3;
|
|
306
|
+
|
|
307
|
+
_classCallCheck(this, RadialTreeRadian);
|
|
308
|
+
|
|
309
|
+
_this3 = _super2.call(this, props);
|
|
310
|
+
|
|
311
|
+
_defineProperty(_assertThisInitialized(_this3), "Element", void 0);
|
|
312
|
+
|
|
313
|
+
_this3.renderRadian = _this3.renderRadian.bind(_assertThisInitialized(_this3));
|
|
314
|
+
return _this3;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
_createClass(RadialTreeRadian, [{
|
|
318
|
+
key: "getInteractiveAreaProps",
|
|
319
|
+
value: function getInteractiveAreaProps(_ref11, index) {
|
|
320
|
+
var $rootProps = _ref11.$rootProps;
|
|
321
|
+
var data = $rootProps.data[index];
|
|
322
|
+
|
|
323
|
+
var _this$computeRadianPo = this.computeRadianPosition(data, index),
|
|
324
|
+
xStart = _this$computeRadianPo.xStart,
|
|
325
|
+
yStart = _this$computeRadianPo.yStart,
|
|
326
|
+
xLabelCenter = _this$computeRadianPo.xLabelCenter,
|
|
327
|
+
yLabelCenter = _this$computeRadianPo.yLabelCenter,
|
|
328
|
+
capSize = _this$computeRadianPo.capSize;
|
|
329
|
+
|
|
330
|
+
return {
|
|
331
|
+
x1: xStart,
|
|
332
|
+
y1: yStart,
|
|
333
|
+
x2: xLabelCenter,
|
|
334
|
+
y2: yLabelCenter,
|
|
335
|
+
strokeWidth: capSize * 3
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
}, {
|
|
339
|
+
key: "getLineProps",
|
|
340
|
+
value: function getLineProps(_ref12, index) {
|
|
341
|
+
var _ref13;
|
|
342
|
+
|
|
343
|
+
var $rootProps = _ref12.$rootProps;
|
|
344
|
+
var data = $rootProps.data[index];
|
|
345
|
+
|
|
346
|
+
var _this$computeRadianPo2 = this.computeRadianPosition(data, index),
|
|
347
|
+
xStart = _this$computeRadianPo2.xStart,
|
|
348
|
+
yStart = _this$computeRadianPo2.yStart,
|
|
349
|
+
xEnd = _this$computeRadianPo2.xEnd,
|
|
350
|
+
yEnd = _this$computeRadianPo2.yEnd;
|
|
351
|
+
|
|
352
|
+
var uid = this.asProps.uid;
|
|
353
|
+
var color = data.color ?? this.asProps.color;
|
|
354
|
+
return _ref13 = {
|
|
355
|
+
x1: xStart,
|
|
356
|
+
y1: yStart,
|
|
357
|
+
x2: xEnd,
|
|
358
|
+
y2: yEnd,
|
|
359
|
+
stroke: color
|
|
360
|
+
}, _defineProperty(_ref13, 'data-radial-animation', "".concat(uid, "-line")), _defineProperty(_ref13, 'data-radian-index', index), _ref13;
|
|
361
|
+
}
|
|
362
|
+
}, {
|
|
363
|
+
key: "getCapProps",
|
|
364
|
+
value: function getCapProps(_ref14, index) {
|
|
365
|
+
var _ref15;
|
|
366
|
+
|
|
367
|
+
var $rootProps = _ref14.$rootProps;
|
|
368
|
+
var data = $rootProps.data[index];
|
|
369
|
+
|
|
370
|
+
var _this$computeRadianPo3 = this.computeRadianPosition(data, index),
|
|
371
|
+
xEnd = _this$computeRadianPo3.xEnd,
|
|
372
|
+
yEnd = _this$computeRadianPo3.yEnd,
|
|
373
|
+
capSize = _this$computeRadianPo3.capSize;
|
|
374
|
+
|
|
375
|
+
var uid = this.asProps.uid;
|
|
376
|
+
var color = data.color ?? this.asProps.color;
|
|
377
|
+
return _ref15 = {
|
|
378
|
+
x: xEnd,
|
|
379
|
+
y: yEnd,
|
|
380
|
+
radius: capSize,
|
|
381
|
+
color: color
|
|
382
|
+
}, _defineProperty(_ref15, 'data-radial-animation', "".concat(uid, "-cap-circle")), _defineProperty(_ref15, 'data-radian-index', index), _ref15;
|
|
383
|
+
}
|
|
384
|
+
}, {
|
|
385
|
+
key: "getIconProps",
|
|
386
|
+
value: function getIconProps(_ref16, index) {
|
|
387
|
+
var _ref17;
|
|
388
|
+
|
|
389
|
+
var $rootProps = _ref16.$rootProps;
|
|
390
|
+
var data = $rootProps.data[index];
|
|
391
|
+
|
|
392
|
+
var _this$computeRadianPo4 = this.computeRadianPosition(data, index),
|
|
393
|
+
xEnd = _this$computeRadianPo4.xEnd,
|
|
394
|
+
yEnd = _this$computeRadianPo4.yEnd,
|
|
395
|
+
isActive = _this$computeRadianPo4.isActive;
|
|
396
|
+
|
|
397
|
+
var uid = this.asProps.uid;
|
|
398
|
+
var iconColor = data.iconColor ?? this.asProps.iconColor;
|
|
399
|
+
var iconSize = data.iconSize ?? this.asProps.iconSize;
|
|
400
|
+
var icon = data.icon ?? this.asProps.icon;
|
|
401
|
+
return _ref17 = {
|
|
402
|
+
x: xEnd - iconSize / 2,
|
|
403
|
+
y: yEnd - iconSize / 2,
|
|
404
|
+
iconSize: iconSize,
|
|
405
|
+
color: iconColor ?? '#fff'
|
|
406
|
+
}, _defineProperty(_ref17, 'data-radial-animation', "".concat(uid, "-cap-icon")), _defineProperty(_ref17, 'data-radian-index', index), _defineProperty(_ref17, "icon", icon), _defineProperty(_ref17, "isActive", isActive), _ref17;
|
|
407
|
+
}
|
|
408
|
+
}, {
|
|
409
|
+
key: "getLabelProps",
|
|
410
|
+
value: function getLabelProps(_ref18, index) {
|
|
411
|
+
var _ref19;
|
|
412
|
+
|
|
413
|
+
var $rootProps = _ref18.$rootProps;
|
|
414
|
+
var data = $rootProps.data[index];
|
|
415
|
+
|
|
416
|
+
var _this$computeRadianPo5 = this.computeRadianPosition(data, index),
|
|
417
|
+
xLabelCenter = _this$computeRadianPo5.xLabelCenter,
|
|
418
|
+
yLabelCenter = _this$computeRadianPo5.yLabelCenter,
|
|
419
|
+
labelAngle = _this$computeRadianPo5.labelAngle,
|
|
420
|
+
isHorizontal = _this$computeRadianPo5.isHorizontal;
|
|
421
|
+
|
|
422
|
+
var _this$asProps5 = this.asProps,
|
|
423
|
+
uid = _this$asProps5.uid,
|
|
424
|
+
textSize = _this$asProps5.textSize;
|
|
425
|
+
var label = data.label;
|
|
426
|
+
var color = data.color ?? this.asProps.color;
|
|
427
|
+
return _ref19 = {
|
|
428
|
+
x: xLabelCenter,
|
|
429
|
+
y: yLabelCenter,
|
|
430
|
+
angle: labelAngle
|
|
431
|
+
}, _defineProperty(_ref19, 'data-radial-animation', "".concat(uid, "-label")), _defineProperty(_ref19, 'data-radian-index', index), _defineProperty(_ref19, "label", label), _defineProperty(_ref19, "color", color), _defineProperty(_ref19, "isHorizontal", isHorizontal), _defineProperty(_ref19, "textSize", textSize), _ref19;
|
|
432
|
+
}
|
|
433
|
+
}, {
|
|
434
|
+
key: "getRadianKey",
|
|
435
|
+
value: function getRadianKey(data, index) {
|
|
436
|
+
return data.key ?? "radian-".concat(index);
|
|
437
|
+
}
|
|
438
|
+
}, {
|
|
439
|
+
key: "computeRadianPosition",
|
|
440
|
+
value: function computeRadianPosition(data, index) {
|
|
441
|
+
var _this$asProps6 = this.asProps,
|
|
442
|
+
centralMargin = _this$asProps6.centralMargin,
|
|
443
|
+
angleOffset = _this$asProps6.angleOffset,
|
|
444
|
+
activeKey = _this$asProps6.activeKey,
|
|
445
|
+
size = _this$asProps6.size,
|
|
446
|
+
radiansCount = _this$asProps6.radiansCount,
|
|
447
|
+
textWidth = _this$asProps6.textWidth;
|
|
448
|
+
|
|
449
|
+
var _size2 = _slicedToArray(size, 2),
|
|
450
|
+
width = _size2[0],
|
|
451
|
+
height = _size2[1];
|
|
452
|
+
|
|
453
|
+
var key = this.getRadianKey(data, index);
|
|
454
|
+
var isActive = activeKey === key;
|
|
455
|
+
var baseCapSize = data.capSize ?? this.asProps.capSize;
|
|
456
|
+
var capSize = baseCapSize * (isActive ? 1 : 0.5);
|
|
457
|
+
var minDemSize = Math.min(width, height) / 2;
|
|
458
|
+
var length = Math.max(minDemSize - textWidth - baseCapSize - centralMargin, 10);
|
|
459
|
+
var angle = baseAngle + angleOffset + index / radiansCount * (Math.PI * 2);
|
|
460
|
+
var isHorizontal = angle - baseAngle > 1 / 6 * Math.PI && angle - baseAngle < 5 / 6 * Math.PI || angle - baseAngle > 7 / 6 * Math.PI && angle - baseAngle < 11 / 6 * Math.PI;
|
|
461
|
+
var topAngle = -Math.PI / 2;
|
|
462
|
+
var labelAngle = (angle - topAngle) % Math.PI + topAngle;
|
|
463
|
+
var center = [width / 2, height / 2];
|
|
464
|
+
var xCenter = center[0],
|
|
465
|
+
yCenter = center[1];
|
|
466
|
+
var start = [xCenter + Math.cos(angle) * centralMargin, yCenter + Math.sin(angle) * centralMargin];
|
|
467
|
+
var end = [xCenter + Math.cos(angle) * (centralMargin + length), yCenter + Math.sin(angle) * (centralMargin + length)];
|
|
468
|
+
var xStart = start[0],
|
|
469
|
+
yStart = start[1];
|
|
470
|
+
var xEnd = end[0],
|
|
471
|
+
yEnd = end[1];
|
|
472
|
+
var labelCenter = [xCenter + Math.cos(angle) * (centralMargin + length + baseCapSize + textWidth / 2), yCenter + Math.sin(angle) * (centralMargin + length + baseCapSize + textWidth / 2)];
|
|
473
|
+
var xLabelCenter = labelCenter[0],
|
|
474
|
+
yLabelCenter = labelCenter[1];
|
|
475
|
+
return {
|
|
476
|
+
xStart: xStart,
|
|
477
|
+
yStart: yStart,
|
|
478
|
+
xEnd: xEnd,
|
|
479
|
+
yEnd: yEnd,
|
|
480
|
+
xLabelCenter: xLabelCenter,
|
|
481
|
+
yLabelCenter: yLabelCenter,
|
|
482
|
+
labelAngle: labelAngle,
|
|
483
|
+
isHorizontal: isHorizontal,
|
|
484
|
+
capSize: capSize,
|
|
485
|
+
isActive: isActive
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
}, {
|
|
489
|
+
key: "renderRadian",
|
|
490
|
+
value: function renderRadian(data, index) {
|
|
491
|
+
var _ref2;
|
|
492
|
+
|
|
493
|
+
var _this$asProps7 = this.asProps,
|
|
494
|
+
styles = _this$asProps7.styles,
|
|
495
|
+
Children = _this$asProps7.Children,
|
|
496
|
+
onRadianClick = _this$asProps7.onRadianClick;
|
|
497
|
+
var key = this.getRadianKey(data, index);
|
|
498
|
+
var SRadian = 'g';
|
|
499
|
+
var children = getOriginChildren(Children);
|
|
500
|
+
|
|
501
|
+
if (typeof children === 'function') {
|
|
502
|
+
var _child = this.asProps.children;
|
|
503
|
+
var mergedProps = assignProps(children(this.asProps), this.asProps);
|
|
504
|
+
children = mergedProps.children;
|
|
505
|
+
mergedProps.children = _child;
|
|
506
|
+
} // hidden from publicly typed export
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
var InteractiveArea = RadialTree.Radian.InteractiveArea;
|
|
510
|
+
return _ref2 = sstyled(styles), /*#__PURE__*/React.createElement(SRadian, _ref2.cn("SRadian", {
|
|
511
|
+
"key": key,
|
|
512
|
+
"onClick": onRadianClick(key)
|
|
513
|
+
}), /*#__PURE__*/React.createElement(InteractiveArea, _ref2.cn("InteractiveArea", {})), children);
|
|
514
|
+
}
|
|
515
|
+
}, {
|
|
516
|
+
key: "render",
|
|
517
|
+
value: function render() {
|
|
518
|
+
var _ref3,
|
|
519
|
+
_this4 = this;
|
|
520
|
+
|
|
521
|
+
var data = this.asProps.data;
|
|
522
|
+
var SRadianList = 'g';
|
|
523
|
+
return _ref3 = sstyled(this.asProps.styles), /*#__PURE__*/React.createElement(SRadianList, _ref3.cn("SRadianList", {}), data.map(function (data, index) {
|
|
524
|
+
return _this4.renderRadian(data, index);
|
|
525
|
+
}));
|
|
526
|
+
}
|
|
527
|
+
}]);
|
|
528
|
+
|
|
529
|
+
return RadialTreeRadian;
|
|
530
|
+
}(Component);
|
|
531
|
+
|
|
532
|
+
_defineProperty(RadialTreeRadian, "displayName", 'RadialTreeRadian');
|
|
533
|
+
|
|
534
|
+
_defineProperty(RadialTreeRadian, "style", style);
|
|
535
|
+
|
|
536
|
+
_defineProperty(RadialTreeRadian, "defaultProps", {
|
|
537
|
+
centralMargin: 50,
|
|
538
|
+
labelMargin: 2,
|
|
539
|
+
iconColor: '#fff',
|
|
540
|
+
capSize: 16,
|
|
541
|
+
iconSize: 16,
|
|
542
|
+
textSize: 14
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
var InteractiveArea = function InteractiveArea(_ref20) {
|
|
546
|
+
var _ref4;
|
|
547
|
+
|
|
548
|
+
var SInteractiveArea = _ref20.Element,
|
|
549
|
+
styles = _ref20.styles;
|
|
550
|
+
return _ref4 = sstyled(styles), /*#__PURE__*/React.createElement(SInteractiveArea, _ref4.cn("SInteractiveArea", {
|
|
551
|
+
"stroke": "transparent",
|
|
552
|
+
"render": "line"
|
|
553
|
+
}));
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
var Line = function Line(_ref21) {
|
|
557
|
+
var _ref5;
|
|
558
|
+
|
|
559
|
+
var SLine = _ref21.Element,
|
|
560
|
+
styles = _ref21.styles;
|
|
561
|
+
return _ref5 = sstyled(styles), /*#__PURE__*/React.createElement(SLine, _ref5.cn("SLine", {
|
|
562
|
+
"render": "line"
|
|
563
|
+
}));
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
var Cap = function Cap(_ref22) {
|
|
567
|
+
var _ref6;
|
|
568
|
+
|
|
569
|
+
var SCap = _ref22.Element,
|
|
570
|
+
styles = _ref22.styles,
|
|
571
|
+
x = _ref22.x,
|
|
572
|
+
y = _ref22.y,
|
|
573
|
+
radius = _ref22.radius,
|
|
574
|
+
color = _ref22.color;
|
|
575
|
+
return _ref6 = sstyled(styles), /*#__PURE__*/React.createElement(SCap, _ref6.cn("SCap", {
|
|
576
|
+
"render": "circle",
|
|
577
|
+
"cx": x,
|
|
578
|
+
"cy": y,
|
|
579
|
+
"r": radius,
|
|
580
|
+
"fill": color
|
|
581
|
+
}));
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
var Icon = function Icon(_ref23) {
|
|
585
|
+
var _ref7;
|
|
586
|
+
|
|
587
|
+
var SIcon = _ref23.Element,
|
|
588
|
+
styles = _ref23.styles,
|
|
589
|
+
isActive = _ref23.isActive,
|
|
590
|
+
tag = _ref23.tag,
|
|
591
|
+
x = _ref23.x,
|
|
592
|
+
y = _ref23.y,
|
|
593
|
+
iconSize = _ref23.iconSize;
|
|
594
|
+
if (!(isActive && tag)) return null;
|
|
595
|
+
var width = iconSize;
|
|
596
|
+
var height = iconSize;
|
|
597
|
+
return _ref7 = sstyled(styles), /*#__PURE__*/React.createElement(SIcon, _ref7.cn("SIcon", {
|
|
598
|
+
"x": x,
|
|
599
|
+
"y": y,
|
|
600
|
+
"width": width,
|
|
601
|
+
"height": height,
|
|
602
|
+
"render": tag
|
|
603
|
+
}));
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
var Label = function Label(_ref24) {
|
|
607
|
+
var SLabel = _ref24.Element,
|
|
608
|
+
Children = _ref24.Children,
|
|
609
|
+
styles = _ref24.styles,
|
|
610
|
+
label = _ref24.label,
|
|
611
|
+
color = _ref24.color,
|
|
612
|
+
isHorizontal = _ref24.isHorizontal,
|
|
613
|
+
x = _ref24.x,
|
|
614
|
+
y = _ref24.y,
|
|
615
|
+
textSize = _ref24.textSize,
|
|
616
|
+
angle = _ref24.angle;
|
|
617
|
+
var lines = String(label).split('\n');
|
|
618
|
+
var linesCount = lines.length;
|
|
619
|
+
var SLabelLine = 'tspan';
|
|
620
|
+
var sstyles = sstyled(styles);
|
|
621
|
+
var sLabelStyles = sstyles.cn('SLabel', {
|
|
622
|
+
color: color,
|
|
623
|
+
'color-hovered': shade(color, -0.12),
|
|
624
|
+
'text-cursor': isHorizontal ? 'text' : 'vertical-text',
|
|
625
|
+
'transform-origin': "".concat(x.toFixed(2), "px ").concat(y.toFixed(2), "px")
|
|
626
|
+
});
|
|
627
|
+
return /*#__PURE__*/React.createElement(SLabel, {
|
|
628
|
+
render: "text",
|
|
629
|
+
textAnchor: "middle",
|
|
630
|
+
dominantBaseline: "central",
|
|
631
|
+
className: sLabelStyles.className,
|
|
632
|
+
style: sLabelStyles.style,
|
|
633
|
+
x: x.toFixed(2),
|
|
634
|
+
y: y.toFixed(2),
|
|
635
|
+
transform: "rotate(".concat((angle / Math.PI * 180).toFixed(2), ")")
|
|
636
|
+
}, lines.map(function (lineText, lineIndex) {
|
|
637
|
+
return /*#__PURE__*/React.createElement(SLabelLine, {
|
|
638
|
+
x: x,
|
|
639
|
+
y: y + (lineIndex - (linesCount - 1) / 2) * textSize,
|
|
640
|
+
key: "#".concat(lineIndex, "-").concat(lineText)
|
|
641
|
+
}, lineText);
|
|
642
|
+
}), /*#__PURE__*/React.createElement(Children, null));
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
var Radian = createElement(RadialTreeRadian, {
|
|
646
|
+
InteractiveArea: InteractiveArea,
|
|
647
|
+
Line: Line,
|
|
648
|
+
Cap: Cap,
|
|
649
|
+
Icon: Icon,
|
|
650
|
+
Label: Label
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
var Title = function Title(_ref25) {
|
|
654
|
+
var _ref8;
|
|
655
|
+
|
|
656
|
+
var STitle = _ref25.Element,
|
|
657
|
+
Children = _ref25.Children,
|
|
658
|
+
styles = _ref25.styles,
|
|
659
|
+
textSize = _ref25.textSize,
|
|
660
|
+
color = _ref25.color,
|
|
661
|
+
x = _ref25.x,
|
|
662
|
+
y = _ref25.y;
|
|
663
|
+
return _ref8 = sstyled(styles), /*#__PURE__*/React.createElement(STitle, _ref8.cn("STitle", {
|
|
664
|
+
"render": "text",
|
|
665
|
+
"textAnchor": "middle",
|
|
666
|
+
"dominantBaseline": "central",
|
|
667
|
+
"fontSize": textSize,
|
|
668
|
+
"fill": color,
|
|
669
|
+
"x": x,
|
|
670
|
+
"y": y
|
|
671
|
+
}), /*#__PURE__*/React.createElement(Children, _ref8.cn("Children", {})));
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
var RadialTree = createElement(RadialTreeBase, {
|
|
675
|
+
Title: Title,
|
|
676
|
+
Radian: Radian
|
|
677
|
+
});
|
|
678
|
+
export default RadialTree;
|
|
679
|
+
//# sourceMappingURL=RadialTree.js.map
|