@easyv/charts 1.0.59 → 1.0.63

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 +7 -2
  10. package/lib/components/LinearGradient.js +2 -2
  11. package/lib/components/PieChart.js +3 -2
  12. package/lib/components/Tooltip.js +23 -4
  13. package/lib/css/index.module.css +41 -41
  14. package/lib/css/piechart.module.css +26 -26
  15. package/lib/formatter/legend.js +2 -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 +5 -5
  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 +196 -193
  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 +1093 -1092
  43. package/src/components/StackData.js +20 -20
  44. package/src/components/StereoBar.tsx +298 -298
  45. package/src/components/Tooltip.js +133 -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 -72
  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,333 +1,333 @@
1
- /**
2
- * x, y, z轴
3
- */
4
- import React, {
5
- ComponentType,
6
- memo,
7
- ReactComponentElement,
8
- useContext,
9
- } from 'react';
10
- import { getTickCoord, getGridCoord } from '../utils';
11
- import { chartContext } from '../context';
12
- import { Line } from '../element';
13
-
14
- const defaultAlign: Align = {
15
- textAnchor: 'middle',
16
- dominantBaseline: 'middle',
17
- };
18
- const defaultOrientation = 'bottom';
19
- const defaultTickSize = 6;
20
- const defaultFormatter: (d: string, { suffix }: { suffix: string }) => string =
21
- (d, { suffix }) => d + suffix;
22
-
23
- const getAxesPath: (
24
- orientation: Orientation,
25
- { width, height }: Context
26
- ) => string = (orientation, { width, height }) => {
27
- switch (orientation) {
28
- case 'top':
29
- case 'bottom':
30
- return 'M-0.5, 0H' + width;
31
- case 'left':
32
- case 'right':
33
- return 'M0, -0.5V' + (height + 0.5);
34
- }
35
- };
36
- /**
37
- * 根据坐标轴位置来确定轴标签的垂直对齐方式,水平对齐方式,以及轴标签位于坐标轴的哪个方向
38
- * @param orientation 坐标轴位置
39
- * @param rotate 旋转角度
40
- * @returns {
41
- * dominantBaseline,
42
- * textAnchor,
43
- * directionX,
44
- * directionY
45
- * }
46
- */
47
- const getLayout: (
48
- orientation: Orientation,
49
- rotate: number
50
- ) => {
51
- dominantBaseline: string;
52
- textAnchor: string;
53
- directionX: number;
54
- directionY: number;
55
- } = (orientation, rotate) => {
56
- switch (orientation) {
57
- case 'top':
58
- return {
59
- dominantBaseline: 'text-after-edge',
60
- textAnchor: rotate ? 'end' : 'middle',
61
- directionX: 1,
62
- directionY: -1,
63
- };
64
- case 'bottom':
65
- return {
66
- dominantBaseline: 'text-before-edge',
67
- textAnchor: rotate ? 'start' : 'middle',
68
- directionX: 1,
69
- directionY: 1,
70
- };
71
- case 'left':
72
- return {
73
- dominantBaseline: 'middle',
74
- textAnchor: 'end',
75
- directionX: -1,
76
- directionY: 1,
77
- };
78
- case 'right':
79
- return {
80
- dominantBaseline: 'middle',
81
- textAnchor: 'start',
82
- directionX: 1,
83
- directionY: 1,
84
- };
85
- }
86
- };
87
- const AxisLine: ({
88
- orientation: Orientation,
89
- config: ChartLine,
90
- }: any) => ReactComponentElement<ComponentType> | null = ({
91
- orientation = defaultOrientation,
92
- config: { show, color, lineWidth },
93
- }) => {
94
- if (!show) return null;
95
- const context: Context = useContext(chartContext);
96
- return (
97
- <path
98
- d={getAxesPath(orientation, context)}
99
- stroke={color}
100
- strokeWidth={lineWidth}
101
- />
102
- );
103
- };
104
-
105
- const Unit: ({
106
- config: {
107
- show: boolean,
108
- text: string,
109
- font: Font,
110
- translate: Translate,
111
- align: Align,
112
- },
113
- }: any) => ReactComponentElement<ComponentType> | null = ({
114
- config: {
115
- show,
116
- text,
117
- font: { bold, color, fontFamily, fontSize, italic, letterSpacing },
118
- translate: { x: translateX, y: translateY },
119
- align: { textAnchor } = defaultAlign,
120
- },
121
- }) => {
122
- if (!show) return null;
123
- return (
124
- <text
125
- className='__easyv-unit'
126
- transform={'translate(' + translateX + ', ' + translateY + ')'}
127
- fontFamily={fontFamily}
128
- fontSize={fontSize}
129
- fill={color}
130
- fontWeight={bold ? 'bold' : 'normal'}
131
- fontStyle={italic ? 'italic' : 'normal'}
132
- letterSpacing={letterSpacing}
133
- textAnchor={textAnchor}
134
- >
135
- {text}
136
- </text>
137
- );
138
- };
139
-
140
- type LabelType = {
141
- className: string;
142
- orientation: Orientation;
143
- label: string;
144
- coordinate: number;
145
- formatter: Function;
146
- tickSize: number;
147
- rotate: number;
148
- config: { show: boolean; translate: Translate; font: Font };
149
- };
150
-
151
- const Label: (props: LabelType) => ReactComponentElement<ComponentType> | null =
152
- ({
153
- className,
154
- orientation = defaultOrientation,
155
- label,
156
- coordinate,
157
- formatter = defaultFormatter,
158
- tickSize,
159
- rotate = 0,
160
- config,
161
- config: {
162
- show,
163
- translate: { x: translateX, y: translateY },
164
- font: { fontFamily, fontSize, color, bold, italic, letterSpacing },
165
- },
166
- }) => {
167
- if (!show) return null;
168
- const _label = formatter(label, config);
169
- const { dominantBaseline, textAnchor, directionX, directionY } = getLayout(
170
- orientation,
171
- rotate
172
- );
173
- const isVertical = orientation == 'left' || orientation == 'right';
174
-
175
- const x =
176
- (isVertical ? tickSize * directionX : coordinate) +
177
- translateX * directionX;
178
- const y =
179
- (isVertical ? coordinate : tickSize * directionY) +
180
- translateY * directionY;
181
-
182
- const translateText = 'translate(' + x + ', ' + y + ')';
183
-
184
- return (
185
- <text
186
- className={className}
187
- dominantBaseline={dominantBaseline}
188
- textAnchor={textAnchor}
189
- fontFamily={fontFamily}
190
- fontSize={fontSize}
191
- fill={color}
192
- fontWeight={bold ? 'bold' : 'normal'}
193
- fontStyle={italic ? 'italic' : 'normal'}
194
- letterSpacing={letterSpacing}
195
- dx='0'
196
- dy='0'
197
- transform={
198
- Array.isArray(_label)
199
- ? rotate !== 0
200
- ? isVertical
201
- ? translateText + 'rotate(' + rotate + ')'
202
- : 'rotate(' + rotate + ', ' + x + ', ' + y + ')'
203
- : isVertical
204
- ? translateText
205
- : ''
206
- : translateText + 'rotate(' + rotate + ')'
207
- }
208
- >
209
- {!!Array.isArray(_label)
210
- ? _label.map((item, index) => (
211
- <tspan key={index} x={x} dy='1em'>
212
- {item}
213
- </tspan>
214
- ))
215
- : _label}
216
- </text>
217
- );
218
- };
219
-
220
- export default memo(
221
- ({
222
- orientation,
223
- scaler,
224
- tickSize = defaultTickSize,
225
- ticks,
226
- formatter,
227
- rotate,
228
- config: { on, label, axisLine, tickLine, gridLine, unit },
229
- positions,
230
- }: any) => {
231
- if (!(on && ticks.length > 0)) return null;
232
- const { width, height } = useContext(chartContext);
233
- const x = orientation == 'right' ? width : 0;
234
- const y = orientation == 'bottom' ? height : 0;
235
-
236
- return (
237
- <>
238
- {axisLine && tickLine && (
239
- <>
240
- {axisLine &&
241
- (positions && positions.length ? (
242
- positions.map(({ x, y }: any, index: number) => (
243
- <g key={index} transform={'translate(' + x + ', ' + y + ')'}>
244
- <AxisLine orientation={orientation} config={axisLine} />
245
- {tickLine &&
246
- ticks.map((tick: string, index: number) => {
247
- const coordinate = scaler(tick);
248
- if (isNaN(coordinate)) return null;
249
- const _tickSize = tickLine.tickSize || tickSize;
250
- return (
251
- <Line
252
- className='__easyv-tickLine'
253
- key={index}
254
- config={tickLine}
255
- {...getTickCoord({
256
- orientation,
257
- coordinate,
258
- tickSize: _tickSize,
259
- })}
260
- />
261
- );
262
- })}
263
- </g>
264
- ))
265
- ) : (
266
- <g transform={'translate(' + x + ', ' + y + ')'}>
267
- <AxisLine orientation={orientation} config={axisLine} />
268
- {tickLine &&
269
- ticks.map((tick: string, index: number) => {
270
- const coordinate = scaler(tick);
271
- if (isNaN(coordinate)) return null;
272
- const _tickSize = tickLine.tickSize || tickSize;
273
- return (
274
- <Line
275
- className='__easyv-tickLine'
276
- key={index}
277
- config={tickLine}
278
- {...getTickCoord({
279
- orientation,
280
- coordinate,
281
- tickSize: _tickSize,
282
- })}
283
- />
284
- );
285
- })}
286
- </g>
287
- ))}
288
- </>
289
- )}
290
- <g transform={'translate(' + x + ', ' + y + ')'}>
291
- {label &&
292
- gridLine &&
293
- ticks.map((tick: string, index: number) => {
294
- const coordinate = scaler(tick);
295
- if (isNaN(coordinate)) return null;
296
- const _tickSize = tickLine.tickSize || tickSize;
297
- return (
298
- <g key={index}>
299
- {label && (
300
- <Label
301
- className='__easyv-label'
302
- orientation={orientation}
303
- coordinate={coordinate}
304
- config={label}
305
- label={tick}
306
- tickSize={_tickSize}
307
- formatter={formatter}
308
- rotate={rotate}
309
- />
310
- )}
311
- {gridLine && (
312
- <Line
313
- className='__easyv-gridLine'
314
- config={gridLine}
315
- {...getGridCoord({
316
- orientation,
317
- coordinate,
318
- end:
319
- orientation == 'left' || orientation == 'right'
320
- ? width
321
- : height,
322
- })}
323
- />
324
- )}
325
- </g>
326
- );
327
- })}
328
- {unit && <Unit config={unit} />}
329
- </g>
330
- </>
331
- );
332
- }
333
- );
1
+ /**
2
+ * x, y, z轴
3
+ */
4
+ import React, {
5
+ ComponentType,
6
+ memo,
7
+ ReactComponentElement,
8
+ useContext,
9
+ } from 'react';
10
+ import { getTickCoord, getGridCoord } from '../utils';
11
+ import { chartContext } from '../context';
12
+ import { Line } from '../element';
13
+
14
+ const defaultAlign: Align = {
15
+ textAnchor: 'middle',
16
+ dominantBaseline: 'middle',
17
+ };
18
+ const defaultOrientation = 'bottom';
19
+ const defaultTickSize = 6;
20
+ const defaultFormatter: (d: string, { suffix }: { suffix: string }) => string =
21
+ (d, { suffix }) => d + suffix;
22
+
23
+ const getAxesPath: (
24
+ orientation: Orientation,
25
+ { width, height }: Context
26
+ ) => string = (orientation, { width, height }) => {
27
+ switch (orientation) {
28
+ case 'top':
29
+ case 'bottom':
30
+ return 'M-0.5, 0H' + width;
31
+ case 'left':
32
+ case 'right':
33
+ return 'M0, -0.5V' + (height + 0.5);
34
+ }
35
+ };
36
+ /**
37
+ * 根据坐标轴位置来确定轴标签的垂直对齐方式,水平对齐方式,以及轴标签位于坐标轴的哪个方向
38
+ * @param orientation 坐标轴位置
39
+ * @param rotate 旋转角度
40
+ * @returns {
41
+ * dominantBaseline,
42
+ * textAnchor,
43
+ * directionX,
44
+ * directionY
45
+ * }
46
+ */
47
+ const getLayout: (
48
+ orientation: Orientation,
49
+ rotate: number
50
+ ) => {
51
+ dominantBaseline: string;
52
+ textAnchor: string;
53
+ directionX: number;
54
+ directionY: number;
55
+ } = (orientation, rotate) => {
56
+ switch (orientation) {
57
+ case 'top':
58
+ return {
59
+ dominantBaseline: 'text-after-edge',
60
+ textAnchor: rotate ? 'end' : 'middle',
61
+ directionX: 1,
62
+ directionY: -1,
63
+ };
64
+ case 'bottom':
65
+ return {
66
+ dominantBaseline: 'text-before-edge',
67
+ textAnchor: rotate ? 'start' : 'middle',
68
+ directionX: 1,
69
+ directionY: 1,
70
+ };
71
+ case 'left':
72
+ return {
73
+ dominantBaseline: 'middle',
74
+ textAnchor: 'end',
75
+ directionX: -1,
76
+ directionY: 1,
77
+ };
78
+ case 'right':
79
+ return {
80
+ dominantBaseline: 'middle',
81
+ textAnchor: 'start',
82
+ directionX: 1,
83
+ directionY: 1,
84
+ };
85
+ }
86
+ };
87
+ const AxisLine: ({
88
+ orientation: Orientation,
89
+ config: ChartLine,
90
+ }: any) => ReactComponentElement<ComponentType> | null = ({
91
+ orientation = defaultOrientation,
92
+ config: { show, color, lineWidth },
93
+ }) => {
94
+ if (!show) return null;
95
+ const context: Context = useContext(chartContext);
96
+ return (
97
+ <path
98
+ d={getAxesPath(orientation, context)}
99
+ stroke={color}
100
+ strokeWidth={lineWidth}
101
+ />
102
+ );
103
+ };
104
+
105
+ const Unit: ({
106
+ config: {
107
+ show: boolean,
108
+ text: string,
109
+ font: Font,
110
+ translate: Translate,
111
+ align: Align,
112
+ },
113
+ }: any) => ReactComponentElement<ComponentType> | null = ({
114
+ config: {
115
+ show,
116
+ text,
117
+ font: { bold, color, fontFamily, fontSize, italic, letterSpacing },
118
+ translate: { x: translateX, y: translateY },
119
+ align: { textAnchor } = defaultAlign,
120
+ },
121
+ }) => {
122
+ if (!show) return null;
123
+ return (
124
+ <text
125
+ className='__easyv-unit'
126
+ transform={'translate(' + translateX + ', ' + translateY + ')'}
127
+ fontFamily={fontFamily}
128
+ fontSize={fontSize}
129
+ fill={color}
130
+ fontWeight={bold ? 'bold' : 'normal'}
131
+ fontStyle={italic ? 'italic' : 'normal'}
132
+ letterSpacing={letterSpacing}
133
+ textAnchor={textAnchor}
134
+ >
135
+ {text}
136
+ </text>
137
+ );
138
+ };
139
+
140
+ type LabelType = {
141
+ className: string;
142
+ orientation: Orientation;
143
+ label: string;
144
+ coordinate: number;
145
+ formatter: Function;
146
+ tickSize: number;
147
+ rotate: number;
148
+ config: { show: boolean; translate: Translate; font: Font };
149
+ };
150
+
151
+ const Label: (props: LabelType) => ReactComponentElement<ComponentType> | null =
152
+ ({
153
+ className,
154
+ orientation = defaultOrientation,
155
+ label,
156
+ coordinate,
157
+ formatter = defaultFormatter,
158
+ tickSize,
159
+ rotate = 0,
160
+ config,
161
+ config: {
162
+ show,
163
+ translate: { x: translateX, y: translateY },
164
+ font: { fontFamily, fontSize, color, bold, italic, letterSpacing },
165
+ },
166
+ }) => {
167
+ if (!show) return null;
168
+ const _label = formatter(label, config);
169
+ const { dominantBaseline, textAnchor, directionX, directionY } = getLayout(
170
+ orientation,
171
+ rotate
172
+ );
173
+ const isVertical = orientation == 'left' || orientation == 'right';
174
+
175
+ const x =
176
+ (isVertical ? tickSize * directionX : coordinate) +
177
+ translateX * directionX;
178
+ const y =
179
+ (isVertical ? coordinate : tickSize * directionY) +
180
+ translateY * directionY;
181
+
182
+ const translateText = 'translate(' + x + ', ' + y + ')';
183
+
184
+ return (
185
+ <text
186
+ className={className}
187
+ dominantBaseline={dominantBaseline}
188
+ textAnchor={textAnchor}
189
+ fontFamily={fontFamily}
190
+ fontSize={fontSize}
191
+ fill={color}
192
+ fontWeight={bold ? 'bold' : 'normal'}
193
+ fontStyle={italic ? 'italic' : 'normal'}
194
+ letterSpacing={letterSpacing}
195
+ dx='0'
196
+ dy='0'
197
+ transform={
198
+ Array.isArray(_label)
199
+ ? rotate !== 0
200
+ ? isVertical
201
+ ? translateText + 'rotate(' + rotate + ')'
202
+ : 'rotate(' + rotate + ', ' + x + ', ' + y + ')'
203
+ : isVertical
204
+ ? translateText
205
+ : ''
206
+ : translateText + 'rotate(' + rotate + ')'
207
+ }
208
+ >
209
+ {!!Array.isArray(_label)
210
+ ? _label.map((item, index) => (
211
+ <tspan key={index} x={x} dy='1em'>
212
+ {item}
213
+ </tspan>
214
+ ))
215
+ : _label}
216
+ </text>
217
+ );
218
+ };
219
+
220
+ export default memo(
221
+ ({
222
+ orientation,
223
+ scaler,
224
+ tickSize = defaultTickSize,
225
+ ticks,
226
+ formatter,
227
+ rotate,
228
+ config: { on, label, axisLine, tickLine, gridLine, unit },
229
+ positions,
230
+ }: any) => {
231
+ if (!(on && ticks.length > 0)) return null;
232
+ const { width, height } = useContext(chartContext);
233
+ const x = orientation == 'right' ? width : 0;
234
+ const y = orientation == 'bottom' ? height : 0;
235
+
236
+ return (
237
+ <>
238
+ {axisLine && tickLine && (
239
+ <>
240
+ {axisLine &&
241
+ (positions && positions.length ? (
242
+ positions.map(({ x, y }: any, index: number) => (
243
+ <g key={index} transform={'translate(' + x + ', ' + y + ')'}>
244
+ <AxisLine orientation={orientation} config={axisLine} />
245
+ {tickLine &&
246
+ ticks.map((tick: string, index: number) => {
247
+ const coordinate = scaler(tick);
248
+ if (isNaN(coordinate)) return null;
249
+ const _tickSize = tickLine.tickSize || tickSize;
250
+ return (
251
+ <Line
252
+ className='__easyv-tickLine'
253
+ key={index}
254
+ config={tickLine}
255
+ {...getTickCoord({
256
+ orientation,
257
+ coordinate,
258
+ tickSize: _tickSize,
259
+ })}
260
+ />
261
+ );
262
+ })}
263
+ </g>
264
+ ))
265
+ ) : (
266
+ <g transform={'translate(' + x + ', ' + y + ')'}>
267
+ <AxisLine orientation={orientation} config={axisLine} />
268
+ {tickLine &&
269
+ ticks.map((tick: string, index: number) => {
270
+ const coordinate = scaler(tick);
271
+ if (isNaN(coordinate)) return null;
272
+ const _tickSize = tickLine.tickSize || tickSize;
273
+ return (
274
+ <Line
275
+ className='__easyv-tickLine'
276
+ key={index}
277
+ config={tickLine}
278
+ {...getTickCoord({
279
+ orientation,
280
+ coordinate,
281
+ tickSize: _tickSize,
282
+ })}
283
+ />
284
+ );
285
+ })}
286
+ </g>
287
+ ))}
288
+ </>
289
+ )}
290
+ <g transform={'translate(' + x + ', ' + y + ')'}>
291
+ {label &&
292
+ gridLine &&
293
+ ticks.map((tick: string, index: number) => {
294
+ const coordinate = scaler(tick);
295
+ if (isNaN(coordinate)) return null;
296
+ const _tickSize = tickLine.tickSize || tickSize;
297
+ return (
298
+ <g key={index}>
299
+ {label && (
300
+ <Label
301
+ className='__easyv-label'
302
+ orientation={orientation}
303
+ coordinate={coordinate}
304
+ config={label}
305
+ label={tick}
306
+ tickSize={_tickSize}
307
+ formatter={formatter}
308
+ rotate={rotate}
309
+ />
310
+ )}
311
+ {gridLine && (
312
+ <Line
313
+ className='__easyv-gridLine'
314
+ config={gridLine}
315
+ {...getGridCoord({
316
+ orientation,
317
+ coordinate,
318
+ end:
319
+ orientation == 'left' || orientation == 'right'
320
+ ? width
321
+ : height,
322
+ })}
323
+ />
324
+ )}
325
+ </g>
326
+ );
327
+ })}
328
+ {unit && <Unit config={unit} />}
329
+ </g>
330
+ </>
331
+ );
332
+ }
333
+ );