@easyv/charts 1.1.8 → 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.
Files changed (69) hide show
  1. package/.babelrc +8 -8
  2. package/.husky/commit-msg +3 -3
  3. package/CHANGELOG.md +18 -18
  4. package/lib/components/AnimateData.js +2 -2
  5. package/lib/components/Axis.js +10 -10
  6. package/lib/components/Background.js +2 -2
  7. package/lib/components/Carousel.js +2 -2
  8. package/lib/components/Chart.js +2 -2
  9. package/lib/components/ConicalGradient.js +21 -21
  10. package/lib/components/Indicator.js +2 -2
  11. package/lib/components/Lighter.js +179 -179
  12. package/lib/components/LinearGradient.js +2 -2
  13. package/lib/components/Marquee.js +97 -0
  14. package/lib/components/PieChart.js +47 -39
  15. package/lib/css/index.module.css +41 -41
  16. package/lib/css/piechart.module.css +26 -26
  17. package/lib/element/ConicGradient.js +72 -72
  18. package/lib/hooks/useAnimateData.js +7 -7
  19. package/lib/hooks/useAxes.js +5 -5
  20. package/lib/hooks/useCarouselAxisX.js +5 -5
  21. package/lib/hooks/useExtentData.js +6 -6
  22. package/lib/hooks/useFilterData.js +5 -5
  23. package/lib/hooks/useStackData.js +5 -5
  24. package/lib/hooks/useTooltip.js +10 -10
  25. package/package.json +51 -52
  26. package/src/components/AnimateData.tsx +24 -24
  27. package/src/components/Axis.tsx +354 -354
  28. package/src/components/Background.tsx +45 -45
  29. package/src/components/Band.tsx +173 -173
  30. package/src/components/Brush.js +159 -159
  31. package/src/components/Carousel.tsx +144 -144
  32. package/src/components/Chart.js +99 -99
  33. package/src/components/ChartContainer.tsx +63 -63
  34. package/src/components/ConicalGradient.js +258 -258
  35. package/src/components/ExtentData.js +17 -17
  36. package/src/components/FilterData.js +23 -23
  37. package/src/components/Indicator.js +13 -13
  38. package/src/components/Label.js +206 -206
  39. package/src/components/Legend.js +158 -158
  40. package/src/components/Lighter.jsx +173 -173
  41. package/src/components/Line.js +144 -144
  42. package/src/components/LinearGradient.js +29 -29
  43. package/src/components/Mapping.js +71 -71
  44. package/src/components/Marquee.js +74 -0
  45. package/src/components/PieChart.js +1288 -1097
  46. package/src/components/StackData.js +20 -20
  47. package/src/components/StereoBar.tsx +310 -310
  48. package/src/components/Tooltip.js +169 -169
  49. package/src/components/index.js +51 -51
  50. package/src/context/index.js +2 -2
  51. package/src/css/index.module.css +41 -41
  52. package/src/css/piechart.module.css +26 -26
  53. package/src/element/ConicGradient.jsx +55 -55
  54. package/src/element/Line.tsx +33 -33
  55. package/src/element/index.ts +3 -3
  56. package/src/formatter/index.js +1 -1
  57. package/src/formatter/legend.js +90 -90
  58. package/src/hooks/index.js +17 -17
  59. package/src/hooks/useAnimateData.ts +67 -62
  60. package/src/hooks/useAxes.js +144 -144
  61. package/src/hooks/useCarouselAxisX.js +163 -163
  62. package/src/hooks/useExtentData.js +88 -88
  63. package/src/hooks/useFilterData.js +72 -72
  64. package/src/hooks/useStackData.js +100 -100
  65. package/src/hooks/useTooltip.ts +96 -96
  66. package/src/index.js +6 -6
  67. package/src/types/index.d.ts +67 -62
  68. package/src/utils/index.js +696 -696
  69. package/tsconfig.json +22 -22
