@easyv/charts 1.2.1 → 1.2.4

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 (90) hide show
  1. package/.babelrc +8 -8
  2. package/.husky/commit-msg +3 -3
  3. package/CHANGELOG.md +18 -18
  4. package/commitlint.config.js +1 -1
  5. package/lib/components/AnimateData.js +40 -36
  6. package/lib/components/Axis.js +333 -329
  7. package/lib/components/Background.js +2 -2
  8. package/lib/components/Band.js +177 -173
  9. package/lib/components/Brush.js +201 -201
  10. package/lib/components/Carousel.js +171 -164
  11. package/lib/components/CartesianChart.js +11 -7
  12. package/lib/components/Chart.js +114 -111
  13. package/lib/components/ChartContainer.js +62 -58
  14. package/lib/components/ConicalGradient.js +268 -264
  15. package/lib/components/ExtentData.js +48 -45
  16. package/lib/components/FilterData.js +56 -53
  17. package/lib/components/Indicator.js +2 -2
  18. package/lib/components/Label.js +278 -278
  19. package/lib/components/Legend.js +160 -154
  20. package/lib/components/Lighter.js +179 -179
  21. package/lib/components/Line.js +187 -181
  22. package/lib/components/LinearGradient.js +2 -2
  23. package/lib/components/Mapping.js +130 -127
  24. package/lib/components/Marquee.js +98 -0
  25. package/lib/components/PieChart.js +1078 -1061
  26. package/lib/components/StackData.js +48 -45
  27. package/lib/components/StereoBar.js +340 -336
  28. package/lib/components/TextOverflow.js +65 -0
  29. package/lib/components/Tooltip.js +155 -155
  30. package/lib/components/index.js +202 -194
  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 +91 -91
  35. package/lib/hooks/index.js +62 -62
  36. package/lib/hooks/useAnimateData.js +88 -88
  37. package/lib/hooks/useAxes.js +135 -135
  38. package/lib/hooks/useCarouselAxisX.js +184 -184
  39. package/lib/hooks/useExtentData.js +128 -128
  40. package/lib/hooks/useFilterData.js +112 -112
  41. package/lib/hooks/useStackData.js +136 -134
  42. package/lib/hooks/useTooltip.js +10 -10
  43. package/lib/index.js +89 -85
  44. package/lib/utils/index.js +835 -832
  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/Brush.js +159 -159
  51. package/src/components/Carousel.tsx +144 -144
  52. package/src/components/Chart.js +99 -99
  53. package/src/components/ChartContainer.tsx +63 -63
  54. package/src/components/ConicalGradient.js +258 -258
  55. package/src/components/ExtentData.js +17 -17
  56. package/src/components/FilterData.js +23 -23
  57. package/src/components/Indicator.js +13 -13
  58. package/src/components/Label.js +206 -206
  59. package/src/components/Legend.js +158 -158
  60. package/src/components/Lighter.jsx +173 -173
  61. package/src/components/Line.js +144 -144
  62. package/src/components/LinearGradient.js +29 -29
  63. package/src/components/Mapping.js +71 -71
  64. package/src/components/Marquee.js +93 -74
  65. package/src/components/PieChart.js +1288 -1097
  66. package/src/components/StackData.js +20 -20
  67. package/src/components/StereoBar.tsx +310 -310
  68. package/src/components/TextOverflow.js +51 -0
  69. package/src/components/Tooltip.js +169 -169
  70. package/src/components/index.js +53 -51
  71. package/src/context/index.js +2 -2
  72. package/src/css/index.module.css +41 -41
  73. package/src/css/piechart.module.css +26 -26
  74. package/src/element/ConicGradient.jsx +55 -55
  75. package/src/element/Line.tsx +33 -33
  76. package/src/element/index.ts +3 -3
  77. package/src/formatter/index.js +1 -1
  78. package/src/formatter/legend.js +90 -90
  79. package/src/hooks/index.js +17 -17
  80. package/src/hooks/useAnimateData.ts +67 -67
  81. package/src/hooks/useAxes.js +144 -144
  82. package/src/hooks/useCarouselAxisX.js +163 -163
  83. package/src/hooks/useExtentData.js +88 -88
  84. package/src/hooks/useFilterData.js +72 -72
  85. package/src/hooks/useStackData.js +100 -100
  86. package/src/hooks/useTooltip.ts +96 -96
  87. package/src/index.js +6 -6
  88. package/src/types/index.d.ts +67 -67
  89. package/src/utils/index.js +696 -696
  90. 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
+ };