@easyv/charts 1.5.28 → 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 (55) 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/components/PieChart.js +3 -2
  10. package/lib/css/index.module.css +42 -42
  11. package/lib/css/piechart.module.css +26 -26
  12. package/lib/hooks/useAnimateData.js +6 -6
  13. package/lib/hooks/useAxes.js +29 -6
  14. package/lib/hooks/useExtentData.js +19 -4
  15. package/lib/hooks/useFilterData.js +5 -5
  16. package/lib/hooks/useStackData.js +5 -5
  17. package/lib/hooks/useTooltip.js +11 -11
  18. package/package.json +55 -55
  19. package/src/components/Background.tsx +61 -61
  20. package/src/components/Band.tsx +271 -271
  21. package/src/components/Brush.js +159 -159
  22. package/src/components/Chart.js +135 -135
  23. package/src/components/ChartContainer.tsx +71 -71
  24. package/src/components/ConicalGradient.js +258 -258
  25. package/src/components/Control.jsx +236 -236
  26. package/src/components/ExtentData.js +18 -18
  27. package/src/components/Indicator.js +58 -58
  28. package/src/components/Label.js +242 -242
  29. package/src/components/Legend.js +166 -166
  30. package/src/components/Lighter.jsx +173 -173
  31. package/src/components/Line.js +153 -153
  32. package/src/components/LinearGradient.js +29 -29
  33. package/src/components/PieChart.js +1 -1
  34. package/src/components/PieTooltip.jsx +160 -160
  35. package/src/components/StereoBar.tsx +307 -307
  36. package/src/components/index.js +59 -59
  37. package/src/context/index.js +2 -2
  38. package/src/css/index.module.css +42 -42
  39. package/src/css/piechart.module.css +26 -26
  40. package/src/element/ConicGradient.jsx +55 -55
  41. package/src/element/Line.tsx +33 -33
  42. package/src/element/index.ts +3 -3
  43. package/src/formatter/index.js +1 -1
  44. package/src/formatter/legend.js +92 -92
  45. package/src/hooks/index.js +20 -20
  46. package/src/hooks/useAnimateData.ts +68 -68
  47. package/src/hooks/useAxes.js +86 -32
  48. package/src/hooks/useExtentData.js +52 -16
  49. package/src/hooks/useFilterData.js +78 -78
  50. package/src/hooks/useStackData.js +102 -102
  51. package/src/hooks/useTooltip.ts +104 -104
  52. package/src/index.js +6 -6
  53. package/src/types/index.d.ts +68 -68
  54. package/src/utils/index.js +762 -762
  55. package/tsconfig.json +23 -23
