@easyv/charts 1.0.68 → 1.0.69

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 (63) hide show
  1. package/.babelrc +8 -8
  2. package/lib/components/AnimateData.js +2 -2
  3. package/lib/components/Axis.js +12 -12
  4. package/lib/components/Background.js +2 -2
  5. package/lib/components/Carousel.js +2 -2
  6. package/lib/components/Chart.js +2 -2
  7. package/lib/components/ConicalGradient.js +21 -21
  8. package/lib/components/Indicator.js +2 -2
  9. package/lib/components/LinearGradient.js +2 -2
  10. package/lib/css/index.module.css +41 -41
  11. package/lib/css/piechart.module.css +26 -26
  12. package/lib/hooks/useAnimateData.js +5 -5
  13. package/lib/hooks/useAxes.js +5 -5
  14. package/lib/hooks/useCarouselAxisX.js +5 -5
  15. package/lib/hooks/useExtentData.js +6 -6
  16. package/lib/hooks/useFilterData.js +5 -5
  17. package/lib/hooks/useStackData.js +5 -5
  18. package/lib/hooks/useTooltip.js +10 -10
  19. package/lib/utils/index.js +36 -7
  20. package/package.json +34 -34
  21. package/src/components/AnimateData.tsx +24 -24
  22. package/src/components/Axis.tsx +333 -333
  23. package/src/components/Background.tsx +45 -45
  24. package/src/components/Band.tsx +160 -160
  25. package/src/components/Brush.js +159 -159
  26. package/src/components/Carousel.tsx +144 -144
  27. package/src/components/Chart.js +99 -99
  28. package/src/components/ChartContainer.tsx +63 -63
  29. package/src/components/ConicalGradient.js +258 -258
  30. package/src/components/ExtentData.js +17 -17
  31. package/src/components/FilterData.js +23 -23
  32. package/src/components/Indicator.js +13 -13
  33. package/src/components/Label.js +196 -196
  34. package/src/components/Legend.js +158 -158
  35. package/src/components/Lighter.jsx +162 -162
  36. package/src/components/Line.js +128 -128
  37. package/src/components/LinearGradient.js +29 -29
  38. package/src/components/Mapping.js +71 -71
  39. package/src/components/PieChart.js +1093 -1093
  40. package/src/components/StackData.js +20 -20
  41. package/src/components/StereoBar.tsx +298 -298
  42. package/src/components/Tooltip.js +133 -133
  43. package/src/components/index.js +49 -49
  44. package/src/context/index.js +2 -2
  45. package/src/css/index.module.css +41 -41
  46. package/src/css/piechart.module.css +26 -26
  47. package/src/element/ConicGradient.jsx +55 -55
  48. package/src/element/Line.tsx +33 -33
  49. package/src/element/index.ts +3 -3
  50. package/src/formatter/index.js +1 -1
  51. package/src/formatter/legend.js +90 -90
  52. package/src/hooks/index.js +17 -17
  53. package/src/hooks/useAnimateData.ts +62 -62
  54. package/src/hooks/useAxes.js +143 -143
  55. package/src/hooks/useCarouselAxisX.js +163 -163
  56. package/src/hooks/useExtentData.js +88 -88
  57. package/src/hooks/useFilterData.js +72 -72
  58. package/src/hooks/useStackData.js +100 -100
  59. package/src/hooks/useTooltip.ts +96 -96
  60. package/src/index.js +6 -6
  61. package/src/types/index.d.ts +59 -59
  62. package/src/utils/index.js +672 -640
  63. package/tsconfig.json +22 -22
