@easyv/charts 1.0.56 → 1.0.60

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.
@@ -72,6 +72,7 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
72
72
  _ref2$data = _ref2.data,
73
73
  x = _ref2$data.x,
74
74
  y = _ref2$data.y,
75
+ showY = _ref2$data.showY,
75
76
  s = _ref2$data.s;
76
77
 
77
78
  var y1 = yScaler(isVertical ? end : start);
@@ -108,7 +109,7 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
108
109
  cy: attr.y,
109
110
  config: icon
110
111
  }), showLabel && /*#__PURE__*/React.createElement(Label, (0, _extends2["default"])({
111
- value: y,
112
+ value: showY,
112
113
  config: label
113
114
  }, attr)));
114
115
  }));
@@ -670,6 +670,7 @@ var Current = function Current(_ref9) {
670
670
  _ref9$config$name = _ref9$config.name,
671
671
  showName = _ref9$config$name.show,
672
672
  nameFont = _ref9$config$name.font,
673
+ textBreak = _ref9$config$name.textBreak,
673
674
  _ref9$config$percent = _ref9$config.percent,
674
675
  showPercent = _ref9$config$percent.show,
675
676
  percentFont = _ref9$config$percent.font,
@@ -704,22 +705,69 @@ var Current = function Current(_ref9) {
704
705
  fieldName = currentData.fieldName,
705
706
  value = currentData.value,
706
707
  percent = currentData.percent;
707
- return show && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, showName && /*#__PURE__*/_react["default"].createElement("text", (0, _extends2["default"])({
708
- textAnchor: "middle",
709
- dy: (showValue && showPercent ? -1 : showValue || showPercent ? -0.5 : 0) * gap
710
- }, (0, _utils.getFontStyle)(nameFont, 'svg')), displayName || fieldName), showValue && /*#__PURE__*/_react["default"].createElement("text", (0, _extends2["default"])({
711
- textAnchor: "middle",
712
- dy: (showName && showPercent ? 0 : showName && !showPercent ? 0.5 : showPercent ? -0.5 : 0) * gap + translateValueY,
713
- dx: translateValueX
714
- }, (0, _utils.getFontStyle)(valueFont, 'svg')), value, showSuffix && text && /*#__PURE__*/_react["default"].createElement("tspan", {
715
- dx: translateSuffixX,
716
- dy: translateSuffixY,
717
- fontSize: fontSize
718
- }, text)), showPercent && /*#__PURE__*/_react["default"].createElement("text", (0, _extends2["default"])({
719
- textAnchor: "middle",
720
- dy: (showName && showValue ? 1 : showName || showValue ? 0.5 : 0) * gap + translatePercentY,
721
- dx: translatePercentX
722
- }, (0, _utils.getFontStyle)(percentFont, 'svg')), percent + '%'));
708
+ var nameTemp = displayName ? displayName : fieldName; //类目名
709
+
710
+ var nameList = [];
711
+
712
+ if (textBreak) {
713
+ //如果限制了首行字符,则切割组件
714
+ while (nameTemp.length > textBreak) {
715
+ nameList.push(nameTemp.slice(0, textBreak));
716
+ nameTemp = nameTemp.slice(textBreak);
717
+ }
718
+ }
719
+
720
+ nameList.push(nameTemp);
721
+ var foreignStyle = {
722
+ //foreignObject标签样式,
723
+ width: "100%",
724
+ height: "100%",
725
+ transform: "translate(-50%,-50%)"
726
+ },
727
+ boxStyle = {
728
+ //弹性盒子样式,用于当前值的上下居中对齐等
729
+ width: "100%",
730
+ height: '100%',
731
+ display: "flex",
732
+ flexDirection: "column",
733
+ justifyContent: "center",
734
+ alignItems: "center"
735
+ };
736
+ return show && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("foreignObject", {
737
+ style: foreignStyle
738
+ }, /*#__PURE__*/_react["default"].createElement("div", {
739
+ style: boxStyle
740
+ }, //类目名称
741
+ showName && /*#__PURE__*/_react["default"].createElement("div", {
742
+ style: _objectSpread(_objectSpread({}, (0, _utils.getFontStyle)(nameFont)), {}, {
743
+ margin: gap / 2 + "px 0",
744
+ display: "flex",
745
+ flexDirection: "column",
746
+ alignItems: "center"
747
+ })
748
+ }, nameList.map(function (d, i) {
749
+ return /*#__PURE__*/_react["default"].createElement("span", {
750
+ key: i
751
+ }, d);
752
+ })), //真实值
753
+ showValue && /*#__PURE__*/_react["default"].createElement("span", {
754
+ style: _objectSpread(_objectSpread({}, (0, _utils.getFontStyle)(valueFont)), {}, {
755
+ transform: "translate(" + translateValueX + "px," + translateValueY + "px)",
756
+ margin: gap / 2 + "px 0"
757
+ })
758
+ }, value, showSuffix && text && /*#__PURE__*/_react["default"].createElement("span", {
759
+ style: {
760
+ transform: "translate(" + translateSuffixX + "px," + translateSuffixY + "px)",
761
+ fontSize: fontSize
762
+ }
763
+ }, text)), //百分比值
764
+ showPercent && /*#__PURE__*/_react["default"].createElement("span", {
765
+ style: _objectSpread(_objectSpread({
766
+ transform: "translate(" + translatePercentX + "px," + translatePercentY + "px)"
767
+ }, (0, _utils.getFontStyle)(percentFont)), {}, {
768
+ margin: gap / 2 + "px 0"
769
+ })
770
+ }, percent + '%'))));
723
771
  };
