@easyv/charts 1.0.61 → 1.0.62

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 (64) 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/components/PieChart.js +2 -1
  11. package/lib/css/index.module.css +41 -41
  12. package/lib/css/piechart.module.css +26 -26
  13. package/lib/formatter/legend.js +2 -2
  14. package/lib/hooks/useAnimateData.js +5 -5
  15. package/lib/hooks/useAxes.js +5 -5
  16. package/lib/hooks/useCarouselAxisX.js +5 -5
  17. package/lib/hooks/useExtentData.js +6 -6
  18. package/lib/hooks/useFilterData.js +5 -5
  19. package/lib/hooks/useStackData.js +5 -5
  20. package/lib/hooks/useTooltip.js +10 -10
  21. package/package.json +34 -34
  22. package/src/components/AnimateData.tsx +24 -24
  23. package/src/components/Axis.tsx +333 -333
  24. package/src/components/Background.tsx +45 -45
  25. package/src/components/Band.tsx +160 -160
  26. package/src/components/Brush.js +159 -159
  27. package/src/components/Carousel.tsx +144 -144
  28. package/src/components/Chart.js +99 -99
  29. package/src/components/ChartContainer.tsx +63 -63
  30. package/src/components/ConicalGradient.js +258 -258
  31. package/src/components/ExtentData.js +17 -17
  32. package/src/components/FilterData.js +23 -23
  33. package/src/components/Indicator.js +13 -13
  34. package/src/components/Label.js +193 -193
  35. package/src/components/Legend.js +158 -158
  36. package/src/components/Lighter.jsx +162 -162
  37. package/src/components/Line.js +126 -126
  38. package/src/components/LinearGradient.js +29 -29
  39. package/src/components/Mapping.js +71 -71
  40. package/src/components/PieChart.js +1093 -1092
  41. package/src/components/StackData.js +20 -20
  42. package/src/components/StereoBar.tsx +298 -298
  43. package/src/components/Tooltip.js +134 -134
  44. package/src/components/index.js +49 -49
  45. package/src/context/index.js +2 -2
  46. package/src/css/index.module.css +41 -41
  47. package/src/css/piechart.module.css +26 -26
  48. package/src/element/ConicGradient.jsx +55 -55
  49. package/src/element/Line.tsx +33 -33
  50. package/src/element/index.ts +3 -3
  51. package/src/formatter/index.js +1 -1
  52. package/src/formatter/legend.js +87 -87
  53. package/src/hooks/index.js +17 -17
  54. package/src/hooks/useAnimateData.ts +62 -62
  55. package/src/hooks/useAxes.js +143 -143
  56. package/src/hooks/useCarouselAxisX.js +163 -163
  57. package/src/hooks/useExtentData.js +88 -88
  58. package/src/hooks/useFilterData.js +72 -72
  59. package/src/hooks/useStackData.js +100 -100
  60. package/src/hooks/useTooltip.ts +96 -96
  61. package/src/index.js +6 -6
  62. package/src/types/index.d.ts +59 -59
  63. package/src/utils/index.js +640 -640
  64. package/tsconfig.json +22 -22
@@ -1,193 +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
- 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
- };
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
+ };