@@ -1,196 +1,196 @@
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 } }) =>
127
- mode == 'single' ? (
128
- <Circle cx={cx} cy={cy} color={color} radius={radius} />
129
- ) : (
130
- <>
131
- <Circle cx={cx} cy={cy} {...inner} />
132
- <Circle cx={cx} cy={cy} {...outer} />
133
- </>
134
- );
135
- const Circle = ({ cx, cy, color, radius }) => (
136
- <circle cx={cx} cy={cy} fill={color} r={radius} stroke='none' />
137
- );
138
-
139
- const getVerticalLabel = ({ position = 'outerStart', width, y, y1, y2 }) => {
140
- switch (position) {
141
- case 'start':
142
- return {
143
- x: y > 0 ? y2 : y1,
144
- textAnchor: 'start',
145
- };
146
- case 'middle':
147
- return {
148
- x: (y1 + y2) / 2,
149
- textAnchor: 'middle',
150
- };
151
- case 'end':
152
- return {
153
- x: y > 0 ? y1 : y2,
154
- textAnchor: 'end',
155
- };
156
- case 'outerStart':
157
- return {
158
- x: y1,
159
- textAnchor: y > 0 ? 'start' : 'end',
160
- };
161
- case 'chartStart':
162
- return {
163
- x: y > 0 ? width : 0,
164
- textAnchor: y > 0 ? 'start' : 'end',
165
- };
166
- }
167
- };
168
- const getHorizontalLabel = ({ position = 'outerStart', height, y, y1, y2 }) => {
169
- switch (position) {
170
- case 'start':
171
- return {
172
- y: y > 0 ? y1 : y2,
173
- dominantBaseline: 'text-after-edge',
174
- };
175
- case 'middle':
176
- return {
177
- y: (y1 + y2) / 2,
178
- dominantBaseline: 'middle',
179
- };
180
- case 'end':
181
- return {
182
- y: y > 0 ? y2 : y1,
183
- dominantBaseline: 'text-before-edge',
184
- };
185
- case 'outerStart':
186
- return {
187
- y: y2,
188
- dominantBaseline: y >= 0 ? 'text-after-edge' : 'text-before-edge',
189
- };
190
- case 'chartStart':
191
- return {
192
- y: y > 0 ? 0 : height,
193
- dominantBaseline: y > 0 ? 'text-after-edge' : 'text-before-edge',
194
- };
195
- }
196
- };
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 } }) =>
127
+ mode == 'single' ? (
128
+ <Circle cx={cx} cy={cy} color={color} radius={radius} />
129
+ ) : (
130
+ <>
131
+ <Circle cx={cx} cy={cy} {...inner} />
132
+ <Circle cx={cx} cy={cy} {...outer} />
133
+ </>
134
+ );
135
+ const Circle = ({ cx, cy, color, radius }) => (
136
+ <circle cx={cx} cy={cy} fill={color} r={radius} stroke='none' />
137
+ );
138
+
139
+ const getVerticalLabel = ({ position = 'outerStart', width, y, y1, y2 }) => {
140
+ switch (position) {
141
+ case 'start':
142
+ return {
143
+ x: y > 0 ? y2 : y1,
144
+ textAnchor: 'start',
145
+ };
146
+ case 'middle':
147
+ return {
148
+ x: (y1 + y2) / 2,
149
+ textAnchor: 'middle',
150
+ };
151
+ case 'end':
152
+ return {
153
+ x: y > 0 ? y1 : y2,
154
+ textAnchor: 'end',
155
+ };
156
+ case 'outerStart':
157
+ return {
158
+ x: y1,
159
+ textAnchor: y > 0 ? 'start' : 'end',
160
+ };
161
+ case 'chartStart':
162
+ return {
163
+ x: y > 0 ? width : 0,
164
+ textAnchor: y > 0 ? 'start' : 'end',
165
+ };
166
+ }
167
+ };
168
+ const getHorizontalLabel = ({ position = 'outerStart', height, y, y1, y2 }) => {
169
+ switch (position) {
170
+ case 'start':
171
+ return {
172
+ y: y > 0 ? y1 : y2,
173
+ dominantBaseline: 'text-after-edge',
174
+ };
175
+ case 'middle':
176
+ return {
177
+ y: (y1 + y2) / 2,
178
+ dominantBaseline: 'middle',
179
+ };
180
+ case 'end':
181
+ return {
182
+ y: y > 0 ? y2 : y1,
183
+ dominantBaseline: 'text-before-edge',
184
+ };
185
+ case 'outerStart':
186
+ return {
187
+ y: y2,
188
+ dominantBaseline: y >= 0 ? 'text-after-edge' : 'text-before-edge',
189
+ };
190
+ case 'chartStart':
191
+ return {
192
+ y: y > 0 ? 0 : height,
193
+ dominantBaseline: y > 0 ? 'text-after-edge' : 'text-before-edge',
194
+ };
195
+ }
196
+ };