@easyv/charts 1.5.29 → 1.5.30

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 (53) 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/Background.js +2 -2
  6. package/lib/components/ConicalGradient.js +21 -21
  7. package/lib/components/Lighter.js +2 -2
  8. package/lib/components/LinearGradient.js +2 -2
  9. package/lib/css/index.module.css +42 -42
  10. package/lib/css/piechart.module.css +26 -26
  11. package/lib/hooks/useAnimateData.js +6 -6
  12. package/lib/hooks/useAxes.js +29 -6
  13. package/lib/hooks/useExtentData.js +19 -4
  14. package/lib/hooks/useFilterData.js +5 -5
  15. package/lib/hooks/useStackData.js +5 -5
  16. package/lib/hooks/useTooltip.js +11 -11
  17. package/package.json +55 -55
  18. package/src/components/Background.tsx +61 -61
  19. package/src/components/Band.tsx +271 -271
  20. package/src/components/Brush.js +159 -159
  21. package/src/components/Chart.js +135 -135
  22. package/src/components/ChartContainer.tsx +71 -71
  23. package/src/components/ConicalGradient.js +258 -258
  24. package/src/components/Control.jsx +236 -236
  25. package/src/components/ExtentData.js +18 -18
  26. package/src/components/Indicator.js +58 -58
  27. package/src/components/Label.js +242 -242
  28. package/src/components/Legend.js +166 -166
  29. package/src/components/Lighter.jsx +173 -173
  30. package/src/components/Line.js +153 -153
  31. package/src/components/LinearGradient.js +29 -29
  32. package/src/components/PieTooltip.jsx +160 -160
  33. package/src/components/StereoBar.tsx +307 -307
  34. package/src/components/index.js +59 -59
  35. package/src/context/index.js +2 -2
  36. package/src/css/index.module.css +42 -42
  37. package/src/css/piechart.module.css +26 -26
  38. package/src/element/ConicGradient.jsx +55 -55
  39. package/src/element/Line.tsx +33 -33
  40. package/src/element/index.ts +3 -3
  41. package/src/formatter/index.js +1 -1
  42. package/src/formatter/legend.js +92 -92
  43. package/src/hooks/index.js +20 -20
  44. package/src/hooks/useAnimateData.ts +68 -68
  45. package/src/hooks/useAxes.js +86 -32
  46. package/src/hooks/useExtentData.js +52 -16
  47. package/src/hooks/useFilterData.js +78 -78
  48. package/src/hooks/useStackData.js +102 -102
  49. package/src/hooks/useTooltip.ts +104 -104
  50. package/src/index.js +6 -6
  51. package/src/types/index.d.ts +68 -68
  52. package/src/utils/index.js +762 -762
  53. package/tsconfig.json +23 -23
