@easyv/charts 1.3.20 → 1.3.21

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.
@@ -1 +1 @@
1
- module.exports = {extends: ['@commitlint/config-conventional']}
1
+ module.exports = {extends: ['@commitlint/config-conventional']}
@@ -33,6 +33,7 @@ var _default = function _default(Component) {
33
33
  rest = (0, _objectWithoutProperties2["default"])(_ref, _excluded2);
34
34
  return /*#__PURE__*/_react["default"].createElement(Component, (0, _extends2["default"])({}, rest, {
35
35
  config: config,
36
+ originData: data,
36
37
  data: (0, _hooks.useAnimateData)(data, dataAnimation)
37
38
  }));
38
39
  });
@@ -223,7 +223,7 @@ var Label = function Label(_ref5) {
223
223
  return /*#__PURE__*/_react["default"].createElement("tspan", {
224
224
  key: index,
225
225
  x: x,
226
- dy: "1em"
226
+ dy: index != 0 ? '1em' : '0'
227
227
  }, item);
228
228
  }) : _label);
229
229
  };
@@ -65,7 +65,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
65
65
  indicator = _ref$config$tooltip$c3 === void 0 ? {} : _ref$config$tooltip$c3,
66
66
  brush = _ref$config.brush,
67
67
  style = _ref.style,
68
- data = _ref.data,
68
+ originData = _ref.originData,
69
69
  filterData = _ref.filterData;
70
70
  var context = (0, _react.useContext)(_context.chartContext);
71
71
 
@@ -96,10 +96,10 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
96
96
  setIndex = _useTooltip.setIndex;
97
97
 
98
98
  var tooltipData = (0, _react.useMemo)(function () {
99
- return tickName !== undefined && data.filter(function (d) {
99
+ return tickName !== undefined && originData.filter(function (d) {
100
100
  return d.x === tickName;
101
101
  });
102
- }, [tickName, data]);
102
+ }, [tickName, originData]);
103
103
  var showTooltip = !!(tooltipData && tooltipData.length && (auto || manual));
104
104
  var isVertical = axisX.direction === 'vertical';
105
105
  var indicatorWidth = indicator.width * axisX.step / 100;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.3.20",
3
+ "version": "1.3.21",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -14,11 +14,12 @@ export default (Component: ComponentType<any>) =>
14
14
  data: DataType[];
15
15
  config: { dataAnimation: DataAnimation; [key: string]: any };
16
16
  [key: string]: any;
17
- }) => (
18
- <Component
17
+ }) => {
18
+ return <Component
19
19
  {...rest}
20
20
  config={config}
21
+ originData={data}
21
22
  data={useAnimateData(data, dataAnimation)}
22
23
  />
23
- )
24
+ }
24
25
  );
@@ -227,7 +227,7 @@ const Label: (
227
227
  >
228
228
  {!!Array.isArray(_label)
229
229
  ? _label.map((item, index) => (
230
- <tspan key={index} x={x} dy='1em'>
230
+ <tspan key={index} x={x} dy={index!=0?'1em':'0'}>
231
231
  {item}
232
232
  </tspan>
233
233
  ))
@@ -55,7 +55,8 @@ const Chart = memo(
55
55
  brush,
56
56
  },
57
57
  style,
58
- data,
58
+ //data,
59
+ originData,
59
60
  filterData,
60
61
  }) => {
61
62
  const context = useContext(chartContext);
@@ -65,7 +66,6 @@ const Chart = memo(
65
66
  triggerOnRelative,
66
67
  onEmit,
67
68
  } = useContext(chartContext);
68
-
69
69
  const svg = createRef();
70
70
  const axes = useAxes({ axes: axesConfig, context });
71
71
  const axisX = useCarouselAxisX(axes.get('x'), animation);
@@ -84,8 +84,8 @@ const Chart = memo(
84
84
  config: tooltipConfig,
85
85
  });
86
86
  const tooltipData = useMemo(
87
- () => tickName !== undefined && data.filter((d) => d.x === tickName),
88
- [tickName, data]
87
+ () => tickName !== undefined && originData.filter((d) => d.x === tickName),
88
+ [tickName, originData]
89
89
  );
90
90
 
