@semcore/d3-chart 2.8.19 → 2.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/lib/cjs/Area.js +10 -10
  3. package/lib/cjs/Axis.js +14 -14
  4. package/lib/cjs/Bar.js +9 -9
  5. package/lib/cjs/Bubble.js +11 -11
  6. package/lib/cjs/Donut.js +8 -8
  7. package/lib/cjs/Dots.js +10 -10
  8. package/lib/cjs/HorizontalBar.js +9 -9
  9. package/lib/cjs/Hover.js +4 -4
  10. package/lib/cjs/Line.js +9 -9
  11. package/lib/cjs/Plot.js +5 -5
  12. package/lib/cjs/Plot.js.map +1 -1
  13. package/lib/cjs/Radar.js +887 -0
  14. package/lib/cjs/Radar.js.map +1 -0
  15. package/lib/cjs/RadialTree.js +13 -13
  16. package/lib/cjs/ReferenceLine.js +10 -10
  17. package/lib/cjs/ScatterPlot.js +8 -8
  18. package/lib/cjs/Tooltip.js +8 -8
  19. package/lib/cjs/Venn.js +8 -8
  20. package/lib/cjs/a11y/PlotA11yModule.js +3 -3
  21. package/lib/cjs/a11y/PlotA11yView.js +4 -4
  22. package/lib/cjs/index.js +16 -0
  23. package/lib/cjs/index.js.map +1 -1
  24. package/lib/cjs/style/radar.shadow.css +73 -0
  25. package/lib/cjs/types/Radar.js +2 -0
  26. package/lib/cjs/types/Radar.js.map +1 -0
  27. package/lib/cjs/types/index.d.js +21 -0
  28. package/lib/cjs/types/index.d.js.map +1 -1
  29. package/lib/cjs/utils.js +2 -1
  30. package/lib/cjs/utils.js.map +1 -1
  31. package/lib/es6/Area.js +10 -10
  32. package/lib/es6/Axis.js +14 -14
  33. package/lib/es6/Bar.js +9 -9
  34. package/lib/es6/Bubble.js +11 -11
  35. package/lib/es6/Donut.js +8 -8
  36. package/lib/es6/Dots.js +10 -10
  37. package/lib/es6/HorizontalBar.js +9 -9
  38. package/lib/es6/Hover.js +4 -4
  39. package/lib/es6/Line.js +9 -9
  40. package/lib/es6/Plot.js +5 -5
  41. package/lib/es6/Plot.js.map +1 -1
  42. package/lib/es6/Radar.js +882 -0
  43. package/lib/es6/Radar.js.map +1 -0
  44. package/lib/es6/RadialTree.js +13 -13
  45. package/lib/es6/ReferenceLine.js +10 -10
  46. package/lib/es6/ScatterPlot.js +8 -8
  47. package/lib/es6/Tooltip.js +8 -8
  48. package/lib/es6/Venn.js +8 -8
  49. package/lib/es6/a11y/PlotA11yModule.js +3 -3
  50. package/lib/es6/a11y/PlotA11yView.js +4 -4
  51. package/lib/es6/index.js +1 -0
  52. package/lib/es6/index.js.map +1 -1
  53. package/lib/es6/style/radar.shadow.css +73 -0
  54. package/lib/es6/types/Radar.js +2 -0
  55. package/lib/es6/types/Radar.js.map +1 -0
  56. package/lib/es6/types/index.d.js +2 -0
  57. package/lib/es6/types/index.d.js.map +1 -1
  58. package/lib/es6/utils.js +2 -1
  59. package/lib/es6/utils.js.map +1 -1
  60. package/lib/types/index.d.ts +3 -0
  61. package/lib/types/types/Radar.d.ts +89 -0
  62. package/package.json +3 -2
