@easyv/charts 1.3.19 → 1.3.20
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/commitlint.config.js +1 -1
- package/lib/components/Legend.js +10 -2
- package/lib/components/PieChart.js +67 -10
- package/package.json +1 -1
- package/src/components/Legend.js +9 -0
- package/src/components/PieChart.js +63 -7
package/commitlint.config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = {extends: ['@commitlint/config-conventional']}
|
|
1
|
+
module.exports = {extends: ['@commitlint/config-conventional']}
|
package/lib/components/Legend.js
CHANGED
|
@@ -62,7 +62,8 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
62
62
|
var _ref$config$unselect$ = _ref$config$unselect.opacity,
|
|
63
63
|
opacity = _ref$config$unselect$ === void 0 ? 1 : _ref$config$unselect$,
|
|
64
64
|
filterData = _ref.filterData,
|
|
65
|
-
formatter = _ref.formatter
|
|
65
|
+
formatter = _ref.formatter,
|
|
66
|
+
judge = _ref.judge;
|
|
66
67
|
if (!show) return null;
|
|
67
68
|
|
|
68
69
|
var _series = (0, _utils.sortPie)(series, order);
|
|
@@ -77,7 +78,14 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
77
78
|
var dataset = e.currentTarget.dataset;
|
|
78
79
|
var name = dataset.name;
|
|
79
80
|
filterData && interactive && filterData(name);
|
|
80
|
-
}, [interactive, filterData]);
|
|
81
|
+
}, [interactive, filterData]); //木然判断数据都为零时做的,此处并不严谨,待想到好方法在进一步解决
|
|
82
|
+
|
|
83
|
+
if (judge == 0) {
|
|
84
|
+
_series.forEach(function (d) {
|
|
85
|
+
d.percent = 0;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
81
89
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
82
90
|
className: "__easyv-legend-wrapper",
|
|
83
91
|
style: _objectSpread({
|
|
@@ -357,7 +357,22 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
357
357
|
return d.y;
|
|
358
358
|
});
|
|
359
359
|
return arcsFunc;
|
|
360
|
+
}, [angle]); //此处创建arcsFuncTwo的原因是为了兼容数据全为零
|
|
361
|
+
|
|
362
|
+
var arcsFuncTwo = (0, _react.useMemo)(function () {
|
|
363
|
+
var _getAngle2 = getAngle(angle),
|
|
364
|
+
_getAngle2$startAngle = _getAngle2.startAngle,
|
|
365
|
+
startAngle = _getAngle2$startAngle === void 0 ? 0 : _getAngle2$startAngle,
|
|
366
|
+
_getAngle2$endAngle = _getAngle2.endAngle,
|
|
367
|
+
endAngle = _getAngle2$endAngle === void 0 ? 360 : _getAngle2$endAngle;
|
|
368
|
+
|
|
369
|
+
var arcsFunc = (0, _d3v.pie)().startAngle(startAngle * PI / 180).endAngle(endAngle * PI / 180).value(function (d) {
|
|
370
|
+
return d.y == 0 ? 1 : d.y;
|
|
371
|
+
});
|
|
372
|
+
return arcsFunc;
|
|
360
373
|
}, [angle]);
|
|
374
|
+
var judgeData = 0; //此处声明全局变量是为了父子组件传递值来判断数据是否都为零
|
|
375
|
+
|
|
361
376
|
var arcs = (0, _react.useMemo)(function () {
|
|
362
377
|
var _chart = Object.assign(defaultChart, chart);
|
|
363
378
|
|
|
@@ -386,9 +401,21 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
386
401
|
return a.y - b.y;
|
|
387
402
|
});
|
|
388
403
|
break;
|
|
389
|
-
}
|
|
404
|
+
} //此处判断data中的y是否都为零,方便饼图都为零时展示
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
var arcs = 0;
|
|
408
|
+
data.forEach(function (item) {
|
|
409
|
+
judgeData += item.y;
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
if (judgeData == 0) {
|
|
413
|
+
arcs = arcsFuncTwo(data);
|
|
414
|
+
} else {
|
|
415
|
+
arcs = arcsFunc(data);
|
|
416
|
+
} //const arcs = arcsFunc(data); 此处是原本的传输饼图data流程
|
|
417
|
+
|
|
390
418
|
|
|
391
|
-
var arcs = arcsFunc(data);
|
|
392
419
|
var legendDataWithPercent = (0, _utils.getDataWithPercent)(arcs, legendPrecision);
|
|
393
420
|
|
|
394
421
|
var _legendDataWithPercent = (0, _utils.sortPie)(legendDataWithPercent, order);
|
|
@@ -427,7 +454,7 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
427
454
|
outerRadius: outerRadius
|
|
428
455
|
});
|
|
429
456
|
});
|
|
430
|
-
}, [data, arcsFunc, chart, legendPrecision]);
|
|
457
|
+
}, [data, arcsFunc, arcsFuncTwo, chart, legendPrecision]);
|
|
431
458
|
|
|
432
459
|
var _arcs = (0, _react.useMemo)(function () {
|
|
433
460
|
var seriesLength = series.size;
|
|
@@ -560,10 +587,12 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
560
587
|
config: _objectSpread(_objectSpread({}, label), {}, {
|
|
561
588
|
maxRadius: maxRadius + 2
|
|
562
589
|
}),
|
|
563
|
-
arcs: _arcs
|
|
590
|
+
arcs: _arcs,
|
|
591
|
+
judge: judgeData
|
|
564
592
|
}))), /*#__PURE__*/_react["default"].createElement(_.Legend, (0, _extends2["default"])({}, legend, {
|
|
565
593
|
series: _arcs,
|
|
566
|
-
formatter: formatter
|
|
594
|
+
formatter: formatter,
|
|
595
|
+
judge: judgeData
|
|
567
596
|
}))) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_.ChartContainer, {
|
|
568
597
|
width: width,
|
|
569
598
|
height: height,
|
|
@@ -654,7 +683,8 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
654
683
|
})));
|
|
655
684
|
}), label && /*#__PURE__*/_react["default"].createElement(Label, {
|
|
656
685
|
config: label,
|
|
657
|
-
arcs: _arcs
|
|
686
|
+
arcs: _arcs,
|
|
687
|
+
judge: judgeData
|
|
658
688
|
}), current && /*#__PURE__*/_react["default"].createElement("g", {
|
|
659
689
|
fillOpacity: y,
|
|
660
690
|
style: {
|
|
@@ -665,6 +695,7 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
665
695
|
width: width,
|
|
666
696
|
height: height,
|
|
667
697
|
data: _arcs,
|
|
698
|
+
judge: judgeData,
|
|
668
699
|
currentIndex: +currentIndex
|
|
669
700
|
})))), decorate && /*#__PURE__*/_react["default"].createElement(_.ConicalGradient, {
|
|
670
701
|
width: width,
|
|
@@ -676,7 +707,8 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
676
707
|
radius: radius
|
|
677
708
|
}), /*#__PURE__*/_react["default"].createElement(_.Legend, (0, _extends2["default"])({}, legend, {
|
|
678
709
|
series: _arcs,
|
|
679
|
-
formatter: formatter
|
|
710
|
+
formatter: formatter,
|
|
711
|
+
judge: judgeData
|
|
680
712
|
})));
|
|
681
713
|
});
|
|
682
714
|
|
|
@@ -714,12 +746,20 @@ var Current = function Current(_ref9) {
|
|
|
714
746
|
width = _ref9.width,
|
|
715
747
|
height = _ref9.height,
|
|
716
748
|
data = _ref9.data,
|
|
749
|
+
judge = _ref9.judge,
|
|
717
750
|
currentIndex = _ref9.currentIndex;
|
|
718
751
|
|
|
719
752
|
var _data = (0, _react.useMemo)(function () {
|
|
720
753
|
var legendDataWithPercent = (0, _utils.getDataWithPercent)(data, precision);
|
|
721
754
|
return (0, _utils.sortPie)(legendDataWithPercent, '');
|
|
722
|
-
}, [data, precision]);
|
|
755
|
+
}, [data, precision]); //数据容错,当data都为零那么需要进行以下容错
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
if (judge == 0) {
|
|
759
|
+
_data.forEach(function (d) {
|
|
760
|
+
d.percent = 0, d.value = 0;
|
|
761
|
+
});
|
|
762
|
+
}
|
|
723
763
|
|
|
724
764
|
var currentData = _data[currentIndex];
|
|
725
765
|
if (!currentData) return null;
|
|
@@ -832,13 +872,22 @@ var Label = function Label(_ref10) {
|
|
|
832
872
|
_ref10$config$percent2 = _ref10$config$percent.sameColor,
|
|
833
873
|
percentSameColor = _ref10$config$percent2 === void 0 ? false : _ref10$config$percent2,
|
|
834
874
|
arcs = _ref10.arcs,
|
|
875
|
+
judge = _ref10.judge,
|
|
835
876
|
animation = _ref10.animation;
|
|
836
877
|
|
|
837
878
|
// const [labels, setLabels] = useState(null);
|
|
838
879
|
// const [opacity, setOpacity] = useState(0);
|
|
880
|
+
// console.log('judeg1111',judge)
|
|
839
881
|
var _arcs = (0, _react.useMemo)(function () {
|
|
840
882
|
return (0, _utils.getDataWithPercent)(arcs, precision);
|
|
841
|
-
}, [arcs, precision]);
|
|
883
|
+
}, [arcs, precision]); //数据做出容错
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
if (judge == 0) {
|
|
887
|
+
_arcs.forEach(function (d) {
|
|
888
|
+
d.percent = 0;
|
|
889
|
+
});
|
|
890
|
+
} // useEffect(() => {
|
|
842
891
|
// if (labels) {
|
|
843
892
|
// const children = [...labels.children];
|
|
844
893
|
// const bbox = children.reduce(
|
|
@@ -989,11 +1038,19 @@ var RingLabel = function RingLabel(_ref12) {
|
|
|
989
1038
|
precision = _ref12$config$percent.precision,
|
|
990
1039
|
_ref12$config$percent2 = _ref12$config$percent.sameColor,
|
|
991
1040
|
percentSameColor = _ref12$config$percent2 === void 0 ? false : _ref12$config$percent2,
|
|
1041
|
+
judge = _ref12.judge,
|
|
992
1042
|
arcs = _ref12.arcs;
|
|
993
1043
|
|
|
994
1044
|
var _arcs = (0, _react.useMemo)(function () {
|
|
995
1045
|
return (0, _utils.getDataWithPercent)(arcs, precision);
|
|
996
|
-
}, [arcs, precision]);
|
|
1046
|
+
}, [arcs, precision]); //数据做出容错
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
if (judge == 0) {
|
|
1050
|
+
_arcs.forEach(function (d) {
|
|
1051
|
+
d.percent = 0;
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
997
1054
|
|
|
998
1055
|
return /*#__PURE__*/_react["default"].createElement("g", null, _arcs.map(function (_ref13, index) {
|
|
999
1056
|
var _ref13$series$color = _ref13.series.color,
|
package/package.json
CHANGED
package/src/components/Legend.js
CHANGED
|
@@ -28,6 +28,7 @@ export default memo(
|
|
|
28
28
|
},
|
|
29
29
|
filterData,
|
|
30
30
|
formatter,
|
|
31
|
+
judge
|
|
31
32
|
}) => {
|
|
32
33
|
if (!show) return null;
|
|
33
34
|
const _series = sortPie(series, order);
|
|
@@ -43,6 +44,14 @@ export default memo(
|
|
|
43
44
|
[interactive, filterData]
|
|
44
45
|
);
|
|
45
46
|
|
|
47
|
+
//木然判断数据都为零时做的,此处并不严谨,待想到好方法在进一步解决
|
|
48
|
+
|
|
49
|
+
if (judge == 0) {
|
|
50
|
+
_series.forEach((d) => {
|
|
51
|
+
d.percent=0
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
46
55
|
return (
|
|
47
56
|
<div
|
|
48
57
|
className='__easyv-legend-wrapper'
|
|
@@ -271,6 +271,7 @@ const Component = memo(
|
|
|
271
271
|
onEvent,
|
|
272
272
|
data:originData = [],
|
|
273
273
|
}) => {
|
|
274
|
+
|
|
274
275
|
const data =originData.map(d=>({...d,y:d.y<0?0:d.y}));
|
|
275
276
|
const prevIndex = useRef(null);
|
|
276
277
|
const { precision: legendPrecision } = legend.config.percent;
|
|
@@ -293,7 +294,16 @@ const Component = memo(
|
|
|
293
294
|
.value((d) => d.y);
|
|
294
295
|
return arcsFunc;
|
|
295
296
|
}, [angle]);
|
|
296
|
-
|
|
297
|
+
//此处创建arcsFuncTwo的原因是为了兼容数据全为零
|
|
298
|
+
const arcsFuncTwo = useMemo(() => {
|
|
299
|
+
const { startAngle = 0, endAngle = 360 } = getAngle(angle);
|
|
300
|
+
const arcsFunc = pie()
|
|
301
|
+
.startAngle((startAngle * PI) / 180)
|
|
302
|
+
.endAngle((endAngle * PI) / 180)
|
|
303
|
+
.value((d) => d.y==0?1:d.y);
|
|
304
|
+
return arcsFunc;
|
|
305
|
+
}, [angle]);
|
|
306
|
+
let judgeData = 0 //此处声明全局变量是为了父子组件传递值来判断数据是否都为零
|
|
297
307
|
const arcs = useMemo(() => {
|
|
298
308
|
const _chart = Object.assign(defaultChart, chart);
|
|
299
309
|
const {
|
|
@@ -317,8 +327,22 @@ const Component = memo(
|
|
|
317
327
|
arcsFunc.sort((a, b) => a.y - b.y);
|
|
318
328
|
break;
|
|
319
329
|
}
|
|
330
|
+
|
|
331
|
+
//此处判断data中的y是否都为零,方便饼图都为零时展示
|
|
332
|
+
|
|
333
|
+
let arcs = 0
|
|
334
|
+
data.forEach(function(item){
|
|
335
|
+
judgeData+=item.y
|
|
336
|
+
});
|
|
337
|
+
if (judgeData == 0) {
|
|
338
|
+
arcs = arcsFuncTwo(data)
|
|
339
|
+
|
|
340
|
+
} else {
|
|
341
|
+
arcs = arcsFunc(data)
|
|
342
|
+
}
|
|
343
|
+
|
|
320
344
|
|
|
321
|
-
const arcs = arcsFunc(data);
|
|
345
|
+
//const arcs = arcsFunc(data); 此处是原本的传输饼图data流程
|
|
322
346
|
const legendDataWithPercent = getDataWithPercent(arcs, legendPrecision);
|
|
323
347
|
const _legendDataWithPercent = sortPie(legendDataWithPercent, order);
|
|
324
348
|
|
|
@@ -349,7 +373,7 @@ const Component = memo(
|
|
|
349
373
|
innerRadius,
|
|
350
374
|
outerRadius,
|
|
351
375
|
}));
|
|
352
|
-
}, [data, arcsFunc, chart, legendPrecision]);
|
|
376
|
+
}, [data, arcsFunc,arcsFuncTwo, chart, legendPrecision]);
|
|
353
377
|
|
|
354
378
|
const _arcs = useMemo(() => {
|
|
355
379
|
const seriesLength = series.size;
|
|
@@ -516,11 +540,12 @@ const Component = memo(
|
|
|
516
540
|
<RingLabel
|
|
517
541
|
config={{ ...label, maxRadius: maxRadius + 2 }}
|
|
518
542
|
arcs={_arcs}
|
|
543
|
+
judge={judgeData}
|
|
519
544
|
/>
|
|
520
545
|
)}
|
|
521
546
|
</g>
|
|
522
547
|
</ChartContainer>
|
|
523
|
-
<Legend {...legend} series={_arcs} formatter={formatter} />
|
|
548
|
+
<Legend {...legend} series={_arcs} formatter={formatter} judge = {judgeData}/>
|
|
524
549
|
</>
|
|
525
550
|
) : (
|
|
526
551
|
<>
|
|
@@ -669,6 +694,7 @@ const Component = memo(
|
|
|
669
694
|
)
|
|
670
695
|
}
|
|
671
696
|
<defs>
|
|
697
|
+
{/* 此处是环的发生地 */}
|
|
672
698
|
<LinearGradient
|
|
673
699
|
id={id}
|
|
674
700
|
colors={current ? currentPie : pie}
|
|
@@ -686,7 +712,7 @@ const Component = memo(
|
|
|
686
712
|
);
|
|
687
713
|
}
|
|
688
714
|
)}
|
|
689
|
-
{label && <Label config={label} arcs={_arcs} />}
|
|
715
|
+
{label && <Label config={label} arcs={_arcs} judge = {judgeData} />}
|
|
690
716
|
{current && (
|
|
691
717
|
<g
|
|
692
718
|
fillOpacity={y}
|
|
@@ -697,6 +723,7 @@ const Component = memo(
|
|
|
697
723
|
width={width}
|
|
698
724
|
height={height}
|
|
699
725
|
data={_arcs}
|
|
726
|
+
judge = {judgeData}
|
|
700
727
|
currentIndex={+currentIndex}
|
|
701
728
|
/>
|
|
702
729
|
</g>
|
|
@@ -714,7 +741,7 @@ const Component = memo(
|
|
|
714
741
|
radius={radius}
|
|
715
742
|
/>
|
|
716
743
|
)}
|
|
717
|
-
<Legend {...legend} series={_arcs} formatter={formatter} />
|
|
744
|
+
<Legend {...legend} series={_arcs} formatter={formatter} judge = {judgeData} />
|
|
718
745
|
</>
|
|
719
746
|
);
|
|
720
747
|
}
|
|
@@ -744,16 +771,28 @@ const Current = ({
|
|
|
744
771
|
translate: { x: translateSuffixX, y: translateSuffixY },
|
|
745
772
|
},
|
|
746
773
|
},
|
|
774
|
+
|
|
747
775
|
},
|
|
748
776
|
width,
|
|
749
777
|
height,
|
|
750
778
|
data,
|
|
779
|
+
judge,
|
|
751
780
|
currentIndex,
|
|
752
781
|
}) => {
|
|
753
782
|
const _data = useMemo(() => {
|
|
754
783
|
const legendDataWithPercent = getDataWithPercent(data, precision);
|
|
755
784
|
return sortPie(legendDataWithPercent, '');
|
|
756
785
|
}, [data, precision]);
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
//数据容错,当data都为零那么需要进行以下容错
|
|
789
|
+
if (judge == 0) {
|
|
790
|
+
_data.forEach((d) => {
|
|
791
|
+
d.percent = 0, d.value = 0
|
|
792
|
+
|
|
793
|
+
})
|
|
794
|
+
}
|
|
795
|
+
|
|
757
796
|
const currentData = _data[currentIndex];
|
|
758
797
|
|
|
759
798
|
if (!currentData) return null;
|
|
@@ -903,15 +942,24 @@ const Label = ({
|
|
|
903
942
|
},
|
|
904
943
|
},
|
|
905
944
|
arcs,
|
|
945
|
+
judge,
|
|
906
946
|
animation,
|
|
907
947
|
}) => {
|
|
908
948
|
// const [labels, setLabels] = useState(null);
|
|
909
949
|
// const [opacity, setOpacity] = useState(0);
|
|
910
|
-
|
|
950
|
+
// console.log('judeg1111',judge)
|
|
911
951
|
const _arcs = useMemo(
|
|
912
952
|
() => getDataWithPercent(arcs, precision),
|
|
913
953
|
[arcs, precision]
|
|
914
954
|
);
|
|
955
|
+
|
|
956
|
+
//数据做出容错
|
|
957
|
+
if (judge == 0) {
|
|
958
|
+
_arcs.forEach((d) => {
|
|
959
|
+
d.percent=0
|
|
960
|
+
})
|
|
961
|
+
}
|
|
962
|
+
|
|
915
963
|
// useEffect(() => {
|
|
916
964
|
// if (labels) {
|
|
917
965
|
// const children = [...labels.children];
|
|
@@ -1121,12 +1169,20 @@ const RingLabel = ({
|
|
|
1121
1169
|
sameColor: percentSameColor = false,
|
|
1122
1170
|
},
|
|
1123
1171
|
},
|
|
1172
|
+
judge,
|
|
1124
1173
|
arcs,
|
|
1125
1174
|
}) => {
|
|
1126
1175
|
const _arcs = useMemo(
|
|
1127
1176
|
() => getDataWithPercent(arcs, precision),
|
|
1128
1177
|
[arcs, precision]
|
|
1129
1178
|
);
|
|
1179
|
+
|
|
1180
|
+
//数据做出容错
|
|
1181
|
+
if (judge == 0) {
|
|
1182
|
+
_arcs.forEach((d) => {
|
|
1183
|
+
d.percent=0
|
|
1184
|
+
})
|
|
1185
|
+
}
|
|
1130
1186
|
|
|
1131
1187
|
return (
|
|
1132
1188
|
<g>
|