91
91
  const showTooltip = !!(
@@ -1,165 +1,165 @@
1
- /**
2
- * 图例
3
- */
4
- import React, { memo, useCallback } from 'react';
5
- import { getIcon, sortPie } from '../utils';
6
-
7
- const defaultFont = {
8
- fontStyle: 'normal',
9
- fontWeight: 'normal',
10
- };
11
-
12
- export default memo(
13
- ({
14
- series,
15
- config,
16
- config: {
17
- show,
18
- order = '',
19
- interactive,
20
- layout: {
21
- alignment = 'right center',
22
- gridTemplateColumns,
23
- gridGap: { gridColumnGap, gridRowGap },
24
- translate: { x, y },
25
- },
26
- font: { italic, bold, ...font } = defaultFont,
27
- unselect: { opacity = 1 } = {},
28
- },
29
- filterData,
30
- formatter,
31
- judge
32
- }) => {
33
- if (!show) return null;
34
- const _series = sortPie(series, order);
35
- const [_alignment, position] = alignment.split(' ');
36
- const length = _series.length;
37
-
38
- const onClick = useCallback(
39
- (e) => {
40
- const { dataset } = e.currentTarget;
41
- const { name } = dataset;
42
- filterData && interactive && filterData(name);
43
- },
44
- [interactive, filterData]
45
- );
46
-
47
- //木然判断数据都为零时做的,此处并不严谨,待想到好方法在进一步解决
48
-
49
- if (judge == 0) {
50
- _series.forEach((d) => {
51
- d.percent=0
52
- })
53
- }
54
-
55
- return (
56
- <div
57
- className='__easyv-legend-wrapper'
58
- style={{
59
- position: 'absolute',
60
- height: 'auto',
61
- display: 'flex',
62
- transform: 'translate3d(' + x + 'px, ' + y + 'px, 0px)',
63
- ...getPosition(position, _alignment),
64
- }}
65
- >
66
- <ul
67
- style={{
68
- display: 'grid',
69
- gridGap: gridRowGap + 'px ' + gridColumnGap + 'px',
70
- gridTemplateColumns:
71
- 'repeat(' + Math.min(gridTemplateColumns, length) + ', 1fr)',
72
- }}
73
- >
74
- {_series.map((series, index) => {
75
- const { type, name, displayName, icon, selected } = series;
76
- const _icon = getIcon(type, icon, series?.config?.line?.type);
77
- return (
78
- <li
79
- key={index}
80
- onClick={onClick}
81
- data-name={name}
82
- style={{
83
- display: 'flex',
84
- opacity: selected === false ? opacity / 100 : 1,
85
- alignItems: 'center',
86
- gap: _icon.gap,
87
- }}
88
- >
89
- {formatter ? (
90
- formatter(series, config)
91
- ) : (
92
- <>
93
- <span style={_icon} />
94
- <span
95
- style={{
96
- ...font,
97
- fontStyle: italic ? 'italic' : 'normal',
98
- fontWeight: bold ? 'bold' : 'normal',
99
- }}
100
- >
101
- {displayName || name}
102
- </span>
103
- </>
104
- )}
105
- </li>
106
- );
107
- })}
108
- </ul>
109
- </div>
110
- );
111
- }
112
- );
113
-
114
- const getPosition = (position, alignment) => {
115
- switch (position) {
116
- case 'top':
117
- return {
118
- left: 0,
119
- right: 0,
120
- top: 5,
121
- justifyContent:
122
- alignment === 'center'
123
- ? 'center'
124
- : alignment === 'left'
125
- ? 'flex-start'
126
- : 'flex-end',
127
- };
128
- case 'right':
129
- return {
130
- top: 0,
131
- bottom: 0,
132
- right: 10,
133
- alignItems:
134
- alignment === 'center'
135
- ? 'center'
136
- : alignment === 'left'
137
- ? 'flex-start'
138
- : 'flex-end',
139
- };
140
- case 'left':
141
- return {
142
- top: 0,
143
- bottom: 0,
144
- left: 10,
145
- alignItems:
146
- alignment === 'center'
147
- ? 'center'
148
- : alignment === 'left'
149
- ? 'flex-start'
150
- : 'flex-end',
151
- };
152
- default:
153
- return {
154
- left: 0,
155
- right: 0,
156
- bottom: 5,
157
- justifyContent:
158
- alignment === 'center'
159
- ? 'center'
160
- : alignment === 'left'
161
- ? 'flex-start'
162
- : 'flex-end',
163
- };
164
- }
165
- };
1
+ /**
2
+ * 图例
3
+ */
4
+ import React, { memo, useCallback } from 'react';
5
+ import { getIcon, sortPie } from '../utils';
6
+
7
+ const defaultFont = {
8
+ fontStyle: 'normal',
9
+ fontWeight: 'normal',
10
+ };
11
+
12
+ export default memo(
13
+ ({
14
+ series,
15
+ config,
16
+ config: {
17
+ show,
18
+ order = '',
19
+ interactive,
20
+ layout: {
21
+ alignment = 'right center',
22
+ gridTemplateColumns,
23
+ gridGap: { gridColumnGap, gridRowGap },
24
+ translate: { x, y },
25
+ },
26
+ font: { italic, bold, ...font } = defaultFont,
27
+ unselect: { opacity = 1 } = {},
28
+ },
29
+ filterData,
30
+ formatter,
31
+ judge
32
+ }) => {
33
+ if (!show) return null;
34
+ const _series = sortPie(series, order);
35
+ const [_alignment, position] = alignment.split(' ');
36
+ const length = _series.length;
37
+
38
+ const onClick = useCallback(
39
+ (e) => {
40
+ const { dataset } = e.currentTarget;
41
+ const { name } = dataset;
42
+ filterData && interactive && filterData(name);
43
+ },
44
+ [interactive, filterData]
45
+ );
46
+
47
+ //木然判断数据都为零时做的,此处并不严谨,待想到好方法在进一步解决
48
+
49
+ if (judge == 0) {
50
+ _series.forEach((d) => {
51
+ d.percent=0
52
+ })
53
+ }
54
+
55
+ return (
56
+ <div
57
+ className='__easyv-legend-wrapper'
58
+ style={{
59
+ position: 'absolute',
60
+ height: 'auto',
61
+ display: 'flex',
62
+ transform: 'translate3d(' + x + 'px, ' + y + 'px, 0px)',
63
+ ...getPosition(position, _alignment),
64
+ }}
65
+ >
66
+ <ul
67
+ style={{
68
+ display: 'grid',
69
+ gridGap: gridRowGap + 'px ' + gridColumnGap + 'px',
70
+ gridTemplateColumns:
71
+ 'repeat(' + Math.min(gridTemplateColumns, length) + ', 1fr)',
72
+ }}
73
+ >
74
+ {_series.map((series, index) => {
75
+ const { type, name, displayName, icon, selected } = series;
76
+ const _icon = getIcon(type, icon, series?.config?.line?.type);
77
+ return (
78
+ <li
79
+ key={index}
80
+ onClick={onClick}
81
+ data-name={name}
82
+ style={{
83
+ display: 'flex',
84
+ opacity: selected === false ? opacity / 100 : 1,
85
+ alignItems: 'center',
86
+ gap: _icon.gap,
87
+ }}
88
+ >
89
+ {formatter ? (
90
+ formatter(series, config)
91
+ ) : (
92
+ <>
93
+ <span style={_icon} />
94
+ <span
95
+ style={{
96
+ ...font,
97
+ fontStyle: italic ? 'italic' : 'normal',
98
+ fontWeight: bold ? 'bold' : 'normal',
99
+ }}
100
+ >
101
+ {displayName || name}
102
+ </span>
103
+ </>
104
+ )}
105
+ </li>
106
+ );
107
+ })}
108
+ </ul>
109
+ </div>
110
+ );
111
+ }
112
+ );
113
+
114
+ const getPosition = (position, alignment) => {
115
+ switch (position) {
116
+ case 'top':
117
+ return {
118
+ left: 0,
119
+ right: 0,
120
+ top: 5,
121
+ justifyContent:
122
+ alignment === 'center'
123
+ ? 'center'
124
+ : alignment === 'left'
125
+ ? 'flex-start'
126
+ : 'flex-end',
127
+ };
128
+ case 'right':
129
+ return {
130
+ top: 0,
131
+ bottom: 0,
132
+ right: 10,
133
+ alignItems:
134
+ alignment === 'center'
135
+ ? 'center'
136
+ : alignment === 'left'
137
+ ? 'flex-start'
138
+ : 'flex-end',
139
+ };
140
+ case 'left':
141
+ return {
142
+ top: 0,
143
+ bottom: 0,
144
+ left: 10,
145
+ alignItems:
146
+ alignment === 'center'
147
+ ? 'center'
148
+ : alignment === 'left'
149
+ ? 'flex-start'
150
+ : 'flex-end',
151
+ };
152
+ default:
153
+ return {
154
+ left: 0,
155
+ right: 0,
156
+ bottom: 5,
157
+ justifyContent:
158
+ alignment === 'center'
159
+ ? 'center'
160
+ : alignment === 'left'
161
+ ? 'flex-start'
162
+ : 'flex-end',
163
+ };
164
+ }
165
+ };