@easyv/charts 1.6.20 → 1.6.21

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 (62) hide show
  1. package/.babelrc +8 -8
  2. package/CHANGELOG.md +18 -18
  3. package/commitlint.config.js +1 -1
  4. package/lib/components/Background.js +2 -2
  5. package/lib/components/Band.js +55 -31
  6. package/lib/components/Brush.js +2 -2
  7. package/lib/components/CartesianChart.js +3 -1
  8. package/lib/components/Chart.js +2 -3
  9. package/lib/components/ChartContainer.js +2 -2
  10. package/lib/components/ConicalGradient.js +21 -21
  11. package/lib/components/ExtentData.js +2 -2
  12. package/lib/components/Indicator.js +2 -2
  13. package/lib/components/Label.js +2 -2
  14. package/lib/components/Legend.js +2 -2
  15. package/lib/components/Lighter.js +2 -2
  16. package/lib/components/Line.js +2 -2
  17. package/lib/components/LinearGradient.js +2 -2
  18. package/lib/components/StereoBar.js +2 -2
  19. package/lib/css/index.module.css +42 -42
  20. package/lib/css/piechart.module.css +26 -26
  21. package/lib/hooks/useAnimateData.js +6 -6
  22. package/lib/hooks/useAxes.js +20 -16
  23. package/lib/hooks/useFilterData.js +5 -5
  24. package/lib/hooks/useStackData.js +5 -5
  25. package/lib/hooks/useTooltip.js +11 -11
  26. package/package.json +55 -55
  27. package/src/components/Background.tsx +61 -61
  28. package/src/components/Band.tsx +321 -302
  29. package/src/components/Brush.js +159 -159
  30. package/src/components/CartesianChart.js +1 -1
  31. package/src/components/Chart.js +153 -153
  32. package/src/components/ChartContainer.tsx +71 -71
  33. package/src/components/ConicalGradient.js +258 -258
  34. package/src/components/Control.jsx +241 -241
  35. package/src/components/ExtentData.js +18 -18
  36. package/src/components/Indicator.js +59 -59
  37. package/src/components/Label.js +262 -262
  38. package/src/components/Legend.js +189 -189
  39. package/src/components/Lighter.jsx +173 -173
  40. package/src/components/Line.js +153 -153
  41. package/src/components/LinearGradient.js +29 -29
  42. package/src/components/PieTooltip.jsx +160 -160
  43. package/src/components/StereoBar.tsx +307 -307
  44. package/src/components/index.js +59 -59
  45. package/src/context/index.js +2 -2
  46. package/src/css/index.module.css +42 -42
  47. package/src/css/piechart.module.css +26 -26
  48. package/src/element/ConicGradient.jsx +55 -55
  49. package/src/element/Line.tsx +33 -33
  50. package/src/element/index.ts +3 -3
  51. package/src/formatter/index.js +1 -1
  52. package/src/formatter/legend.js +114 -114
  53. package/src/hooks/index.js +20 -20
  54. package/src/hooks/useAnimateData.ts +68 -68
  55. package/src/hooks/useAxes.js +20 -16
  56. package/src/hooks/useFilterData.js +78 -78
  57. package/src/hooks/useStackData.js +102 -102
  58. package/src/hooks/useTooltip.ts +104 -104
  59. package/src/index.js +6 -6
  60. package/src/types/index.d.ts +68 -68
  61. package/src/utils/index.js +800 -800
  62. package/tsconfig.json +23 -23
