@easyv/charts 1.0.44 → 1.0.48

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 (65) 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 +4 -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 +1 -1
  10. package/lib/components/LinearGradient.js +2 -2
  11. package/lib/components/PieChart.js +326 -139
  12. package/lib/css/index.module.css +42 -42
  13. package/lib/css/piechart.module.css +27 -0
  14. package/lib/formatter/legend.js +3 -2
  15. package/lib/hooks/useAnimateData.js +5 -5
  16. package/lib/hooks/useAxes.js +5 -5
  17. package/lib/hooks/useCarouselAxisX.js +5 -5
  18. package/lib/hooks/useExtentData.js +6 -6
  19. package/lib/hooks/useFilterData.js +5 -5
  20. package/lib/hooks/useStackData.js +5 -5
  21. package/lib/hooks/useTooltip.js +10 -10
  22. package/lib/utils/index.js +1 -1
  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 -142
  30. package/src/components/Chart.js +99 -101
  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 +194 -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 -72
  42. package/src/components/PieChart.js +876 -709
  43. package/src/components/StackData.js +20 -20
  44. package/src/components/StereoBar.tsx +298 -298
  45. package/src/components/Tooltip.js +116 -116
  46. package/src/components/index.js +49 -49
  47. package/src/context/index.js +2 -2
  48. package/src/css/index.module.css +42 -42
  49. package/src/css/piechart.module.css +27 -0
  50. package/src/element/Line.tsx +33 -33
  51. package/src/element/index.ts +3 -3
  52. package/src/formatter/index.js +1 -1
  53. package/src/formatter/legend.js +87 -87
  54. package/src/hooks/index.js +17 -17
  55. package/src/hooks/useAnimateData.ts +62 -62
  56. package/src/hooks/useAxes.js +143 -143
  57. package/src/hooks/useCarouselAxisX.js +163 -163
  58. package/src/hooks/useExtentData.js +88 -88
  59. package/src/hooks/useFilterData.js +65 -65
  60. package/src/hooks/useStackData.js +100 -100
  61. package/src/hooks/useTooltip.ts +96 -96
  62. package/src/index.js +6 -6
  63. package/src/types/index.d.ts +59 -59
  64. package/src/utils/index.js +640 -641
  65. package/tsconfig.json +22 -22
@@ -1,194 +1,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
-
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
+
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
+ };