@easyv/charts 1.2.3 → 1.2.6

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 (92) 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 +11 -7
  5. package/lib/components/Axis.js +18 -14
  6. package/lib/components/Background.js +2 -2
  7. package/lib/components/Band.js +8 -4
  8. package/lib/components/BaseLine.js +76 -0
  9. package/lib/components/Brush.js +2 -2
  10. package/lib/components/Carousel.js +15 -8
  11. package/lib/components/CartesianChart.js +26 -7
  12. package/lib/components/Chart.js +9 -6
  13. package/lib/components/ChartContainer.js +8 -4
  14. package/lib/components/ConicalGradient.js +27 -23
  15. package/lib/components/ExtentData.js +7 -4
  16. package/lib/components/FilterData.js +7 -4
  17. package/lib/components/Indicator.js +2 -2
  18. package/lib/components/Label.js +2 -2
  19. package/lib/components/Legend.js +11 -5
  20. package/lib/components/Lighter.js +179 -179
  21. package/lib/components/Line.js +11 -5
  22. package/lib/components/LinearGradient.js +2 -2
  23. package/lib/components/Mapping.js +8 -5
  24. package/lib/components/Marquee.js +14 -14
  25. package/lib/components/PieChart.js +17 -8
  26. package/lib/components/StackData.js +7 -4
  27. package/lib/components/StereoBar.js +8 -4
  28. package/lib/components/TextOverflow.js +65 -0
  29. package/lib/components/Tooltip.js +2 -2
  30. package/lib/components/index.js +58 -50
  31. package/lib/css/index.module.css +41 -41
  32. package/lib/css/piechart.module.css +26 -26
  33. package/lib/element/ConicGradient.js +72 -72
  34. package/lib/formatter/legend.js +2 -2
  35. package/lib/hooks/index.js +14 -14
  36. package/lib/hooks/useAnimateData.js +7 -7
  37. package/lib/hooks/useAxes.js +7 -7
  38. package/lib/hooks/useCarouselAxisX.js +7 -7
  39. package/lib/hooks/useExtentData.js +8 -8
  40. package/lib/hooks/useFilterData.js +8 -8
  41. package/lib/hooks/useStackData.js +10 -8
  42. package/lib/hooks/useTooltip.js +10 -10
  43. package/lib/index.js +6 -2
  44. package/lib/utils/index.js +31 -8
  45. package/package.json +53 -51
  46. package/src/components/AnimateData.tsx +24 -24
  47. package/src/components/Axis.tsx +354 -354
  48. package/src/components/Background.tsx +45 -45
  49. package/src/components/Band.tsx +173 -173
  50. package/src/components/BaseLine.js +76 -0
  51. package/src/components/Brush.js +159 -159
  52. package/src/components/Carousel.tsx +144 -144
  53. package/src/components/CartesianChart.js +22 -5
  54. package/src/components/Chart.js +99 -99
  55. package/src/components/ChartContainer.tsx +63 -63
  56. package/src/components/ConicalGradient.js +258 -258
  57. package/src/components/ExtentData.js +17 -17
  58. package/src/components/FilterData.js +23 -23
  59. package/src/components/Indicator.js +13 -13
  60. package/src/components/Label.js +206 -206
  61. package/src/components/Legend.js +158 -158
  62. package/src/components/Lighter.jsx +173 -173
  63. package/src/components/Line.js +144 -144
  64. package/src/components/LinearGradient.js +29 -29
  65. package/src/components/Mapping.js +71 -71
  66. package/src/components/Marquee.js +93 -93
  67. package/src/components/PieChart.js +1288 -1288
  68. package/src/components/StackData.js +20 -20
  69. package/src/components/StereoBar.tsx +310 -310
  70. package/src/components/TextOverflow.js +51 -0
  71. package/src/components/Tooltip.js +169 -169
  72. package/src/components/index.js +55 -53
  73. package/src/context/index.js +2 -2
  74. package/src/css/index.module.css +41 -41
  75. package/src/css/piechart.module.css +26 -26
  76. package/src/element/ConicGradient.jsx +55 -55
  77. package/src/element/Line.tsx +33 -33
  78. package/src/element/index.ts +3 -3
  79. package/src/formatter/index.js +1 -1
  80. package/src/formatter/legend.js +90 -90
  81. package/src/hooks/index.js +17 -17
  82. package/src/hooks/useAnimateData.ts +67 -67
  83. package/src/hooks/useAxes.js +144 -144
  84. package/src/hooks/useCarouselAxisX.js +163 -163
  85. package/src/hooks/useExtentData.js +88 -88
  86. package/src/hooks/useFilterData.js +72 -72
  87. package/src/hooks/useStackData.js +100 -100
  88. package/src/hooks/useTooltip.ts +96 -96
  89. package/src/index.js +6 -6
  90. package/src/types/index.d.ts +67 -67
  91. package/src/utils/index.js +714 -696
  92. 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
+ };