@@ -1,114 +1,114 @@
1
- import css from '../css/index.module.css';
2
- import { getFontStyle } from '../utils';
3
- import { TextOverflow } from '../components';
4
-
5
- export const pieLegendFormatter = (
6
- { displayName, data, percent, series: { color: seriesColor, icon="" } },
7
- {
8
- name: { show: showName, font: nameFont, textOverflow, speed, maxWidth, translate: { x:nameX, y:nameY } },
9
- value: {
10
- show: showValue,
11
- font: valueFont,
12
- sameColor: valueSameColor,
13
- gap: valueGap,
14
- align: valueAlign,
15
- translate: {
16
- x:valueX,
17
- y:valueY
18
- },
19
- suffix: {
20
- show: showSuffix,
21
- text,
22
- fontSize,
23
- translate: { x, y },
24
- },
25
- },
26
- percent: {
27
- show: showPercent,
28
- font: percentFont,
29
- sameColor: percentSameColor,
30
- gap: percentGap,
31
- align: percentAlign,
32
- translate: {
33
- x:percentX,
34
- y:percentY
35
- }
36
- },
37
- }
38
- ) => {
39
- const {
40
- type: seriesColorType,
41
- pure,
42
- linear: { stops },
43
- } = seriesColor;
44
-
45
- const _color = seriesColorType == 'pure' ? pure : stops[0].color;
46
- const textMarginLeft = 5;
47
-
48
- return (
49
- <>
50
- {icon &&<span style={{ ...icon, marginRight: icon.marginRight, transform:`translate(${nameX}px, ${nameY}px)` }} />}
51
- <div
52
- className={
53
- showName && showValue && showPercent
54
- ? css.showAllStyle
55
- : css.notShowAllStyle
56
- }
57
- style={{
58
- width:`calc( 100% + ${textMarginLeft+valueGap+percentGap}px )`
59
- }}
60
- >
61
- {showName && (
62
- <TextOverflow value={displayName} type={textOverflow} speed={speed} style={{
63
- width:maxWidth, marginLeft: textMarginLeft, ...getFontStyle(nameFont), transform:`translate(${nameX}px, ${nameY}px)`
64
- }}></TextOverflow>
65
- )}
66
- {showValue && (
67
- <span
68
- style={{
69
- whiteSpace:"nowrap",
70
- ...getFontStyle(valueFont),
71
- marginLeft: valueGap,
72
- transform:`translate(${valueX}px,${valueY}px)`,
73
- display: 'flex',
74
- flex:1,
75
- color: valueSameColor ? _color : valueFont.color,
76
- alignItems: 'center',
77
- justifyContent: valueAlign=="left"?"flex-start":valueAlign=="right"?"flex-end":'center',
78
- }}
79
- >
80
- <span>{data.y}</span>
81
- {showSuffix && (
82
- <span
83
- style={{
84
- whiteSpace:"nowrap",
85
- fontSize,
86
- transform: 'translate3d(' + x + 'px, ' + y + 'px, 0px)',
87
- }}
88
- >
89
- {text}
90
- </span>
91
- )}
92
- </span>
93
- )}
94
- {showPercent && (
95
- <span
96
- style={{
97
- whiteSpace:"nowrap",
98
- ...getFontStyle(percentFont),
99
- marginLeft: percentGap,
100
- transform:`translate(${percentX}px,${percentY}px)`,
101
- display:"flex",
102
- flex:1,
103
- alignItems: 'center',
104
- justifyContent: percentAlign=="left"?"flex-start":percentAlign=="right"?"flex-end":'center',
105
- color: percentSameColor ? _color : percentFont.color,
106
- }}
107
- >
108
- {percent + '%'}
109
- </span>
110
- )}
111
- </div>
112
- </>
113
- );
114
- };
1
+ import css from '../css/index.module.css';
2
+ import { getFontStyle } from '../utils';
3
+ import { TextOverflow } from '../components';
4
+
5
+ export const pieLegendFormatter = (
6
+ { displayName, data, percent, series: { color: seriesColor, icon="" } },
7
+ {
8
+ name: { show: showName, font: nameFont, textOverflow, speed, maxWidth, translate: { x:nameX, y:nameY } },
9
+ value: {
10
+ show: showValue,
11
+ font: valueFont,
12
+ sameColor: valueSameColor,
13
+ gap: valueGap,
14
+ align: valueAlign,
15
+ translate: {
16
+ x:valueX,
17
+ y:valueY
18
+ },
19
+ suffix: {
20
+ show: showSuffix,
21
+ text,
22
+ fontSize,
23
+ translate: { x, y },
24
+ },
25
+ },
26
+ percent: {
27
+ show: showPercent,
28
+ font: percentFont,
29
+ sameColor: percentSameColor,
30
+ gap: percentGap,
31
+ align: percentAlign,
32
+ translate: {
33
+ x:percentX,
34
+ y:percentY
35
+ }
36
+ },
37
+ }
38
+ ) => {
39
+ const {
40
+ type: seriesColorType,
41
+ pure,
42
+ linear: { stops },
43
+ } = seriesColor;
44
+
45
+ const _color = seriesColorType == 'pure' ? pure : stops[0].color;
46
+ const textMarginLeft = 5;
47
+
48
+ return (
49
+ <>
50
+ {icon &&<span style={{ ...icon, marginRight: icon.marginRight, transform:`translate(${nameX}px, ${nameY}px)` }} />}
51
+ <div
52
+ className={
53
+ showName && showValue && showPercent
54
+ ? css.showAllStyle
55
+ : css.notShowAllStyle
56
+ }
57
+ style={{
58
+ width:`calc( 100% + ${textMarginLeft+valueGap+percentGap}px )`
59
+ }}
60
+ >
61
+ {showName && (
62
+ <TextOverflow value={displayName} type={textOverflow} speed={speed} style={{
63
+ width:maxWidth, marginLeft: textMarginLeft, ...getFontStyle(nameFont), transform:`translate(${nameX}px, ${nameY}px)`
64
+ }}></TextOverflow>
65
+ )}
66
+ {showValue && (
67
+ <span
68
+ style={{
69
+ whiteSpace:"nowrap",
70
+ ...getFontStyle(valueFont),
71
+ marginLeft: valueGap,
72
+ transform:`translate(${valueX}px,${valueY}px)`,
73
+ display: 'flex',
74
+ flex:1,
75
+ color: valueSameColor ? _color : valueFont.color,
76
+ alignItems: 'center',
77
+ justifyContent: valueAlign=="left"?"flex-start":valueAlign=="right"?"flex-end":'center',
78
+ }}
79
+ >
80
+ <span>{data.y}</span>
81
+ {showSuffix && (
82
+ <span
83
+ style={{
84
+ whiteSpace:"nowrap",
85
+ fontSize,
86
+ transform: 'translate3d(' + x + 'px, ' + y + 'px, 0px)',
87
+ }}
88
+ >
89
+ {text}
90
+ </span>
91
+ )}
92
+ </span>
93
+ )}
94
+ {showPercent && (
95
+ <span
96
+ style={{
97
+ whiteSpace:"nowrap",
98
+ ...getFontStyle(percentFont),
99
+ marginLeft: percentGap,
100
+ transform:`translate(${percentX}px,${percentY}px)`,
101
+ display:"flex",
102
+ flex:1,
103
+ alignItems: 'center',
104
+ justifyContent: percentAlign=="left"?"flex-start":percentAlign=="right"?"flex-end":'center',
105
+ color: percentSameColor ? _color : percentFont.color,
106
+ }}
107
+ >
108
+ {percent + '%'}
109
+ </span>
110
+ )}
111
+ </div>
112
+ </>
113
+ );
114
+ };
@@ -1,20 +1,20 @@
1
- import useFilterData from './useFilterData';
2
- import useStackData from './useStackData';
3
- import useAxes from './useAxes';
4
- import useTooltip from './useTooltip';
5
- import useAnimateData from './useAnimateData';
6
- import useCarouselAxisX from './useCarouselAxisX';
7
- import useExtentData from './useExtentData';
8
- import { useAiData, useAiDataOfPie } from './useAiData';
9
-
10
- export {
11
- useFilterData,
12
- useStackData,
13
- useAxes,
14
- useTooltip,
15
- useAnimateData,
16
- useCarouselAxisX,
17
- useExtentData,
18
- useAiData,
19
- useAiDataOfPie
20
- };
1
+ import useFilterData from './useFilterData';
2
+ import useStackData from './useStackData';
3
+ import useAxes from './useAxes';
4
+ import useTooltip from './useTooltip';
5
+ import useAnimateData from './useAnimateData';
6
+ import useCarouselAxisX from './useCarouselAxisX';
7
+ import useExtentData from './useExtentData';
8
+ import { useAiData, useAiDataOfPie } from './useAiData';
9
+
10
+ export {
11
+ useFilterData,
12
+ useStackData,
13
+ useAxes,
14
+ useTooltip,
15
+ useAnimateData,
16
+ useCarouselAxisX,
17
+ useExtentData,
18
+ useAiData,
19
+ useAiDataOfPie
20
+ };
@@ -1,68 +1,68 @@
1
- import { useEffect, useState } from 'react';
2
- import { animate, easeIn, easeOut, linear } from 'popmotion';
3
-
4
- /**
5
- * 图表数据动画
6
- * @param {Array} data data列表
7
- * @param {boolean} dataAnimation 是否开启数据增长动画
8
- * @param {boolean} active 是否处于活跃状态,false为休眠
9
- * @returns 改变后的数据
10
- */
11
-
12
- export default (data: DataType[], dataAnimation: DataAnimation, active:boolean) => {
13
- const [animateData, setAnimateData] = useState<DataType[]>([]);
14
- useEffect(() => {
15
- let animateRef: any = null;
16
- if (
17
- dataAnimation &&
18
- dataAnimation.show &&
19
- dataAnimation.duration &&
20
- data.length &&
21
- active
22
- ) {
23
- animateRef = animate({
24
- autoplay: true,
25
- repeat: 0,
26
- from: 0,
27
- to: 1,
28
- duration: dataAnimation.duration * 1000,
29
- ease: linear,
30
- onUpdate: (v: number) => {
31
- setAnimateData((oldData: DataType[]) => {
32
- const oldLength = oldData.length;
33
- const newLength = data.length;
34
- if (oldLength >= newLength) {
35
- return oldData.map(({ y }: DataType, i: number) => {
36
- const current: DataType = data[i] || { y: 0 };
37
- const delta: number = current.y - y;
38
- return {
39
- ...current,
40
- y: y + delta * v,
41
- };
42
- });
43
- } else {
44
- return data.map((current: DataType, i: number) => {
45
- const oldCurrent: DataType = oldData[i] || { y: 0 };
46
- const delta = oldCurrent.y - current.y;
47
- return {
48
- ...current,
49
- y:oldCurrent.y + delta * v,
50
- };
51
- });
52
- }
53
- });
54
- },
55
- onComplete: () => {
56
- setAnimateData(data);
57
- },
58
- });
59
- } else {
60
- setAnimateData(data);
61
- }
62
- return () => {
63
- animateRef && animateRef.stop();
64
- };
65
- }, [data, dataAnimation, active]);
66
-
67
- return animateData;
68
- };
1
+ import { useEffect, useState } from 'react';
2
+ import { animate, easeIn, easeOut, linear } from 'popmotion';
3
+
4
+ /**
5
+ * 图表数据动画
6
+ * @param {Array} data data列表
7
+ * @param {boolean} dataAnimation 是否开启数据增长动画
8
+ * @param {boolean} active 是否处于活跃状态,false为休眠
9
+ * @returns 改变后的数据
10
+ */
11
+
12
+ export default (data: DataType[], dataAnimation: DataAnimation, active:boolean) => {
13
+ const [animateData, setAnimateData] = useState<DataType[]>([]);
14
+ useEffect(() => {
15
+ let animateRef: any = null;
16
+ if (
17
+ dataAnimation &&
18
+ dataAnimation.show &&
19
+ dataAnimation.duration &&
20
+ data.length &&
21
+ active
22
+ ) {
23
+ animateRef = animate({
24
+ autoplay: true,
25
+ repeat: 0,
26
+ from: 0,
27
+ to: 1,
28
+ duration: dataAnimation.duration * 1000,
29
+ ease: linear,
30
+ onUpdate: (v: number) => {
31
+ setAnimateData((oldData: DataType[]) => {
32
+ const oldLength = oldData.length;
33
+ const newLength = data.length;
34
+ if (oldLength >= newLength) {
35
+ return oldData.map(({ y }: DataType, i: number) => {
36
+ const current: DataType = data[i] || { y: 0 };
37
+ const delta: number = current.y - y;
38
+ return {
39
+ ...current,
40
+ y: y + delta * v,
41
+ };
42
+ });
43
+ } else {
44
+ return data.map((current: DataType, i: number) => {
45
+ const oldCurrent: DataType = oldData[i] || { y: 0 };
46
+ const delta = oldCurrent.y - current.y;
47
+ return {
48
+ ...current,
49
+ y:oldCurrent.y + delta * v,
50
+ };
51
+ });
52
+ }
53
+ });
54
+ },
55
+ onComplete: () => {
56
+ setAnimateData(data);
57
+ },
58
+ });
59
+ } else {
60
+ setAnimateData(data);
61
+ }
62
+ return () => {
63
+ animateRef && animateRef.stop();
64
+ };
65
+ }, [data, dataAnimation, active]);
66
+
67
+ return animateData;
68
+ };
@@ -63,6 +63,9 @@ const getNewDomain = (
63
63
  }
