@easyv/charts 1.6.12 → 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 (68) 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 +32 -21
  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/components/Tooltip.js +4 -4
  24. package/lib/css/index.module.css +42 -42
  25. package/lib/css/piechart.module.css +26 -26
  26. package/lib/hooks/useAnimateData.js +6 -6
  27. package/lib/hooks/useAxes.js +1 -2
  28. package/lib/hooks/useFilterData.js +5 -5
  29. package/lib/hooks/useStackData.js +5 -5
  30. package/lib/hooks/useTooltip.js +11 -11
  31. package/lib/utils/index.js +3 -3
  32. package/package.json +55 -55
  33. package/src/components/Background.tsx +61 -61
  34. package/src/components/Band.tsx +271 -271
  35. package/src/components/Brush.js +159 -159
  36. package/src/components/Chart.js +154 -154
  37. package/src/components/ChartContainer.tsx +71 -71
  38. package/src/components/ConicalGradient.js +258 -258
  39. package/src/components/Control.jsx +241 -241
  40. package/src/components/ExtentData.js +18 -18
  41. package/src/components/Indicator.js +58 -58
  42. package/src/components/Label.js +247 -242
  43. package/src/components/Legend.js +166 -166
  44. package/src/components/Lighter.jsx +173 -173
  45. package/src/components/Line.js +153 -153
  46. package/src/components/LinearGradient.js +29 -29
  47. package/src/components/PieTooltip.jsx +160 -160
  48. package/src/components/StereoBar.tsx +307 -307
  49. package/src/components/Tooltip.js +4 -4
  50. package/src/components/index.js +59 -59
  51. package/src/context/index.js +2 -2
  52. package/src/css/index.module.css +42 -42
  53. package/src/css/piechart.module.css +26 -26
  54. package/src/element/ConicGradient.jsx +55 -55
  55. package/src/element/Line.tsx +33 -33
  56. package/src/element/index.ts +3 -3
  57. package/src/formatter/index.js +1 -1
  58. package/src/formatter/legend.js +112 -112
  59. package/src/hooks/index.js +20 -20
  60. package/src/hooks/useAnimateData.ts +68 -68
  61. package/src/hooks/useAxes.js +1 -2
  62. package/src/hooks/useFilterData.js +78 -78
  63. package/src/hooks/useStackData.js +102 -102
  64. package/src/hooks/useTooltip.ts +104 -104
  65. package/src/index.js +6 -6
  66. package/src/types/index.d.ts +68 -68
  67. package/src/utils/index.js +782 -782
  68. package/tsconfig.json +23 -23