@@ -1,206 +1,206 @@
1
- /**
2
- * 轴类图表标签
3
- */
4
- import { memo, useContext } from 'react';
5
- import {
6
- getTranslate2d,
7
- getBandwidth,
8
- getBandSeriesStepAndWidth,
9
- } from '../utils';
10
- import { chartContext } from '../context';
11
-
12
- export default memo(
13
- ({
14
- config: {
15
- seriesIntervalWidth: paddingInner = 0,
16
- paddingInner: paddingOuter = 0,
17
- label,
18
- icon,
19
- },
20
- config,
21
- bandLength = 0,
22
- data,
23
- xAxis: { scaler: xScaler, step, direction },
24
- yAxis: { scaler: yScaler },
25
- triggerClick,
26
- }) => {
27
- const lineType = config.hasOwnProperty('line') //堆叠处理
28
- const showIcon = icon && icon.show;
29
- const showLabel = label && label.show;
30
-
31
- if (!(data.length && (showIcon || showLabel))) return null;
32
- const { width, height } = useContext(chartContext);
33
- const bandwidth = getBandwidth(step, paddingOuter);
34
- const { seriesStep, seriesWidth } = getBandSeriesStepAndWidth({
35
- width: bandwidth,
36
- paddingInner,
37
- bandLength,
38
- });
39
-
40
- const offset =
41
- (seriesWidth + paddingInner * seriesStep) * bandLength -
42
- paddingInner * seriesStep;
43
- const isVertical = direction === 'vertical';
44
- const _position = label.position;
45
- return (
46
- <g className='__easyv-label'>
47
- {data.map(
48
- ({ index, bound: [start, end], data, data: { x, y, showY, s } }, i) => {
49
- const y1 = yScaler(isVertical ? end : start);
50
- //处理z型折线图和堆叠柱图的逻辑冲突
51
- const y2 = lineType ? start ? yScaler(isVertical ? start : end - start) : yScaler(isVertical ? start : end) : yScaler(isVertical ? start : end);
52
- // const y2 = yScaler(isVertical ? start : end);
53
- const positionX = xScaler(x) + seriesStep * index - offset / 2;
54
- if (isNaN(positionX)) return null;
55
- const position = positionX + seriesWidth / 2;
56
- const labelPosition = isVertical
57
- ? getVerticalLabel({
58
- position: _position,
59
- y,
60
- y1,
61
- y2,
62
- width,
63
- })
64
- : getHorizontalLabel({
65
- position: _position,
66
- y,
67
- y1,
68
- y2,
69
- height,
70
- });
71
- const attr = isVertical
72
- ? {
73
- ...labelPosition,
74
- y: position,
75
- dominantBaseline: 'middle',
76
- }
77
- : {
78
- ...labelPosition,
79
- x: position,
80
- textAnchor: 'middle',
81
- };
82
- return (
83
- <g
84
- key={i}
85
- onClick={triggerClick}
86
- data-data={JSON.stringify(data)}
87
- >
88
- {showIcon && <Icon cx={attr.x} cy={attr.y} config={icon} />}
89
- {showLabel && <Label value={showY} config={label} {...attr} />}
90
- </g>
91
- );
92
- }
93
- )}
94
- </g>
95
- );
96
- }
97
- );
98
-
99
- const Label = ({
100
- x,
101
- y,
102
- value,
103
- config: {
104
- font,
105
- translate: { x: translateX = 0, y: translateY = 0 },
106
- },
107
- textAnchor = 'middle',
108
- dominantBaseline = 'middle',
109
- }) => {
110
- return (
111
- <text
112
- x={x}
113
- y={y}
114
- transform={getTranslate2d({
115
- x: translateX,
116
- y: translateY * (value >= 0 ? 1 : -1),
117
- })}
118
- textAnchor={textAnchor}
119
- dominantBaseline={dominantBaseline}
120
- {...font}
121
- >
122
- {value}
123
- </text>
124
- );
125
- };
126
- const Icon = ({ cx, cy, config: { mode, inner, outer, color, radius, image, size: { width, height } } }) =>
127
- mode == 'single' ? (
128
- <Circle cx={cx} cy={cy} color={color} radius={radius} />
129
- ) : mode == 'double' ? (
130
- <>
131
- <Circle cx={cx} cy={cy} {...inner} />
132
- <Circle cx={cx} cy={cy} {...outer} />
133
- </>
134
- ) : (
135
- <>
136
- <image
137
- width={width}
138
- height={height}
139
- x={cx - width / 2}
140
- y={cy - height / 2}
141
- xlinkHref={window.appConfig.ASSETS_URL + image} />
142
- </>
143
- );
144
-
145
- const Circle = ({ cx, cy, color, radius }) => (
146
- <circle cx={cx} cy={cy} fill={color} r={radius} stroke='none' />
147
- );
148
-
149
- const getVerticalLabel = ({ position = 'outerStart', width, y, y1, y2 }) => {
150
- switch (position) {
151
- case 'start':
152
- return {
153
- x: y > 0 ? y2 : y1,
154
- textAnchor: 'start',
155
- };
156
- case 'middle':
157
- return {
158
- x: (y1 + y2) / 2,
159
- textAnchor: 'middle',
160
- };
161
- case 'end':
162
- return {
163
- x: y > 0 ? y1 : y2,
164
- textAnchor: 'end',
165
- };
166
- case 'outerStart':
167
- return {
168
- x: y1,
169
- textAnchor: y > 0 ? 'start' : 'end',
170
- };
171
- case 'chartStart':
172
- return {
173
- x: y > 0 ? width : 0,
174
- textAnchor: y > 0 ? 'start' : 'end',
175
- };
176
- }
177
- };
178
- const getHorizontalLabel = ({ position = 'outerStart', height, y, y1, y2 }) => {
179
- switch (position) {
180
- case 'start':
181
- return {
182
- y: y > 0 ? y1 : y2,
183
- dominantBaseline: 'text-after-edge',
184
- };
185
- case 'middle':
186
- return {
187
- y: (y1 + y2) / 2,
188
- dominantBaseline: 'middle',
189
- };
190
- case 'end':
191
- return {
192
- y: y > 0 ? y2 : y1,
193
- dominantBaseline: 'text-before-edge',
194
- };
195
- case 'outerStart':
196
- return {
197
- y: y2,
198
- dominantBaseline: y >= 0 ? 'text-after-edge' : 'text-before-edge',
199
- };
200
- case 'chartStart':
201
- return {
202
- y: y > 0 ? 0 : height,
203
- dominantBaseline: y > 0 ? 'text-after-edge' : 'text-before-edge',
204
- };
205
- }
206
- };
1
+ /**
2
+ * 轴类图表标签
3
+ */
4
+ import { memo, useContext } from 'react';
5
+ import {
6
+ getTranslate2d,
7
+ getBandwidth,
8
+ getBandSeriesStepAndWidth,
9
+ } from '../utils';
10
+ import { chartContext } from '../context';
11
+
12
+ export default memo(
13
+ ({
14
+ config: {
15
+ seriesIntervalWidth: paddingInner = 0,
16
+ paddingInner: paddingOuter = 0,
17
+ label,
18
+ icon,
19
+ },
20
+ config,
21
+ bandLength = 0,
22
+ data,
23
+ xAxis: { scaler: xScaler, step, direction },
24
+ yAxis: { scaler: yScaler },
25
+ triggerClick,
26
+ }) => {
27
+ const lineType = config.hasOwnProperty('line') //堆叠处理
28
+ const showIcon = icon && icon.show;
29
+ const showLabel = label && label.show;
30
+
31
+ if (!(data.length && (showIcon || showLabel))) return null;
32
+ const { width, height } = useContext(chartContext);
33
+ const bandwidth = getBandwidth(step, paddingOuter);
34
+ const { seriesStep, seriesWidth } = getBandSeriesStepAndWidth({
35
+ width: bandwidth,
36
+ paddingInner,
37
+ bandLength,
38
+ });
39
+
40
+ const offset =
41
+ (seriesWidth + paddingInner * seriesStep) * bandLength -
42
+ paddingInner * seriesStep;
43
+ const isVertical = direction === 'vertical';
44
+ const _position = label.position;
45
+ return (
46
+ <g className='__easyv-label'>
47
+ {data.map(
48
+ ({ index, bound: [start, end], data, data: { x, y, showY, s } }, i) => {
49
+ const y1 = yScaler(isVertical ? end : start);
50
+ //处理z型折线图和堆叠柱图的逻辑冲突
51
+ const y2 = lineType ? start ? yScaler(isVertical ? start : end - start) : yScaler(isVertical ? start : end) : yScaler(isVertical ? start : end);
52
+ // const y2 = yScaler(isVertical ? start : end);
53
+ const positionX = xScaler(x) + seriesStep * index - offset / 2;
54
+ if (isNaN(positionX)) return null;
55
+ const position = positionX + seriesWidth / 2;
56
+ const labelPosition = isVertical
57
+ ? getVerticalLabel({
58
+ position: _position,
59
+ y,
60
+ y1,
61
+ y2,
62
+ width,
63
+ })
64
+ : getHorizontalLabel({
65
+ position: _position,
66
+ y,
67
+ y1,
68
+ y2,
69
+ height,
70
+ });
71
+ const attr = isVertical
72
+ ? {
73
+ ...labelPosition,
74
+ y: position,
75
+ dominantBaseline: 'middle',
76
+ }
77
+ : {
78
+ ...labelPosition,
79
+ x: position,
80
+ textAnchor: 'middle',
81
+ };
82
+ return (
83
+ <g
84
+ key={i}
85
+ onClick={triggerClick}
86
+ data-data={JSON.stringify(data)}
87
+ >
88
+ {showIcon && <Icon cx={attr.x} cy={attr.y} config={icon} />}
89
+ {showLabel && <Label value={showY} config={label} {...attr} />}
90
+ </g>
91
+ );
92
+ }
93
+ )}
94
+ </g>
95
+ );
96
+ }
97
+ );
98
+
99
+ const Label = ({
100
+ x,
101
+ y,
102
+ value,
103
+ config: {
104
+ font,
105
+ translate: { x: translateX = 0, y: translateY = 0 },
106
+ },
107
+ textAnchor = 'middle',
108
+ dominantBaseline = 'middle',
109
+ }) => {
110
+ return (
111
+ <text
112
+ x={x}
113
+ y={y}
114
+ transform={getTranslate2d({
115
+ x: translateX,
116
+ y: translateY * (value >= 0 ? 1 : -1),
117
+ })}
118
+ textAnchor={textAnchor}
119
+ dominantBaseline={dominantBaseline}
120
+ {...font}
121
+ >
122
+ {value}
123
+ </text>
124
+ );
125
+ };
126
+ const Icon = ({ cx, cy, config: { mode, inner, outer, color, radius, image, size: { width, height } } }) =>
127
+ mode == 'single' ? (
128
+ <Circle cx={cx} cy={cy} color={color} radius={radius} />
129
+ ) : mode == 'double' ? (
130
+ <>
131
+ <Circle cx={cx} cy={cy} {...inner} />
132
+ <Circle cx={cx} cy={cy} {...outer} />
133
+ </>
134
+ ) : (
135
+ <>
136
+ <image
137
+ width={width}
138
+ height={height}
139
+ x={cx - width / 2}
140
+ y={cy - height / 2}
141
+ xlinkHref={window.appConfig.ASSETS_URL + image} />
142
+ </>
143
+ );
144
+
145
+ const Circle = ({ cx, cy, color, radius }) => (
146
+ <circle cx={cx} cy={cy} fill={color} r={radius} stroke='none' />
147
+ );
148
+
149
+ const getVerticalLabel = ({ position = 'outerStart', width, y, y1, y2 }) => {
150
+ switch (position) {
151
+ case 'start':
152
+ return {
153
+ x: y > 0 ? y2 : y1,
154
+ textAnchor: 'start',
155
+ };
156
+ case 'middle':
157
+ return {
158
+ x: (y1 + y2) / 2,
159
+ textAnchor: 'middle',
160
+ };
161
+ case 'end':
162
+ return {
163
+ x: y > 0 ? y1 : y2,
164
+ textAnchor: 'end',
165
+ };
166
+ case 'outerStart':
167
+ return {
168
+ x: y1,
169
+ textAnchor: y > 0 ? 'start' : 'end',
170
+ };
171
+ case 'chartStart':
172
+ return {
173
+ x: y > 0 ? width : 0,
174
+ textAnchor: y > 0 ? 'start' : 'end',
175
+ };
176
+ }
177
+ };
178
+ const getHorizontalLabel = ({ position = 'outerStart', height, y, y1, y2 }) => {
179
+ switch (position) {
180
+ case 'start':
181
+ return {
182
+ y: y > 0 ? y1 : y2,
183
+ dominantBaseline: 'text-after-edge',
184
+ };
185
+ case 'middle':
186
+ return {
187
+ y: (y1 + y2) / 2,
188
+ dominantBaseline: 'middle',
189
+ };
190
+ case 'end':
191
+ return {
192
+ y: y > 0 ? y2 : y1,
193
+ dominantBaseline: 'text-before-edge',
194
+ };
195
+ case 'outerStart':
196
+ return {
197
+ y: y2,
198
+ dominantBaseline: y >= 0 ? 'text-after-edge' : 'text-before-edge',
199
+ };
200
+ case 'chartStart':
201
+ return {
202
+ y: y > 0 ? 0 : height,
203
+ dominantBaseline: y > 0 ? 'text-after-edge' : 'text-before-edge',
204
+ };
205
+ }
206
+ };