@easyv/charts 1.0.71 → 1.0.72

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 (62) hide show
  1. package/.babelrc +8 -8
  2. package/lib/components/AnimateData.js +2 -2
  3. package/lib/components/Axis.js +15 -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/css/index.module.css +41 -41
  11. package/lib/css/piechart.module.css +26 -26
  12. package/lib/hooks/useAnimateData.js +5 -5
  13. package/lib/hooks/useAxes.js +5 -5
  14. package/lib/hooks/useCarouselAxisX.js +5 -5
  15. package/lib/hooks/useExtentData.js +6 -6
  16. package/lib/hooks/useFilterData.js +5 -5
  17. package/lib/hooks/useStackData.js +5 -5
  18. package/lib/hooks/useTooltip.js +10 -10
  19. package/package.json +34 -34
  20. package/src/components/AnimateData.tsx +24 -24
  21. package/src/components/Axis.tsx +336 -333
  22. package/src/components/Background.tsx +45 -45
  23. package/src/components/Band.tsx +160 -160
  24. package/src/components/Brush.js +159 -159
  25. package/src/components/Carousel.tsx +144 -144
  26. package/src/components/Chart.js +99 -99
  27. package/src/components/ChartContainer.tsx +63 -63
  28. package/src/components/ConicalGradient.js +258 -258
  29. package/src/components/ExtentData.js +17 -17
  30. package/src/components/FilterData.js +23 -23
  31. package/src/components/Indicator.js +13 -13
  32. package/src/components/Label.js +206 -206
  33. package/src/components/Legend.js +158 -158
  34. package/src/components/Lighter.jsx +162 -162
  35. package/src/components/Line.js +128 -128
  36. package/src/components/LinearGradient.js +29 -29
  37. package/src/components/Mapping.js +71 -71
  38. package/src/components/PieChart.js +1093 -1093
  39. package/src/components/StackData.js +20 -20
  40. package/src/components/StereoBar.tsx +298 -298
  41. package/src/components/Tooltip.js +133 -133
  42. package/src/components/index.js +49 -49
  43. package/src/context/index.js +2 -2
  44. package/src/css/index.module.css +41 -41
  45. package/src/css/piechart.module.css +26 -26
  46. package/src/element/ConicGradient.jsx +55 -55
  47. package/src/element/Line.tsx +33 -33
  48. package/src/element/index.ts +3 -3
  49. package/src/formatter/index.js +1 -1
  50. package/src/formatter/legend.js +90 -90
  51. package/src/hooks/index.js +17 -17
  52. package/src/hooks/useAnimateData.ts +62 -62
  53. package/src/hooks/useAxes.js +143 -143
  54. package/src/hooks/useCarouselAxisX.js +163 -163
  55. package/src/hooks/useExtentData.js +88 -88
  56. package/src/hooks/useFilterData.js +72 -72
  57. package/src/hooks/useStackData.js +100 -100
  58. package/src/hooks/useTooltip.ts +96 -96
  59. package/src/index.js +6 -6
  60. package/src/types/index.d.ts +59 -59
  61. package/src/utils/index.js +671 -671
  62. package/tsconfig.json +22 -22