@@ -1,159 +1,159 @@
1
- /**
2
- * 实现中
3
- */
4
- import { memo, useState, useCallback, useEffect, useRef } from 'react';
5
-
6
- const left = {
7
- position: 'relative',
8
- width: 5,
9
- height: '100%',
10
- cursor: 'col-resize',
11
- backgroundClip: 'content-box',
12
- };
13
- const center = {
14
- flex: '1 1 0%',
15
- height: '100%',
16
- cursor: 'move',
17
- };
18
- const right = {
19
- position: 'relative',
20
- width: 5,
21
- height: '100%',
22
- cursor: 'col-resize',
23
- backgroundClip: 'content-box',
24
- };
25
- const initialPosition = {
26
- start: 0,
27
- end: 0,
28
- status: '',
29
- };
30
- const getValue = (x, min, max) => Math.max(min, Math.min(x, max));
31
- export default ({
32
- width,
33
- config: {
34
- height,
35
- background,
36
- margin: { marginLeft, marginRight },
37
- detail: { width: blockWidth, color },
38
- },
39
- }) => {
40
- const [state, setState] = useState({ translateX: 0, width: blockWidth });
41
- const availableWidth = width - marginLeft - marginRight;
42
- const cache = useRef(state);
43
-
44
- const move = useCallback(
45
- ({ delta, status, name }) => {
46
- let { width, translateX } = cache.current;
47
- const minWidth = 40;
48
- const minX = 0;
49
- switch (name) {
50
- case 'center':
51
- translateX = getValue(
52
- translateX + delta,
53
- minX,
54
- availableWidth - width
55
- );
56
- break;
57
- case 'left':
58
- let tempWidth = width;
59
- width = getValue(width + delta * -1, minWidth, translateX + width);
60
- translateX = getValue(
61
- translateX + delta,
62
- minX,
63
- translateX + tempWidth - width
64
- );
65
- break;
66
- case 'right':
67
- width = getValue(
68
- width + delta,
69
- minWidth,
70
- availableWidth - translateX
71
- );
72
- break;
73
- }
74
-
75
- if (status === 'up') {
76
- cache.current = { width, translateX };
77
- }
78
-
79
- setState({ width, translateX });
80
- },
81
- [availableWidth]
82
- );
83
- useEffect(() => {}, [state]);
84
- return (
85
- <div
86
- style={{
87
- marginLeft,
88
- marginRight,
89
- height,
90
- background,
91
- position: 'absolute',
92
- bottom: 0,
93
- width: availableWidth,
94
- }}
95
- >
96
- <div
97
- style={{
98
- display: 'flex',
99
- justifyContent: 'space-between',
100
- position: 'absolute',
101
- top: 0,
102
- left: 0,
103
- transform: 'translate3d(' + state.translateX + 'px, 0, 0)',
104
- height: '100%',
105
- width: state.width + 'px',
106
- backgroundColor: color,
107
- }}
108
- >
109
- <Move style={left} move={move} name='left' />
110
- <Move style={center} move={move} name='center' />
111
- <Move style={right} move={move} name='right' />
112
- </div>
113
- </div>
114
- );
115
- };
116
- const Move = memo(({ style, move, name }) => {
117
- const [position, setPosition] = useState(initialPosition);
118
-
119
- const documentOnMouseMove = useCallback((e) => {
120
- // console.log('documentOnMouseMove');
121
- setPosition((position) => {
122
- return {
123
- ...position,
124
- end: e.clientX,
125
- status: 'move',
126
- };
127
- });
128
- }, []);
129
-
130
- const documentOnMouseUp = useCallback((e) => {
131
- // console.log('documentOnMouseUp');
132
- setPosition((position) => {
133
- return {
134
- ...position,
135
- end: e.clientX,
136
- status: 'up',
137
- };
138
- });
139
- document.removeEventListener('mousemove', documentOnMouseMove);
140
- document.removeEventListener('mouseup', documentOnMouseUp);
141
- }, []);
142
-
143
- const onMouseDown = useCallback((e) => {
144
- // console.log('onMouseDown');
145
- setPosition({
146
- end: e.clientX,
147
- start: e.clientX,
148
- status: 'down',
149
- });
150
- document.addEventListener('mousemove', documentOnMouseMove);
151
- document.addEventListener('mouseup', documentOnMouseUp);
152
- }, []);
153
-
154
- useEffect(() => {
155
- const { start, end, status } = position;
156
- move({ delta: end - start, status, name });
157
- }, [position, move, name]);
158
- return <div style={style} onMouseDown={onMouseDown} />;
159
- });
1
+ /**
2
+ * 实现中
3
+ */
4
+ import { memo, useState, useCallback, useEffect, useRef } from 'react';
5
+
6
+ const left = {
7
+ position: 'relative',
8
+ width: 5,
9
+ height: '100%',
10
+ cursor: 'col-resize',
11
+ backgroundClip: 'content-box',
12
+ };
13
+ const center = {
14
+ flex: '1 1 0%',
15
+ height: '100%',
16
+ cursor: 'move',
17
+ };
18
+ const right = {
19
+ position: 'relative',
20
+ width: 5,
21
+ height: '100%',
22
+ cursor: 'col-resize',
23
+ backgroundClip: 'content-box',
24
+ };
25
+ const initialPosition = {
26
+ start: 0,
27
+ end: 0,
28
+ status: '',
29
+ };
30
+ const getValue = (x, min, max) => Math.max(min, Math.min(x, max));
31
+ export default ({
32
+ width,
33
+ config: {
34
+ height,
35
+ background,
36
+ margin: { marginLeft, marginRight },
37
+ detail: { width: blockWidth, color },
38
+ },
39
+ }) => {
40
+ const [state, setState] = useState({ translateX: 0, width: blockWidth });
41
+ const availableWidth = width - marginLeft - marginRight;
42
+ const cache = useRef(state);
43
+
44
+ const move = useCallback(
45
+ ({ delta, status, name }) => {
46
+ let { width, translateX } = cache.current;
47
+ const minWidth = 40;
48
+ const minX = 0;
49
+ switch (name) {
50
+ case 'center':
51
+ translateX = getValue(
52
+ translateX + delta,
53
+ minX,
54
+ availableWidth - width
55
+ );
56
+ break;
57
+ case 'left':
58
+ let tempWidth = width;
59
+ width = getValue(width + delta * -1, minWidth, translateX + width);
60
+ translateX = getValue(
61
+ translateX + delta,
62
+ minX,
63
+ translateX + tempWidth - width
64
+ );
65
+ break;
66
+ case 'right':
67
+ width = getValue(
68
+ width + delta,
69
+ minWidth,
70
+ availableWidth - translateX
71
+ );
72
+ break;
73
+ }
74
+
75
+ if (status === 'up') {
76
+ cache.current = { width, translateX };
77
+ }
78
+
79
+ setState({ width, translateX });
80
+ },
81
+ [availableWidth]
82
+ );
83
+ useEffect(() => {}, [state]);
84
+ return (
85
+ <div
86
+ style={{
87
+ marginLeft,
88
+ marginRight,
89
+ height,
90
+ background,
91
+ position: 'absolute',
92
+ bottom: 0,
93
+ width: availableWidth,
94
+ }}
95
+ >
96
+ <div
97
+ style={{
98
+ display: 'flex',
99
+ justifyContent: 'space-between',
100
+ position: 'absolute',
101
+ top: 0,
102
+ left: 0,
103
+ transform: 'translate3d(' + state.translateX + 'px, 0, 0)',
104
+ height: '100%',
105
+ width: state.width + 'px',
106
+ backgroundColor: color,
107
+ }}
108
+ >
109
+ <Move style={left} move={move} name='left' />
110
+ <Move style={center} move={move} name='center' />
111
+ <Move style={right} move={move} name='right' />
112
+ </div>
113
+ </div>
114
+ );
115
+ };
116
+ const Move = memo(({ style, move, name }) => {
117
+ const [position, setPosition] = useState(initialPosition);
118
+
119
+ const documentOnMouseMove = useCallback((e) => {
120
+ // console.log('documentOnMouseMove');
121
+ setPosition((position) => {
122
+ return {
123
+ ...position,
124
+ end: e.clientX,
125
+ status: 'move',
126
+ };
127
+ });
128
+ }, []);
129
+
130
+ const documentOnMouseUp = useCallback((e) => {
131
+ // console.log('documentOnMouseUp');
132
+ setPosition((position) => {
133
+ return {
134
+ ...position,
135
+ end: e.clientX,
136
+ status: 'up',
137
+ };
138
+ });
139
+ document.removeEventListener('mousemove', documentOnMouseMove);
140
+ document.removeEventListener('mouseup', documentOnMouseUp);
141
+ }, []);
142
+
143
+ const onMouseDown = useCallback((e) => {
144
+ // console.log('onMouseDown');
145
+ setPosition({
146
+ end: e.clientX,
147
+ start: e.clientX,
148
+ status: 'down',
149
+ });
150
+ document.addEventListener('mousemove', documentOnMouseMove);
151
+ document.addEventListener('mouseup', documentOnMouseUp);
152
+ }, []);
153
+
154
+ useEffect(() => {
155
+ const { start, end, status } = position;
156
+ move({ delta: end - start, status, name });
157
+ }, [position, move, name]);
158
+ return <div style={style} onMouseDown={onMouseDown} />;
159
+ });
@@ -1,135 +1,135 @@
1
- /**
2
- * 总入口,通过外面传进来的type来确定渲染哪种图表,饼环图表为“pie”,否则为轴类图表
3
- */
4
- import React, { memo, useMemo, useRef, createRef, useState, useEffect, useCallback } from 'react';
5
- import { chartContext } from '../context';
6
- import { PieChart, CartesianChart } from '.';
7
- import { group } from 'd3v7';
8
-
9
- const getCallbackData = (action,callbacks, data) => {
10
- const callbackData={};
11
- if (callbacks && Array.isArray(callbacks) && callbacks.length && data) {
12
- callbacks.forEach(({ origin, target, actions:_action }) => {
13
- if(action === _action){
14
- callbackData[target] = data[origin];
15
- }
16
- });
17
- }
18
- return callbackData;
19
- };
20
-
21
- const Chart = memo(
22
- ({
23
- id,
24
- type,
25
- config,
26
- config: {
27
- axes,
28
- chart: {
29
- dimension: {
30
- chartDimension: { height, width },
31
- },
32
- margin: { marginRight, marginLeft, marginBottom, marginTop },
33
- },
34
- interaction,
35
- },
36
- data:originData,
37
- onRelative,
38
- emit,
39
- emitEvent,
40
- ...props
41
- }) => {
42
- const isIOS = useRef(/iPad|iPhone|iPod|iOS|CriOS/i.test(navigator.userAgent));
43
- const svg = createRef();
44
- const chartWidth = width - marginLeft - marginRight;
45
- const chartHeight = height - marginTop - marginBottom;
46
- const [active, setActive] = useState(true);
47
-
48
- const triggerOnRelative = useCallback(
49
- (action,data) => {
50
- if (!interaction) return;
51
- const { callbacks, remoteControls } = interaction;
52
- const callbackData = getCallbackData(action,callbacks, data);
53
- if (JSON.stringify(callbackData)!="{}") {
54
- onRelative && onRelative(id, callbackData);
55
- remoteControls &&
56
- emitEvent &&
57
- remoteControls.forEach((o) => {
58
- const control = JSON.parse(o.control);
59
- if (
60
- control.screen &&
61
- control.type &&
62
- control.type === 'callback'
63
- ) {
64
- emitEvent({
65
- screen: control.screen,
66
- type: 'callback',
67
- callbackData,
68
- });
69
- }
70
- });
71
- }
72
- },
73
- [ JSON.stringify(interaction)]
74
- );
75
-
76
- const onEmit = useCallback(
77
- (type = 'click', data) => emit && emit(type, data),
78
- [emit]
79
- );
80
-
81
- const context = useMemo(
82
- () => ({
83
- id,
84
- isIOS:isIOS.current,
85
- width: chartWidth,
86
- height: chartHeight,
87
- triggerOnRelative,
88
- svg,
89
- onEmit,
90
- }),
91
- [id, chartWidth, chartHeight, triggerOnRelative, svg, onEmit]
92
- );
93
-
94
- useEffect(()=>{
95
- let isAnimation = window.screenConfig?window.screenConfig.isAnimation:true; //大屏的全局设置是否允许开启动画,false为不允许
96
- if(!isAnimation) setActive(false);
97
- const activeHandler=(e)=>{
98
- const { dynamicData = true } = e;
99
- // console.log("当前组件(id="+id+")状态:",dynamicData?"唤醒":"休眠");
100
- isAnimation && setActive(dynamicData);
101
- }
102
- document.addEventListener(`switchActive_${id}`,activeHandler);
103
- return ()=>{
104
- document.removeEventListener(`switchActive_${id}`,activeHandler);
105
- }
106
- },[]);
107
-
108
- let data = originData;
109
- //对轴类图表进行自动排序
110
- // if(axes){
111
- // const xAxis = axes.find(d=>d.axisType=="x");
112
- // if(xAxis){
113
- // const { config:{ label:{ autoSort, format:{ type } } } } = xAxis;
114
- // if(type=="date" && autoSort){
115
- // const groupBySeries = group(data, (d) => d.s);
116
- // data=[...groupBySeries].flatMap(d=>{
117
- // return d[1].sort((a,b)=>a.x>b.x?1:-1)
118
- // });
119
- // }
120
- // }
121
- // }
122
-
123
- return (
124
- <chartContext.Provider value={context}>
125
- {type == 'pie' ? (
126
- <PieChart id={id} config={config} data={data} active={active} {...props} />
127
- ) : (
128
- <CartesianChart id={id} config={config} data={data} active={active} {...props} />
129
- )}
130
- </chartContext.Provider>
131
- );
132
- }
133
- );
134
-
135
- export default Chart;
1
+ /**
2
+ * 总入口,通过外面传进来的type来确定渲染哪种图表,饼环图表为“pie”,否则为轴类图表
3
+ */
4
+ import React, { memo, useMemo, useRef, createRef, useState, useEffect, useCallback } from 'react';
5
+ import { chartContext } from '../context';
6
+ import { PieChart, CartesianChart } from '.';
7
+ import { group } from 'd3v7';
8
+
9
+ const getCallbackData = (action,callbacks, data) => {
10
+ const callbackData={};
11
+ if (callbacks && Array.isArray(callbacks) && callbacks.length && data) {
12
+ callbacks.forEach(({ origin, target, actions:_action }) => {
13
+ if(action === _action){
14
+ callbackData[target] = data[origin];
15
+ }
16
+ });
17
+ }
18
+ return callbackData;
19
+ };
20
+
21
+ const Chart = memo(
22
+ ({
23
+ id,
24
+ type,
25
+ config,
26
+ config: {
27
+ axes,
28
+ chart: {
29
+ dimension: {
30
+ chartDimension: { height, width },
31
+ },
32
+ margin: { marginRight, marginLeft, marginBottom, marginTop },
33
+ },
34
+ interaction,
35
+ },
36
+ data:originData,
37
+ onRelative,
38
+ emit,
39
+ emitEvent,
40
+ ...props
41
+ }) => {
42
+ const isIOS = useRef(/iPad|iPhone|iPod|iOS|CriOS/i.test(navigator.userAgent));
43
+ const svg = createRef();
44
+ const chartWidth = width - marginLeft - marginRight;
45
+ const chartHeight = height - marginTop - marginBottom;
46
+ const [active, setActive] = useState(true);
47
+
48
+ const triggerOnRelative = useCallback(
49
+ (action,data) => {
50
+ if (!interaction) return;
51
+ const { callbacks, remoteControls } = interaction;
52
+ const callbackData = getCallbackData(action,callbacks, data);
53
+ if (JSON.stringify(callbackData)!="{}") {
54
+ onRelative && onRelative(id, callbackData);
55
+ remoteControls &&
56
+ emitEvent &&
57
+ remoteControls.forEach((o) => {
58
+ const control = JSON.parse(o.control);
59
+ if (
60
+ control.screen &&
61
+ control.type &&
62
+ control.type === 'callback'
63
+ ) {
64
+ emitEvent({
65
+ screen: control.screen,
66
+ type: 'callback',
67
+ callbackData,
68
+ });
69
+ }
70
+ });
71
+ }
72
+ },
73
+ [ JSON.stringify(interaction)]
74
+ );
75
+
76
+ const onEmit = useCallback(
77
+ (type = 'click', data) => emit && emit(type, data),
78
+ [emit]
79
+ );
80
+
81
+ const context = useMemo(
82
+ () => ({
83
+ id,
84
+ isIOS:isIOS.current,
85
+ width: chartWidth,
86
+ height: chartHeight,
87
+ triggerOnRelative,
88
+ svg,
89
+ onEmit,
90
+ }),
91
+ [id, chartWidth, chartHeight, triggerOnRelative, svg, onEmit]
92
+ );
93
+
94
+ useEffect(()=>{
95
+ let isAnimation = window.screenConfig?window.screenConfig.isAnimation:true; //大屏的全局设置是否允许开启动画,false为不允许
96
+ if(!isAnimation) setActive(false);
97
+ const activeHandler=(e)=>{
98
+ const { dynamicData = true } = e;
99
+ // console.log("当前组件(id="+id+")状态:",dynamicData?"唤醒":"休眠");
100
+ isAnimation && setActive(dynamicData);
101
+ }
102
+ document.addEventListener(`switchActive_${id}`,activeHandler);
103
+ return ()=>{
104
+ document.removeEventListener(`switchActive_${id}`,activeHandler);
105
+ }
106
+ },[]);
107
+
108
+ let data = originData;
109
+ //对轴类图表进行自动排序
110
+ // if(axes){
111
+ // const xAxis = axes.find(d=>d.axisType=="x");
112
+ // if(xAxis){
113
+ // const { config:{ label:{ autoSort, format:{ type } } } } = xAxis;
114
+ // if(type=="date" && autoSort){
115
+ // const groupBySeries = group(data, (d) => d.s);
116
+ // data=[...groupBySeries].flatMap(d=>{
117
+ // return d[1].sort((a,b)=>a.x>b.x?1:-1)
118
+ // });
119
+ // }
120
+ // }
121
+ // }
122
+
123
+ return (
124
+ <chartContext.Provider value={context}>
125
+ {type == 'pie' ? (
126
+ <PieChart id={id} config={config} data={data} active={active} {...props} />
127
+ ) : (
128
+ <CartesianChart id={id} config={config} data={data} active={active} {...props} />
129
+ )}
130
+ </chartContext.Provider>
131
+ );
132
+ }
133
+ );
134
+
135
+ export default Chart;