@easyv/charts 1.1.7 → 1.2.1

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