@easyv/charts 1.6.13 → 1.6.14

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 (66) 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/Axis.js +1 -1
  6. package/lib/components/Background.js +2 -2
  7. package/lib/components/Band.js +3 -3
  8. package/lib/components/Brush.js +2 -2
  9. package/lib/components/Chart.js +2 -2
  10. package/lib/components/ChartContainer.js +3 -3
  11. package/lib/components/ConicalGradient.js +21 -21
  12. package/lib/components/Control.js +1 -1
  13. package/lib/components/ExtentData.js +2 -2
  14. package/lib/components/Indicator.js +2 -2
  15. package/lib/components/Label.js +7 -5
  16. package/lib/components/Legend.js +2 -2
  17. package/lib/components/Lighter.js +2 -2
  18. package/lib/components/Line.js +2 -2
  19. package/lib/components/LinearGradient.js +2 -2
  20. package/lib/components/Marquee.js +1 -1
  21. package/lib/components/StereoBar.js +2 -2
  22. package/lib/components/TextOverflow.js +1 -1
  23. package/lib/css/index.module.css +42 -42
  24. package/lib/css/piechart.module.css +26 -26
  25. package/lib/hooks/useAnimateData.js +6 -6
  26. package/lib/hooks/useAxes.js +1 -2
  27. package/lib/hooks/useFilterData.js +5 -5
  28. package/lib/hooks/useStackData.js +5 -5
  29. package/lib/hooks/useTooltip.js +11 -11
  30. package/lib/utils/index.js +3 -3
  31. package/package.json +55 -55
  32. package/src/components/Background.tsx +61 -61
  33. package/src/components/Band.tsx +271 -271
  34. package/src/components/Brush.js +159 -159
  35. package/src/components/Chart.js +154 -154
  36. package/src/components/ChartContainer.tsx +71 -71
  37. package/src/components/ConicalGradient.js +258 -258
  38. package/src/components/Control.jsx +241 -241
  39. package/src/components/ExtentData.js +18 -18
  40. package/src/components/Indicator.js +58 -58
  41. package/src/components/Label.js +247 -246
  42. package/src/components/Legend.js +166 -166
  43. package/src/components/Lighter.jsx +173 -173
  44. package/src/components/Line.js +153 -153
  45. package/src/components/LinearGradient.js +29 -29
  46. package/src/components/PieTooltip.jsx +160 -160
  47. package/src/components/StereoBar.tsx +307 -307
  48. package/src/components/index.js +59 -59
  49. package/src/context/index.js +2 -2
  50. package/src/css/index.module.css +42 -42
  51. package/src/css/piechart.module.css +26 -26
  52. package/src/element/ConicGradient.jsx +55 -55
  53. package/src/element/Line.tsx +33 -33
  54. package/src/element/index.ts +3 -3
  55. package/src/formatter/index.js +1 -1
  56. package/src/formatter/legend.js +112 -112
  57. package/src/hooks/index.js +20 -20
  58. package/src/hooks/useAnimateData.ts +68 -68
  59. package/src/hooks/useAxes.js +1 -2
  60. package/src/hooks/useFilterData.js +78 -78
  61. package/src/hooks/useStackData.js +102 -102
  62. package/src/hooks/useTooltip.ts +104 -104
  63. package/src/index.js +6 -6
  64. package/src/types/index.d.ts +68 -68
  65. package/src/utils/index.js +782 -782
  66. 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,154 +1,154 @@
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
- const scaleRef = useRef([1,1]);
48
-
49
- const triggerOnRelative = useCallback(
50
- (action,data) => {
51
- if (!interaction) return;
52
- const { callbacks, remoteControls } = interaction;
53
- const callbackData = getCallbackData(action,callbacks, data);
54
- if (JSON.stringify(callbackData)!="{}") {
55
- onRelative && onRelative(id, callbackData);
56
- remoteControls &&
57
- emitEvent &&
58
- remoteControls.forEach((o) => {
59
- const control = JSON.parse(o.control);
60
- if (
61
- control.screen &&
62
- control.type &&
63
- control.type === 'callback'
64
- ) {
65
- emitEvent({
66
- screen: control.screen,
67
- type: 'callback',
68
- callbackData,
69
- });
70
- }
71
- });
72
- }
73
- },
74
- [ JSON.stringify(interaction)]
75
- );
76
-
77
- const onEmit = useCallback(
78
- (type = 'click', data) => emit && emit(type, data),
79
- [emit]
80
- );
81
-
82
- const context = useMemo(
83
- () => ({
84
- id,
85
- isIOS:isIOS.current, //是否为IOS设备
86
- scale:scaleRef, //大屏的缩放比
87
- width: chartWidth,
88
- height: chartHeight,
89
- triggerOnRelative,
90
- svg,
91
- onEmit,
92
- }),
93
- [id, chartWidth, chartHeight, triggerOnRelative, svg, onEmit]
94
- );
95
-
96
- useEffect(()=>{
97
- let isAnimation = window.screenConfig?window.screenConfig.isAnimation:true; //大屏的全局设置是否允许开启动画,false为不允许
98
- if(!isAnimation) setActive(false);
99
- const activeHandler=(e)=>{
100
- const { dynamicData = true } = e;
101
- // console.log("当前组件(id="+id+")状态:",dynamicData?"唤醒":"休眠");
102
- isAnimation && setActive(dynamicData);
103
- }
104
- getScreenScale();
105
- document.addEventListener(`switchActive_${id}`,activeHandler);
106
- document.addEventListener("resize",getScreenScale);
107
- return ()=>{
108
- document.removeEventListener(`switchActive_${id}`,activeHandler);
109
- document.removeEventListener("resize",getScreenScale);
110
- }
111
- },[]);
112
-
113
- let data = originData;
114
- //对轴类图表进行自动排序
115
- // if(axes){
116
- // const xAxis = axes.find(d=>d.axisType=="x");
117
- // if(xAxis){
118
- // const { config:{ label:{ autoSort, format:{ type } } } } = xAxis;
119
- // if(type=="date" && autoSort){
120
- // const groupBySeries = group(data, (d) => d.s);
121
- // data=[...groupBySeries].flatMap(d=>{
122
- // return d[1].sort((a,b)=>a.x>b.x?1:-1)
123
- // });
124
- // }
125
- // }
126
- // }
127
-
128
- return (
129
- <chartContext.Provider value={context}>
130
- {type == 'pie' ? (
131
- <PieChart id={id} config={config} data={data} active={active} {...props} />
132
- ) : (
133
- <CartesianChart id={id} config={config} data={data} active={active} {...props} />
134
- )}
135
- </chartContext.Provider>
136
-
137
- );
138
- //获取大屏缩放系数
139
- function getScreenScale(){
140
- setTimeout(()=>{
141
- //获取大屏缩放系数
142
- let dom = document.getElementById("bigscreen-container") || document.getElementById("m-simulator");
143
- if(dom){
144
- const transform = dom.style.transform;
145
- const scale = transform?transform.match(/^scale\((.+)\)$/)[1]:"1,1";
146
- const arr = scale.split(",");
147
- scaleRef.current = [1/arr[0],1/(arr.length===1?arr[0]:arr[1])]; //这里做一次除法,后面就可以用乘法计算值了
148
- }
149
- },50);
150
- }
151
- }
152
- );
153
-
154
- 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
+ const scaleRef = useRef([1,1]);
48
+
49
+ const triggerOnRelative = useCallback(
50
+ (action,data) => {
51
+ if (!interaction) return;
52
+ const { callbacks, remoteControls } = interaction;
53
+ const callbackData = getCallbackData(action,callbacks, data);
54
+ if (JSON.stringify(callbackData)!="{}") {
55
+ onRelative && onRelative(id, callbackData);
56
+ remoteControls &&
57
+ emitEvent &&
58
+ remoteControls.forEach((o) => {
59
+ const control = JSON.parse(o.control);
60
+ if (
61
+ control.screen &&
62
+ control.type &&
63
+ control.type === 'callback'
64
+ ) {
65
+ emitEvent({
66
+ screen: control.screen,
67
+ type: 'callback',
68
+ callbackData,
69
+ });
70
+ }
71
+ });
72
+ }
73
+ },
74
+ [ JSON.stringify(interaction)]
75
+ );
76
+
77
+ const onEmit = useCallback(
78
+ (type = 'click', data) => emit && emit(type, data),
79
+ [emit]
80
+ );
81
+
82
+ const context = useMemo(
83
+ () => ({
84
+ id,
85
+ isIOS:isIOS.current, //是否为IOS设备
86
+ scale:scaleRef, //大屏的缩放比
87
+ width: chartWidth,
88
+ height: chartHeight,
89
+ triggerOnRelative,
90
+ svg,
91
+ onEmit,
92
+ }),
93
+ [id, chartWidth, chartHeight, triggerOnRelative, svg, onEmit]
94
+ );
95
+
96
+ useEffect(()=>{
97
+ let isAnimation = window.screenConfig?window.screenConfig.isAnimation:true; //大屏的全局设置是否允许开启动画,false为不允许
98
+ if(!isAnimation) setActive(false);
99
+ const activeHandler=(e)=>{
100
+ const { dynamicData = true } = e;
101
+ // console.log("当前组件(id="+id+")状态:",dynamicData?"唤醒":"休眠");
102
+ isAnimation && setActive(dynamicData);
103
+ }
104
+ getScreenScale();
105
+ document.addEventListener(`switchActive_${id}`,activeHandler);
106
+ document.addEventListener("resize",getScreenScale);
107
+ return ()=>{
108
+ document.removeEventListener(`switchActive_${id}`,activeHandler);
109
+ document.removeEventListener("resize",getScreenScale);
110
+ }
111
+ },[]);
112
+
113
+ let data = originData;
114
+ //对轴类图表进行自动排序
115
+ // if(axes){
116
+ // const xAxis = axes.find(d=>d.axisType=="x");
117
+ // if(xAxis){
118
+ // const { config:{ label:{ autoSort, format:{ type } } } } = xAxis;
119
+ // if(type=="date" && autoSort){
120
+ // const groupBySeries = group(data, (d) => d.s);
121
+ // data=[...groupBySeries].flatMap(d=>{
122
+ // return d[1].sort((a,b)=>a.x>b.x?1:-1)
123
+ // });
124
+ // }
125
+ // }
126
+ // }
127
+
128
+ return (
129
+ <chartContext.Provider value={context}>
130
+ {type == 'pie' ? (
131
+ <PieChart id={id} config={config} data={data} active={active} {...props} />
132
+ ) : (
133
+ <CartesianChart id={id} config={config} data={data} active={active} {...props} />
134
+ )}
135
+ </chartContext.Provider>
136
+
137
+ );
138
+ //获取大屏缩放系数
139
+ function getScreenScale(){
140
+ setTimeout(()=>{
141
+ //获取大屏缩放系数
142
+ let dom = document.getElementById("bigscreen-container") || document.getElementById("m-simulator");
143
+ if(dom){
144
+ const transform = dom.style.transform;
145
+ const scale = transform?transform.match(/^scale\((.+)\)$/)[1]:"1,1";
146
+ const arr = scale.split(",");
147
+ scaleRef.current = [1/arr[0],1/(arr.length===1?arr[0]:arr[1])]; //这里做一次除法,后面就可以用乘法计算值了
148
+ }
149
+ },50);
150
+ }
151
+ }
152
+ );
153
+
154
+ export default Chart;