724
772
 
725
773
  var Label = function Label(_ref10) {
@@ -81,7 +81,7 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
81
81
  transform: (0, _utils.getTranslate3d)(translateXAxis)
82
82
  }, font)
83
83
  }, x), data.map(function (_ref2, index) {
84
- var y = _ref2.y,
84
+ var showY = _ref2.showY,
85
85
  s = _ref2.s;
86
86
 
87
87
  var _series$find = series.find(function (series) {
@@ -112,7 +112,7 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
112
112
  style: (0, _utils.getFontStyle)(name)
113
113
  }, displayName || s)), /*#__PURE__*/React.createElement("span", {
114
114
  style: (0, _utils.getFontStyle)(value)
115
- }, y));
115
+ }, showY));
116
116
  })));
117
117
  });
118
118
 
@@ -58,9 +58,11 @@ var pieLegendFormatter = function pieLegendFormatter(_ref, _ref2) {
58
58
  }), /*#__PURE__*/React.createElement("span", {
59
59
  className: showName && showValue && showPercent ? _indexModule["default"].showAllStyle : _indexModule["default"].notShowAllStyle
60
60
  }, showName && /*#__PURE__*/React.createElement("span", {
61
- style: _objectSpread({
61
+ style: _objectSpread(_objectSpread({
62
62
  paddingLeft: 5
63
- }, (0, _utils.getFontStyle)(nameFont))
63
+ }, (0, _utils.getFontStyle)(nameFont)), {}, {
64
+ whiteSpace: "nowrap"
65
+ })
64
66
  }, displayName), showValue && /*#__PURE__*/React.createElement("span", {
65
67
  style: _objectSpread(_objectSpread({}, (0, _utils.getFontStyle)(valueFont)), {}, {
66
68
  marginLeft: valueGap,
@@ -101,7 +101,12 @@ var _default = function _default(_ref) {
101
101
  }, [series]);
102
102
  return [{
103
103
  series: _series,
104
- data: _data
104
+ data: _data.map(function (d) {
105
+ return _objectSpread(_objectSpread({}, d), {}, {
106
+ y: parseFloat(d.y),
107
+ showY: d.y
108
+ });
109
+ })
105
110
  }, onClick];
106
111
  };
107
112
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.0.56",
3
+ "version": "1.0.60",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -40,11 +40,10 @@ export default memo(
40
40
  paddingInner * seriesStep;
41
41
  const isVertical = direction === 'vertical';
42
42
  const _position = label.position;
43
-
44
43
  return (
45
44
  <g className='__easyv-label'>
46
45
  {data.map(
47
- ({ index, bound: [start, end], data, data: { x, y, s } }, i) => {
46
+ ({ index, bound: [start, end], data, data: { x, y, showY, s } }, i) => {
48
47
 
49
48
  const y1 = yScaler(isVertical ? end : start);
50
49
  const y2 = start ? yScaler(isVertical ? start : end - start) : yScaler(isVertical ? start : end);
@@ -84,7 +83,7 @@ export default memo(
84
83
  data-data={JSON.stringify(data)}
85
84
  >
86
85
  {showIcon && <Icon cx={attr.x} cy={attr.y} config={icon} />}
87
- {showLabel && <Label value={y} config={label} {...attr} />}
86
+ {showLabel && <Label value={showY} config={label} {...attr} />}
88
87
  </g>
89
88
  );
90
89
  }
@@ -630,7 +630,7 @@ const Current = ({
630
630
  config: {
631
631
  show,
632
632
  gap,
633
- name: { show: showName, font: nameFont },
633
+ name: { show: showName, font: nameFont, textBreak },
634
634
  percent: {
635
635
  show: showPercent,
636
636
  font: percentFont,
@@ -661,68 +661,83 @@ const Current = ({
661
661
  if (!currentData) return null;
662
662
 
663
663
  const { displayName, fieldName, value, percent } = currentData;
664
+ let nameTemp = displayName? displayName : fieldName; //类目名
665
+ let nameList = [];
666
+ if(textBreak){ //如果限制了首行字符,则切割组件
667
+ while(nameTemp.length>textBreak){
668
+ nameList.push(nameTemp.slice(0,textBreak));
669
+ nameTemp = nameTemp.slice(textBreak)
670
+ }
671
+ }
672
+ nameList.push(nameTemp)
673
+ let foreignStyle={ //foreignObject标签样式,
674
+ width:"100%",
675
+ height:"100%",
676
+ transform:"translate(-50%,-50%)",
677
+ },
678
+ boxStyle={ //弹性盒子样式,用于当前值的上下居中对齐等
679
+ width:"100%",
680
+ height:'100%',
681
+ display:"flex",
682
+ flexDirection:"column",
683
+ justifyContent:"center",
684
+ alignItems:"center"
685
+ }
664
686
 
665
687
  return (
666
688
  show && (
667
689
  <>
668
- {showName && (
669
- <text
670
- textAnchor='middle'
671
- dy={
672
- (showValue && showPercent
673
- ? -1
674
- : showValue || showPercent
675
- ? -0.5
676
- : 0) * gap
690
+ <foreignObject style={foreignStyle}>
691
+ <div style={boxStyle}>
692
+ { //类目名称
693
+ showName && <div
694
+ style={{
695
+ ...getFontStyle(nameFont),
696
+ margin:gap/2+"px 0",
697
+ display:"flex",
698
+ flexDirection:"column",
699
+ alignItems:"center"
700
+ }}>
701
+ {
702
+ nameList.map((d,i)=>{
703
+ return <span key={i}>{d}</span>
704
+ })
705
+ }
706
+ </div>
677
707
  }
678
- {...getFontStyle(nameFont, 'svg')}
679
- >
680
- {displayName || fieldName}
681
- </text>
682
- )}
683
- {showValue && (
684
- <text
685
- textAnchor='middle'
686
- dy={
687
- (showName && showPercent
688
- ? 0
689
- : showName && !showPercent
690
- ? 0.5
691
- : showPercent
692
- ? -0.5
693
- : 0) *
694
- gap +
695
- translateValueY
708
+ { //真实值
709
+ showValue && <span
710
+ style={{
711
+ ...getFontStyle(valueFont),
712
+ transform:"translate("+translateValueX+"px,"+translateValueY+"px)",
713
+ margin:gap/2+"px 0"
714
+ }}>
715
+ {value}
716
+ {showSuffix && text && (
717
+ <span
718
+ style={{
719
+ transform:"translate("+translateSuffixX+"px,"+translateSuffixY+"px)",
720
+ fontSize:fontSize
721
+ }}
722
+ >
723
+ {text}
724
+ </span>
725
+ )}
726
+ </span>
696
727
  }
697
- dx={translateValueX}
698
- {...getFontStyle(valueFont, 'svg')}
699
- >
700
- {value}
701
- {showSuffix && text && (
702
- <tspan
703
- dx={translateSuffixX}
704
- dy={translateSuffixY}
705
- fontSize={fontSize}
728
+ { //百分比值
729
+ showPercent && <span
730
+ style={{
731
+ transform:"translate("+translatePercentX+"px,"+translatePercentY+"px)",
732
+ ...getFontStyle(percentFont),
733
+ margin:gap/2+"px 0"
734
+ }}
706
735
  >
707
- {text}
708
- </tspan>
709
- )}
710
- </text>
711
- )}
712
- {showPercent && (
713
- <text
714
- textAnchor='middle'
715
- dy={
716
- (showName && showValue ? 1 : showName || showValue ? 0.5 : 0) *
717
- gap +
718
- translatePercentY
736
+ {percent + '%'}
737
+ </span>
719
738
  }
720
- dx={translatePercentX}
721
- {...getFontStyle(percentFont, 'svg')}
722
- >
723
- {percent + '%'}
724
- </text>
725
- )}
739
+ </div>
740
+ </foreignObject>
726
741
  </>
727
742
  )
728
743
  );
@@ -759,7 +774,7 @@ const Label = ({
759
774
  arcs,
760
775
  animation
761
776
  }) => {
762
- // const [labels, setLabels] = useState(null);
777
+ // const [labels, setLabels] = useState(null);
763
778
  // const [opacity, setOpacity] = useState(0);
764
779
 
765
780
  const _arcs = useMemo(
@@ -803,11 +818,11 @@ const Label = ({
803
818
  // console.log('bbox: ', bbox);
804
819
  // }
805
820
  // }, [labels]);
806
-
821
+
807
822
  return (
808
823
  <g
809
- // style={{ opacity }} ref={setLabels}
810
- >
824
+ // style={{ opacity }} ref={setLabels}
825
+ >
811
826
  {_arcs.map(
812
827
  (
813
828
  {
@@ -81,7 +81,7 @@ export default memo(
81
81
  >
82
82
  {x}
83
83
  </dt>
84
- {data.map(({ y, s }, index) => {
84
+ {data.map(({ showY, s }, index) => {
85
85
  const { type, icon, displayName } = series.find(
86
86
  (series) => series.name == s
87
87
  );
@@ -105,7 +105,7 @@ export default memo(
105
105
  <span style={_icon} />
106
106
  <span style={getFontStyle(name)}>{displayName || s}</span>
107
107
  </span>
108
- <span style={getFontStyle(value)}>{y}</span>
108
+ <span style={getFontStyle(value)}>{showY}</span>
109
109
  </dd>
110
110
  );
111
111
  })}
@@ -0,0 +1,56 @@
1
+ import * as d3 from 'd3';
2
+
3
+ //只支持在svg中使用
4
+ //在<clipPath>标签中绘制圆环路径,在<foreignObject>中使用conic-gradient来制作角向渐变
5
+ //然后在foreignObject中调用clipPath来剪切dom元素,实现环形渐变效果
6
+ export default function ConicGradient(props){
7
+ const {
8
+ gradientId, //渐变ID,每一个环形渐变都需要使用独有的id,防止大屏中存在多个环形渐变时,出现渐变混用的情况。
9
+ colorConfig={},
10
+ circleConfig={}
11
+ } = props,
12
+ {
13
+ colorType = "linear", //渐变类型
14
+ colors = [{offset:0,color:"rgba(255,0,0,0.5)"},
15
+ {offset:50,color:"rgba(0,255,0,0.5)"},
16
+ {offset:100,color:"rgba(0,0,255,0.5)"}] //渐变颜色
17
+ } = colorConfig,
18
+ {
19
+ innerRadius = 80, //圆环内半径
20
+ outerRadius = 100, //圆环外半径
21
+ startAngle = 0, //初始角度
22
+ endAngle = 360, //结束角度
23
+ cornerRadius = 0, //圆环两端的圆角
24
+ padAngle = 0 //圆环内边距,用于多个圆环之间的间距
25
+ } = circleConfig;
26
+ const arc = d3
27
+ .arc()
28
+ .innerRadius(innerRadius)
29
+ .outerRadius(outerRadius)
30
+ .startAngle((startAngle * Math.PI) / 180)
31
+ .endAngle((endAngle * Math.PI) / 180)
32
+ .cornerRadius(cornerRadius)
33
+ .padAngle(padAngle);
34
+ return <g>
35
+ <clipPath id={""+gradientId} style={{transform:`translate(50%,50%)`}}>
36
+ <path d={arc()}></path>
37
+ </clipPath>
38
+ <foreignObject style={{
39
+ width:"100%",
40
+ height:"100%",
41
+ transform:`translate(-50%,-50%)`,
42
+ background:colorType==="pure"?
43
+ colors : `conic-gradient(${colorsToString(colors)})`,
44
+ clipPath:`url(${'#'+gradientId})`
45
+ }}></foreignObject>
46
+ </g>
47
+ }
48
+ function colorsToString(colors){
49
+ let s="";
50
+ colors.sort((a,b)=>{
51
+ return a.offset-b.offset;
52
+ }).map(d=>{
53
+ s=s+d.color+" "+d.offset+"%,";
54
+ })
55
+ return s.slice(0,-1)
56
+ }
@@ -42,7 +42,7 @@ export const pieLegendFormatter = (
42
42
  }
43
43
  >
44
44
  {showName && (
45
- <span style={{ paddingLeft: 5, ...getFontStyle(nameFont) }}>
45
+ <span style={{ paddingLeft: 5, ...getFontStyle(nameFont), whiteSpace:"nowrap" }}>
46
46
  {displayName}
47
47
  </span>
48
48
  )}
@@ -29,7 +29,7 @@ const getSelected = (selected, name) => {
29
29
 
30
30
  export default ({ data, series }) => {
31
31
  const [selected, setSelected] = useState(getInitialSelected(series));
32
-
32
+
33
33
  const _series = useMemo(() => {
34
34
  const tmp = new Map();
35
35
  series.forEach((currentSeries, key) => {
@@ -55,10 +55,17 @@ export default ({ data, series }) => {
55
55
  useEffect(() => {
56
56
  setSelected(getInitialSelected(series));
57
57
  }, [series]);
58
+
58
59
  return [
59
60
  {
60
61
  series: _series,
61
- data: _data,
62
+ data: _data.map(d=>{
63
+ return {
64
+ ...d,
65
+ y:parseFloat(d.y),
66
+ showY:d.y
67
+ }
68
+ }),
62
69
  },
63
70
  onClick,
64
71
  ];