@@ -1,112 +1,112 @@
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
- return (
47
- <>
48
- {icon &&<span style={{ ...icon, marginRight: icon.marginRight, transform:`translate(${nameX}px, ${nameY}px)` }} />}
49
- <div
50
- className={
51
- showName && showValue && showPercent
52
- ? css.showAllStyle
53
- : css.notShowAllStyle
54
- }
55
- style={{
56
- width:`calc( 100% + ${valueGap+percentGap}px )`
57
- }}
58
- >
59
- {showName && (
60
- <TextOverflow value={displayName} type={textOverflow} speed={speed} style={{
61
- width:maxWidth, marginLeft: 5, ...getFontStyle(nameFont), transform:`translate(${nameX}px, ${nameY}px)`
62
- }}></TextOverflow>
63
- )}
64
- {showValue && (
65
- <span
66
- style={{
67
- whiteSpace:"nowrap",
68
- ...getFontStyle(valueFont),
69
- marginLeft: valueGap,
70
- transform:`translate(${valueX}px,${valueY}px)`,
71
- display: 'flex',
72
- flex:1,
73
- color: valueSameColor ? _color : valueFont.color,
74
- alignItems: 'center',
75
- justifyContent: valueAlign=="left"?"flex-start":valueAlign=="right"?"flex-end":'center',
76
- }}
77
- >
78
- <span>{data.y}</span>
79
- {showSuffix && (
80
- <span
81
- style={{
82
- whiteSpace:"nowrap",
83
- fontSize,
84
- transform: 'translate3d(' + x + 'px, ' + y + 'px, 0px)',
85
- }}
86
- >
87
- {text}
88
- </span>
89
- )}
90
- </span>
91
- )}
92
- {showPercent && (
93
- <span
94
- style={{
95
- whiteSpace:"nowrap",
96
- ...getFontStyle(percentFont),
97
- marginLeft: percentGap,
98
- transform:`translate(${percentX}px,${percentY}px)`,
99
- display:"flex",
100
- flex:1,
101
- alignItems: 'center',
102
- justifyContent: percentAlign=="left"?"flex-start":percentAlign=="right"?"flex-end":'center',
103
- color: percentSameColor ? _color : percentFont.color,
104
- }}
105
- >
106
- {percent + '%'}
107
- </span>
108
- )}
109
- </div>
110
- </>
111
- );
112
- };
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
+ return (
47
+ <>
48
+ {icon &&<span style={{ ...icon, marginRight: icon.marginRight, transform:`translate(${nameX}px, ${nameY}px)` }} />}
49
+ <div
50
+ className={
51
+ showName && showValue && showPercent
52
+ ? css.showAllStyle
53
+ : css.notShowAllStyle
54
+ }
55
+ style={{
56
+ width:`calc( 100% + ${valueGap+percentGap}px )`
57
+ }}
58
+ >
59
+ {showName && (
60
+ <TextOverflow value={displayName} type={textOverflow} speed={speed} style={{
61
+ width:maxWidth, marginLeft: 5, ...getFontStyle(nameFont), transform:`translate(${nameX}px, ${nameY}px)`
62
+ }}></TextOverflow>
63
+ )}
64
+ {showValue && (
65
+ <span
66
+ style={{
67
+ whiteSpace:"nowrap",
68
+ ...getFontStyle(valueFont),
69
+ marginLeft: valueGap,
70
+ transform:`translate(${valueX}px,${valueY}px)`,
71
+ display: 'flex',
72
+ flex:1,
73
+ color: valueSameColor ? _color : valueFont.color,
74
+ alignItems: 'center',
75
+ justifyContent: valueAlign=="left"?"flex-start":valueAlign=="right"?"flex-end":'center',
76
+ }}
77
+ >
78
+ <span>{data.y}</span>
79
+ {showSuffix && (
80
+ <span
81
+ style={{
82
+ whiteSpace:"nowrap",
83
+ fontSize,
84
+ transform: 'translate3d(' + x + 'px, ' + y + 'px, 0px)',
85
+ }}
86
+ >
87
+ {text}
88
+ </span>
89
+ )}
90
+ </span>
91
+ )}
92
+ {showPercent && (
93
+ <span
94
+ style={{
95
+ whiteSpace:"nowrap",
96
+ ...getFontStyle(percentFont),
97
+ marginLeft: percentGap,
98
+ transform:`translate(${percentX}px,${percentY}px)`,
99
+ display:"flex",
100
+ flex:1,
101
+ alignItems: 'center',
102
+ justifyContent: percentAlign=="left"?"flex-start":percentAlign=="right"?"flex-end":'center',
103
+ color: percentSameColor ? _color : percentFont.color,
104
+ }}
105
+ >
106
+ {percent + '%'}
107
+ </span>
108
+ )}
109
+ </div>
110
+ </>
111
+ );
112
+ };
@@ -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
+ };
@@ -34,7 +34,6 @@ const getNewDomain = (
34
34
  max = domain[1];
35
35
  let minCount = Math.pow(10, getCount(min)),
36
36
  maxCount = Math.pow(10, getCount(max));
37
-
38
37
  //轴标签,范围模式,百分比模式
39
38
  if (numericalRangeModel == "percentage") {
40
39
  let _max = defaultPercentageMax === "" ? 100 : defaultPercentageMax;
@@ -48,7 +47,7 @@ const getNewDomain = (
48
47
  newDomain[0] =
49
48
  bottom != "" ? bottom : Math.floor(domain[0] / minCount) * minCount;
50
49
  newDomain[1] =
51
- top != "" ? top : Math.ceil(domain[1] / maxCount) * maxCount;
50
+ top != "" ? top : maxCount==1?domain[1]:Math.ceil(domain[1] / maxCount) * maxCount;
52
51
  break;
53
52
  case "step":
54
53
  if (defaultTop != "") {
@@ -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
+ };