64
64
  break;
65
65
  }
66
+ if(newDomain[0]==newDomain[1]){
67
+ newDomain[1]+=1;
68
+ }
66
69
  return newDomain;
67
70
  };
68
71
 
@@ -421,22 +424,23 @@ export default ({
421
424
  }
422
425
  }
423
426
  const lengthWithoutPaddingOuter = length - _paddingOuter;
424
- if (type == "linear" && config.on) {
425
- const zeroPosition = scaler(0);
426
- if (!isNaN(zeroPosition)) {
427
- if (direction === "horizontal") {
428
- xAxisPositions.add(JSON.stringify({
429
- x: zeroPosition,
430
- y: 0,
431
- }));
432
- } else if (direction === "vertical") {
433
- xAxisPositions.add(JSON.stringify({
434
- x: 0,
435
- y: zeroPosition,
436
- }));
437
- }
438
- }
439
- }
427
+ // 额外的X轴坐标轴,对应于数值0的位置
428
+ // if (type == "linear" && config.on) {
429
+ // const zeroPosition = scaler(0);
430
+ // if (!isNaN(zeroPosition)) {
431
+ // if (direction === "horizontal") {
432
+ // xAxisPositions.add(JSON.stringify({
433
+ // x: zeroPosition,
434
+ // y: 0,
435
+ // }));
436
+ // } else if (direction === "vertical") {
437
+ // xAxisPositions.add(JSON.stringify({
438
+ // x: 0,
439
+ // y: zeroPosition,
440
+ // }));
441
+ // }
442
+ // }
443
+ // }
440
444
  let step = lengthWithoutPaddingOuter / allTicks.length;
