@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,45 +1,45 @@
1
- /**
2
- * 轴类图背景
3
- */
4
- import React from 'react';
5
- import { getBandwidth } from '../utils';
6
-
7
- export default ({
8
- axis: { ticks, scaler, step, direction },
9
- config: { background, paddingInner: paddingOuter },
10
- length,
11
- }: {
12
- axis: {
13
- ticks: Array<string>;
14
- scaler: Function;
15
- step: number;
16
- direction: string;
17
- };
18
- config: { background: string; paddingInner: number };
19
- length: number;
20
- }) => {
21
- const isVertical: boolean = direction === 'vertical';
22
- const bandwidth = getBandwidth(step, paddingOuter);
23
- const size = isVertical
24
- ? {
25
- width: length,
26
- height: bandwidth,
27
- }
28
- : {
29
- width: bandwidth,
30
- height: length,
31
- };
32
-
33
- return ticks.map((tick, index: number) => {
34
- return (
35
- <rect
36
- key={index}
37
- {...size}
38
- x={isVertical ? 0 : scaler(tick) - bandwidth / 2}
39
- y={isVertical ? scaler(tick) - bandwidth / 2 : 0}
40
- fill={background}
41
- stroke='none'
42
- />
43
- );
44
- });
45
- };
1
+ /**
2
+ * 轴类图背景
3
+ */
4
+ import React from 'react';
5
+ import { getBandwidth } from '../utils';
6
+
7
+ export default ({
8
+ axis: { ticks, scaler, step, direction },
9
+ config: { background, paddingInner: paddingOuter },
10
+ length,
11
+ }: {
12
+ axis: {
13
+ ticks: Array<string>;
14
+ scaler: Function;
15
+ step: number;
16
+ direction: string;
17
+ };
18
+ config: { background: string; paddingInner: number };
19
+ length: number;
20
+ }) => {
21
+ const isVertical: boolean = direction === 'vertical';
22
+ const bandwidth = getBandwidth(step, paddingOuter);
23
+ const size = isVertical
24
+ ? {
25
+ width: length,
26
+ height: bandwidth,
27
+ }
28
+ : {
29
+ width: bandwidth,
30
+ height: length,
31
+ };
32
+
33
+ return ticks.map((tick, index: number) => {
34
+ return (
35
+ <rect
36
+ key={index}
37
+ {...size}
38
+ x={isVertical ? 0 : scaler(tick) - bandwidth / 2}
39
+ y={isVertical ? scaler(tick) - bandwidth / 2 : 0}
40
+ fill={background}
41
+ stroke='none'
42
+ />
43
+ );
44
+ });
45
+ };
@@ -1,160 +1,160 @@
1
- /**
2
- * (柱状/条形)图柱子
3
- */
4
- import React, { memo } from 'react';
5
- import { min, max } from 'd3v7';
6
- import {
7
- getBandBackground,
8
- getBandwidth,
9
- getBandSeriesStepAndWidth,
10
- } from '../utils';
11
-
12
- const getHighlightData = (data: Array<DataWithBoundType>, extent: string) => {
13
- switch (extent) {
14
- case 'min':
15
- const minData = min(data, (d: DataWithBoundType) => d.data.y);
16
- return data.map((item) => ({
17
- ...item,
18
- flag: minData == item.data.y ? 'min' : '',
19
- }));
20
- case 'max':
21
- const maxData = max(data, (d: DataWithBoundType) => d.data.y);
22
- return data.map((item) => ({
23
- ...item,
24
- flag: maxData == item.data.y ? 'max' : '',
25
- }));
26
- default:
27
- return data;
28
- }
29
- };
30
-
31
- const getAttr = ({
32
- isVertical,
33
- seriesWidth,
34
- length,
35
- x,
36
- y,
37
- }: {
38
- isVertical: boolean;
39
- seriesWidth: number;
40
- length: number;
41
- x: number;
42
- y: number;
43
- }) => {
44
- if (isVertical) return { width: length, height: seriesWidth, x: y, y: x };
45
- return {
46
- x,
47
- y,
48
- width: seriesWidth,
49
- height: length,
50
- };
51
- };
52
-
53
- const getBorderRadius = ({
54
- isVertical,
55
- positive,
56
- seriesWidth,
57
- }: {
58
- isVertical: boolean;
59
- positive: boolean;
60
- seriesWidth: number;
61
- }) => {
62
- return isVertical
63
- ? positive
64
- ? '0px ' + seriesWidth + 'px ' + seriesWidth + 'px 0'
65
- : seriesWidth + 'px 0 0 ' + seriesWidth + 'px'
66
- : positive
67
- ? seriesWidth / 2 + 'px ' + seriesWidth / 2 + 'px 0 0'
68
- : '0 0 ' + seriesWidth / 2 + 'px ' + seriesWidth / 2 + 'px';
69
- };
70
-
71
- export default memo(
72
- ({
73
- triggerClick,
74
- config: {
75
- pattern = {},
76
- seriesIntervalWidth: paddingInner = 0,
77
- paddingInner: paddingOuter = 0,
78
- style,
79
- fill,
80
- highlight: { show: showHighlight, extent, fill: highlightFill },
81
- },
82
- bandLength = 0,
83
- data,
84
- xAxis: { scaler: xScaler, step, direction },
85
- yAxis: { scaler: yScaler },
86
- }: any) => {
87
- if (!data.length) return null;
88
- const bandwidth = getBandwidth(step, paddingOuter);
89
- const { seriesStep, seriesWidth } = getBandSeriesStepAndWidth({
90
- width: bandwidth,
91
- paddingInner,
92
- bandLength,
93
- });
94
-
95
- const _data = showHighlight ? getHighlightData(data, extent) : data;
96
-
97
- const offset =
98
- (seriesWidth + paddingInner * seriesStep) * bandLength -
99
- paddingInner * seriesStep;
100
-
101
- const isVertical = direction === 'vertical';
102
- return (
103
- <g className='__easyv-band'>
104
- {_data.map(
105
- (
106
- {
107
- flag,
108
- index,
109
- bound: [start, end],
110
- data,
111
- data: { x, y, s },
112
- }: DataWithBoundType,
113
- i: number
114
- ) => {
115
- const y1 = yScaler(isVertical ? end : start);
116
- const y2 = yScaler(isVertical ? start : end);
117
- const positionX = xScaler(x) + seriesStep * index - offset / 2;
118
- if (isNaN(positionX)) return null;
119
- const positionY = y < 0 ? y1 : y2;
120
- const attr = getAttr({
121
- isVertical,
122
- x: positionX,
123
- y: positionY,
124
- length: Math.abs(y1 - y2),
125
- seriesWidth,
126
- });
127
-
128
- return (
129
- <foreignObject
130
- key={i}
131
- {...attr}
132
- onClick={triggerClick}
133
- data-data={JSON.stringify(data)}
134
- >
135
- <div
136
- style={{
137
- width: '100%',
138
- height: '100%',
139
- background: getBandBackground(
140
- pattern,
141
- extent === flag ? highlightFill : fill
142
- ),
143
- borderRadius:
144
- style == 'square'
145
- ? '0 0 0 0'
146
- : getBorderRadius({
147
- isVertical,
148
- positive: y > 0,
149
- seriesWidth,
150
- }),
151
- }}
152
- />
153
- </foreignObject>
154
- );
155
- }
156
- )}
157
- </g>
158
- );
159
- }
160
- );
1
+ /**
2
+ * (柱状/条形)图柱子
3
+ */
4
+ import React, { memo } from 'react';
5
+ import { min, max } from 'd3v7';
6
+ import {
7
+ getBandBackground,
8
+ getBandwidth,
9
+ getBandSeriesStepAndWidth,
10
+ } from '../utils';
11
+
12
+ const getHighlightData = (data: Array<DataWithBoundType>, extent: string) => {
13
+ switch (extent) {
14
+ case 'min':
15
+ const minData = min(data, (d: DataWithBoundType) => d.data.y);
16
+ return data.map((item) => ({
17
+ ...item,
18
+ flag: minData == item.data.y ? 'min' : '',
19
+ }));
20
+ case 'max':
21
+ const maxData = max(data, (d: DataWithBoundType) => d.data.y);
22
+ return data.map((item) => ({
23
+ ...item,
24
+ flag: maxData == item.data.y ? 'max' : '',
25
+ }));
26
+ default:
27
+ return data;
28
+ }
29
+ };
30
+
31
+ const getAttr = ({
32
+ isVertical,
33
+ seriesWidth,
34
+ length,
35
+ x,
36
+ y,
37
+ }: {
38
+ isVertical: boolean;
39
+ seriesWidth: number;
40
+ length: number;
41
+ x: number;
42
+ y: number;
43
+ }) => {
44
+ if (isVertical) return { width: length, height: seriesWidth, x: y, y: x };
45
+ return {
46
+ x,
47
+ y,
48
+ width: seriesWidth,
49
+ height: length,
50
+ };
51
+ };
52
+
53
+ const getBorderRadius = ({
54
+ isVertical,
55
+ positive,
56
+ seriesWidth,
57
+ }: {
58
+ isVertical: boolean;
59
+ positive: boolean;
60
+ seriesWidth: number;
61
+ }) => {
62
+ return isVertical
63
+ ? positive
64
+ ? '0px ' + seriesWidth + 'px ' + seriesWidth + 'px 0'
65
+ : seriesWidth + 'px 0 0 ' + seriesWidth + 'px'
66
+ : positive
67
+ ? seriesWidth / 2 + 'px ' + seriesWidth / 2 + 'px 0 0'
68
+ : '0 0 ' + seriesWidth / 2 + 'px ' + seriesWidth / 2 + 'px';
69
+ };
70
+
71
+ export default memo(
72
+ ({
73
+ triggerClick,
74
+ config: {
75
+ pattern = {},
76
+ seriesIntervalWidth: paddingInner = 0,
77
+ paddingInner: paddingOuter = 0,
78
+ style,
79
+ fill,
80
+ highlight: { show: showHighlight, extent, fill: highlightFill },
81
+ },
82
+ bandLength = 0,
83
+ data,
84
+ xAxis: { scaler: xScaler, step, direction },
85
+ yAxis: { scaler: yScaler },
86
+ }: any) => {
87
+ if (!data.length) return null;
88
+ const bandwidth = getBandwidth(step, paddingOuter);
89
+ const { seriesStep, seriesWidth } = getBandSeriesStepAndWidth({
90
+ width: bandwidth,
91
+ paddingInner,
92
+ bandLength,
93
+ });
94
+
95
+ const _data = showHighlight ? getHighlightData(data, extent) : data;
96
+
97
+ const offset =
98
+ (seriesWidth + paddingInner * seriesStep) * bandLength -
99
+ paddingInner * seriesStep;
100
+
101
+ const isVertical = direction === 'vertical';
102
+ return (
103
+ <g className='__easyv-band'>
104
+ {_data.map(
105
+ (
106
+ {
107
+ flag,
108
+ index,
109
+ bound: [start, end],
110
+ data,
111
+ data: { x, y, s },
112
+ }: DataWithBoundType,
113
+ i: number
114
+ ) => {
115
+ const y1 = yScaler(isVertical ? end : start);
116
+ const y2 = yScaler(isVertical ? start : end);
117
+ const positionX = xScaler(x) + seriesStep * index - offset / 2;
118
+ if (isNaN(positionX)) return null;
119
+ const positionY = y < 0 ? y1 : y2;
120
+ const attr = getAttr({
121
+ isVertical,
122
+ x: positionX,
123
+ y: positionY,
124
+ length: Math.abs(y1 - y2),
125
+ seriesWidth,
126
+ });
127
+
128
+ return (
129
+ <foreignObject
130
+ key={i}
131
+ {...attr}
132
+ onClick={triggerClick}
133
+ data-data={JSON.stringify(data)}
134
+ >
135
+ <div
136
+ style={{
137
+ width: '100%',
138
+ height: '100%',
139
+ background: getBandBackground(
140
+ pattern,
141
+ extent === flag ? highlightFill : fill
142
+ ),
143
+ borderRadius:
144
+ style == 'square'
145
+ ? '0 0 0 0'
146
+ : getBorderRadius({
147
+ isVertical,
148
+ positive: y > 0,
149
+ seriesWidth,
150
+ }),
151
+ }}
152
+ />
153
+ </foreignObject>
154
+ );
155
+ }
156
+ )}
157
+ </g>
158
+ );
159
+ }
160
+ );