@easyv/charts 1.0.47 → 1.0.48

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.
@@ -35,6 +35,8 @@ var _LinearGradient = _interopRequireDefault(require("./LinearGradient"));
35
35
 
36
36
  var _formatter = require("../formatter");
37
37
 
38
+ var _piechartModule = _interopRequireDefault(require("../css/piechart.module.css"));
39
+
38
40
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
39
41
 
40
42
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@@ -167,63 +169,100 @@ var getArc = function getArc(radius, _ref3, series) {
167
169
  });
168
170
  };
169
171
 
170
- var Component = /*#__PURE__*/(0, _react.memo)(function (_ref4) {
171
- var _ref4$config = _ref4.config,
172
- _ref4$config$chart = _ref4$config.chart,
173
- _ref4$config$chart$di = _ref4$config$chart.dimension.chartDimension,
174
- width = _ref4$config$chart$di.width,
175
- height = _ref4$config$chart$di.height,
176
- label = _ref4$config$chart.label,
177
- _ref4$config$chart$le = _ref4$config$chart.legend,
178
- _ref4$config$chart$le2 = _ref4$config$chart$le.formatter,
179
- formatter = _ref4$config$chart$le2 === void 0 ? _formatter.pieLegendFormatter : _ref4$config$chart$le2,
180
- legend = (0, _objectWithoutProperties2["default"])(_ref4$config$chart$le, ["formatter"]),
181
- _ref4$config$chart$ma = _ref4$config$chart.margin,
182
- marginLeft = _ref4$config$chart$ma.marginLeft,
183
- marginTop = _ref4$config$chart$ma.marginTop,
184
- _ref4$config$fan = _ref4$config.fan;
185
- _ref4$config$fan = _ref4$config$fan === void 0 ? {} : _ref4$config$fan;
186
- var _ref4$config$fan$char = _ref4$config$fan.chart,
187
- chart = _ref4$config$fan$char === void 0 ? defaultChart : _ref4$config$fan$char,
188
- _ref4$config$fan$char2 = _ref4$config$fan.chart,
189
- _ref4$config$fan$char3 = _ref4$config$fan$char2.outerRadius,
190
- outerRadius = _ref4$config$fan$char3 === void 0 ? defaultChart.outerRadius : _ref4$config$fan$char3,
191
- padAngle = _ref4$config$fan$char2.padAngle,
192
- _ref4$config$fan$angl = _ref4$config$fan.angle,
193
- angle = _ref4$config$fan$angl === void 0 ? defaultAngle : _ref4$config$fan$angl,
194
- _ref4$config$fan$stro = _ref4$config$fan.stroke;
195
- _ref4$config$fan$stro = _ref4$config$fan$stro === void 0 ? {
172
+ var getCircleScale = function getCircleScale() {
173
+ var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : tick,
174
+ count = _ref4.count,
175
+ color = _ref4.color,
176
+ width = _ref4.width,
177
+ length = _ref4.length;
178
+
179
+ var radius = arguments.length > 1 ? arguments[1] : undefined;
180
+ var data = [],
181
+ arcs = [],
182
+ centroids = [];
183
+
184
+ for (var i = 0; i < count; i++) {
185
+ data.push(1);
186
+ }
187
+
188
+ var scaleData = (0, _d3v.pie)()(data);
189
+ scaleData.map(function (data) {
190
+ var _arc = (0, _d3v.arc)().innerRadius(radius + length / 2).outerRadius(radius + length / 2).startAngle(data.startAngle).endAngle(data.endAngle);
191
+
192
+ arcs.push(_arc());
193
+ centroids.push(_arc.centroid());
194
+ });
195
+ return /*#__PURE__*/_react["default"].createElement("g", null, centroids.map(function (center, index) {
196
+ var x = center[0],
197
+ y = center[1];
198
+ var rate = length / Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
199
+ return /*#__PURE__*/_react["default"].createElement("path", {
200
+ key: index,
201
+ d: "M".concat(x, ",").concat(y, "l").concat(x * rate, ",").concat(y * rate),
202
+ strokeWidth: width,
203
+ stroke: color
204
+ });
205
+ }));
206
+ };
207
+
208
+ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
209
+ var _ref5$config = _ref5.config,
210
+ _ref5$config$chart = _ref5$config.chart,
211
+ _ref5$config$chart$di = _ref5$config$chart.dimension.chartDimension,
212
+ width = _ref5$config$chart$di.width,
213
+ height = _ref5$config$chart$di.height,
214
+ label = _ref5$config$chart.label,
215
+ _ref5$config$chart$le = _ref5$config$chart.legend,
216
+ _ref5$config$chart$le2 = _ref5$config$chart$le.formatter,
217
+ formatter = _ref5$config$chart$le2 === void 0 ? _formatter.pieLegendFormatter : _ref5$config$chart$le2,
218
+ legend = (0, _objectWithoutProperties2["default"])(_ref5$config$chart$le, ["formatter"]),
219
+ _ref5$config$chart$ma = _ref5$config$chart.margin,
220
+ marginLeft = _ref5$config$chart$ma.marginLeft,
221
+ marginTop = _ref5$config$chart$ma.marginTop,
222
+ _ref5$config$fan = _ref5$config.fan;
223
+ _ref5$config$fan = _ref5$config$fan === void 0 ? {} : _ref5$config$fan;
224
+ var _ref5$config$fan$char = _ref5$config$fan.chart,
225
+ chart = _ref5$config$fan$char === void 0 ? defaultChart : _ref5$config$fan$char,
226
+ _ref5$config$fan$char2 = _ref5$config$fan.chart,
227
+ _ref5$config$fan$char3 = _ref5$config$fan$char2.outerRadius,
228
+ outerRadius = _ref5$config$fan$char3 === void 0 ? defaultChart.outerRadius : _ref5$config$fan$char3,
229
+ padAngle = _ref5$config$fan$char2.padAngle,
230
+ _ref5$config$fan$angl = _ref5$config$fan.angle,
231
+ angle = _ref5$config$fan$angl === void 0 ? defaultAngle : _ref5$config$fan$angl,
232
+ _ref5$config$fan$stro = _ref5$config$fan.stroke;
233
+ _ref5$config$fan$stro = _ref5$config$fan$stro === void 0 ? {
196
234
  show: false
197
- } : _ref4$config$fan$stro;
198
- var show = _ref4$config$fan$stro.show,
199
- strokeWidth = _ref4$config$fan$stro.strokeWidth,
200
- color = _ref4$config$fan$stro.color,
201
- decorate = _ref4$config$fan.decorate,
202
- decorate2 = _ref4$config$fan.decorate2,
203
- categoryText = _ref4$config$fan.categoryText,
204
- current = _ref4$config$fan.current,
205
- order = _ref4$config.order,
206
- series = _ref4$config.series,
207
- _ref4$config$animatio = _ref4$config.animation,
208
- on = _ref4$config$animatio.on,
209
- _ref4$config$animatio2 = _ref4$config$animatio.current,
210
- _ref4$config$animatio3 = _ref4$config$animatio2.heighten,
211
- heighten = _ref4$config$animatio3 === void 0 ? 0 : _ref4$config$animatio3,
212
- _ref4$config$animatio4 = _ref4$config$animatio2.opacity,
213
- opacity = _ref4$config$animatio4 === void 0 ? 0 : _ref4$config$animatio4,
214
- _ref4$config$animatio5 = _ref4$config$animatio2.width,
215
- radiusWidthAdd = _ref4$config$animatio5 === void 0 ? 0 : _ref4$config$animatio5,
216
- animateColor = _ref4$config$animatio2.color,
217
- _ref4$config$animatio6 = _ref4$config$animatio2.gap,
218
- gap = _ref4$config$animatio6 === void 0 ? 0 : _ref4$config$animatio6,
219
- _ref4$config$animatio7 = _ref4$config$animatio.rotate,
220
- rotate = _ref4$config$animatio7 === void 0 ? 0 : _ref4$config$animatio7,
221
- _ref4$state = _ref4.state,
222
- currentIndex = _ref4$state.currentIndex,
223
- trigger = _ref4$state.trigger,
224
- onEvent = _ref4.onEvent,
225
- _ref4$data = _ref4.data,
226
- data = _ref4$data === void 0 ? [] : _ref4$data;
235
+ } : _ref5$config$fan$stro;
236
+ var show = _ref5$config$fan$stro.show,
237
+ strokeWidth = _ref5$config$fan$stro.strokeWidth,
238
+ color = _ref5$config$fan$stro.color,
239
+ decorate = _ref5$config$fan.decorate,
240
+ decorate2 = _ref5$config$fan.decorate2,
241
+ categoryText = _ref5$config$fan.categoryText,
242
+ outerDecorate = _ref5$config$fan.outerDecorate,
243
+ current = _ref5$config$fan.current,
244
+ order = _ref5$config.order,
245
+ series = _ref5$config.series,
246
+ _ref5$config$animatio = _ref5$config.animation,
247
+ on = _ref5$config$animatio.on,
248
+ _ref5$config$animatio2 = _ref5$config$animatio.current,
249
+ _ref5$config$animatio3 = _ref5$config$animatio2.heighten,
250
+ heighten = _ref5$config$animatio3 === void 0 ? 0 : _ref5$config$animatio3,
251
+ _ref5$config$animatio4 = _ref5$config$animatio2.opacity,
252
+ opacity = _ref5$config$animatio4 === void 0 ? 0 : _ref5$config$animatio4,
253
+ _ref5$config$animatio5 = _ref5$config$animatio2.width,
254
+ radiusWidthAdd = _ref5$config$animatio5 === void 0 ? 0 : _ref5$config$animatio5,
255
+ animateColor = _ref5$config$animatio2.color,
256
+ _ref5$config$animatio6 = _ref5$config$animatio2.gap,
257
+ gap = _ref5$config$animatio6 === void 0 ? 0 : _ref5$config$animatio6,
258
+ _ref5$config$animatio7 = _ref5$config$animatio.rotate,
259
+ rotate = _ref5$config$animatio7 === void 0 ? 0 : _ref5$config$animatio7,
260
+ _ref5$state = _ref5.state,
261
+ currentIndex = _ref5$state.currentIndex,
262
+ trigger = _ref5$state.trigger,
263
+ onEvent = _ref5.onEvent,
264
+ _ref5$data = _ref5.data,
265
+ data = _ref5$data === void 0 ? [] : _ref5$data;
227
266
  var prevIndex = (0, _react.useRef)(null);
228
267
  var legendPrecision = legend.config.percent.precision;
229
268
 
@@ -296,10 +335,10 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref4) {
296
335
 
297
336
  var _angle = PI * 2 / _legendDataWithPercent.length;
298
337
 
299
- return _legendDataWithPercent.map(function (_ref5, index) {
300
- var startAngle = _ref5.startAngle,
301
- endAngle = _ref5.endAngle,
302
- arc = (0, _objectWithoutProperties2["default"])(_ref5, ["startAngle", "endAngle"]);
338
+ return _legendDataWithPercent.map(function (_ref6, index) {
339
+ var startAngle = _ref6.startAngle,
340
+ endAngle = _ref6.endAngle,
341
+ arc = (0, _objectWithoutProperties2["default"])(_ref6, ["startAngle", "endAngle"]);
303
342
  return _objectSpread(_objectSpread({}, arc), {}, {
304
343
  id: id + '_linear_' + index,
305
344
  startAngle: roseType == 'area' ? _angle * index : startAngle,
@@ -388,7 +427,78 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref4) {
388
427
  var halfChartWidth = chartWidth / 2;
389
428
  var halfChartHeight = chartHeight / 2;
390
429
  var rotate_ = decorate2 ? -(arcs[+currentIndex].startAngle + arcs[+currentIndex].endAngle) * 90 / Math.PI + rotate : 0;
391
- return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_.ChartContainer, {
430
+ var maxRadius = 0;
431
+
432
+ _arcs.map(function (d) {
433
+ maxRadius = Math.max(maxRadius, d.outerRadius);
434
+ });
435
+
436
+ var centerRadius = 0.5 * maxRadius + 0.5 * _arcs[0].innerRadius;
437
+ return outerDecorate ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_.ChartContainer //用于生成甜甜圈图,判断依据是外环装饰这个配置项(outerDecorate)
438
+ , {
439
+ width: width,
440
+ height: height,
441
+ marginLeft: marginLeft,
442
+ marginTop: marginTop
443
+ }, /*#__PURE__*/_react["default"].createElement("g", {
444
+ style: {
445
+ transition: "transform ease-in-out 0.3s",
446
+ transform: 'translate(' + halfChartWidth + 'px, ' + halfChartHeight + 'px) rotate(' + rotate_ + "deg)"
447
+ }
448
+ }, //用于生成外环装饰的刻度
449
+ outerDecorate.tick.show && getCircleScale(outerDecorate.tick, maxRadius), /*#__PURE__*/_react["default"].createElement("circle", {
450
+ //外环装饰
451
+ cx: "0",
452
+ cy: "0",
453
+ r: maxRadius + 2,
454
+ fill: "none",
455
+ stroke: outerDecorate.color,
456
+ strokeWidth: outerDecorate.width
457
+ }), _arcs.map(function (_ref7, index) {
458
+ var id = _ref7.id,
459
+ value = _ref7.value,
460
+ series = _ref7.series,
461
+ arc = _ref7.arc,
462
+ innerRadius = _ref7.innerRadius,
463
+ outerRadius = _ref7.outerRadius,
464
+ dataIndex = _ref7.index;
465
+ var arcWidth = outerRadius - innerRadius;
466
+ var path = arc.innerRadius(centerRadius).outerRadius(centerRadius)(value);
467
+ var dashLength = Math.ceil(Math.PI * centerRadius * 2 / _arcs.length);
468
+ var pie = (0, _utils.getColorList)(series.color);
469
+ return /*#__PURE__*/_react["default"].createElement(_react.Fragment, {
470
+ key: index
471
+ }, /*#__PURE__*/_react["default"].createElement("path", {
472
+ className: _piechartModule["default"]['inner-arc'],
473
+ style: {
474
+ strokeDasharray: "".concat(dashLength, ",").concat(2 * dashLength),
475
+ strokeDashoffset: dashLength,
476
+ animationDelay: "".concat(index * 2000, "ms")
477
+ },
478
+ "data-index": dataIndex,
479
+ onClick: onClick,
480
+ onMouseEnter: onMouseEnter,
481
+ onMouseLeave: onMouseLeave,
482
+ d: path.split("L")[0],
483
+ stroke: 'url(#' + id + ')',
484
+ strokeWidth: arcWidth,
485
+ fill: "none"
486
+ }), /*#__PURE__*/_react["default"].createElement("defs", null, /*#__PURE__*/_react["default"].createElement(_LinearGradient["default"], {
487
+ id: id,
488
+ colors: pie,
489
+ rotate: series.color.linear.angle + 180 // gradientUnits='objectBoundingBox'
490
+
491
+ })));
492
+ }), label && /*#__PURE__*/_react["default"].createElement(Label, {
493
+ config: _objectSpread(_objectSpread({}, label), {}, {
494
+ maxRadius: maxRadius + 2
495
+ }),
496
+ arcs: _arcs,
497
+ animation: true
498
+ }))), /*#__PURE__*/_react["default"].createElement(_.Legend, (0, _extends2["default"])({}, legend, {
499
+ series: _arcs,
500
+ formatter: formatter
501
+ }))) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_.ChartContainer, {
392
502
  width: width,
393
503
  height: height,
394
504
  marginLeft: marginLeft,
@@ -398,14 +508,14 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref4) {
398
508
  transition: "transform ease-in-out 0.3s",
399
509
  transform: 'translate(' + halfChartWidth + 'px, ' + halfChartHeight + 'px) rotate(' + rotate_ + "deg)"
400
510
  }
401
- }, _arcs.map(function (_ref6, index) {
402
- var id = _ref6.id,
403
- value = _ref6.value,
404
- series = _ref6.series,
405
- arc = _ref6.arc,
406
- innerRadius = _ref6.innerRadius,
407
- outerRadius = _ref6.outerRadius,
408
- dataIndex = _ref6.index;
511
+ }, _arcs.map(function (_ref8, index) {
512
+ var id = _ref8.id,
513
+ value = _ref8.value,
514
+ series = _ref8.series,
515
+ arc = _ref8.arc,
516
+ innerRadius = _ref8.innerRadius,
517
+ outerRadius = _ref8.outerRadius,
518
+ dataIndex = _ref8.index;
409
519
  var current = index == currentIndex;
410
520
  var prev = index == prevIndex.current;
411
521
  var offset = current ? y : prev ? 1 - y : 0;
@@ -501,35 +611,35 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref4) {
501
611
  })));
502
612
  });
503
613
 
504
- var Current = function Current(_ref7) {
505
- var _ref7$config = _ref7.config,
506
- show = _ref7$config.show,
507
- gap = _ref7$config.gap,
508
- _ref7$config$name = _ref7$config.name,
509
- showName = _ref7$config$name.show,
510
- nameFont = _ref7$config$name.font,
511
- _ref7$config$percent = _ref7$config.percent,
512
- showPercent = _ref7$config$percent.show,
513
- percentFont = _ref7$config$percent.font,
514
- precision = _ref7$config$percent.precision,
515
- _ref7$config$percent$ = _ref7$config$percent.translate,
516
- translatePercentX = _ref7$config$percent$.x,
517
- translatePercentY = _ref7$config$percent$.y,
518
- _ref7$config$value = _ref7$config.value,
519
- showValue = _ref7$config$value.show,
520
- valueFont = _ref7$config$value.font,
521
- _ref7$config$value$tr = _ref7$config$value.translate,
522
- translateValueX = _ref7$config$value$tr.x,
523
- translateValueY = _ref7$config$value$tr.y,
524
- _ref7$config$value$su = _ref7$config$value.suffix,
525
- showSuffix = _ref7$config$value$su.show,
526
- fontSize = _ref7$config$value$su.fontSize,
527
- text = _ref7$config$value$su.text,
528
- _ref7$config$value$su2 = _ref7$config$value$su.translate,
529
- translateSuffixX = _ref7$config$value$su2.x,
530
- translateSuffixY = _ref7$config$value$su2.y,
531
- data = _ref7.data,
532
- currentIndex = _ref7.currentIndex;
614
+ var Current = function Current(_ref9) {
615
+ var _ref9$config = _ref9.config,
616
+ show = _ref9$config.show,
617
+ gap = _ref9$config.gap,
618
+ _ref9$config$name = _ref9$config.name,
619
+ showName = _ref9$config$name.show,
620
+ nameFont = _ref9$config$name.font,
621
+ _ref9$config$percent = _ref9$config.percent,
622
+ showPercent = _ref9$config$percent.show,
623
+ percentFont = _ref9$config$percent.font,
624
+ precision = _ref9$config$percent.precision,
625
+ _ref9$config$percent$ = _ref9$config$percent.translate,
626
+ translatePercentX = _ref9$config$percent$.x,
627
+ translatePercentY = _ref9$config$percent$.y,
628
+ _ref9$config$value = _ref9$config.value,
629
+ showValue = _ref9$config$value.show,
630
+ valueFont = _ref9$config$value.font,
631
+ _ref9$config$value$tr = _ref9$config$value.translate,
632
+ translateValueX = _ref9$config$value$tr.x,
633
+ translateValueY = _ref9$config$value$tr.y,
634
+ _ref9$config$value$su = _ref9$config$value.suffix,
635
+ showSuffix = _ref9$config$value$su.show,
636
+ fontSize = _ref9$config$value$su.fontSize,
637
+ text = _ref9$config$value$su.text,
638
+ _ref9$config$value$su2 = _ref9$config$value$su.translate,
639
+ translateSuffixX = _ref9$config$value$su2.x,
640
+ translateSuffixY = _ref9$config$value$su2.y,
641
+ data = _ref9.data,
642
+ currentIndex = _ref9.currentIndex;
533
643
 
534
644
  var _data = (0, _react.useMemo)(function () {
535
645
  var legendDataWithPercent = (0, _utils.getDataWithPercent)(data, precision);
@@ -560,37 +670,41 @@ var Current = function Current(_ref7) {
560
670
  }, (0, _utils.getFontStyle)(percentFont, 'svg')), percent + '%'));
561
671
  };
562
672
 
563
- var Label = function Label(_ref8) {
564
- var _ref8$config = _ref8.config,
565
- lineLength = _ref8$config.lineLength,
566
- distance = _ref8$config.distance,
567
- mode = _ref8$config.mode,
568
- show = _ref8$config.show,
569
- _ref8$config$translat = _ref8$config.translate,
570
- translateX = _ref8$config$translat.x,
571
- translateY = _ref8$config$translat.y,
572
- _ref8$config$name = _ref8$config.name,
573
- showName = _ref8$config$name.show,
574
- nameFont = _ref8$config$name.font,
575
- _ref8$config$value = _ref8$config.value,
576
- showValue = _ref8$config$value.show,
577
- valueFont = _ref8$config$value.font,
578
- _ref8$config$value$su = _ref8$config$value.suffix,
579
- showSuffix = _ref8$config$value$su.show,
580
- text = _ref8$config$value$su.text,
581
- suffixFontSize = _ref8$config$value$su.fontSize,
582
- _ref8$config$value$su2 = _ref8$config$value$su.translate,
583
- suffixTranslateX = _ref8$config$value$su2.x,
584
- suffixTranslateY = _ref8$config$value$su2.y,
585
- _ref8$config$value$sa = _ref8$config$value.sameColor,
586
- valueSameColor = _ref8$config$value$sa === void 0 ? false : _ref8$config$value$sa,
587
- _ref8$config$percent = _ref8$config.percent,
588
- showPercent = _ref8$config$percent.show,
589
- percentFont = _ref8$config$percent.font,
590
- precision = _ref8$config$percent.precision,
591
- _ref8$config$percent$ = _ref8$config$percent.sameColor,
592
- percentSameColor = _ref8$config$percent$ === void 0 ? false : _ref8$config$percent$,
593
- arcs = _ref8.arcs;
673
+ var Label = function Label(_ref10) {
674
+ var _ref10$config = _ref10.config,
675
+ _ref10$config$maxRadi = _ref10$config.maxRadius,
676
+ maxRadius = _ref10$config$maxRadi === void 0 ? 0 : _ref10$config$maxRadi,
677
+ lineLength = _ref10$config.lineLength,
678
+ lineColor = _ref10$config.lineColor,
679
+ distance = _ref10$config.distance,
680
+ mode = _ref10$config.mode,
681
+ show = _ref10$config.show,
682
+ _ref10$config$transla = _ref10$config.translate,
683
+ translateX = _ref10$config$transla.x,
684
+ translateY = _ref10$config$transla.y,
685
+ _ref10$config$name = _ref10$config.name,
686
+ showName = _ref10$config$name.show,
687
+ nameFont = _ref10$config$name.font,
688
+ _ref10$config$value = _ref10$config.value,
689
+ showValue = _ref10$config$value.show,
690
+ valueFont = _ref10$config$value.font,
691
+ _ref10$config$value$s = _ref10$config$value.suffix,
692
+ showSuffix = _ref10$config$value$s.show,
693
+ text = _ref10$config$value$s.text,
694
+ suffixFontSize = _ref10$config$value$s.fontSize,
695
+ _ref10$config$value$s2 = _ref10$config$value$s.translate,
696
+ suffixTranslateX = _ref10$config$value$s2.x,
697
+ suffixTranslateY = _ref10$config$value$s2.y,
698
+ _ref10$config$value$s3 = _ref10$config$value.sameColor,
699
+ valueSameColor = _ref10$config$value$s3 === void 0 ? false : _ref10$config$value$s3,
700
+ _ref10$config$percent = _ref10$config.percent,
701
+ showPercent = _ref10$config$percent.show,
702
+ percentFont = _ref10$config$percent.font,
703
+ precision = _ref10$config$percent.precision,
704
+ _ref10$config$percent2 = _ref10$config$percent.sameColor,
705
+ percentSameColor = _ref10$config$percent2 === void 0 ? false : _ref10$config$percent2,
706
+ arcs = _ref10.arcs,
707
+ animation = _ref10.animation;
594
708
 
595
709
  // const [labels, setLabels] = useState(null);
596
710
  // const [opacity, setOpacity] = useState(0);
@@ -633,16 +747,17 @@ var Label = function Label(_ref8) {
633
747
  // }, [labels]);
634
748
 
635
749
 
636
- return /*#__PURE__*/_react["default"].createElement("g", null, _arcs.map(function (_ref9, index) {
637
- var _ref9$series$color = _ref9.series.color,
638
- type = _ref9$series$color.type,
639
- pure = _ref9$series$color.pure,
640
- stops = _ref9$series$color.linear.stops,
641
- displayName = _ref9.displayName,
642
- value = _ref9.value,
643
- percent = _ref9.percent,
644
- arc = _ref9.arc,
645
- outerRadius = _ref9.outerRadius;
750
+ return /*#__PURE__*/_react["default"].createElement("g", null, _arcs.map(function (_ref11, index) {
751
+ var _ref11$series$color = _ref11.series.color,
752
+ type = _ref11$series$color.type,
753
+ pure = _ref11$series$color.pure,
754
+ stops = _ref11$series$color.linear.stops,
755
+ displayName = _ref11.displayName,
756
+ value = _ref11.value,
757
+ percent = _ref11.percent,
758
+ arc = _ref11.arc,
759
+ outerRadius = _ref11.outerRadius,
760
+ actualIndex = _ref11.index;
646
761
 
647
762
  var _arc$centroid = arc.centroid(),
648
763
  _arc$centroid2 = (0, _slicedToArray2["default"])(_arc$centroid, 2),
@@ -651,12 +766,12 @@ var Label = function Label(_ref8) {
651
766
 
652
767
  var midAngle = Math.atan2(y, x);
653
768
 
654
- var _getCoord = getCoord(midAngle, outerRadius),
769
+ var _getCoord = getCoord(midAngle, maxRadius ? maxRadius : outerRadius),
655
770
  _getCoord2 = (0, _slicedToArray2["default"])(_getCoord, 2),
656
771
  x1 = _getCoord2[0],
657
772
  y1 = _getCoord2[1];
658
773
 
659
- var radius = outerRadius + distance;
774
+ var radius = (maxRadius ? maxRadius : outerRadius) + distance;
660
775
 
661
776
  var _getCoord3 = getCoord(midAngle, radius),
662
777
  _getCoord4 = (0, _slicedToArray2["default"])(_getCoord3, 2),
@@ -675,10 +790,18 @@ var Label = function Label(_ref8) {
675
790
  return show && (_showName || showPercent || _showValue) && /*#__PURE__*/_react["default"].createElement("g", {
676
791
  key: index
677
792
  }, /*#__PURE__*/_react["default"].createElement("path", {
793
+ className: animation ? _piechartModule["default"]['label-line'] : "",
794
+ style: {
795
+ animationDelay: "".concat(animation ? (actualIndex + 1) * 2000 - 800 : 0, "ms")
796
+ },
678
797
  d: 'M' + x1 + ', ' + y1 + 'L' + x2 + ', ' + y2 + 'L' + x3 + ', ' + y2,
679
- stroke: type == 'pure' ? pure : stops[0].color,
798
+ stroke: lineColor ? lineColor : type == 'pure' ? pure : stops[0].color,
680
799
  fill: "none"
681
800
  }), /*#__PURE__*/_react["default"].createElement("text", {
801
+ className: animation ? _piechartModule["default"]['label-text'] : "",
802
+ style: {
803
+ animationDelay: "".concat(animation ? (actualIndex + 1) * 2000 - 800 : 0, "ms")
804
+ },
682
805
  x: _x,
683
806
  y: y2 + translateY,
684
807
  dominantBaseline: "middle",
@@ -699,7 +822,7 @@ var Label = function Label(_ref8) {
699
822
  }, text)), showPercent && /*#__PURE__*/_react["default"].createElement("tspan", {
700
823
  x: percentX(_showName, _showValue, mode, _x),
701
824
  dx: percentDx(_showName, _showValue, mode),
702
- dy: percentDy(_showName, _showValue, mode) + (_showValue && showSuffix ? suffixTranslateY * -1 : 0),
825
+ dy: percentDy(_showName, _showValue, mode) + (_showValue && showSuffix ? suffixTranslateY * -1 : ""),
703
826
  style: (0, _utils.getFontStyle)(percentFont, 'svg')
704
827
  }, (_showValue ? '(' : '') + percent + '%' + (_showValue ? ')' : ''))));
705
828
  }));
@@ -39,4 +39,4 @@
39
39
  align-items: center;
40
40
  flex-direction: row;
41
41
  justify-content: space-between;
42
- }
42
+ }
@@ -0,0 +1,27 @@
1
+ /*甜甜圈图专用css*/
2
+ .label-line {
3
+ stroke-dasharray: 100;
4
+ stroke-dashoffset: 100;
5
+ animation: dash 800ms ease forwards;
6
+ }
7
+
8
+ .label-text {
9
+ opacity: 0;
10
+ animation: show 800ms ease forwards;
11
+ }
12
+
13
+ .inner-arc {
14
+ animation: dash 2s ease forwards;
15
+ }
16
+
17
+ @keyframes dash {
18
+ 100% {
19
+ stroke-dashoffset: 0%;
20
+ }
21
+ }
22
+
23
+ @keyframes show {
24
+ 100% {
25
+ opacity: 1;
26
+ }
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.0.47",
3
+ "version": "1.0.48",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -23,6 +23,7 @@ import { pie, arc, extent, scaleLinear } from 'd3v7';
23
23
  import { animate, linear } from 'popmotion';
24
24
  import LinearGradient from './LinearGradient';
25
25
  import { pieLegendFormatter as legendFormatter } from '../formatter';
26
+ import ringCss from '../css/piechart.module.css';
26
27
 
27
28
  const PI = Math.PI;
28
29
 
@@ -141,6 +142,42 @@ const getArc = (
141
142
  .padAngle(padAngle),
142
143
  });
143
144
 
145
+ const getCircleScale = ({ count, color, width, length }=tick, radius)=>{
146
+ let data = [],
147
+ arcs = [],
148
+ centroids = [];
149
+ for (let i = 0; i < count; i++) {
150
+ data.push(1);
151
+ }
152
+ let scaleData = pie()(data);
153
+ scaleData.map((data) => {
154
+ let _arc = arc()
155
+ .innerRadius(radius + length/2)
156
+ .outerRadius(radius + length/2)
157
+ .startAngle(data.startAngle)
158
+ .endAngle(data.endAngle);
159
+ arcs.push(_arc());
160
+ centroids.push(_arc.centroid());
161
+ });
162
+ return (
163
+ <g>
164
+ {centroids.map((center, index) => {
165
+ let x = center[0],
166
+ y = center[1];
167
+ let rate = length / Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
168
+ return (
169
+ <path
170
+ key={index}
171
+ d={`M${x},${y}l${x * rate},${y * rate}`}
172
+ strokeWidth={width}
173
+ stroke={color}
174
+ />
175
+ );
176
+ })}
177
+ </g>
178
+ );
179
+ }
180
+
144
181
  const Component = memo(
145
182
  ({
146
183
  config: {
@@ -160,6 +197,7 @@ const Component = memo(
160
197
  decorate,
161
198
  decorate2,
162
199
  categoryText,
200
+ outerDecorate,
163
201
  current,
164
202
  } = {},
165
203
  order,
@@ -176,7 +214,6 @@ const Component = memo(
176
214
  }) => {
177
215
  const prevIndex = useRef(null);
178
216
  const { precision: legendPrecision } = legend.config.percent;
179
-
180
217
  const {
181
218
  id,
182
219
  width: chartWidth,
@@ -330,9 +367,82 @@ const Component = memo(
330
367
  const halfChartHeight = chartHeight / 2;
331
368
 
332
369
  const rotate_ = decorate2?-(arcs[+currentIndex].startAngle+arcs[+currentIndex].endAngle)*90/Math.PI+rotate:0;
333
-
370
+ let maxRadius = 0;
371
+ _arcs.map(d=>{
372
+ maxRadius=Math.max(maxRadius,d.outerRadius);
373
+ })
374
+ let centerRadius =0.5*maxRadius + 0.5*_arcs[0].innerRadius
334
375
  return (
335
- <>
376
+ outerDecorate?<>
377
+ <ChartContainer //用于生成甜甜圈图,判断依据是外环装饰这个配置项(outerDecorate)
378
+ width={width}
379
+ height={height}
380
+ marginLeft={marginLeft}
381
+ marginTop={marginTop}
382
+ >
383
+ <g
384
+ style={{
385
+ transition:"transform ease-in-out 0.3s",
386
+ transform:'translate(' + halfChartWidth + 'px, ' + halfChartHeight + 'px) rotate('+rotate_+"deg)"
387
+ }}
388
+ >
389
+ {
390
+ //用于生成外环装饰的刻度
391
+ outerDecorate.tick.show && getCircleScale(outerDecorate.tick, maxRadius)
392
+ }
393
+ <circle //外环装饰
394
+ cx='0'
395
+ cy='0'
396
+ r={maxRadius+2}
397
+ fill='none'
398
+ stroke={outerDecorate.color}
399
+ strokeWidth={outerDecorate.width}
400
+ />
401
+ {
402
+ _arcs.map(
403
+ ({ id, value, series, arc, innerRadius, outerRadius, index: dataIndex }, index) => {
404
+ const arcWidth = (outerRadius-innerRadius);
405
+ const path = arc
406
+ .innerRadius(centerRadius)
407
+ .outerRadius(centerRadius)(value);
408
+ const dashLength=Math.ceil(Math.PI*(centerRadius)*2/_arcs.length);
409
+ const pie = getColorList(series.color);
410
+ return (
411
+ <Fragment key={index}>
412
+ <path
413
+ className={ringCss['inner-arc']}
414
+ style={{
415
+ strokeDasharray:`${dashLength},${2*dashLength}`,
416
+ strokeDashoffset: dashLength,
417
+ animationDelay: `${index * 2000}ms`
418
+ }}
419
+ data-index={dataIndex}
420
+ onClick={onClick}
421
+ onMouseEnter={onMouseEnter}
422
+ onMouseLeave={onMouseLeave}
423
+ d={path.split("L")[0]}
424
+ stroke={'url(#' + id + ')'}
425
+ strokeWidth={arcWidth}
426
+ fill="none"
427
+ />
428
+ <defs>
429
+ <LinearGradient
430
+ id={id}
431
+ colors={pie}
432
+ rotate={series.color.linear.angle + 180}
433
+ // gradientUnits='objectBoundingBox'
434
+ />
435
+ </defs>
436
+ </Fragment>
437
+ );
438
+ }
439
+ )
440
+ }
441
+ {label && <Label config={{...label,maxRadius: maxRadius+2}} arcs={_arcs} animation={true}/>}
442
+ </g>
443
+ </ChartContainer>
444
+ <Legend {...legend} series={_arcs} formatter={formatter}/>
445
+ </> : <>
336
446
  <ChartContainer
337
447
  width={width}
338
448
  height={height}
@@ -570,7 +680,9 @@ const Current = ({
570
680
 
571
681
  const Label = ({
572
682
  config: {
683
+ maxRadius = 0,
573
684
  lineLength,
685
+ lineColor,
574
686
  distance,
575
687
  mode,
576
688
  show,
@@ -595,6 +707,7 @@ const Label = ({
595
707
  },
596
708
  },
597
709
  arcs,
710
+ animation
598
711
  }) => {
599
712
  // const [labels, setLabels] = useState(null);
600
713
  // const [opacity, setOpacity] = useState(0);
@@ -603,7 +716,6 @@ const Label = ({
603
716
  () => getDataWithPercent(arcs, precision),
604
717
  [arcs, precision]
605
718
  );
606
-
607
719
  // useEffect(() => {
608
720
  // if (labels) {
609
721
  // const children = [...labels.children];
@@ -641,7 +753,7 @@ const Label = ({
641
753
  // console.log('bbox: ', bbox);
642
754
  // }
643
755
  // }, [labels]);
644
-
756
+
645
757
  return (
646
758
  <g
647
759
  // style={{ opacity }} ref={setLabels}
@@ -661,16 +773,18 @@ const Label = ({
661
773
  percent,
662
774
  arc,
663
775
  outerRadius,
776
+ index:actualIndex
664
777
  },
665
778
  index
666
779
  ) => {
780
+
667
781
  const [x, y] = arc.centroid();
668
782
 
669
783
  const midAngle = Math.atan2(y, x);
670
784
 
671
- const [x1, y1] = getCoord(midAngle, outerRadius);
785
+ const [x1, y1] = getCoord(midAngle, maxRadius?maxRadius:outerRadius);
672
786
 
673
- const radius = outerRadius + distance;
787
+ const radius = (maxRadius?maxRadius:outerRadius) + distance;
674
788
  const [x2, y2] = getCoord(midAngle, radius);
675
789
 
676
790
  const direction = x2 < 0 ? -1 : 1;
@@ -686,24 +800,19 @@ const Label = ({
686
800
  (_showName || showPercent || _showValue) && (
687
801
  <g key={index}>
688
802
  <path
803
+ className={animation? ringCss['label-line']:""}
804
+ style={{ animationDelay:`${animation? ((actualIndex+1) * 2000 - 800) : 0}ms`}}
689
805
  d={
690
- 'M' +
691
- x1 +
692
- ', ' +
693
- y1 +
694
- 'L' +
695
- x2 +
696
- ', ' +
697
- y2 +
698
- 'L' +
699
- x3 +
700
- ', ' +
701
- y2
806
+ 'M' + x1 + ', ' + y1 + 'L' +
807
+ x2 + ', ' + y2 + 'L' +
808
+ x3 + ', ' + y2
702
809
  }
703
- stroke={type == 'pure' ? pure : stops[0].color}
810
+ stroke={lineColor?lineColor:(type == 'pure' ? pure : stops[0].color)}
704
811
  fill='none'
705
812
  />
706
813
  <text
814
+ className={animation? ringCss['label-text']:""}
815
+ style={{ animationDelay:`${animation? ((actualIndex+1) * 2000 - 800) : 0}ms`}}
707
816
  x={_x}
708
817
  y={y2 + translateY}
709
818
  dominantBaseline='middle'
@@ -744,7 +853,7 @@ const Label = ({
744
853
  dx={percentDx(_showName, _showValue, mode)}
745
854
  dy={
746
855
  percentDy(_showName, _showValue, mode) +
747
- (_showValue && showSuffix ? suffixTranslateY * -1 : 0)
856
+ (_showValue && showSuffix ? suffixTranslateY * -1 : "")
748
857
  }
749
858
  style={getFontStyle(percentFont, 'svg')}
750
859
  >
@@ -39,4 +39,4 @@
39
39
  align-items: center;
40
40
  flex-direction: row;
41
41
  justify-content: space-between;
42
- }
42
+ }
@@ -0,0 +1,27 @@
1
+ /*甜甜圈图专用css*/
2
+ .label-line {
3
+ stroke-dasharray: 100;
4
+ stroke-dashoffset: 100;
5
+ animation: dash 800ms ease forwards;
6
+ }
7
+
8
+ .label-text {
9
+ opacity: 0;
10
+ animation: show 800ms ease forwards;
11
+ }
12
+
13
+ .inner-arc {
14
+ animation: dash 2s ease forwards;
15
+ }
16
+
17
+ @keyframes dash {
18
+ 100% {
19
+ stroke-dashoffset: 0%;
20
+ }
21
+ }
22
+
23
+ @keyframes show {
24
+ 100% {
25
+ opacity: 1;
26
+ }
27
+ }