441
445
  const controlCfg = {
442
446
  controlStep: 0,
@@ -1,78 +1,78 @@
1
- import { useState, useCallback, useEffect, useMemo } from 'react';
2
-
3
- const getInitialSelected = (series) => {
4
- const status = new Map();
5
- for (let [name] of series.entries()) {
6
- status.set(name, true);
7
- }
8
- return status;
9
- };
10
-
11
- const getSelected = (selected, name) => {
12
- const tmp = new Map();
13
- selected.forEach((value, key) => {
14
- if (name == key) {
15
- tmp.set(key, !value);
16
- } else {
17
- tmp.set(key, value);
18
- }
19
- });
20
- return tmp;
21
- };
22
-
23
- /**
24
- * 图例点击状态管理
25
- * @param {Array} data 数据
26
- * @param {Map} series 系列
27
- * @returns {Array} 返回筛选后的数据和是否选中状态,及控制选中函数
28
- */
29
-
30
- export default ({ data, series }) => {
31
- const [selected, setSelected] = useState(getInitialSelected(series));
32
-
33
- const _series = useMemo(() => {
34
- const tmp = new Map();
35
- series.forEach((currentSeries, key) => {
36
- const value = selected.get(key);
37
- tmp.set(key, {
38
- ...currentSeries,
39
- selected: value,
40
- });
41
- });
42
- return tmp;
43
- }, [selected, series]);
44
-
45
- const _data = useMemo(() => {
46
- return data.filter(({ s }) => {
47
- return s && _series.get(s) && _series.get(s).selected;
48
- });
49
- }, [data, _series]);
50
-
51
- const onClick = useCallback((name) => {
52
- setSelected((selected) => getSelected(selected, name));
53
- }, []);
54
-
55
- useEffect(() => {
56
- const map = getInitialSelected(series);
57
- for(let [ key ] of map.entries()){
58
- if(selected.has(key)){
59
- map.set(key, selected.get(key));
60
- }
61
- }
62
- setSelected(map);
63
- }, [series]);
64
-
65
- return [
66
- {
67
- series: _series,
68
- data: _data.map(d=>{
69
- return {
70
- ...d,
71
- y:parseFloat(d.y),
72
- showY:d.y
73
- }
74
- }),
75
- },
76
- onClick,
77
- ];
78
- };
1
+ import { useState, useCallback, useEffect, useMemo } from 'react';
2
+
3
+ const getInitialSelected = (series) => {
4
+ const status = new Map();
5
+ for (let [name] of series.entries()) {
6
+ status.set(name, true);
7
+ }
8
+ return status;
9
+ };
10
+
11
+ const getSelected = (selected, name) => {
12
+ const tmp = new Map();
13
+ selected.forEach((value, key) => {
14
+ if (name == key) {
15
+ tmp.set(key, !value);
16
+ } else {
17
+ tmp.set(key, value);
18
+ }
19
+ });
20
+ return tmp;
21
+ };
22
+
23
+ /**
24
+ * 图例点击状态管理
25
+ * @param {Array} data 数据
26
+ * @param {Map} series 系列
27
+ * @returns {Array} 返回筛选后的数据和是否选中状态,及控制选中函数
28
+ */
29
+
30
+ export default ({ data, series }) => {
31
+ const [selected, setSelected] = useState(getInitialSelected(series));
32
+
33
+ const _series = useMemo(() => {
34
+ const tmp = new Map();
35
+ series.forEach((currentSeries, key) => {
36
+ const value = selected.get(key);
37
+ tmp.set(key, {
38
+ ...currentSeries,
39
+ selected: value,
40
+ });
41
+ });
42
+ return tmp;
43
+ }, [selected, series]);
44
+
45
+ const _data = useMemo(() => {
46
+ return data.filter(({ s }) => {
47
+ return s && _series.get(s) && _series.get(s).selected;
48
+ });
49
+ }, [data, _series]);
50
+
51
+ const onClick = useCallback((name) => {
52
+ setSelected((selected) => getSelected(selected, name));
53
+ }, []);
54
+
55
+ useEffect(() => {
56
+ const map = getInitialSelected(series);
57
+ for(let [ key ] of map.entries()){
58
+ if(selected.has(key)){
59
+ map.set(key, selected.get(key));
60
+ }
61
+ }
62
+ setSelected(map);
63
+ }, [series]);
64
+
65
+ return [
66
+ {
67
+ series: _series,
68
+ data: _data.map(d=>{
69
+ return {
70
+ ...d,
71
+ y:parseFloat(d.y),
72
+ showY:d.y
73
+ }
74
+ }),
75
+ },
76
+ onClick,
77
+ ];
78
+ };