@@ -0,0 +1,887 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
+
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports["default"] = void 0;
11
+ exports.getLabelOffsetPosition = getLabelOffsetPosition;
12
+
13
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
14
+
15
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
16
+
17
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
18
+
19
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
20
+
21
+ var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
22
+
23
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
24
+
25
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
26
+
27
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
28
+
29
+ var _core = require("@semcore/core");
30
+
31
+ var _react = _interopRequireWildcard(require("react"));
32
+
33
+ var _uniqueID = _interopRequireDefault(require("@semcore/utils/lib/uniqueID"));
34
+
35
+ var _getOriginChildren = _interopRequireDefault(require("@semcore/utils/lib/getOriginChildren"));
36
+
37
+ var _rafTrottle = _interopRequireDefault(require("@semcore/utils/lib/rafTrottle"));
38
+
39
+ var _canUseDOM = _interopRequireDefault(require("@semcore/utils/lib/canUseDOM"));
40
+
41
+ var _d3Polygon = require("d3-polygon");
42
+
43
+ var _d3Shape = require("d3-shape");
44
+
45
+ var _createElement = _interopRequireDefault(require("./createElement"));
46
+
47
+ var _utils = require("./utils");
48
+
49
+ /*__reshadow-styles__:"./style/radar.shadow.css"*/
50
+ var style = (
51
+ /*__reshadow_css_start__*/
52
+ _core.sstyled.insert(
53
+ /*__inner_css_start__*/
54
+ ".___SAxisLine_jqen1_gg_,.___SAxisTick_jqen1_gg_,.___SAxis_jqen1_gg_{stroke:var(--intergalactic-chart-grid-line, #e0e1e9);stroke-width:1;fill:transparent}.___SAxisLine_jqen1_gg_,.___SAxisTick_jqen1_gg_{stroke-dasharray:2}.___SAxisLine_jqen1_gg_.__active_jqen1_gg_{stroke:var(--intergalactic-chart-grid-y-accent-hover-line, #a9abb6)}.___SAxisLabel_jqen1_gg_{text-anchor:middle;dominant-baseline:central;font-size:12px}.___SAxisLabel_jqen1_gg_.__xDirection_jqen1_gg_{text-anchor:var(--xDirection_jqen1)}.___SAxisLabel_jqen1_gg_.__yDirection_jqen1_gg_{dominant-baseline:var(--yDirection_jqen1)}.___SPolygonDot_jqen1_gg_,.___SPolygon_jqen1_gg_{fill:var(--intergalactic-chart-palette-order-1, #2bb3ff)}.___SPolygon_jqen1_gg_{opacity:.2}.___SPolygon_jqen1_gg_.__color_jqen1_gg_{fill:var(--color_jqen1)}.___SPolygonDot_jqen1_gg_{stroke-width:2px;stroke:var(--intergalactic-chart-grid-border, #ffffff);r:6px}.___SPolygonDot_jqen1_gg_.__transparent_jqen1_gg_{opacity:.3}.___SPolygonDot_jqen1_gg_.__color_jqen1_gg_{fill:var(--color_jqen1)}.___SPolygonLine_jqen1_gg_{stroke:var(--intergalactic-chart-palette-order-1, #2bb3ff);stroke-width:3;fill:transparent}.___SPolygonLine_jqen1_gg_.__transparent_jqen1_gg_{opacity:.3}.___SPolygonLine_jqen1_gg_.__color_jqen1_gg_{stroke:var(--color_jqen1)}.___SPieRect_jqen1_gg_{fill:var(--intergalactic-chart-grid-bar-chart-hover, rgba(196, 199, 207, 0.3))}"
55
+ /*__inner_css_end__*/
56
+ , "jqen1_gg_")
57
+ /*__reshadow_css_end__*/
58
+ , {
59
+ "__SAxis": "___SAxis_jqen1_gg_",
60
+ "__SAxisLine": "___SAxisLine_jqen1_gg_",
61
+ "__SAxisTick": "___SAxisTick_jqen1_gg_",
62
+ "_active": "__active_jqen1_gg_",
63
+ "__SAxisLabel": "___SAxisLabel_jqen1_gg_",
64
+ "_xDirection": "__xDirection_jqen1_gg_",
65
+ "--xDirection": "--xDirection_jqen1",
66
+ "_yDirection": "__yDirection_jqen1_gg_",
67
+ "--yDirection": "--yDirection_jqen1",
68
+ "__SPolygon": "___SPolygon_jqen1_gg_",
69
+ "_color": "__color_jqen1_gg_",
70
+ "--color": "--color_jqen1",
71
+ "__SPolygonDot": "___SPolygonDot_jqen1_gg_",
72
+ "_transparent": "__transparent_jqen1_gg_",
73
+ "__SPolygonLine": "___SPolygonLine_jqen1_gg_",
74
+ "__SPieRect": "___SPieRect_jqen1_gg_"
75
+ });
76
+
77
+ function getAngle(i, range, func, total) {
78
+ var angle = (total - i) * 2 * Math.PI / total;
79
+ return range * (1 - func(angle)) - range;
80
+ }
81
+
82
+ function getRadianPosition(i, range, total) {
83
+ return [getAngle(i, range, Math.sin, total), getAngle(i, range, Math.cos, total)];
84
+ }
85
+
86
+ function getLabelDirection(i, total) {
87
+ var angle = -Math.PI / 2 + i / total * (Math.PI * 2);
88
+ return [Math.abs(angle) === Math.PI / 2 ? 'middle' : angle < Math.PI / 2 ? 'start' : 'end', angle === Math.PI / 2 ? 'mathematical' : angle === -Math.PI / 2 ? 'alphabetic' : 'middle'];
89
+ }
90
+
91
+ function computeTextWidth(texts, textSize) {
92
+ var defaultWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 50;
93
+ var defaultHeight = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 20;
94
+ var widths = texts.map(function (text) {
95
+ if (typeof text === 'string') {
96
+ return (0, _utils.measureText)(text, textSize);
97
+ }
98
+
99
+ if ( /*#__PURE__*/_react["default"].isValidElement(text)) {
100
+ var _text$props, _text$props2;
101
+
102
+ // @ts-ignore
103
+ return Math.max(((_text$props = text.props) === null || _text$props === void 0 ? void 0 : _text$props.width) || defaultWidth, ((_text$props2 = text.props) === null || _text$props2 === void 0 ? void 0 : _text$props2.height) || defaultHeight);
104
+ }
105
+
106
+ return defaultWidth;
107
+ });
108
+ return Math.max.apply(Math, (0, _toConsumableArray2["default"])(widths));
109
+ }
110
+
111
+ function getTicks(tickSize, radius) {
112
+ var ticks = 0;
113
+
114
+ while (Math.trunc(radius / (tickSize / 2)) > ticks) {
115
+ ticks += 1;
116
+ }
117
+
118
+ return (0, _toConsumableArray2["default"])(Array(ticks).keys()).reduce(function (ticks, t, i, total) {
119
+ if (i) ticks.push(i / total.length);
120
+ return ticks;
121
+ }, []);
122
+ }
123
+
124
+ function pieContains(_ref10, _ref11) {
125
+ var _ref12 = (0, _slicedToArray2["default"])(_ref10, 3),
126
+ startAngle = _ref12[0],
127
+ endAngle = _ref12[1],
128
+ radius = _ref12[2];
129
+
130
+ var _ref13 = (0, _slicedToArray2["default"])(_ref11, 2),
131
+ x = _ref13[0],
132
+ y = _ref13[1];
133
+
134
+ var distance = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
135
+ if (distance > radius) return false;
136
+ var angle = Math.atan2(y, x) + Math.PI / 2;
137
+
138
+ if (angle < 0) {
139
+ // angle from 0 to 6.28...
140
+ angle += 2 * Math.PI;
141
+ }
142
+
143
+ if (startAngle < 0) {
144
+ if (angle < endAngle) {
145
+ angle += Math.abs(startAngle);
146
+ } else {
147
+ angle += Math.abs(startAngle) - Math.PI * 2;
148
+ }
149
+
150
+ endAngle += Math.abs(startAngle);
151
+ startAngle = 0;
152
+ }
153
+
154
+ return angle > startAngle && angle < endAngle;
155
+ }
156
+
157
+ function getLabelOffsetPosition(xDirection, yDirection, width, height) {
158
+ var xOffset = 0;
159
+ var yOffset = 0;
160
+
161
+ switch ("".concat(xDirection, "-").concat(yDirection)) {
162
+ case 'middle-alphabetic':
163
+ yOffset = height / 2;
164
+ break;
165
+
166
+ case 'start-middle':
167
+ xOffset = -width / 2;
168
+ break;
169
+
170
+ case 'middle-mathematical':
171
+ yOffset = -height / 2;
172
+ break;
173
+
174
+ case 'end-middle':
175
+ xOffset = width / 2;
176
+ break;
177
+ }
178
+
179
+ return [xOffset + width / 2, yOffset + height / 2];
180
+ }
181
+
182
+ var MINIMUM_OFFSET = 5;
183
+
184
+ var RadarRoot = /*#__PURE__*/function (_Component) {
185
+ (0, _inherits2["default"])(RadarRoot, _Component);
186
+
187
+ var _super = (0, _createSuper2["default"])(RadarRoot);
188
+
189
+ function RadarRoot() {
190
+ var _this;
191
+
192
+ (0, _classCallCheck2["default"])(this, RadarRoot);
193
+
194
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
195
+ args[_key] = arguments[_key];
196
+ }
197
+
198
+ _this = _super.call.apply(_super, [this].concat(args));
199
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "computeOffset", 0);
200
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "categoriesKey", null);
201
+ return _this;
202
+ }
203
+
204
+ (0, _createClass2["default"])(RadarRoot, [{
205
+ key: "id",
206
+ get: function get() {
207
+ var _this$asProps = this.asProps,
208
+ id = _this$asProps.id,
209
+ uid = _this$asProps.uid;
210
+ return id || uid;
211
+ }
212
+ }, {
213
+ key: "offset",
214
+ get: function get() {
215
+ var offset = this.asProps.offset;
216
+ return offset !== null && offset !== void 0 ? offset : this.computeOffset;
217
+ }
218
+ }, {
219
+ key: "textSize",
220
+ get: function get() {
221
+ var textSize = this.asProps.textSize;
222
+ return textSize !== null && textSize !== void 0 ? textSize : 12;
223
+ }
224
+ }, {
225
+ key: "getAxisProps",
226
+ value: function getAxisProps() {
227
+ return {
228
+ offset: this.offset,
229
+ textSize: this.textSize,
230
+ type: this.asProps.type
231
+ };
232
+ }
233
+ }, {
234
+ key: "getPolygonProps",
235
+ value: function getPolygonProps(_ref14) {
236
+ var dataKey = _ref14.dataKey;
237
+ var _this$asProps2 = this.asProps,
238
+ data = _this$asProps2.data,
239
+ scale = _this$asProps2.scale;
240
+ return {
241
+ offset: this.offset,
242
+ data: data[dataKey] || [],
243
+ scale: scale
244
+ };
245
+ }
246
+ }, {
247
+ key: "getHoverProps",
248
+ value: function getHoverProps() {
249
+ return {
250
+ type: this.asProps.type,
251
+ offset: this.offset,
252
+ categories: this.asProps.data[this.categoriesKey]
253
+ };
254
+ }
255
+ }, {
256
+ key: "render",
257
+ value: function render() {
258
+ var _ref;
259
+
260
+ var SRadar = this.Element;
261
+ var _this$asProps3 = this.asProps,
262
+ Children = _this$asProps3.Children,
263
+ style = _this$asProps3.style,
264
+ size = _this$asProps3.size,
265
+ data = _this$asProps3.data,
266
+ offset = _this$asProps3.offset;
267
+
268
+ var _size = (0, _slicedToArray2["default"])(size, 2),
269
+ width = _size[0],
270
+ height = _size[1];
271
+
272
+ var dataKey;
273
+
274
+ _react["default"].Children.toArray((0, _getOriginChildren["default"])(Children)).forEach(function (child) {
275
+ if ( /*#__PURE__*/_react["default"].isValidElement(child) && child.type === Radar.Axis) {
276
+ dataKey = child.props.dataKey;
277
+ }
278
+ });
279
+
280
+ if (dataKey) {
281
+ if (offset === undefined) {
282
+ // +5 because font might not be loaded and just in case)
283
+ this.computeOffset = computeTextWidth(data[dataKey], this.textSize) + MINIMUM_OFFSET;
284
+ }
285
+
286
+ this.categoriesKey = dataKey;
287
+ }
288
+
289
+ return _ref = (0, _core.sstyled)(style), /*#__PURE__*/_react["default"].createElement(SRadar, _ref.cn("SRadar", {
290
+ "aria-hidden": true,
291
+ "id": this.id,
292
+ "render": 'g',
293
+ "childrenPosition": 'inside',
294
+ "transform": "translate(".concat(width / 2, ",").concat(height / 2, ")")
295
+ }));
296
+ }
297
+ }]);
298
+ return RadarRoot;
299
+ }(_core.Component);
300
+
301
+ (0, _defineProperty2["default"])(RadarRoot, "displayName", 'Line');
302
+ (0, _defineProperty2["default"])(RadarRoot, "style", style);
303
+ (0, _defineProperty2["default"])(RadarRoot, "enhance", [(0, _uniqueID["default"])()]);
304
+ (0, _defineProperty2["default"])(RadarRoot, "defaultProps", {
305
+ type: 'polygon'
306
+ });
307
+
308
+ var PolygonRoot = /*#__PURE__*/function (_Component2) {
309
+ (0, _inherits2["default"])(PolygonRoot, _Component2);
310
+
311
+ var _super2 = (0, _createSuper2["default"])(PolygonRoot);
312
+
313
+ function PolygonRoot() {
314
+ (0, _classCallCheck2["default"])(this, PolygonRoot);
315
+ return _super2.apply(this, arguments);
316
+ }
317
+
318
+ (0, _createClass2["default"])(PolygonRoot, [{
319
+ key: "getDotsProps",
320
+ value: function getDotsProps() {
321
+ var _this$asProps4 = this.asProps,
322
+ data = _this$asProps4.data,
323
+ scale = _this$asProps4.scale,
324
+ color = _this$asProps4.color,
325
+ transparent = _this$asProps4.transparent;
326
+ return {
327
+ data: data,
328
+ scale: scale,
329
+ color: color,
330
+ transparent: transparent
331
+ };
332
+ }
333
+ }, {
334
+ key: "getLineProps",
335
+ value: function getLineProps() {
336
+ var _this$asProps5 = this.asProps,
337
+ d3 = _this$asProps5.d3,
338
+ data = _this$asProps5.data,
339
+ color = _this$asProps5.color,
340
+ transparent = _this$asProps5.transparent;
341
+ return {
342
+ data: data,
343
+ color: color,
344
+ transparent: transparent,
345
+ d3: d3
346
+ };
347
+ }
348
+ }, {
349
+ key: "render",
350
+ value: function render() {
351
+ var _ref2;
352
+
353
+ var _this$asProps6 = this.asProps,
354
+ SPolygon = _this$asProps6.Element,
355
+ styles = _this$asProps6.styles,
356
+ d3 = _this$asProps6.d3,
357
+ data = _this$asProps6.data,
358
+ color = _this$asProps6.color,
359
+ fill = _this$asProps6.fill;
360
+ return _ref2 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SPolygon, _ref2.cn("SPolygon", {
361
+ "render": 'path',
362
+ "d": d3(data),
363
+ "color": fill || color
364
+ }));
365
+ }
366
+ }]);
367
+ return PolygonRoot;
368
+ }(_core.Component);
369
+
370
+ (0, _defineProperty2["default"])(PolygonRoot, "displayName", 'Polygon');
371
+ (0, _defineProperty2["default"])(PolygonRoot, "style", style);
372
+ (0, _defineProperty2["default"])(PolygonRoot, "defaultProps", function (_ref18) {
373
+ var scale = _ref18.scale,
374
+ _ref18$curve = _ref18.curve,
375
+ curve = _ref18$curve === void 0 ? _d3Shape.curveLinearClosed : _ref18$curve,
376
+ size = _ref18.size,
377
+ offset = _ref18.offset;
378
+ scale.range([0, Math.min(size[0], size[1]) / 2 - offset]);
379
+ return {
380
+ d3: (0, _d3Shape.lineRadial)().curve(curve).radius(function (d) {
381
+ return scale(d || 0);
382
+ }).angle(function (d, i, data) {
383
+ return i / data.length * 2 * Math.PI;
384
+ })
385
+ };
386
+ });
387
+
388
+ function PolygonLine(props) {
389
+ var _ref3;
390
+
391
+ var SPolygonLine = props.Element,
392
+ styles = props.styles,
393
+ d3 = props.d3,
394
+ color = props.color,
395
+ data = props.data,
396
+ transparent = props.transparent;
397
+ return _ref3 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SPolygonLine, _ref3.cn("SPolygonLine", {
398
+ "render": 'path',
399
+ "d": d3(data),
400
+ "color": color,
401
+ "transparent": transparent
402
+ }));
403
+ }
404
+
405
+ function PolygonDots(props) {
406
+ var SPolygonDot = props.Element,
407
+ styles = props.styles,
408
+ color = props.color,
409
+ data = props.data,
410
+ scale = props.scale,
411
+ transparent = props.transparent;
412
+ return data.map(function (value, i) {
413
+ var _ref4;
414
+
415
+ if (value === null || value === undefined) return;
416
+ var radius = scale(value);
417
+
418
+ var _getRadianPosition = getRadianPosition(i, radius, data.length),
419
+ _getRadianPosition2 = (0, _slicedToArray2["default"])(_getRadianPosition, 2),
420
+ cx = _getRadianPosition2[0],
421
+ cy = _getRadianPosition2[1];
422
+
423
+ return _ref4 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SPolygonDot, _ref4.cn("SPolygonDot", {
424
+ "key": i,
425
+ "render": 'circle',
426
+ "cx": cx,
427
+ "cy": cy,
428
+ "color": color,
429
+ "transparent": transparent
430
+ }));
431
+ });
432
+ }
433
+
434
+ var AxisRoot = /*#__PURE__*/function (_Component3) {
435
+ (0, _inherits2["default"])(AxisRoot, _Component3);
436
+
437
+ var _super3 = (0, _createSuper2["default"])(AxisRoot);
438
+
439
+ function AxisRoot() {
440
+ var _this2;
441
+
442
+ (0, _classCallCheck2["default"])(this, AxisRoot);
443
+
444
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
445
+ args[_key2] = arguments[_key2];
446
+ }
447
+
448
+ _this2 = _super3.call.apply(_super3, [this].concat(args));
449
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "unsubscribeTooltipVisible", null);
450
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "state", {
451
+ activeLineIndex: null
452
+ });
453
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "handlerTooltipVisible", function (visible, _ref15) {
454
+ var index = _ref15.index;
455
+
456
+ _this2.setState({
457
+ activeLineIndex: index
458
+ });
459
+ });
460
+ return _this2;
461
+ }
462
+
463
+ (0, _createClass2["default"])(AxisRoot, [{
464
+ key: "createLineRadial",
465
+ value: function createLineRadial(radius, total) {
466
+ return (0, _d3Shape.lineRadial)().curve(_d3Shape.curveLinearClosed).radius(function () {
467
+ return radius;
468
+ }).angle(function (d, i) {
469
+ return i / total * 2 * Math.PI;
470
+ });
471
+ }
472
+ }, {
473
+ key: "getTicksProps",
474
+ value: function getTicksProps(_ref16) {
475
+ var _ref16$tickSize = _ref16.tickSize,
476
+ tickSize = _ref16$tickSize === void 0 ? 100 : _ref16$tickSize;
477
+ var _this$asProps7 = this.asProps,
478
+ data = _this$asProps7.data,
479
+ offset = _this$asProps7.offset,
480
+ categories = _this$asProps7.categories,
481
+ size = _this$asProps7.size,
482
+ type = _this$asProps7.type;
483
+ var radius = Math.min(size[0], size[1]) / 2 - offset;
484
+ return {
485
+ type: type,
486
+ data: data,
487
+ categories: categories,
488
+ ticks: getTicks(tickSize, radius),
489
+ offset: offset,
490
+ d3: this.createLineRadial(radius, categories.length)
491
+ };
492
+ }
493
+ }, {
494
+ key: "getLabelsProps",
495
+ value: function getLabelsProps(_ref17) {
496
+ var _ref17$labelOffset = _ref17.labelOffset,
497
+ labelOffset = _ref17$labelOffset === void 0 ? 10 : _ref17$labelOffset;
498
+ var _this$asProps8 = this.asProps,
499
+ offset = _this$asProps8.offset,
500
+ categories = _this$asProps8.categories,
501
+ textSize = _this$asProps8.textSize;
502
+ return {
503
+ categories: categories,
504
+ textSize: textSize,
505
+ offset: offset - labelOffset
506
+ };
507
+ }
508
+ }, {
509
+ key: "componentDidMount",
510
+ value: function componentDidMount() {
511
+ var eventEmitter = this.asProps.eventEmitter;
512
+ this.unsubscribeTooltipVisible = eventEmitter.subscribe('onTooltipVisible', this.handlerTooltipVisible);
513
+ }
514
+ }, {
515
+ key: "componentWillUnmount",
516
+ value: function componentWillUnmount() {
517
+ if (this.unsubscribeTooltipVisible) {
518
+ this.unsubscribeTooltipVisible();
519
+ }
520
+ }
521
+ }, {
522
+ key: "render",
523
+ value: function render() {
524
+ var _ref5;
525
+
526
+ var _this$asProps9 = this.asProps,
527
+ SAxis = _this$asProps9.Element,
528
+ styles = _this$asProps9.styles,
529
+ categories = _this$asProps9.categories,
530
+ size = _this$asProps9.size,
531
+ offset = _this$asProps9.offset,
532
+ type = _this$asProps9.type;
533
+ var activeLineIndex = this.state.activeLineIndex;
534
+ var radius = Math.min(size[0], size[1]) / 2 - offset;
535
+ var total = categories.length;
536
+ return _ref5 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, type === 'circle' ? /*#__PURE__*/_react["default"].createElement(SAxis, _ref5.cn("SAxis", {
537
+ "render": 'circle',
538
+ "cx": 0,
539
+ "cy": 0,
540
+ "r": radius
541
+ })) : /*#__PURE__*/_react["default"].createElement(SAxis, _ref5.cn("SAxis", {
542
+ "render": 'path',
543
+ "d": this.createLineRadial(radius, total)(categories)
544
+ })), categories.map(function (category, i) {
545
+ var _getRadianPosition3 = getRadianPosition(i, radius, total),
546
+ _getRadianPosition4 = (0, _slicedToArray2["default"])(_getRadianPosition3, 2),
547
+ x = _getRadianPosition4[0],
548
+ y = _getRadianPosition4[1];
549
+
550
+ var _sstyled$cn = (0, _core.sstyled)(styles).cn('SAxisLine', {
551
+ active: activeLineIndex === i
552
+ }),
553
+ className = _sstyled$cn.className;
554
+
555
+ return /*#__PURE__*/_react["default"].createElement("line", {
556
+ key: i,
557
+ x1: 0,
558
+ y1: 0,
559
+ x2: x,
560
+ y2: y,
561
+ className: className
562
+ });
563
+ }));
564
+ }
565
+ }]);
566
+ return AxisRoot;
567
+ }(_core.Component);
568
+
569
+ (0, _defineProperty2["default"])(AxisRoot, "displayName", 'Polygon');
570
+ (0, _defineProperty2["default"])(AxisRoot, "style", style);
571
+ (0, _defineProperty2["default"])(AxisRoot, "defaultProps", function (_ref19) {
572
+ var data = _ref19.data,
573
+ dataKey = _ref19.dataKey;
574
+ var categories = data[dataKey];
575
+ return {
576
+ categories: categories
577
+ };
578
+ });
579
+
580
+ function AxisTicks(props) {
581
+ var SAxisTick = props.Element,
582
+ styles = props.styles,
583
+ size = props.size,
584
+ ticks = props.ticks,
585
+ d3 = props.d3,
586
+ categories = props.categories,
587
+ offset = props.offset,
588
+ type = props.type;
589
+ var radius = Math.min(size[0], size[1]) / 2 - offset;
590
+ return ticks.map(function (tick, i) {
591
+ var _ref6;
592
+
593
+ d3.radius(function () {
594
+ return radius * tick;
595
+ });
596
+ return _ref6 = (0, _core.sstyled)(styles), type === 'circle' ? /*#__PURE__*/_react["default"].createElement(SAxisTick, _ref6.cn("SAxisTick", {
597
+ "key": i,
598
+ "render": 'circle',
599
+ "cx": 0,
600
+ "cy": 0,
601
+ "r": radius * tick
602
+ })) : /*#__PURE__*/_react["default"].createElement(SAxisTick, _ref6.cn("SAxisTick", {
603
+ "render": 'path',
604
+ "key": i,
605
+ "d": d3(categories)
606
+ }));
607
+ });
608
+ }
609
+
610
+ function AxisLabels(props) {
611
+ var SAxisLabel = props.Element,
612
+ styles = props.styles,
613
+ textSize = props.textSize,
614
+ size = props.size,
615
+ offset = props.offset,
616
+ categories = props.categories;
617
+ var radius = Math.min(size[0], size[1]) / 2 - offset;
618
+ return categories.map(function (category, i) {
619
+ var _getRadianPosition5 = getRadianPosition(i, radius, categories.length),
620
+ _getRadianPosition6 = (0, _slicedToArray2["default"])(_getRadianPosition5, 2),
621
+ x = _getRadianPosition6[0],
622
+ y = _getRadianPosition6[1];
623
+
624
+ var _getLabelDirection = getLabelDirection(i, categories.length),
625
+ _getLabelDirection2 = (0, _slicedToArray2["default"])(_getLabelDirection, 2),
626
+ xDirection = _getLabelDirection2[0],
627
+ yDirection = _getLabelDirection2[1];
628
+
629
+ if (typeof category === 'string') {
630
+ var _ref7;
631
+
632
+ var lines = category.split('\n');
633
+ return _ref7 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SAxisLabel, _ref7.cn("SAxisLabel", {
634
+ "key": i,
635
+ "render": 'text',
636
+ "childrenPosition": 'inside',
637
+ "x": x,
638
+ "y": y,
639
+ "xDirection": xDirection,
640
+ "yDirection": yDirection
641
+ }), lines.map(function (lineText, lineIndex) {
642
+ return /*#__PURE__*/_react["default"].createElement("tspan", {
643
+ x: x,
644
+ y: y + (lineIndex - (lines.length - 1) / 2) * textSize,
645
+ key: "#".concat(lineIndex, "-").concat(lineText)
646
+ }, lineText);
647
+ }));
648
+ }
649
+
650
+ if ( /*#__PURE__*/_react["default"].isValidElement(category)) {
651
+ var _category$props = category === null || category === void 0 ? void 0 : category.props,
652
+ _category$props$width = _category$props.width,
653
+ width = _category$props$width === void 0 ? 0 : _category$props$width,
654
+ _category$props$heigh = _category$props.height,
655
+ height = _category$props$heigh === void 0 ? 0 : _category$props$heigh;
656
+
657
+ var _getLabelOffsetPositi = getLabelOffsetPosition(xDirection, yDirection, width, height),
658
+ _getLabelOffsetPositi2 = (0, _slicedToArray2["default"])(_getLabelOffsetPositi, 2),
659
+ xOffset = _getLabelOffsetPositi2[0],
660
+ yOffset = _getLabelOffsetPositi2[1];
661
+
662
+ return /*#__PURE__*/(0, _react.cloneElement)(category, {
663
+ key: i,
664
+ x: x - xOffset,
665
+ y: y - yOffset
666
+ });
667
+ }
668
+ });
669
+ }
670
+
671
+ var Hover = /*#__PURE__*/function (_Component4) {
672
+ (0, _inherits2["default"])(Hover, _Component4);
673
+
674
+ var _super4 = (0, _createSuper2["default"])(Hover);
675
+
676
+ function Hover() {
677
+ var _this3;
678
+
679
+ (0, _classCallCheck2["default"])(this, Hover);
680
+
681
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
682
+ args[_key3] = arguments[_key3];
683
+ }
684
+
685
+ _this3 = _super4.call.apply(_super4, [this].concat(args));
686
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this3), "state", {
687
+ index: null
688
+ });
689
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this3), "virtualElement", (0, _canUseDOM["default"])() ? document.createElement('div') : {});
690
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this3), "unsubscribeMouseMoveRoot", null);
691
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this3), "unsubscribeMouseLeaveRoot", null);
692
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this3), "handlerMouseMoveRoot", (0, _rafTrottle["default"])(function (e) {
693
+ var _this3$asProps = _this3.asProps,
694
+ eventEmitter = _this3$asProps.eventEmitter,
695
+ size = _this3$asProps.size,
696
+ rootRef = _this3$asProps.rootRef;
697
+ var point = (0, _utils.eventToPoint)(e, rootRef.current);
698
+ var diam = Math.min(size[0], size[1]);
699
+ var centerX = point[0] - diam / 2;
700
+ var centerY = point[1] - diam / 2;
701
+ var clientX = e.clientX,
702
+ clientY = e.clientY; // @ts-ignore
703
+
704
+ _this3.virtualElement.getBoundingClientRect = _this3.generateGetBoundingClientRect(clientX, clientY);
705
+ _this3.virtualElement[_utils.CONSTANT.VIRTUAL_ELEMENT] = true;
706
+
707
+ var index = _this3.getIndex([centerX, centerY]);
708
+
709
+ _this3.setState({
710
+ index: index
711
+ }, function () {
712
+ eventEmitter.emit('onTooltipVisible', index !== null, {
713
+ index: index
714
+ }, _this3.virtualElement);
715
+ });
716
+ }));
717
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this3), "handlerMouseLeaveRoot", (0, _rafTrottle["default"])(function () {
718
+ _this3.setState({
719
+ index: null
720
+ }, function () {
721
+ _this3.asProps.eventEmitter.emit('onTooltipVisible', false, {
722
+ index: null
723
+ });
724
+ });
725
+ }));
726
+ return _this3;
727
+ }
728
+
729
+ (0, _createClass2["default"])(Hover, [{
730
+ key: "generateGetBoundingClientRect",
731
+ value: function generateGetBoundingClientRect() {
732
+ var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
733
+ var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
734
+ return function () {
735
+ return {
736
+ width: 0,
737
+ height: 0,
738
+ top: y,
739
+ right: x,
740
+ bottom: y,
741
+ left: x
742
+ };
743
+ };
744
+ }
745
+ }, {
746
+ key: "getPolygon",
747
+ value: function getPolygon(index) {
748
+ var _this$asProps10 = this.asProps,
749
+ categories = _this$asProps10.categories,
750
+ size = _this$asProps10.size,
751
+ offset = _this$asProps10.offset;
752
+ var total = categories.length;
753
+ var diam = Math.min(size[0], size[1]);
754
+ var radius = diam / 2 - offset;
755
+ var prevIndex = (index - 1 + total) % total;
756
+ var nextIndex = (index + 1 + total) % total;
757
+
758
+ var _getRadianPosition7 = getRadianPosition(prevIndex, radius, total),
759
+ _getRadianPosition8 = (0, _slicedToArray2["default"])(_getRadianPosition7, 2),
760
+ prevX1 = _getRadianPosition8[0],
761
+ prevY1 = _getRadianPosition8[1];
762
+
763
+ var _getRadianPosition9 = getRadianPosition(index, radius, total),
764
+ _getRadianPosition10 = (0, _slicedToArray2["default"])(_getRadianPosition9, 2),
765
+ x = _getRadianPosition10[0],
766
+ y = _getRadianPosition10[1];
767
+
768
+ var _getRadianPosition11 = getRadianPosition(nextIndex, radius, total),
769
+ _getRadianPosition12 = (0, _slicedToArray2["default"])(_getRadianPosition11, 2),
770
+ nextX1 = _getRadianPosition12[0],
771
+ nextY1 = _getRadianPosition12[1];
772
+
773
+ return [[0, 0], [(prevX1 + x) / 2, (prevY1 + y) / 2], [x, y], [(nextX1 + x) / 2, (nextY1 + y) / 2]];
774
+ }
775
+ }, {
776
+ key: "getPie",
777
+ value: function getPie(index) {
778
+ var _this$asProps11 = this.asProps,
779
+ categories = _this$asProps11.categories,
780
+ size = _this$asProps11.size,
781
+ offset = _this$asProps11.offset;
782
+ var angle = Math.PI * 2 / categories.length;
783
+ var radius = Math.min(size[0], size[1]) / 2 - offset;
784
+ return [index * angle - angle / 2, (index + 1) * angle - angle / 2, radius];
785
+ }
786
+ }, {
787
+ key: "getIndex",
788
+ value: function getIndex(point) {
789
+ var _this4 = this;
790
+
791
+ var _this$asProps12 = this.asProps,
792
+ categories = _this$asProps12.categories,
793
+ type = _this$asProps12.type;
794
+ var index;
795
+
796
+ if (type === 'circle') {
797
+ index = categories.findIndex(function (c, i) {
798
+ return pieContains(_this4.getPie(i), point);
799
+ });
800
+ } else {
801
+ index = categories.findIndex(function (c, i) {
802
+ return (0, _d3Polygon.polygonContains)(_this4.getPolygon(i), point);
803
+ });
804
+ }
805
+
806
+ return index === -1 ? null : index;
807
+ }
808
+ }, {
809
+ key: "componentDidMount",
810
+ value: function componentDidMount() {
811
+ var _this5 = this;
812
+
813
+ var eventEmitter = this.asProps.eventEmitter;
814
+ this.unsubscribeMouseMoveRoot = eventEmitter.subscribe('onMouseMoveRoot', function (e) {
815
+ e.persist();
816
+
817
+ _this5.handlerMouseMoveRoot(e);
818
+ });
819
+ this.unsubscribeMouseLeaveRoot = eventEmitter.subscribe('onMouseLeaveRoot', this.handlerMouseLeaveRoot);
820
+ }
821
+ }, {
822
+ key: "componentWillUnmount",
823
+ value: function componentWillUnmount() {
824
+ if (this.unsubscribeMouseMoveRoot) {
825
+ this.unsubscribeMouseMoveRoot();
826
+ }
827
+
828
+ if (this.unsubscribeMouseLeaveRoot) {
829
+ this.unsubscribeMouseLeaveRoot();
830
+ }
831
+ }
832
+ }, {
833
+ key: "render",
834
+ value: function render() {
835
+ var _this$asProps13 = this.asProps,
836
+ styles = _this$asProps13.styles,
837
+ type = _this$asProps13.type;
838
+ var index = this.state.index;
839
+ var SPieRect = this.Element;
840
+
841
+ if (index !== null) {
842
+ if (type === 'circle') {
843
+ var _ref8;
844
+
845
+ var _this$getPie = this.getPie(index),
846
+ _this$getPie2 = (0, _slicedToArray2["default"])(_this$getPie, 3),
847
+ startAngle = _this$getPie2[0],
848
+ endAngle = _this$getPie2[1],
849
+ radius = _this$getPie2[2];
850
+
851
+ var circle = (0, _d3Shape.arc)().innerRadius(0).outerRadius(radius).startAngle(startAngle).endAngle(endAngle);
852
+ return _ref8 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SPieRect, _ref8.cn("SPieRect", {
853
+ "render": 'path',
854
+ "d": circle()
855
+ }));
856
+ } else {
857
+ var _ref9;
858
+
859
+ return _ref9 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SPieRect, _ref9.cn("SPieRect", {
860
+ "render": 'path',
861
+ "d": (0, _d3Shape.line)()(this.getPolygon(index))
862
+ }));
863
+ }
864
+ }
865
+
866
+ return null;
867
+ }
868
+ }]);
869
+ return Hover;
870
+ }(_core.Component);
871
+
872
+ var Axis = (0, _createElement["default"])(AxisRoot, {
873
+ Ticks: AxisTicks,
874
+ Labels: AxisLabels
875
+ });
876
+ var Polygon = (0, _createElement["default"])(PolygonRoot, {
877
+ Line: PolygonLine,
878
+ Dots: PolygonDots
879
+ });
880
+ var Radar = (0, _createElement["default"])(RadarRoot, {
881
+ Axis: Axis,
882
+ Polygon: Polygon,
883
+ Hover: Hover
884
+ });
885
+ var _default = Radar;
886
+ exports["default"] = _default;
887
+ //# sourceMappingURL=Radar.js.map