@easyv/charts 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,35 +39,35 @@ const defaultChart = {
39
39
  const defaultAngle = { startAngle: 0, endAngle: 360, antiClockwise: false };
40
40
 
41
41
  const nameDy = (showValue, showPercent, mode, dir) => {
42
- if(showValue||showPercent){
43
- if(mode=="vertical"){
44
- return dir==1?"1.1em":"-2.6em"
45
- }else{
46
- return 0
42
+ if (showValue || showPercent) {
43
+ if (mode == 'vertical') {
44
+ return dir == 1 ? '1.1em' : '-2.6em';
45
+ } else {
46
+ return 0;
47
47
  }
48
- }else{
49
- if(mode=="vertical"){
50
- return dir*1.1+"em"
51
- }else{
52
- return 0
48
+ } else {
49
+ if (mode == 'vertical') {
50
+ return dir * 1.1 + 'em';
51
+ } else {
52
+ return 0;
53
53
  }
54
54
  }
55
- }
56
- const valueDy = (value1, mode, dir)=>{
57
- if(value1){
58
- if(mode=="vertical"){
59
- return "1.5em"
60
- }else{
61
- return 0
55
+ };
56
+ const valueDy = (value1, mode, dir) => {
57
+ if (value1) {
58
+ if (mode == 'vertical') {
59
+ return '1.5em';
60
+ } else {
61
+ return 0;
62
62
  }
63
- }else{
64
- if(mode=="vertical"){
65
- return dir==1?"1.1em":"-1.1em"
66
- }else{
67
- return 0
63
+ } else {
64
+ if (mode == 'vertical') {
65
+ return dir == 1 ? '1.1em' : '-1.1em';
66
+ } else {
67
+ return 0;
68
68
  }
69
69
  }
70
- }
70
+ };
71
71
 
72
72
  const percentDy_ = (showName, showValue, mode, dir) => {
73
73
  if (showValue) {
@@ -81,7 +81,7 @@ const percentDy_ = (showName, showValue, mode, dir) => {
81
81
  }
82
82
  } else {
83
83
  if (mode == 'vertical') {
84
- return dir*1.1+'em';
84
+ return dir * 1.1 + 'em';
85
85
  } else {
86
86
  return 0;
87
87
  }
@@ -192,41 +192,41 @@ const getArc = (
192
192
  .padAngle(padAngle),
193
193
  });
194
194
 
195
- const getCircleScale = ({ count, color, width, length }=tick, radius)=>{
195
+ const getCircleScale = ({ count, color, width, length } = tick, radius) => {
196
196
  let data = [],
197
- arcs = [],
198
- centroids = [];
199
- for (let i = 0; i < count; i++) {
200
- data.push(1);
201
- }
202
- let scaleData = pie()(data);
203
- scaleData.map((data) => {
204
- let _arc = arc()
205
- .innerRadius(radius + length/2)
206
- .outerRadius(radius + length/2)
207
- .startAngle(data.startAngle)
208
- .endAngle(data.endAngle);
209
- arcs.push(_arc());
210
- centroids.push(_arc.centroid());
211
- });
212
- return (
213
- <g>
214
- {centroids.map((center, index) => {
215
- let x = center[0],
216
- y = center[1];
217
- let rate = length / Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
218
- return (
219
- <path
220
- key={index}
221
- d={`M${x},${y}l${x * rate},${y * rate}`}
222
- strokeWidth={width}
223
- stroke={color}
224
- />
225
- );
226
- })}
227
- </g>
228
- );
229
- }
197
+ arcs = [],
198
+ centroids = [];
199
+ for (let i = 0; i < count; i++) {
200
+ data.push(1);
201
+ }
202
+ let scaleData = pie()(data);
203
+ scaleData.map((data) => {
204
+ let _arc = arc()
205
+ .innerRadius(radius + length / 2)
206
+ .outerRadius(radius + length / 2)
207
+ .startAngle(data.startAngle)
208
+ .endAngle(data.endAngle);
209
+ arcs.push(_arc());
210
+ centroids.push(_arc.centroid());
211
+ });
212
+ return (
213
+ <g>
214
+ {centroids.map((center, index) => {
215
+ let x = center[0],
216
+ y = center[1];
217
+ let rate = length / Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
218
+ return (
219
+ <path
220
+ key={index}
221
+ d={`M${x},${y}l${x * rate},${y * rate}`}
222
+ strokeWidth={width}
223
+ stroke={color}
224
+ />
225
+ );
226
+ })}
227
+ </g>
228
+ );
229
+ };
230
230
 
231
231
  const Component = memo(
232
232
  ({
@@ -241,7 +241,7 @@ const Component = memo(
241
241
  },
242
242
  fan: {
243
243
  chart = defaultChart,
244
- chart: { outerRadius = defaultChart.outerRadius,padAngle },
244
+ chart: { outerRadius = defaultChart.outerRadius, padAngle },
245
245
  angle = defaultAngle,
246
246
  stroke: { show, strokeWidth, color } = { show: false },
247
247
  decorate,
@@ -254,8 +254,15 @@ const Component = memo(
254
254
  series,
255
255
  animation: {
256
256
  on,
257
- current: { heighten=0, opacity=0, width:radiusWidthAdd=0, color:animateColor, textStyle:animateCTS, gap=0 },
258
- rotate = 0
257
+ current: {
258
+ heighten = 0,
259
+ opacity = 0,
260
+ width: radiusWidthAdd = 0,
261
+ color: animateColor,
262
+ textStyle: animateCTS,
263
+ gap = 0,
264
+ },
265
+ rotate = 0,
259
266
  },
260
267
  },
261
268
  state: { currentIndex, trigger },
@@ -416,15 +423,20 @@ const Component = memo(
416
423
  const halfChartWidth = chartWidth / 2;
417
424
  const halfChartHeight = chartHeight / 2;
418
425
 
419
- const rotate_ = decorate2?-(arcs[+currentIndex].startAngle+arcs[+currentIndex].endAngle)*90/Math.PI+rotate:0;
426
+ const rotate_ = decorate2
427
+ ? (-(arcs[+currentIndex].startAngle + arcs[+currentIndex].endAngle) *
428
+ 90) /
429
+ Math.PI +
430
+ rotate
431
+ : 0;
420
432
  let maxRadius = 0;
421
- _arcs.map(d=>{
422
- maxRadius=Math.max(maxRadius,d.outerRadius);
423
- })
424
- let centerRadius =0.5*maxRadius + 0.5*_arcs[0].innerRadius
425
- return (
426
- outerDecorate?<>
427
- <ChartContainer //用于生成甜甜圈图,判断依据是外环装饰这个配置项(outerDecorate)
433
+ _arcs.map((d) => {
434
+ maxRadius = Math.max(maxRadius, d.outerRadius);
435
+ });
436
+ let centerRadius = 0.5 * maxRadius + 0.5 * _arcs[0].innerRadius;
437
+ return outerDecorate ? (
438
+ <>
439
+ <ChartContainer //用于生成甜甜圈图,判断依据是外环装饰这个配置项(outerDecorate)
428
440
  width={width}
429
441
  height={height}
430
442
  marginLeft={marginLeft}
@@ -432,67 +444,93 @@ const Component = memo(
432
444
  >
433
445
  <g
434
446
  style={{
435
- transition:"transform ease-in-out 0.3s",
436
- transform:'translate(' + halfChartWidth + 'px, ' + halfChartHeight + 'px) rotate('+rotate_+"deg)"
447
+ transition: 'transform ease-in-out 0.3s',
448
+ transform:
449
+ 'translate(' +
450
+ halfChartWidth +
451
+ 'px, ' +
452
+ halfChartHeight +
453
+ 'px) rotate(' +
454
+ rotate_ +
455
+ 'deg)',
437
456
  }}
438
457
  >
439
458
  {
440
459
  //用于生成外环装饰的刻度
441
- outerDecorate.tick.show && getCircleScale(outerDecorate.tick, maxRadius)
460
+ outerDecorate.tick.show &&
461
+ getCircleScale(outerDecorate.tick, maxRadius)
442
462
  }
443
- <circle //外环装饰
463
+ <circle //外环装饰
444
464
  cx='0'
445
465
  cy='0'
446
- r={maxRadius+2}
466
+ r={maxRadius + 2}
447
467
  fill='none'
448
468
  stroke={outerDecorate.color}
449
469
  strokeWidth={outerDecorate.width}
450
470
  />
451
- {
452
- _arcs.map(
453
- ({ id, value, series, arc, innerRadius, outerRadius, index: dataIndex }, index) => {
454
- const arcWidth = (outerRadius-innerRadius);
455
- const path = arc
456
- .innerRadius(centerRadius)
457
- .outerRadius(centerRadius)(value);
458
- const dashLength=Math.ceil(Math.PI*(centerRadius)*2/_arcs.length);
459
- const pie = getColorList(series.color);
460
- return (
461
- <Fragment key={index}>
462
- <path
463
- className={ringCss['inner-arc']}
464
- style={{
465
- strokeDasharray:`${dashLength},${2*dashLength}`,
466
- strokeDashoffset: dashLength,
467
- animationDelay: `${index * 2000}ms`
468
- }}
469
- data-index={dataIndex}
470
- onClick={onClick}
471
- onMouseEnter={onMouseEnter}
472
- onMouseLeave={onMouseLeave}
473
- d={path.split("L")[0]}
474
- stroke={'url(#' + id + ')'}
475
- strokeWidth={arcWidth}
476
- fill="none"
471
+ {_arcs.map(
472
+ (
473
+ {
474
+ id,
475
+ value,
476
+ series,
477
+ arc,
478
+ innerRadius,
479
+ outerRadius,
480
+ index: dataIndex,
481
+ },
482
+ index
483
+ ) => {
484
+ const arcWidth = outerRadius - innerRadius;
485
+ const path = arc
486
+ .innerRadius(centerRadius)
487
+ .outerRadius(centerRadius)(value);
488
+ const dashLength = Math.ceil(
489
+ (Math.PI * centerRadius * 2) / _arcs.length
490
+ );
491
+ const pie = getColorList(series.color);
492
+ return (
493
+ <Fragment key={index}>
494
+ <path
495
+ className={ringCss['inner-arc']}
496
+ style={{
497
+ strokeDasharray: `${dashLength},${2 * dashLength}`,
498
+ strokeDashoffset: dashLength,
499
+ animationDelay: `${index * 2000}ms`,
500
+ }}
501
+ data-index={dataIndex}
502
+ onClick={onClick}
503
+ onMouseEnter={onMouseEnter}
504
+ onMouseLeave={onMouseLeave}
505
+ d={path.split('L')[0]}
506
+ stroke={'url(#' + id + ')'}
507
+ strokeWidth={arcWidth}
508
+ fill='none'
509
+ />
510
+ <defs>
511
+ <LinearGradient
512
+ id={id}
513
+ colors={pie}
514
+ rotate={series.color.linear.angle + 180}
515
+ // gradientUnits='objectBoundingBox'
477
516
  />
478
- <defs>
479
- <LinearGradient
480
- id={id}
481
- colors={pie}
482
- rotate={series.color.linear.angle + 180}
483
- // gradientUnits='objectBoundingBox'
484
- />
485
- </defs>
486
- </Fragment>
487
- );
488
- }
489
- )
490
- }
491
- {label && <RingLabel config={{...label,maxRadius: maxRadius+2}} arcs={_arcs}/>}
517
+ </defs>
518
+ </Fragment>
519
+ );
520
+ }
521
+ )}
522
+ {label && (
523
+ <RingLabel
524
+ config={{ ...label, maxRadius: maxRadius + 2 }}
525
+ arcs={_arcs}
526
+ />
527
+ )}
492
528
  </g>
493
529
  </ChartContainer>
494
- <Legend {...legend} series={_arcs} formatter={formatter}/>
495
- </> : <>
530
+ <Legend {...legend} series={_arcs} formatter={formatter} />
531
+ </>
532
+ ) : (
533
+ <>
496
534
  <ChartContainer
497
535
  width={width}
498
536
  height={height}
@@ -501,31 +539,67 @@ const Component = memo(
501
539
  >
502
540
  <g
503
541
  style={{
504
- transition:"transform ease-in-out 0.3s",
505
- transform:'translate(' + halfChartWidth + 'px, ' + halfChartHeight + 'px) rotate('+rotate_+"deg)"
542
+ transition: 'transform ease-in-out 0.3s',
543
+ transform:
544
+ 'translate(' +
545
+ halfChartWidth +
546
+ 'px, ' +
547
+ halfChartHeight +
548
+ 'px) rotate(' +
549
+ rotate_ +
550
+ 'deg)',
506
551
  }}
507
552
  >
508
553
  {_arcs.map(
509
- ({ id, value, series, arc, innerRadius, outerRadius, index: dataIndex }, index) => {
554
+ (
555
+ {
556
+ id,
557
+ value,
558
+ series,
559
+ arc,
560
+ innerRadius,
561
+ outerRadius,
562
+ index: dataIndex,
563
+ },
564
+ index
565
+ ) => {
510
566
  const current = index == currentIndex;
511
567
  const prev = index == prevIndex.current;
512
568
  const offset = current ? y : prev ? 1 - y : 0;
513
569
 
514
- const fillOpacity = animateColor?1:(current ? opacity / 100 : 1);
515
- const deltaHeighten= offset*heighten;
570
+ const fillOpacity = animateColor
571
+ ? 1
572
+ : current
573
+ ? opacity / 100
574
+ : 1;
575
+ const deltaHeighten = offset * heighten;
516
576
  const path = arc
517
577
  .innerRadius(innerRadius + deltaHeighten)
518
578
  .outerRadius(outerRadius + deltaHeighten)(value);
519
579
  const pie = getColorList(series.color);
520
- const currentPie = animateColor?getColorList(animateColor):getColorList(series.color);
521
- let textPath="",categoryTextStyle={};
522
- if(categoryText && categoryText.show){ //如果有类目文本,则需要计算文字路径
580
+ const currentPie = animateColor
581
+ ? getColorList(animateColor)
582
+ : getColorList(series.color);
583
+ let textPath = '',
584
+ categoryTextStyle = {};
585
+ if (categoryText && categoryText.show) {
586
+ //如果有类目文本,则需要计算文字路径
523
587
  //let offsetWidth=decorate2.radiusWidth/2 + radiusWidthAdd/2; //当前文字需生成在装饰物内,故而半径需要减小
524
- let textArc=arc.innerRadius(outerRadius+(current?gap:categoryText.gap))
525
- .outerRadius(outerRadius+(current?gap:categoryText.gap))(value);
526
- let lastA=textArc.lastIndexOf('A');
527
- textPath=textArc.slice(0, lastA > 0 ? lastA : textArc.length); //文字路径
528
- categoryTextStyle=current?animateCTS:categoryText.textStyle; //这里把textstyle拿出来
588
+ let textArc = arc
589
+ .innerRadius(
590
+ outerRadius + (current ? gap : categoryText.gap)
591
+ )
592
+ .outerRadius(
593
+ outerRadius + (current ? gap : categoryText.gap)
594
+ )(value);
595
+ let lastA = textArc.lastIndexOf('A');
596
+ textPath = textArc.slice(
597
+ 0,
598
+ lastA > 0 ? lastA : textArc.length
599
+ ); //文字路径
600
+ categoryTextStyle = current
601
+ ? animateCTS
602
+ : categoryText.textStyle; //这里把textstyle拿出来
529
603
  }
530
604
 
531
605
  return (
@@ -541,56 +615,77 @@ const Component = memo(
541
615
  fill={'url(#' + id + ')'}
542
616
  fillOpacity={fillOpacity}
543
617
  />
544
- { //装饰物2,产生于每个弧的外部
545
- decorate2 && decorate2.show &&
546
- <path
547
- data-index={dataIndex}
548
- onClick={onClick}
549
- onMouseEnter={onMouseEnter}
550
- onMouseLeave={onMouseLeave}
551
- d={arc.innerRadius(outerRadius)
552
- .outerRadius(outerRadius + decorate2.radiusWidth + (current?radiusWidthAdd:0))(value)}
553
- stroke={show ? color : 'none'}
554
- strokeWidth={show ? strokeWidth : '0'}
555
- fill={'url(#' + id + ')'}
556
- fillOpacity={decorate2.opacity/100}
557
- />
558
- }
559
- { //类目文本
560
- categoryText && categoryText.show &&<g>
618
+ {
619
+ //装饰物2,产生于每个弧的外部
620
+ decorate2 && decorate2.show && (
561
621
  <path
622
+ data-index={dataIndex}
562
623
  onClick={onClick}
563
624
  onMouseEnter={onMouseEnter}
564
625
  onMouseLeave={onMouseLeave}
565
- id={id + '_text_' + index}
566
- d={textPath}
567
- fill='none'
568
- stroke='none'
626
+ d={arc
627
+ .innerRadius(outerRadius)
628
+ .outerRadius(
629
+ outerRadius +
630
+ decorate2.radiusWidth +
631
+ (current ? radiusWidthAdd : 0)
632
+ )(value)}
633
+ stroke={show ? color : 'none'}
634
+ strokeWidth={show ? strokeWidth : '0'}
635
+ fill={'url(#' + id + ')'}
636
+ fillOpacity={decorate2.opacity / 100}
569
637
  />
570
- <text
571
- textAnchor='middle'
572
- style={{
573
- ...categoryTextStyle,
574
- fontWeight:categoryTextStyle.bold?"bold":"normal",
575
- fontStyle:categoryTextStyle.italic?"italic":"normal",
576
- pointerEvents:"none"
577
- }}
578
- fill={categoryTextStyle.color}
579
- >
580
- <textPath
581
- startOffset='50%'
582
- href={'#' + id + '_text_' + index}
638
+ )
639
+ }
640
+ {
641
+ //类目文本
642
+ categoryText && categoryText.show && (
643
+ <g>
644
+ <path
645
+ onClick={onClick}
646
+ onMouseEnter={onMouseEnter}
647
+ onMouseLeave={onMouseLeave}
648
+ id={id + '_text_' + index}
649
+ d={textPath}
650
+ fill='none'
651
+ stroke='none'
652
+ />
653
+ <text
654
+ textAnchor='middle'
655
+ style={{
656
+ ...categoryTextStyle,
657
+ fontWeight: categoryTextStyle.bold
658
+ ? 'bold'
659
+ : 'normal',
660
+ fontStyle: categoryTextStyle.italic
661
+ ? 'italic'
662
+ : 'normal',
663
+ pointerEvents: 'none',
664
+ }}
665
+ fill={categoryTextStyle.color}
583
666
  >
584
- {_arcs[index].displayName || _arcs[index].fieldName}
585
- </textPath>
586
- </text>
587
- </g>
667
+ <textPath
668
+ startOffset='50%'
669
+ href={'#' + id + '_text_' + index}
670
+ >
671
+ {_arcs[index].displayName ||
672
+ _arcs[index].fieldName}
673
+ </textPath>
674
+ </text>
675
+ </g>
676
+ )
588
677
  }
589
678
  <defs>
590
679
  <LinearGradient
591
680
  id={id}
592
- colors={current?currentPie:pie}
593
- rotate={current?(animateColor?animateColor.linear.angle + 180:series.color.linear.angle + 180):series.color.linear.angle + 180}
681
+ colors={current ? currentPie : pie}
682
+ rotate={
683
+ current
684
+ ? animateColor
685
+ ? animateColor.linear.angle + 180
686
+ : series.color.linear.angle + 180
687
+ : series.color.linear.angle + 180
688
+ }
594
689
  // gradientUnits='objectBoundingBox'
595
690
  />
596
691
  </defs>
@@ -600,7 +695,10 @@ const Component = memo(
600
695
  )}
601
696
  {label && <Label config={label} arcs={_arcs} />}
602
697
  {current && (
603
- <g fillOpacity={y} style={{ transform:"rotate("+(-rotate_)+"deg)" }}>
698
+ <g
699
+ fillOpacity={y}
700
+ style={{ transform: 'rotate(' + -rotate_ + 'deg)' }}
701
+ >
604
702
  <Current
605
703
  config={current}
606
704
  width={width}
@@ -633,15 +731,17 @@ const Current = ({
633
731
  config: {
634
732
  show,
635
733
  gap,
636
- name: { show: showName, font: nameFont, textBreak },
734
+ name: { show: showName, sameColor: nameColor, font: nameFont, textBreak },
637
735
  percent: {
638
736
  show: showPercent,
737
+ sameColor: percentColor,
639
738
  font: percentFont,
640
739
  precision,
641
740
  translate: { x: translatePercentX, y: translatePercentY },
642
741
  },
643
742
  value: {
644
743
  show: showValue,
744
+ sameColor: valueColor,
645
745
  font: valueFont,
646
746
  translate: { x: translateValueX, y: translateValueY },
647
747
  suffix: {
@@ -666,80 +766,114 @@ const Current = ({
666
766
  if (!currentData) return null;
667
767
 
668
768
  const { displayName, fieldName, value, percent } = currentData;
669
- let nameTemp = displayName? displayName : fieldName; //类目名
769
+ let nameTemp = displayName ? displayName : fieldName; //类目名
670
770
  let nameList = [];
671
- if(textBreak){ //如果限制了首行字符,则切割组件
672
- while(nameTemp.length>textBreak){
673
- nameList.push(nameTemp.slice(0,textBreak));
674
- nameTemp = nameTemp.slice(textBreak)
771
+ if (textBreak) {
772
+ //如果限制了首行字符,则切割组件
773
+ while (nameTemp.length > textBreak) {
774
+ nameList.push(nameTemp.slice(0, textBreak));
775
+ nameTemp = nameTemp.slice(textBreak);
675
776
  }
676
777
  }
677
- nameList.push(nameTemp)
678
- let foreignStyle={ //foreignObject标签样式,
679
- width,
680
- height,
681
- transform:`translate(-${width/2}px,-${height/2}px)`,
682
- pointerEvents:"none"
683
- },
684
- boxStyle={ //弹性盒子样式,用于当前值的上下居中对齐等
685
- width,
686
- height,
687
- display:"flex",
688
- flexDirection:"column",
689
- justifyContent:"center",
690
- alignItems:"center"
691
- }
692
-
778
+ nameList.push(nameTemp);
779
+ let foreignStyle = {
780
+ //foreignObject标签样式,
781
+ width,
782
+ height,
783
+ transform: `translate(-${width / 2}px,-${height / 2}px)`,
784
+ pointerEvents: 'none',
785
+ },
786
+ boxStyle = {
787
+ //弹性盒子样式,用于当前值的上下居中对齐等
788
+ width,
789
+ height,
790
+ display: 'flex',
791
+ flexDirection: 'column',
792
+ justifyContent: 'center',
793
+ alignItems: 'center',
794
+ };
795
+ let seriesColor = currentData.series.color;
796
+ seriesColor =
797
+ seriesColor.type == 'pure'
798
+ ? seriesColor.pure
799
+ : seriesColor.linear.stops[0].color;
693
800
  return (
694
801
  show && (
695
802
  <foreignObject style={foreignStyle}>
696
803
  <div style={boxStyle}>
697
- { //类目名称
698
- showName && <div
699
- style={{
700
- ...getFontStyle(nameFont),
701
- margin:gap/2+"px 0",
702
- display:"flex",
703
- flexDirection:"column",
704
- alignItems:"center"
705
- }}>
706
- {
707
- nameList.map((d,i)=>{
708
- return <span key={i}>{d}</span>
709
- })
710
- }
711
- </div>
804
+ {
805
+ //类目名称
806
+ showName && (
807
+ <div
808
+ style={{
809
+ ...getFontStyle(nameFont),
810
+ margin: gap / 2 + 'px 0',
811
+ display: 'flex',
812
+ flexDirection: 'column',
813
+ alignItems: 'center',
814
+ color: nameColor ? seriesColor : nameFont.color,
815
+ }}
816
+ >
817
+ {nameList.map((d, i) => {
818
+ return <span key={i}>{d}</span>;
819
+ })}
820
+ </div>
821
+ )
712
822
  }
713
- { //真实值
714
- showValue && <span
715
- style={{
716
- ...getFontStyle(valueFont),
717
- transform:"translate("+translateValueX+"px,"+translateValueY+"px)",
718
- margin:gap/2+"px 0"
719
- }}>
720
- {value}
721
- {showSuffix && text && (
722
- <span
723
- style={{
724
- transform:"translate("+translateSuffixX+"px,"+translateSuffixY+"px)",
725
- fontSize:fontSize
726
- }}
727
- >
728
- {text}
729
- </span>
730
- )}
731
- </span>
823
+ {
824
+ //真实值
825
+ showValue && (
826
+ <span
827
+ style={{
828
+ ...getFontStyle(valueFont),
829
+ transform:
830
+ 'translate(' +
831
+ translateValueX +
832
+ 'px,' +
833
+ translateValueY +
834
+ 'px)',
835
+ margin: gap / 2 + 'px 0',
836
+ color: valueColor ? seriesColor : valueFont.color,
837
+ }}
838
+ >
839
+ {value}
840
+ {showSuffix && text && (
841
+ <span
842
+ style={{
843
+ transform:
844
+ 'translate(' +
845
+ translateSuffixX +
846
+ 'px,' +
847
+ translateSuffixY +
848
+ 'px)',
849
+ fontSize: fontSize,
850
+ }}
851
+ >
852
+ {text}
853
+ </span>
854
+ )}
855
+ </span>
856
+ )
732
857
  }
733
- { //百分比值
734
- showPercent && <span
735
- style={{
736
- transform:"translate("+translatePercentX+"px,"+translatePercentY+"px)",
737
- ...getFontStyle(percentFont),
738
- margin:gap/2+"px 0"
739
- }}
740
- >
741
- {percent + '%'}
742
- </span>
858
+ {
859
+ //百分比值
860
+ showPercent && (
861
+ <span
862
+ style={{
863
+ transform:
864
+ 'translate(' +
865
+ translatePercentX +
866
+ 'px,' +
867
+ translatePercentY +
868
+ 'px)',
869
+ ...getFontStyle(percentFont),
870
+ margin: gap / 2 + 'px 0',
871
+ color: percentColor ? seriesColor : percentFont.color,
872
+ }}
873
+ >
874
+ {percent + '%'}
875
+ </span>
876
+ )
743
877
  }
744
878
  </div>
745
879
  </foreignObject>
@@ -776,9 +910,9 @@ const Label = ({
776
910
  },
777
911
  },
778
912
  arcs,
779
- animation
913
+ animation,
780
914
  }) => {
781
- // const [labels, setLabels] = useState(null);
915
+ // const [labels, setLabels] = useState(null);
782
916
  // const [opacity, setOpacity] = useState(0);
783
917
 
784
918
  const _arcs = useMemo(
@@ -825,8 +959,8 @@ const Label = ({
825
959
 
826
960
  return (
827
961
  <g
828
- // style={{ opacity }} ref={setLabels}
829
- >
962
+ // style={{ opacity }} ref={setLabels}
963
+ >
830
964
  {_arcs.map(
831
965
  (
832
966
  {
@@ -842,22 +976,24 @@ const Label = ({
842
976
  percent,
843
977
  arc,
844
978
  outerRadius,
845
- index:actualIndex
979
+ index: actualIndex,
846
980
  },
847
981
  index
848
982
  ) => {
849
-
850
983
  const [x, y] = arc.centroid();
851
984
  const midAngle = Math.atan2(y, x);
852
985
 
853
- const [x1, y1] = getCoord(midAngle, maxRadius?maxRadius:outerRadius);
986
+ const [x1, y1] = getCoord(
987
+ midAngle,
988
+ maxRadius ? maxRadius : outerRadius
989
+ );
854
990
 
855
- const radius = (maxRadius?maxRadius:outerRadius) + distance;
991
+ const radius = (maxRadius ? maxRadius : outerRadius) + distance;
856
992
  const [x2, y2] = getCoord(midAngle, radius);
857
-
993
+
858
994
  const direction = x2 < 0 ? -1 : 1;
859
995
  const x3 = x2 + lineLength * direction;
860
-
996
+
861
997
  const _x = x3 + (translateX + 6) * direction;
862
998
 
863
999
  const _showName = showName && displayName;
@@ -868,19 +1004,42 @@ const Label = ({
868
1004
  (_showName || showPercent || showValue) && (
869
1005
  <g key={index}>
870
1006
  <path
871
- className={animation? ringCss['label-line']:""}
872
- style={{ animationDelay:`${animation? ((actualIndex+1) * 2000 - 800) : 0}ms`}}
1007
+ className={animation ? ringCss['label-line'] : ''}
1008
+ style={{
1009
+ animationDelay: `${
1010
+ animation ? (actualIndex + 1) * 2000 - 800 : 0
1011
+ }ms`,
1012
+ }}
873
1013
  d={
874
- 'M' + x1 + ', ' + y1 + 'L' +
875
- x2 + ', ' + y2 + 'L' +
876
- x3 + ', ' + y2
1014
+ 'M' +
1015
+ x1 +
1016
+ ', ' +
1017
+ y1 +
1018
+ 'L' +
1019
+ x2 +
1020
+ ', ' +
1021
+ y2 +
1022
+ 'L' +
1023
+ x3 +
1024
+ ', ' +
1025
+ y2
1026
+ }
1027
+ stroke={
1028
+ lineColor
1029
+ ? lineColor
1030
+ : type == 'pure'
1031
+ ? pure
1032
+ : stops[0].color
877
1033
  }
878
- stroke={lineColor?lineColor:(type == 'pure' ? pure : stops[0].color)}
879
1034
  fill='none'
880
1035
  />
881
1036
  <text
882
- className={animation? ringCss['label-text']:""}
883
- style={{ animationDelay:`${animation? ((actualIndex+1) * 2000 - 800) : 0}ms`}}
1037
+ className={animation ? ringCss['label-text'] : ''}
1038
+ style={{
1039
+ animationDelay: `${
1040
+ animation ? (actualIndex + 1) * 2000 - 800 : 0
1041
+ }ms`,
1042
+ }}
884
1043
  x={_x}
885
1044
  y={y2 + translateY}
886
1045
  dominantBaseline='middle'
@@ -921,7 +1080,7 @@ const Label = ({
921
1080
  dx={percentDx(_showName, _showValue, mode)}
922
1081
  dy={
923
1082
  percentDy(_showName, _showValue, mode) +
924
- (_showValue && showSuffix ? suffixTranslateY * -1 : "")
1083
+ (_showValue && showSuffix ? suffixTranslateY * -1 : '')
925
1084
  }
926
1085
  style={getFontStyle(percentFont, 'svg')}
927
1086
  >
@@ -941,7 +1100,7 @@ const Label = ({
941
1100
  );
942
1101
  };
943
1102
 
944
- const RingLabel =({
1103
+ const RingLabel = ({
945
1104
  config: {
946
1105
  maxRadius = 0,
947
1106
  lineLength,
@@ -969,13 +1128,13 @@ const RingLabel =({
969
1128
  sameColor: percentSameColor = false,
970
1129
  },
971
1130
  },
972
- arcs
1131
+ arcs,
973
1132
  }) => {
974
1133
  const _arcs = useMemo(
975
1134
  () => getDataWithPercent(arcs, precision),
976
1135
  [arcs, precision]
977
1136
  );
978
-
1137
+
979
1138
  return (
980
1139
  <g>
981
1140
  {_arcs.map(
@@ -988,31 +1147,33 @@ const RingLabel =({
988
1147
  linear: { stops },
989
1148
  },
990
1149
  },
991
- data:realData,
1150
+ data: realData,
992
1151
  displayName,
993
1152
  value,
994
1153
  percent,
995
1154
  arc,
996
1155
  outerRadius,
997
- index:actualIndex
1156
+ index: actualIndex,
998
1157
  },
999
1158
  index
1000
1159
  ) => {
1001
-
1002
1160
  const [x, y] = arc.centroid();
1003
-
1161
+
1004
1162
  const midAngle = Math.atan2(y, x);
1005
1163
 
1006
- const [x1, y1] = getCoord(midAngle, maxRadius?maxRadius:outerRadius);
1007
-
1008
- const radius = (maxRadius?maxRadius:outerRadius) + distance;
1164
+ const [x1, y1] = getCoord(
1165
+ midAngle,
1166
+ maxRadius ? maxRadius : outerRadius
1167
+ );
1168
+
1169
+ const radius = (maxRadius ? maxRadius : outerRadius) + distance;
1009
1170
  const [x2, y2] = getCoord(midAngle, radius);
1010
1171
 
1011
1172
  const directionX = x2 < 0 ? -1 : 1;
1012
1173
  const directionY = y2 < 0 ? -1 : 1;
1013
1174
  const x3 = x2 + lineLength * directionX;
1014
1175
  const _x = x3 + (translateX + 6) * directionX;
1015
-
1176
+
1016
1177
  const _showName = showName && displayName;
1017
1178
  const _showValue = showValue && (value || showSuffix);
1018
1179
 
@@ -1022,32 +1183,54 @@ const RingLabel =({
1022
1183
  <g key={index}>
1023
1184
  <path
1024
1185
  className={ringCss['label-line']}
1025
- style={{ animationDelay:`${(actualIndex+1) * 2000 - 800}ms`}}
1186
+ style={{
1187
+ animationDelay: `${(actualIndex + 1) * 2000 - 800}ms`,
1188
+ }}
1026
1189
  d={
1027
- 'M' + x1 + ', ' + y1 + 'L' +
1028
- x2 + ', ' + y2 + 'L' +
1029
- x3 + ', ' + y2
1190
+ 'M' +
1191
+ x1 +
1192
+ ', ' +
1193
+ y1 +
1194
+ 'L' +
1195
+ x2 +
1196
+ ', ' +
1197
+ y2 +
1198
+ 'L' +
1199
+ x3 +
1200
+ ', ' +
1201
+ y2
1202
+ }
1203
+ stroke={
1204
+ lineColor
1205
+ ? lineColor
1206
+ : type == 'pure'
1207
+ ? pure
1208
+ : stops[0].color
1030
1209
  }
1031
- stroke={lineColor?lineColor:(type == 'pure' ? pure : stops[0].color)}
1032
1210
  fill='none'
1033
1211
  />
1034
1212
  <text
1035
1213
  className={ringCss['label-text']}
1036
- style={{ animationDelay:`${(actualIndex+1) * 2000 - 800}ms`}}
1037
- x={mode=="horizontal"?_x:x2}
1214
+ style={{
1215
+ animationDelay: `${(actualIndex + 1) * 2000 - 800}ms`,
1216
+ }}
1217
+ x={mode == 'horizontal' ? _x : x2}
1038
1218
  y={y2 + translateY}
1039
1219
  dominantBaseline='middle'
1040
1220
  textAnchor={x3 >= 0 ? 'start' : 'end'}
1041
1221
  >
1042
1222
  {_showName && (
1043
- <tspan dy={nameDy(_showValue, showPercent, mode, directionY)} style={getFontStyle(nameFont, 'svg')}>
1223
+ <tspan
1224
+ dy={nameDy(_showValue, showPercent, mode, directionY)}
1225
+ style={getFontStyle(nameFont, 'svg')}
1226
+ >
1044
1227
  {displayName + (showValue || showPercent ? ':' : '')}
1045
1228
  </tspan>
1046
1229
  )}
1047
1230
  {_showValue && (
1048
1231
  <>
1049
1232
  <tspan
1050
- x={ _showName?(mode=="horizontal"?'':x2):'' }
1233
+ x={_showName ? (mode == 'horizontal' ? '' : x2) : ''}
1051
1234
  dx={valueDx(_showName, mode)}
1052
1235
  dy={valueDy(_showName, mode, directionY)}
1053
1236
  style={getFontStyle(valueFont, 'svg')}
@@ -1070,11 +1253,19 @@ const RingLabel =({
1070
1253
  )}
1071
1254
  {showPercent && (
1072
1255
  <tspan
1073
- x={_showName?(_showValue?'':(mode=="vertical"?x2:'')):''}
1256
+ x={
1257
+ _showName
1258
+ ? _showValue
1259
+ ? ''
1260
+ : mode == 'vertical'
1261
+ ? x2
1262
+ : ''
1263
+ : ''
1264
+ }
1074
1265
  dx={percentDx(_showName, _showValue, mode)}
1075
1266
  dy={
1076
1267
  percentDy_(_showName, _showValue, mode, directionY) +
1077
- (_showValue && showSuffix ? suffixTranslateY * -1 : "")
1268
+ (_showValue && showSuffix ? suffixTranslateY * -1 : '')
1078
1269
  }
1079
1270
  style={getFontStyle(percentFont, 'svg')}
1080
1271
  >