@@ -1,61 +1,61 @@
1
- /**
2
- * 轴类图背景
3
- */
4
- import React from 'react';
5
- import { getSeriesInfo } from '../utils';
6
-
7
- export default ({
8
- axis: { ticks, scaler, step, direction },
9
- bandLength,
10
- config: {
11
- background,
12
- seriesIntervalWidth: paddingInner,
13
- paddingInner: paddingOuter,
14
- },
15
- length,
16
- }: {
17
- axis: {
18
- ticks: Array<string>;
19
- scaler: Function;
20
- step: number;
21
- direction: string;
22
- };
23
- bandLength: number;
24
- config: {
25
- background: string;
26
- seriesIntervalWidth: number;
27
- paddingInner: number;
28
- };
29
- length: number;
30
- }) => {
31
- const isVertical: boolean = direction === 'vertical';
32
-
33
- const { width: bandwidth } = getSeriesInfo({
34
- step,
35
- bandLength,
36
- paddingInner,
37
- paddingOuter,
38
- });
39
-
40
- const size = isVertical
41
- ? {
42
- width: length,
43
- height: bandwidth,
44
- }
45
- : {
46
- width: bandwidth,
47
- height: length,
48
- };
49
- return ticks.map((tick, index: number) => {
50
- return (
51
- <rect
52
- key={index}
53
- {...size}
54
- x={isVertical ? 0 : scaler(tick) - bandwidth / 2}
55
- y={isVertical ? scaler(tick) - bandwidth / 2 : 0}
56
- fill={background}
57
- stroke='none'
58
- />
59
- );
60
- });
61
- };
1
+ /**
2
+ * 轴类图背景
3
+ */
4
+ import React from 'react';
5
+ import { getSeriesInfo } from '../utils';
6
+
7
+ export default ({
8
+ axis: { ticks, scaler, step, direction },
9
+ bandLength,
10
+ config: {
11
+ background,
12
+ seriesIntervalWidth: paddingInner,
13
+ paddingInner: paddingOuter,
14
+ },
15
+ length,
16
+ }: {
17
+ axis: {
18
+ ticks: Array<string>;
19
+ scaler: Function;
20
+ step: number;
21
+ direction: string;
22
+ };
23
+ bandLength: number;
24
+ config: {
25
+ background: string;
26
+ seriesIntervalWidth: number;
27
+ paddingInner: number;
28
+ };
29
+ length: number;
30
+ }) => {
31
+ const isVertical: boolean = direction === 'vertical';
32
+
33
+ const { width: bandwidth } = getSeriesInfo({
34
+ step,
35
+ bandLength,
36
+ paddingInner,
37
+ paddingOuter,
38
+ });
39
+
40
+ const size = isVertical
41
+ ? {
42
+ width: length,
43
+ height: bandwidth,
44
+ }
45
+ : {
46
+ width: bandwidth,
47
+ height: length,
48
+ };
49
+ return ticks.map((tick, index: number) => {
50
+ return (
51
+ <rect
52
+ key={index}
53
+ {...size}
54
+ x={isVertical ? 0 : scaler(tick) - bandwidth / 2}
55
+ y={isVertical ? scaler(tick) - bandwidth / 2 : 0}
56
+ fill={background}
57
+ stroke='none'
58
+ />
59
+ );
60
+ });
61
+ };
@@ -1,271 +1,271 @@
1
- /**
2
- * (柱状/条形)图柱子
3
- */
4
- import React, { memo } from "react";
5
- import { min, max } from "d3v7";
6
- import { getBandBackground, getSeriesInfo } from "../utils";
7
-
8
- const getHighlightData = (data: Array<DataWithBoundType>, extent: string) => {
9
- switch (extent) {
10
- case "min":
11
- const minData = min(data, (d: DataWithBoundType) => d.data.y);
12
- return data.map((item) => ({
13
- ...item,
14
- flag: minData == item.data.y ? "min" : "",
15
- }));
16
- case "max":
17
- const maxData = max(data, (d: DataWithBoundType) => d.data.y);
18
- return data.map((item) => ({
19
- ...item,
20
- flag: maxData == item.data.y ? "max" : "",
21
- }));
22
- default:
23
- return data;
24
- }
25
- };
26
-
27
- const getAttr = ({
28
- isVertical,
29
- seriesWidth,
30
- length,
31
- x,
32
- y,
33
- }: {
34
- isVertical: boolean;
35
- seriesWidth: number;
36
- length: number;
37
- x: number;
38
- y: number;
39
- }) => {
40
- if (isVertical) return { width: length, height: seriesWidth, x: y, y: x };
41
- return {
42
- x,
43
- y,
44
- width: seriesWidth,
45
- height: length,
46
- };
47
- };
48
-
49
- const getBorderRadius = ({
50
- isVertical,
51
- positive,
52
- seriesWidth,
53
- }: {
54
- isVertical: boolean;
55
- positive: boolean;
56
- seriesWidth: number;
57
- }) => {
58
- return isVertical
59
- ? positive
60
- ? "0px " + seriesWidth + "px " + seriesWidth + "px 0"
61
- : seriesWidth + "px 0 0 " + seriesWidth + "px"
62
- : positive
63
- ? seriesWidth / 2 + "px " + seriesWidth / 2 + "px 0 0"
64
- : "0 0 " + seriesWidth / 2 + "px " + seriesWidth / 2 + "px";
65
- };
66
-
67
- export default memo(
68
- ({
69
- //控制图部分,主要是为了控制图的指示器,在悬浮的时候显示
70
- triggerClick,
71
- indicatorWidth,
72
- isControlChart = false,
73
- setCtlTip,
74
- config: {
75
- pattern = {},
76
- seriesIntervalWidth: paddingInner = 0,
77
- paddingInner: paddingOuter = 0,
78
- style,
79
- fillType,
80
- url,
81
- size,
82
- fill,
83
- border,
84
- opacity,
85
- highlight: { show: showHighlight, extent, fill: highlightFill },
86
- headDecorate,
87
- },
88
- bandLength = 0,
89
- data,
90
- xAxis: { scaler: normalScaler, step:normalStep, controlStep, direction, controlDragScaler },
91
- yAxis: { scaler: yScaler, isClipAxis, clipValue, reverse },
92
- }: any) => {
93
- if (!data.length) return null;
94
- const step = isControlChart?controlStep:normalStep;
95
- const xScaler = isControlChart?controlDragScaler:normalScaler;
96
- const { seriesWidth, seriesStep, seriesStart } = getSeriesInfo({
97
- step,
98
- bandLength,
99
- paddingInner,
100
- paddingOuter,
101
- });
102
- const _data = showHighlight ? getHighlightData(data, extent) : data;
103
- const isVertical = direction === "vertical";
104
- const borderStr = `${border.borderColor} solid ${border.borderWidth}px`;
105
- return (
106
- <g className="__easyv-band">
107
- {_data.map(
108
- (
109
- {
110
- flag,
111
- index,
112
- bound: [start, end],
113
- data,
114
- data: { x, y, s },
115
- }: DataWithBoundType,
116
- i: number
117
- ) => {
118
- let y1: number, y2: number;
119
- //断轴图相关,断轴图的scaler是一个数组,内含上断轴下断轴的scaler
120
- if (isClipAxis) {
121
- if (end > +clipValue) {
122
- y1 = yScaler[1](start);
123
- y2 = yScaler[0](end);
124
- } else {
125
- y1 = yScaler[1](start);
126
- y2 = yScaler[1](end);
127
- }
128
- } else {
129
- y1 = yScaler(isVertical ? end : start);
130
- y2 = yScaler(isVertical ? start : end);
131
- }
132
- const positionX = xScaler(x) - step / 2 + seriesStart + index * seriesStep;
133
-
134
- let showHead, headUrl, headWidth, headHeight, headTranslate;
135
- if (headDecorate) {
136
- (showHead = headDecorate.show),
137
- (headUrl = headDecorate.url),
138
- (headWidth = headDecorate.size.width),
139
- (headHeight = headDecorate.size.height),
140
- (headTranslate = headDecorate.translate);
141
- }
142
- //断轴图相关,将柱形在断轴处切开
143
- const setClipPath = () => {
144
- if (isClipAxis && end > +clipValue) {
145
- let clipValueY2 = yScaler[0](clipValue); //上方
146
- let clipValueY1 = yScaler[1](clipValue); //下方
147
- let top = Math.abs((y2 - clipValueY2) / (y1 - y2)) * 100;
148
- let bottom = Math.abs((y2 - clipValueY1) / (y1 - y2)) * 100;
149
-
150
- //clip path属性
151
- return `polygon(0% 0%, 0% 100%, 0 100%, 0 ${top}%, 100% ${top}%, 100% ${bottom}%, 0 ${bottom}%, 0 100%, 100% 100%, 100% 0%)`;
152
- } else {
153
- return "none";
154
- }
155
- };
156
- if (isNaN(positionX)) return null;
157
- const positionY = reverse?
158
- y > 0 ? y1 : y2:
159
- y < 0 ? y1 : y2;
160
- const attr = getAttr({
161
- isVertical,
162
- x: positionX,
163
- y: positionY,
164
- length: Math.abs(y1 - y2),
165
- seriesWidth,
166
- });
167
- return (
168
- <foreignObject
169
- key={i}
170
- style={{
171
- overflow: "visible",
172
- position: "relative",
173
- cursor: "pointer",
174
- }}
175
- {...attr}
176
- onClick={triggerClick}
177
- //enter和leave事件,用于控制图的提示框
178
- onMouseEnter={() => {
179
- if(isControlChart){
180
- setCtlTip((pre:any)=>({
181
- show:true,
182
- x:xScaler(x),
183
- xName:data.x,
184
- indicatorList:pre.indicatorList.map((item:any)=>{
185
- if (item.tick === data.x) {
186
- return { ...item, isShow: true };
187
- } else {
188
- return item;
189
- }
190
- })
191
- }))
192
- }
193
- }}
194
- onMouseLeave={() => {
195
- if(isControlChart){
196
- setCtlTip((pre:any)=>({
197
- show:false,
198
- x:undefined,
199
- xName:undefined,
200
- indicatorList:pre.indicatorList.map((item:any)=>{
201
- return { ...item, isShow:false }
202
- })
203
- }))
204
- }
205
- }}
206
- data-data={JSON.stringify(data)}
207
- >
208
- {headUrl && showHead && (
209
- <div
210
- style={{
211
- position: "absolute",
212
- background: `url(${
213
- //@ts-ignore
214
- window.appConfig.ASSETS_URL + headUrl
215
- }) 0 0/100% 100%`,
216
- width: headWidth,
217
- height: headHeight,
218
- left: isVertical ? "100%" : "50%",
219
- top: isVertical ? "50%" : "0",
220
- zIndex: 1,
221
- transform: `translate(calc(-50% + ${headTranslate.x}px), calc(-50% + ${headTranslate.y}px))`,
222
- }}
223
- ></div>
224
- )}
225
- <div
226
- style={{
227
- width: "100%",
228
- height: "100%",
229
- /** Safari Bug **/
230
- // position: "fixed",
231
- clipPath: setClipPath(),
232
- opacity: fillType == "pattern" ? opacity : 1,
233
- background:
234
- fillType == "pattern"
235
- ? `50% 50% / ${size.width}px ${size.height}px repeat ` +
236
- "url(" +
237
- url +
238
- ")"
239
- : getBandBackground(
240
- pattern,
241
- extent === flag ? highlightFill : fill
242
- ),
243
- borderRadius:
244
- style == "square"
245
- ? "0 0 0 0"
246
- : getBorderRadius({
247
- isVertical,
248
- positive: y > 0,
249
- seriesWidth,
250
- }),
251
- ...(isVertical
252
- ? {
253
- borderTop: borderStr,
254
- borderRight: borderStr,
255
- borderBottom: borderStr,
256
- }
257
- : {
258
- borderTop: borderStr,
259
- borderRight: borderStr,
260
- borderLeft: borderStr,
261
- }),
262
- }}
263
- />
264
- </foreignObject>
265
- );
266
- }
267
- )}
268
- </g>
269
- );
270
- }
271
- );
1
+ /**
2
+ * (柱状/条形)图柱子
3
+ */
4
+ import React, { memo } from "react";
5
+ import { min, max } from "d3v7";
6
+ import { getBandBackground, getSeriesInfo } from "../utils";
7
+
8
+ const getHighlightData = (data: Array<DataWithBoundType>, extent: string) => {
9
+ switch (extent) {
10
+ case "min":
11
+ const minData = min(data, (d: DataWithBoundType) => d.data.y);
12
+ return data.map((item) => ({
13
+ ...item,
14
+ flag: minData == item.data.y ? "min" : "",
15
+ }));
16
+ case "max":
17
+ const maxData = max(data, (d: DataWithBoundType) => d.data.y);
18
+ return data.map((item) => ({
19
+ ...item,
20
+ flag: maxData == item.data.y ? "max" : "",
21
+ }));
22
+ default:
23
+ return data;
24
+ }
25
+ };
26
+
27
+ const getAttr = ({
28
+ isVertical,
29
+ seriesWidth,
30
+ length,
31
+ x,
32
+ y,
33
+ }: {
34
+ isVertical: boolean;
35
+ seriesWidth: number;
36
+ length: number;
37
+ x: number;
38
+ y: number;
39
+ }) => {
40
+ if (isVertical) return { width: length, height: seriesWidth, x: y, y: x };
41
+ return {
42
+ x,
43
+ y,
44
+ width: seriesWidth,
45
+ height: length,
46
+ };
47
+ };
48
+
49
+ const getBorderRadius = ({
50
+ isVertical,
51
+ positive,
52
+ seriesWidth,
53
+ }: {
54
+ isVertical: boolean;
55
+ positive: boolean;
56
+ seriesWidth: number;
57
+ }) => {
58
+ return isVertical
59
+ ? positive
60
+ ? "0px " + seriesWidth + "px " + seriesWidth + "px 0"
61
+ : seriesWidth + "px 0 0 " + seriesWidth + "px"
62
+ : positive
63
+ ? seriesWidth / 2 + "px " + seriesWidth / 2 + "px 0 0"
64
+ : "0 0 " + seriesWidth / 2 + "px " + seriesWidth / 2 + "px";
65
+ };
66
+
67
+ export default memo(
68
+ ({
69
+ //控制图部分,主要是为了控制图的指示器,在悬浮的时候显示
70
+ triggerClick,
71
+ indicatorWidth,
72
+ isControlChart = false,
73
+ setCtlTip,
74
+ config: {
75
+ pattern = {},
76
+ seriesIntervalWidth: paddingInner = 0,
77
+ paddingInner: paddingOuter = 0,
78
+ style,
79
+ fillType,
80
+ url,
81
+ size,
82
+ fill,
83
+ border,
84
+ opacity,
85
+ highlight: { show: showHighlight, extent, fill: highlightFill },
86
+ headDecorate,
87
+ },
88
+ bandLength = 0,
89
+ data,
90
+ xAxis: { scaler: normalScaler, step:normalStep, controlStep, direction, controlDragScaler },
91
+ yAxis: { scaler: yScaler, isClipAxis, clipValue, reverse },
92
+ }: any) => {
93
+ if (!data.length) return null;
94
+ const step = isControlChart?controlStep:normalStep;
95
+ const xScaler = isControlChart?controlDragScaler:normalScaler;
96
+ const { seriesWidth, seriesStep, seriesStart } = getSeriesInfo({
97
+ step,
98
+ bandLength,
99
+ paddingInner,
100
+ paddingOuter,
101
+ });
102
+ const _data = showHighlight ? getHighlightData(data, extent) : data;
103
+ const isVertical = direction === "vertical";
104
+ const borderStr = `${border.borderColor} solid ${border.borderWidth}px`;
105
+ return (
106
+ <g className="__easyv-band">
107
+ {_data.map(
108
+ (
109
+ {
110
+ flag,
111
+ index,
112
+ bound: [start, end],
113
+ data,
114
+ data: { x, y, s },
115
+ }: DataWithBoundType,
116
+ i: number
117
+ ) => {
118
+ let y1: number, y2: number;
119
+ //断轴图相关,断轴图的scaler是一个数组,内含上断轴下断轴的scaler
120
+ if (isClipAxis) {
121
+ if (end > +clipValue) {
122
+ y1 = yScaler[1](start);
123
+ y2 = yScaler[0](end);
124
+ } else {
125
+ y1 = yScaler[1](start);
126
+ y2 = yScaler[1](end);
127
+ }
128
+ } else {
129
+ y1 = yScaler(isVertical ? end : start);
130
+ y2 = yScaler(isVertical ? start : end);
131
+ }
132
+ const positionX = xScaler(x) - step / 2 + seriesStart + index * seriesStep;
133
+
134
+ let showHead, headUrl, headWidth, headHeight, headTranslate;
135
+ if (headDecorate) {
136
+ (showHead = headDecorate.show),
137
+ (headUrl = headDecorate.url),
138
+ (headWidth = headDecorate.size.width),
139
+ (headHeight = headDecorate.size.height),
140
+ (headTranslate = headDecorate.translate);
141
+ }
142
+ //断轴图相关,将柱形在断轴处切开
143
+ const setClipPath = () => {
144
+ if (isClipAxis && end > +clipValue) {
145
+ let clipValueY2 = yScaler[0](clipValue); //上方
146
+ let clipValueY1 = yScaler[1](clipValue); //下方
147
+ let top = Math.abs((y2 - clipValueY2) / (y1 - y2)) * 100;
148
+ let bottom = Math.abs((y2 - clipValueY1) / (y1 - y2)) * 100;
149
+
150
+ //clip path属性
151
+ return `polygon(0% 0%, 0% 100%, 0 100%, 0 ${top}%, 100% ${top}%, 100% ${bottom}%, 0 ${bottom}%, 0 100%, 100% 100%, 100% 0%)`;
152
+ } else {
153
+ return "none";
154
+ }
155
+ };
156
+ if (isNaN(positionX)) return null;
157
+ const positionY = reverse?
158
+ y > 0 ? y1 : y2:
159
+ y < 0 ? y1 : y2;
160
+ const attr = getAttr({
161
+ isVertical,
162
+ x: positionX,
163
+ y: positionY,
164
+ length: Math.abs(y1 - y2),
165
+ seriesWidth,
166
+ });
167
+ return (
168
+ <foreignObject
169
+ key={i}
170
+ style={{
171
+ overflow: "visible",
172
+ position: "relative",
173
+ cursor: "pointer",
174
+ }}
175
+ {...attr}
176
+ onClick={triggerClick}
177
+ //enter和leave事件,用于控制图的提示框
178
+ onMouseEnter={() => {
179
+ if(isControlChart){
180
+ setCtlTip((pre:any)=>({
181
+ show:true,
182
+ x:xScaler(x),
183
+ xName:data.x,
184
+ indicatorList:pre.indicatorList.map((item:any)=>{
185
+ if (item.tick === data.x) {
186
+ return { ...item, isShow: true };
187
+ } else {
188
+ return item;
189
+ }
190
+ })
191
+ }))
192
+ }
193
+ }}
194
+ onMouseLeave={() => {
195
+ if(isControlChart){
196
+ setCtlTip((pre:any)=>({
197
+ show:false,
198
+ x:undefined,
199
+ xName:undefined,
200
+ indicatorList:pre.indicatorList.map((item:any)=>{
201
+ return { ...item, isShow:false }
202
+ })
203
+ }))
204
+ }
205
+ }}
206
+ data-data={JSON.stringify(data)}
207
+ >
208
+ {headUrl && showHead && (
209
+ <div
210
+ style={{
211
+ position: "absolute",
212
+ background: `url(${
213
+ //@ts-ignore
214
+ window.appConfig.ASSETS_URL + headUrl
215
+ }) 0 0/100% 100%`,
216
+ width: headWidth,
217
+ height: headHeight,
218
+ left: isVertical ? "100%" : "50%",
219
+ top: isVertical ? "50%" : "0",
220
+ zIndex: 1,
221
+ transform: `translate(calc(-50% + ${headTranslate.x}px), calc(-50% + ${headTranslate.y}px))`,
222
+ }}
223
+ ></div>
224
+ )}
225
+ <div
226
+ style={{
227
+ width: "100%",
228
+ height: "100%",
229
+ /** Safari Bug **/
230
+ // position: "fixed",
231
+ clipPath: setClipPath(),
232
+ opacity: fillType == "pattern" ? opacity : 1,
233
+ background:
234
+ fillType == "pattern"
235
+ ? `50% 50% / ${size.width}px ${size.height}px repeat ` +
236
+ "url(" +
237
+ url +
238
+ ")"
239
+ : getBandBackground(
240
+ pattern,
241
+ extent === flag ? highlightFill : fill
242
+ ),
243
+ borderRadius:
244
+ style == "square"
245
+ ? "0 0 0 0"
246
+ : getBorderRadius({
247
+ isVertical,
248
+ positive: y > 0,
249
+ seriesWidth,
250
+ }),
251
+ ...(isVertical
252
+ ? {
253
+ borderTop: borderStr,
254
+ borderRight: borderStr,
255
+ borderBottom: borderStr,
256
+ }
257
+ : {
258
+ borderTop: borderStr,
259
+ borderRight: borderStr,
260
+ borderLeft: borderStr,
261
+ }),
262
+ }}
263
+ />
264
+ </foreignObject>
265
+ );
266
+ }
267
+ )}
268
+ </g>
269
+ );
270
+ }
271
+ );