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