@easyv/charts 1.0.57 → 1.0.61

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