@easyv/charts 1.4.18 → 1.4.20
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.
- package/lib/components/BaseLine.js +14 -1
- package/lib/components/CartesianChart.js +23 -1
- package/lib/hooks/index.js +9 -1
- package/lib/hooks/useAiData.js +57 -0
- package/package.json +1 -1
- package/src/components/Background.tsx +0 -1
- package/src/components/BaseLine.js +18 -7
- package/src/components/CartesianChart.js +26 -6
- package/src/hooks/index.js +2 -0
- package/src/hooks/useAiData.js +42 -0
|
@@ -46,10 +46,12 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
46
46
|
marginLeft = _ref$config$line$marg.marginLeft,
|
|
47
47
|
marginRight = _ref$config$line$marg.marginRight,
|
|
48
48
|
strokeDasharray = _ref$config$line.strokeDasharray,
|
|
49
|
+
yOrZ = _ref.yOrZ,
|
|
49
50
|
_ref$yAxis = _ref.yAxis,
|
|
50
51
|
yScaler = _ref$yAxis.scaler,
|
|
51
52
|
clipValue = _ref$yAxis.clipValue,
|
|
52
53
|
isClipAxis = _ref$yAxis.isClipAxis,
|
|
54
|
+
scaler = _ref.axisX.scaler,
|
|
53
55
|
data = _ref.data;
|
|
54
56
|
|
|
55
57
|
try {
|
|
@@ -62,7 +64,18 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
62
64
|
x1 = orientation == 'left' ? yScaler[1](data.value) : marginLeft, x2 = orientation == 'left' ? yScaler[1](data.value) : width - marginRight, y1 = orientation == 'left' ? marginLeft : yScaler[1](data.value), y2 = orientation == 'left' ? height - marginRight : yScaler[1](data.value);
|
|
63
65
|
}
|
|
64
66
|
} else {
|
|
65
|
-
|
|
67
|
+
if (yOrZ == "x") {
|
|
68
|
+
x1 = orientation == 'left' ? marginLeft : scaler(data.value), x2 = orientation == 'left' ? width - marginRight : scaler(data.value), y1 = orientation == 'left' ? scaler(data.value) : marginLeft, y2 = orientation == 'left' ? scaler(data.value) : height - marginRight;
|
|
69
|
+
} else {
|
|
70
|
+
x1 = orientation == 'left' ? yScaler(data.value) : marginLeft, x2 = orientation == 'left' ? yScaler(data.value) : width - marginRight, y1 = orientation == 'left' ? marginLeft : yScaler(data.value), y2 = orientation == 'left' ? height - marginRight : yScaler(data.value);
|
|
71
|
+
}
|
|
72
|
+
} //当坐标值存在undefined时,返回null
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if ([x1, x2, y1, y2].some(function (d) {
|
|
76
|
+
return d == undefined;
|
|
77
|
+
})) {
|
|
78
|
+
return null;
|
|
66
79
|
}
|
|
67
80
|
|
|
68
81
|
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("g", {
|
|
@@ -70,7 +70,9 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
70
70
|
brush = _ref$config.brush,
|
|
71
71
|
style = _ref.style,
|
|
72
72
|
originData = _ref.originData,
|
|
73
|
-
filterData = _ref.filterData
|
|
73
|
+
filterData = _ref.filterData,
|
|
74
|
+
aiFormatter = _ref.aiFormatter,
|
|
75
|
+
id = _ref.id;
|
|
74
76
|
var context = (0, _react.useContext)(_context.chartContext);
|
|
75
77
|
|
|
76
78
|
var _useState = (0, _react.useState)(false),
|
|
@@ -89,9 +91,27 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
89
91
|
axes: axesConfig,
|
|
90
92
|
context: context
|
|
91
93
|
});
|
|
94
|
+
var aiData = aiFormatter ? aiFormatter(originData, axes, series) : (0, _hooks.useAiData)(originData, axes, series);
|
|
92
95
|
var axisX = (0, _hooks.useCarouselAxisX)(axes.get('x'), animation, isHover);
|
|
93
96
|
var xLineRange = width - marginLeft - marginRight;
|
|
94
97
|
var yLineRange = height - marginTop - marginBottom;
|
|
98
|
+
(0, _react.useEffect)(function () {
|
|
99
|
+
if (aiData.length) {
|
|
100
|
+
if (!window.aiData) {
|
|
101
|
+
window.aiData = {};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
window.aiData[id] = {
|
|
105
|
+
getAI: function getAI() {
|
|
106
|
+
return aiData;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return function () {
|
|
112
|
+
delete window.aiData[id];
|
|
113
|
+
};
|
|
114
|
+
}, [JSON.stringify(aiData), id]);
|
|
95
115
|
|
|
96
116
|
var _useTooltip = (0, _hooks.useTooltip)({
|
|
97
117
|
svg: svg,
|
|
@@ -225,7 +245,9 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
225
245
|
key: index,
|
|
226
246
|
config: baseLineConfig[index],
|
|
227
247
|
baseLineOri: baseLineOri,
|
|
248
|
+
yOrZ: yOrZ,
|
|
228
249
|
yAxis: yAxis,
|
|
250
|
+
axisX: axisX,
|
|
229
251
|
data: item
|
|
230
252
|
});
|
|
231
253
|
})), /*#__PURE__*/_react["default"].createElement(_.Legend, (0, _extends2["default"])({}, legend, {
|
package/lib/hooks/index.js
CHANGED
|
@@ -5,6 +5,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
+
Object.defineProperty(exports, "useAiData", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _useAiData["default"];
|
|
12
|
+
}
|
|
13
|
+
});
|
|
8
14
|
Object.defineProperty(exports, "useAnimateData", {
|
|
9
15
|
enumerable: true,
|
|
10
16
|
get: function get() {
|
|
@@ -60,4 +66,6 @@ var _useAnimateData = _interopRequireDefault(require("./useAnimateData"));
|
|
|
60
66
|
|
|
61
67
|
var _useCarouselAxisX = _interopRequireDefault(require("./useCarouselAxisX"));
|
|
62
68
|
|
|
63
|
-
var _useExtentData = _interopRequireDefault(require("./useExtentData"));
|
|
69
|
+
var _useExtentData = _interopRequireDefault(require("./useExtentData"));
|
|
70
|
+
|
|
71
|
+
var _useAiData = _interopRequireDefault(require("./useAiData"));
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
|
|
14
|
+
//生成AI图表分析所需的数据
|
|
15
|
+
var _default = function _default(data, axes, series) {
|
|
16
|
+
try {
|
|
17
|
+
var xAxis = axes.get("x");
|
|
18
|
+
var xType = xAxis.config.label.format.type == "date" ? "时间" : "类别";
|
|
19
|
+
var seriesMap = new Map(series.map(function (d) {
|
|
20
|
+
var type = d.yOrZ;
|
|
21
|
+
var yAxis = axes.get(type);
|
|
22
|
+
var _yAxis$config$unit = yAxis.config.unit,
|
|
23
|
+
show = _yAxis$config$unit.show,
|
|
24
|
+
text = _yAxis$config$unit.text;
|
|
25
|
+
var unit = show ? text : "";
|
|
26
|
+
return [d.name, d.displayName + (unit === "" ? "" : "(".concat(unit, ")"))];
|
|
27
|
+
}));
|
|
28
|
+
var res = new Map();
|
|
29
|
+
data.forEach(function (d) {
|
|
30
|
+
var x = d.x,
|
|
31
|
+
y = d.y,
|
|
32
|
+
s = d.s;
|
|
33
|
+
var arr = res.get(x);
|
|
34
|
+
var sObj = seriesMap.get(s);
|
|
35
|
+
|
|
36
|
+
if (arr) {
|
|
37
|
+
arr.push((0, _defineProperty2["default"])({}, sObj, y));
|
|
38
|
+
} else {
|
|
39
|
+
res.set(x, [(0, _defineProperty2["default"])({}, sObj, y)]);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return (0, _toConsumableArray2["default"])(res).map(function (d) {
|
|
43
|
+
var obj = (0, _defineProperty2["default"])({}, xType, d[0]);
|
|
44
|
+
d[1].forEach(function (v) {
|
|
45
|
+
var target = Object.entries(v)[0];
|
|
46
|
+
obj[target[0]] = target[1];
|
|
47
|
+
});
|
|
48
|
+
return obj;
|
|
49
|
+
});
|
|
50
|
+
} catch (e) {
|
|
51
|
+
console.error("生成AI数据失败:", e);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return [];
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
exports["default"] = _default;
|
package/package.json
CHANGED
|
@@ -34,11 +34,12 @@ export default memo(
|
|
|
34
34
|
strokeDasharray,
|
|
35
35
|
},
|
|
36
36
|
},
|
|
37
|
-
|
|
37
|
+
yOrZ,
|
|
38
|
+
yAxis: { scaler: yScaler, clipValue, isClipAxis },
|
|
39
|
+
axisX: { scaler },
|
|
38
40
|
data
|
|
39
41
|
}) => {
|
|
40
42
|
try{
|
|
41
|
-
|
|
42
43
|
let x1,x2,y1,y2
|
|
43
44
|
if (isClipAxis) {
|
|
44
45
|
if (data.value > +clipValue) {
|
|
@@ -53,12 +54,22 @@ export default memo(
|
|
|
53
54
|
y2 = orientation == 'left' ? height - marginRight : yScaler[1](data.value);
|
|
54
55
|
}
|
|
55
56
|
} else {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
if(yOrZ=="x"){
|
|
58
|
+
x1 = orientation == 'left' ? marginLeft:scaler(data.value),
|
|
59
|
+
x2 = orientation == 'left' ? width - marginRight:scaler(data.value),
|
|
60
|
+
y1 = orientation == 'left' ? scaler(data.value):marginLeft ,
|
|
61
|
+
y2 = orientation == 'left' ? scaler(data.value):height - marginRight;
|
|
62
|
+
}else{
|
|
63
|
+
x1 = orientation == 'left' ? yScaler(data.value) : marginLeft,
|
|
64
|
+
x2 = orientation == 'left' ? yScaler(data.value) : width - marginRight,
|
|
65
|
+
y1 = orientation == 'left' ? marginLeft : yScaler(data.value),
|
|
66
|
+
y2 = orientation == 'left' ? height - marginRight : yScaler(data.value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//当坐标值存在undefined时,返回null
|
|
70
|
+
if([x1,x2,y1,y2].some(d=>d==undefined)){
|
|
71
|
+
return null
|
|
60
72
|
}
|
|
61
|
-
|
|
62
73
|
return (
|
|
63
74
|
<>
|
|
64
75
|
<g className='__easyv-baseLine' >
|
|
@@ -8,8 +8,9 @@ import React, {
|
|
|
8
8
|
useRef,
|
|
9
9
|
useContext,
|
|
10
10
|
useCallback,
|
|
11
|
+
useEffect
|
|
11
12
|
} from 'react';
|
|
12
|
-
import { useAxes, useTooltip, useCarouselAxisX } from '../hooks';
|
|
13
|
+
import { useAxes, useTooltip, useCarouselAxisX, useAiData } from '../hooks';
|
|
13
14
|
import { chartContext } from '../context';
|
|
14
15
|
import {
|
|
15
16
|
ChartContainer,
|
|
@@ -53,12 +54,13 @@ const Chart = memo(
|
|
|
53
54
|
config: tooltipConfig = {},
|
|
54
55
|
config: { auto, manual, indicator = {} } = {},
|
|
55
56
|
} = {},
|
|
56
|
-
brush
|
|
57
|
+
brush
|
|
57
58
|
},
|
|
58
59
|
style,
|
|
59
|
-
//data,
|
|
60
60
|
originData,
|
|
61
61
|
filterData,
|
|
62
|
+
aiFormatter,
|
|
63
|
+
id
|
|
62
64
|
}) => {
|
|
63
65
|
const context = useContext(chartContext);
|
|
64
66
|
const [isHover, setIsHover] = useState(false);
|
|
@@ -70,10 +72,26 @@ const Chart = memo(
|
|
|
70
72
|
} = useContext(chartContext);
|
|
71
73
|
const svg = useRef();
|
|
72
74
|
const axes = useAxes({ axes: axesConfig, context });
|
|
73
|
-
|
|
75
|
+
const aiData = aiFormatter?aiFormatter(originData, axes, series):useAiData(originData, axes, series);
|
|
74
76
|
const axisX = useCarouselAxisX(axes.get('x'), animation, isHover);
|
|
75
77
|
const xLineRange = width-marginLeft-marginRight;
|
|
76
78
|
const yLineRange = height-marginTop-marginBottom;
|
|
79
|
+
|
|
80
|
+
useEffect(()=>{
|
|
81
|
+
if(aiData.length){
|
|
82
|
+
if(!window.aiData){
|
|
83
|
+
window.aiData={};
|
|
84
|
+
}
|
|
85
|
+
window.aiData[id]={
|
|
86
|
+
getAI:()=>{
|
|
87
|
+
return aiData;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return ()=>{
|
|
92
|
+
delete window.aiData[id];
|
|
93
|
+
}
|
|
94
|
+
},[JSON.stringify(aiData),id]);
|
|
77
95
|
|
|
78
96
|
const {
|
|
79
97
|
x: tooltipX,
|
|
@@ -122,7 +140,7 @@ const Chart = memo(
|
|
|
122
140
|
},
|
|
123
141
|
[triggerOnRelative, onEmit]
|
|
124
142
|
);
|
|
125
|
-
|
|
143
|
+
|
|
126
144
|
return (
|
|
127
145
|
<>
|
|
128
146
|
<ChartContainer
|
|
@@ -179,7 +197,7 @@ const Chart = memo(
|
|
|
179
197
|
/>
|
|
180
198
|
)
|
|
181
199
|
);
|
|
182
|
-
})}
|
|
200
|
+
})}
|
|
183
201
|
{series.map(({ Component, yOrZ, ...config }, index) => {
|
|
184
202
|
const yAxis = axes.get(yOrZ);
|
|
185
203
|
return (
|
|
@@ -218,7 +236,9 @@ const Chart = memo(
|
|
|
218
236
|
key={index}
|
|
219
237
|
config={baseLineConfig[index]}
|
|
220
238
|
baseLineOri={baseLineOri}
|
|
239
|
+
yOrZ={yOrZ}
|
|
221
240
|
yAxis={yAxis}
|
|
241
|
+
axisX={axisX}
|
|
222
242
|
data={item}
|
|
223
243
|
/>
|
|
224
244
|
)
|
package/src/hooks/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import useTooltip from './useTooltip';
|
|
|
5
5
|
import useAnimateData from './useAnimateData';
|
|
6
6
|
import useCarouselAxisX from './useCarouselAxisX';
|
|
7
7
|
import useExtentData from './useExtentData';
|
|
8
|
+
import useAiData from './useAiData';
|
|
8
9
|
|
|
9
10
|
export {
|
|
10
11
|
useFilterData,
|
|
@@ -14,4 +15,5 @@ export {
|
|
|
14
15
|
useAnimateData,
|
|
15
16
|
useCarouselAxisX,
|
|
16
17
|
useExtentData,
|
|
18
|
+
useAiData
|
|
17
19
|
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//生成AI图表分析所需的数据
|
|
2
|
+
export default (data, axes, series)=>{
|
|
3
|
+
try{
|
|
4
|
+
const xAxis = axes.get("x");
|
|
5
|
+
const xType = xAxis.config.label.format.type=="date"?"时间":"类别";
|
|
6
|
+
const seriesMap = new Map(series.map(d=>{
|
|
7
|
+
const type = d.yOrZ;
|
|
8
|
+
const yAxis = axes.get(type);
|
|
9
|
+
const { show, text } = yAxis.config.unit;
|
|
10
|
+
const unit = show?text:"";
|
|
11
|
+
return [d.name, d.displayName+(unit===""?"":`(${unit})`)];
|
|
12
|
+
}));
|
|
13
|
+
const res = new Map();
|
|
14
|
+
data.forEach(d=>{
|
|
15
|
+
const { x, y, s } = d;
|
|
16
|
+
const arr = res.get(x);
|
|
17
|
+
const sObj = seriesMap.get(s);
|
|
18
|
+
if(arr){
|
|
19
|
+
arr.push({
|
|
20
|
+
[sObj]:y
|
|
21
|
+
});
|
|
22
|
+
}else{
|
|
23
|
+
res.set(x,[{
|
|
24
|
+
[sObj]:y
|
|
25
|
+
}]);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return [...res].map(d=>{
|
|
29
|
+
const obj = {
|
|
30
|
+
[xType]:d[0]
|
|
31
|
+
}
|
|
32
|
+
d[1].forEach(v=>{
|
|
33
|
+
const target = Object.entries(v)[0];
|
|
34
|
+
obj[target[0]] = target[1];
|
|
35
|
+
});
|
|
36
|
+
return obj;
|
|
37
|
+
})
|
|
38
|
+
}catch(e){
|
|
39
|
+
console.error("生成AI数据失败:",e);
|
|
40
|
+
}
|
|
41
|
+
return [];
|
|
42
|
+
}
|