@@ -1,333 +1,336 @@
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
- : 'translate(' + translateX + ', ' + translateY + ')'
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
+ style={{
188
+ whiteSpace:"pre"
189
+ }}
190
+ dominantBaseline={dominantBaseline}
191
+ textAnchor={textAnchor}
192
+ fontFamily={fontFamily}
193
+ fontSize={fontSize}
194
+ fill={color}
195
+ fontWeight={bold ? 'bold' : 'normal'}
196
+ fontStyle={italic ? 'italic' : 'normal'}
197
+ letterSpacing={letterSpacing}
198
+ dx='0'
199
+ dy='0'
200
+ transform={
201
+ Array.isArray(_label)
202
+ ? rotate !== 0
203
+ ? isVertical
204
+ ? translateText + 'rotate(' + rotate + ')'
205
+ : 'rotate(' + rotate + ', ' + x + ', ' + y + ')'
206
+ : isVertical
207
+ ? translateText
208
+ : 'translate(' + translateX + ', ' + translateY + ')'
209
+ : translateText + 'rotate(' + rotate + ')'
210
+ }
211
+ >
212
+ {!!Array.isArray(_label)
213
+ ? _label.map((item, index) => (
214
+ <tspan key={index} x={x} dy='1em'>
215
+ {item}
216
+ </tspan>
217
+ ))
218
+ : _label}
219
+ </text>
220
+ );
221
+ };
222
+
223
+ export default memo(
224
+ ({
225
+ orientation,
226
+ scaler,
227
+ tickSize = defaultTickSize,
228
+ ticks,
229
+ formatter,
230
+ rotate,
231
+ config: { on, label, axisLine, tickLine, gridLine, unit },
232
+ positions,
233
+ }: any) => {
234
+ if (!(on && ticks.length > 0)) return null;
235
+ const { width, height } = useContext(chartContext);
236
+ const x = orientation == 'right' ? width : 0;
237
+ const y = orientation == 'bottom' ? height : 0;
238
+
239
+ return (
240
+ <>
241
+ {axisLine && tickLine && (
242
+ <>
243
+ {axisLine &&
244
+ (positions && positions.length ? (
245
+ positions.map(({ x, y }: any, index: number) => (
246
+ <g key={index} transform={'translate(' + x + ', ' + y + ')'}>
247
+ <AxisLine orientation={orientation} config={axisLine} />
248
+ {tickLine &&
249
+ ticks.map((tick: string, index: number) => {
250
+ const coordinate = scaler(tick);
251
+ if (isNaN(coordinate)) return null;
252
+ const _tickSize = tickLine.tickSize || tickSize;
253
+ return (
254
+ <Line
255
+ className='__easyv-tickLine'
256
+ key={index}
257
+ config={tickLine}
258
+ {...getTickCoord({
259
+ orientation,
260
+ coordinate,
261
+ tickSize: _tickSize,
262
+ })}
263
+ />
264
+ );
265
+ })}
266
+ </g>
267
+ ))
268
+ ) : (
269
+ <g transform={'translate(' + x + ', ' + y + ')'}>
270
+ <AxisLine orientation={orientation} config={axisLine} />
271
+ {tickLine &&
272
+ ticks.map((tick: string, index: number) => {
273
+ const coordinate = scaler(tick);
274
+ if (isNaN(coordinate)) return null;
275
+ const _tickSize = tickLine.tickSize || tickSize;
276
+ return (
277
+ <Line
278
+ className='__easyv-tickLine'
279
+ key={index}
280
+ config={tickLine}
281
+ {...getTickCoord({
282
+ orientation,
283
+ coordinate,
284
+ tickSize: _tickSize,
285
+ })}
286
+ />
287
+ );
288
+ })}
289
+ </g>
290
+ ))}
291
+ </>
292
+ )}
293
+ <g transform={'translate(' + x + ', ' + y + ')'}>
294
+ {label &&
295
+ gridLine &&
296
+ ticks.map((tick: string, index: number) => {
297
+ const coordinate = scaler(tick);
298
+ if (isNaN(coordinate)) return null;
299
+ const _tickSize = tickLine.tickSize || tickSize;
300
+ return (
301
+ <g key={index}>
302
+ {label && (
303
+ <Label
304
+ className='__easyv-label'
305
+ orientation={orientation}
306
+ coordinate={coordinate}
307
+ config={label}
308
+ label={tick}
309
+ tickSize={_tickSize}
310
+ formatter={formatter}
311
+ rotate={rotate}
312
+ />
313
+ )}
314
+ {gridLine && (
315
+ <Line
316
+ className='__easyv-gridLine'
317
+ config={gridLine}
318
+ {...getGridCoord({
319
+ orientation,
320
+ coordinate,
321
+ end:
322
+ orientation == 'left' || orientation == 'right'
323
+ ? width
324
+ : height,
325
+ })}
326
+ />
327
+ )}
328
+ </g>
329
+ );
330
+ })}
331
+ {unit && <Unit config={unit} />}
332
+ </g>
333
+ </>
334
+ );
335
+ }
336
+ );