@easyv/charts 1.6.24 → 1.6.26
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/Axis.js +1 -1
- package/lib/components/Band.js +5 -1
- package/lib/components/CartesianChart.js +61 -18
- package/lib/components/Chart.js +1 -16
- package/lib/components/ChartContainer.js +1 -1
- package/lib/components/Control.js +1 -1
- package/lib/components/Indicator.js +6 -2
- package/lib/components/Marquee.js +1 -1
- package/lib/components/TextOverflow.js +1 -1
- package/lib/hooks/useAxes.js +3 -1
- package/lib/utils/index.js +3 -3
- package/package.json +1 -1
- package/src/components/Axis.tsx +1 -1
- package/src/components/Band.tsx +2 -1
- package/src/components/CartesianChart.js +52 -17
- package/src/components/Chart.js +2 -16
- package/src/components/Indicator.js +3 -1
- package/src/hooks/useAxes.js +5 -3
package/lib/components/Axis.js
CHANGED
|
@@ -228,7 +228,7 @@ var Label = function Label(_ref5) {
|
|
|
228
228
|
}
|
|
229
229
|
})));
|
|
230
230
|
};
|
|
231
|
-
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(
|
|
231
|
+
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(0, _react.forwardRef)(function (_ref6, ref) {
|
|
232
232
|
var orientation = _ref6.orientation,
|
|
233
233
|
scaler = _ref6.scaler,
|
|
234
234
|
_ref6$tickSize = _ref6.tickSize,
|
package/lib/components/Band.js
CHANGED
|
@@ -273,6 +273,10 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
273
273
|
});
|
|
274
274
|
}
|
|
275
275
|
},
|
|
276
|
+
"data-mobile": JSON.stringify({
|
|
277
|
+
x: xScaler(x),
|
|
278
|
+
xName: data.x
|
|
279
|
+
}),
|
|
276
280
|
"data-data": JSON.stringify(data)
|
|
277
281
|
})), /*#__PURE__*/_react["default"].createElement("foreignObject", (0, _extends2["default"])({
|
|
278
282
|
style: {
|
|
@@ -316,7 +320,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
316
320
|
width: "100%",
|
|
317
321
|
height: "100%",
|
|
318
322
|
/** Safari Bug **/
|
|
319
|
-
// position: "
|
|
323
|
+
// position: "absolute",
|
|
320
324
|
clipPath: setClipPath(),
|
|
321
325
|
opacity: fillType == "pattern" ? opacity : 1,
|
|
322
326
|
background: fillType == "pattern" ? "".concat(isVertical ? y < 0 ? "100%" : "0%" : "50%", " ").concat(isVertical ? "50%" : y < 0 ? "0%" : "100%", " / ").concat(size.width, "px ").concat(size.height, "px repeat ") + "url(" +
|
|
@@ -144,6 +144,26 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
144
144
|
});
|
|
145
145
|
var aiData = aiFormatter ? aiFormatter(originData, axes, series) : (0, _hooks.useAiData)(originData, axes, series);
|
|
146
146
|
var axisX = (0, _hooks.useCarouselAxisX)(axes.get("x"), animation, isHover, controlInfo, active);
|
|
147
|
+
|
|
148
|
+
//初始化控制图提示框状态的函数
|
|
149
|
+
var initCtlTip = function initCtlTip() {
|
|
150
|
+
return {
|
|
151
|
+
show: false,
|
|
152
|
+
xName: "",
|
|
153
|
+
x: undefined,
|
|
154
|
+
indicatorList: axisX.ticks.map(function (tick) {
|
|
155
|
+
return {
|
|
156
|
+
tick: tick,
|
|
157
|
+
isShow: false
|
|
158
|
+
};
|
|
159
|
+
})
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
var _useState7 = (0, _react.useState)(initCtlTip),
|
|
163
|
+
_useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
|
|
164
|
+
ctlTip = _useState8[0],
|
|
165
|
+
setCtlTip = _useState8[1]; //控制图的提示框
|
|
166
|
+
|
|
147
167
|
(0, _react.useEffect)(function () {
|
|
148
168
|
var handleAction = function handleAction(e) {
|
|
149
169
|
var dynamicData = e.dynamicData;
|
|
@@ -186,6 +206,39 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
186
206
|
tooltipX = _useTooltip.x,
|
|
187
207
|
tickName = _useTooltip.name,
|
|
188
208
|
setIndex = _useTooltip.setIndex;
|
|
209
|
+
var setTouchIndex = function setTouchIndex(e) {
|
|
210
|
+
e.preventDefault();
|
|
211
|
+
var touch = e.touches[0];
|
|
212
|
+
if (isControl) {
|
|
213
|
+
var target = document.elementFromPoint(touch.clientX, touch.clientY);
|
|
214
|
+
var mobile = target.dataset.mobile;
|
|
215
|
+
if (mobile) {
|
|
216
|
+
var _JSON$parse = JSON.parse(mobile),
|
|
217
|
+
x = _JSON$parse.x,
|
|
218
|
+
xName = _JSON$parse.xName;
|
|
219
|
+
setCtlTip(function (pre) {
|
|
220
|
+
return {
|
|
221
|
+
show: true,
|
|
222
|
+
x: x,
|
|
223
|
+
xName: xName,
|
|
224
|
+
indicatorList: pre.indicatorList.map(function (item) {
|
|
225
|
+
if (item.tick === xName) {
|
|
226
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
227
|
+
isShow: true
|
|
228
|
+
});
|
|
229
|
+
} else {
|
|
230
|
+
return item;
|
|
231
|
+
}
|
|
232
|
+
})
|
|
233
|
+
};
|
|
234
|
+
});
|
|
235
|
+
} else {
|
|
236
|
+
setCtlTip(initCtlTip);
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
setIndex(touch);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
189
242
|
var tooltipData = (0, _react.useMemo)(function () {
|
|
190
243
|
return tickName !== undefined && originData.filter(function (d) {
|
|
191
244
|
return d.x === tickName;
|
|
@@ -359,24 +412,6 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
359
412
|
};
|
|
360
413
|
}
|
|
361
414
|
}, [JSON.stringify(animation), control, cWidth, cHeight, cBarWidth, cPercent]);
|
|
362
|
-
//初始化控制图提示框状态的函数
|
|
363
|
-
var initCtlTip = function initCtlTip() {
|
|
364
|
-
return {
|
|
365
|
-
show: false,
|
|
366
|
-
xName: "",
|
|
367
|
-
x: undefined,
|
|
368
|
-
indicatorList: axisX.ticks.map(function (tick) {
|
|
369
|
-
return {
|
|
370
|
-
tick: tick,
|
|
371
|
-
isShow: false
|
|
372
|
-
};
|
|
373
|
-
})
|
|
374
|
-
};
|
|
375
|
-
};
|
|
376
|
-
var _useState7 = (0, _react.useState)(initCtlTip),
|
|
377
|
-
_useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
|
|
378
|
-
ctlTip = _useState8[0],
|
|
379
|
-
setCtlTip = _useState8[1];
|
|
380
415
|
var showCtl = ctlTip.show,
|
|
381
416
|
ctlXName = ctlTip.xName,
|
|
382
417
|
ctlX = ctlTip.x,
|
|
@@ -406,6 +441,14 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
406
441
|
};
|
|
407
442
|
});
|
|
408
443
|
}, [tooltipX, tickName]);
|
|
444
|
+
(0, _react.useEffect)(function () {
|
|
445
|
+
svg.current.addEventListener("touchmove", setTouchIndex, {
|
|
446
|
+
passive: false
|
|
447
|
+
});
|
|
448
|
+
return function () {
|
|
449
|
+
svg.current.removeEventListener("touchmove", setTouchIndex);
|
|
450
|
+
};
|
|
451
|
+
}, [control]);
|
|
409
452
|
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_.ChartContainer, {
|
|
410
453
|
style: _objectSpread(_objectSpread({}, style), {}, {
|
|
411
454
|
position: "absolute"
|
package/lib/components/Chart.js
CHANGED
|
@@ -54,7 +54,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
|
|
|
54
54
|
emit = _ref2.emit,
|
|
55
55
|
emitEvent = _ref2.emitEvent,
|
|
56
56
|
props = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
|
|
57
|
-
var isIOS = (0, _react.useRef)(/iPad|iPhone|iPod|iOS|CriOS/i.test(navigator.userAgent));
|
|
57
|
+
var isIOS = (0, _react.useRef)(/iPad|iPhone|iPod|iOS|CriOS|Mac OS/i.test(navigator.userAgent));
|
|
58
58
|
var svg = /*#__PURE__*/(0, _react.createRef)();
|
|
59
59
|
var chartWidth = width - marginLeft - marginRight;
|
|
60
60
|
var chartHeight = height - marginTop - marginBottom;
|
|
@@ -107,7 +107,6 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
|
|
|
107
107
|
var activeHandler = function activeHandler(e) {
|
|
108
108
|
var _e$dynamicData = e.dynamicData,
|
|
109
109
|
dynamicData = _e$dynamicData === void 0 ? true : _e$dynamicData;
|
|
110
|
-
// console.log("当前组件(id="+id+")状态:",dynamicData?"唤醒":"休眠");
|
|
111
110
|
isAnimation && setActive(dynamicData);
|
|
112
111
|
};
|
|
113
112
|
getScreenScale();
|
|
@@ -119,20 +118,6 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
|
|
|
119
118
|
};
|
|
120
119
|
}, []);
|
|
121
120
|
var data = originData;
|
|
122
|
-
//对轴类图表进行自动排序
|
|
123
|
-
// if(axes){
|
|
124
|
-
// const xAxis = axes.find(d=>d.axisType=="x");
|
|
125
|
-
// if(xAxis){
|
|
126
|
-
// const { config:{ label:{ autoSort, format:{ type } } } } = xAxis;
|
|
127
|
-
// if(type=="date" && autoSort){
|
|
128
|
-
// const groupBySeries = group(data, (d) => d.s);
|
|
129
|
-
// data=[...groupBySeries].flatMap(d=>{
|
|
130
|
-
// return d[1].sort((a,b)=>a.x>b.x?1:-1)
|
|
131
|
-
// });
|
|
132
|
-
// }
|
|
133
|
-
// }
|
|
134
|
-
// }
|
|
135
|
-
|
|
136
121
|
return /*#__PURE__*/_react["default"].createElement(_context.chartContext.Provider, {
|
|
137
122
|
value: context
|
|
138
123
|
}, type == 'pie' ? /*#__PURE__*/_react["default"].createElement(_.PieChart, (0, _extends2["default"])({
|
|
@@ -15,7 +15,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
15
15
|
* svg外框
|
|
16
16
|
*/
|
|
17
17
|
var event = function event() {};
|
|
18
|
-
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(
|
|
18
|
+
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
19
19
|
var width = _ref.width,
|
|
20
20
|
height = _ref.height,
|
|
21
21
|
marginLeft = _ref.marginLeft,
|
|
@@ -18,7 +18,7 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
18
18
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
19
19
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
20
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
21
|
-
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(
|
|
21
|
+
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
22
22
|
var _props$actions = props.actions,
|
|
23
23
|
setX = _props$actions.setX,
|
|
24
24
|
setWorking = _props$actions.setWorking,
|
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _react = require("react");
|
|
10
9
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
/**
|
|
12
12
|
* 轴类图表移上去的指示框背景
|
|
13
13
|
*/
|
|
14
14
|
var _default = exports["default"] = function _default(_ref) {
|
|
@@ -37,6 +37,10 @@ var _default = exports["default"] = function _default(_ref) {
|
|
|
37
37
|
width: width,
|
|
38
38
|
height: height,
|
|
39
39
|
x: x,
|
|
40
|
+
"data-mobile": JSON.stringify({
|
|
41
|
+
x: x + width / 2,
|
|
42
|
+
xName: xName
|
|
43
|
+
}),
|
|
40
44
|
onMouseEnter: function onMouseEnter() {
|
|
41
45
|
if (isControlChart) {
|
|
42
46
|
setCtlTip(function (pre) {
|
|
@@ -17,7 +17,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
17
17
|
* 文字跑马灯组件
|
|
18
18
|
* eg: <Marquee value={文本内容} speed={跑马灯速度} style={额外样式}></Marquee>
|
|
19
19
|
*/
|
|
20
|
-
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(
|
|
20
|
+
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
21
21
|
var value = props.value,
|
|
22
22
|
style = props.style,
|
|
23
23
|
_props$speed = props.speed,
|
|
@@ -17,7 +17,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
17
17
|
* 文本溢出组件
|
|
18
18
|
* eg: <TextOverflow type={溢出形式} value={文本内容} speed={跑马灯速度} style={额外样式}></Marquee>
|
|
19
19
|
*/
|
|
20
|
-
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(
|
|
20
|
+
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
21
21
|
var type = props.type,
|
|
22
22
|
value = props.value,
|
|
23
23
|
style = props.style,
|
package/lib/hooks/useAxes.js
CHANGED
|
@@ -16,7 +16,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
16
16
|
var getCount = function getCount(num) {
|
|
17
17
|
var i = 0,
|
|
18
18
|
num_ = Math.abs(num);
|
|
19
|
-
if (num_ < 1) return
|
|
19
|
+
if (num_ < 1) return 0;
|
|
20
20
|
while (num_ > 10) {
|
|
21
21
|
i++;
|
|
22
22
|
num_ = Math.floor(num_ / 10);
|
|
@@ -57,6 +57,8 @@ var getNewDomain = function getNewDomain(domain, mode, step) {
|
|
|
57
57
|
case "count":
|
|
58
58
|
newDomain[0] = bottom != "" ? bottom : Math.floor(domain[0] / minCount) * minCount;
|
|
59
59
|
newDomain[1] = top != "" ? top : maxCount == 1 ? domain[1] : Math.ceil(domain[1] / maxCount) * maxCount;
|
|
60
|
+
if (newDomain[0] > 0 && newDomain[0] < 10 && defaultBottom === "") newDomain[0] = 0;
|
|
61
|
+
if (newDomain[1] < 0 && newDomain[1] > -10 && defaultTop === "") newDomain[1] = 0;
|
|
60
62
|
break;
|
|
61
63
|
case "step":
|
|
62
64
|
if (defaultTop != "") {
|
package/lib/utils/index.js
CHANGED
|
@@ -390,11 +390,11 @@ function band() {
|
|
|
390
390
|
};
|
|
391
391
|
scale.range = function (_) {
|
|
392
392
|
var _ref12;
|
|
393
|
-
return arguments.length ? (
|
|
393
|
+
return arguments.length ? (_ref12 = (0, _slicedToArray2["default"])(_, 2), r0 = _ref12[0], r1 = _ref12[1], r0 = +r0, r1 = +r1, rescale()) : [r0, r1];
|
|
394
394
|
};
|
|
395
395
|
scale.rangeRound = function (_) {
|
|
396
396
|
var _ref13;
|
|
397
|
-
return
|
|
397
|
+
return _ref13 = (0, _slicedToArray2["default"])(_, 2), r0 = _ref13[0], r1 = _ref13[1], r0 = +r0, r1 = +r1, round = true, rescale();
|
|
398
398
|
};
|
|
399
399
|
scale.bandwidth = function () {
|
|
400
400
|
return bandwidth;
|
|
@@ -535,7 +535,7 @@ var getBandBackground = exports.getBandBackground = function getBandBackground(p
|
|
|
535
535
|
var _pattern$backgroundSi = pattern.backgroundSize,
|
|
536
536
|
backgroundSize = _pattern$backgroundSi === void 0 ? '100% 100%' : _pattern$backgroundSi,
|
|
537
537
|
_pattern = (0, _objectWithoutProperties2["default"])(pattern, _excluded2);
|
|
538
|
-
return 'center top / ' + backgroundSize + ' url("data:image/svg+xml,' + encodeURIComponent((0, _server.renderToStaticMarkup)(
|
|
538
|
+
return 'center top / ' + backgroundSize + ' url("data:image/svg+xml,' + encodeURIComponent((0, _server.renderToStaticMarkup)(/*#__PURE__*/React.createElement(SvgBackground, {
|
|
539
539
|
fill: fill,
|
|
540
540
|
pattern: _pattern
|
|
541
541
|
}))) + '")';
|
package/package.json
CHANGED
package/src/components/Axis.tsx
CHANGED
|
@@ -298,7 +298,7 @@ export default memo(
|
|
|
298
298
|
const { cHeight, isC, cPercent } = controlInfo;
|
|
299
299
|
const x = orientation == "right" ? width : 0;
|
|
300
300
|
const y = orientation == "bottom" ? height-cHeight : 0;
|
|
301
|
-
|
|
301
|
+
|
|
302
302
|
function drawAxisTickLine() {
|
|
303
303
|
const draw = (ticks: any, scaler: any) => {
|
|
304
304
|
return ticks.map((tick: string, index: number) => {
|
package/src/components/Band.tsx
CHANGED
|
@@ -233,6 +233,7 @@ export default memo(
|
|
|
233
233
|
}))
|
|
234
234
|
}
|
|
235
235
|
}}
|
|
236
|
+
data-mobile={JSON.stringify({x:xScaler(x),xName:data.x})}
|
|
236
237
|
data-data={JSON.stringify(data)}></foreignObject>
|
|
237
238
|
<foreignObject
|
|
238
239
|
style={{
|
|
@@ -279,7 +280,7 @@ export default memo(
|
|
|
279
280
|
width: "100%",
|
|
280
281
|
height: "100%",
|
|
281
282
|
/** Safari Bug **/
|
|
282
|
-
// position: "
|
|
283
|
+
// position: "absolute",
|
|
283
284
|
clipPath: setClipPath(),
|
|
284
285
|
opacity: fillType == "pattern" ? opacity : 1,
|
|
285
286
|
background:
|
|
@@ -70,6 +70,7 @@ const Chart = memo(
|
|
|
70
70
|
const context = useContext(chartContext);
|
|
71
71
|
const [isHover, setIsHover] = useState(false);
|
|
72
72
|
const [curXLabel, setCurXLabel] = useState("");
|
|
73
|
+
|
|
73
74
|
const {
|
|
74
75
|
isIOS,
|
|
75
76
|
width: chartWidth,
|
|
@@ -99,6 +100,7 @@ const Chart = memo(
|
|
|
99
100
|
}
|
|
100
101
|
const [controlInfo, setControlInfo] = useState({ isC:isControl, cWidth:controlWidth, cHeight:controlHeight, cBarWidth:controlBarWidth, cPercent:dragPercent, cBarX:controlX });
|
|
101
102
|
const { cWidth, cHeight, cBarWidth, cPercent, cBarX } = controlInfo;
|
|
103
|
+
|
|
102
104
|
yLineRange -= cHeight;
|
|
103
105
|
useEffect(()=>{
|
|
104
106
|
setControlInfo({
|
|
@@ -125,6 +127,23 @@ const Chart = memo(
|
|
|
125
127
|
controlInfo,
|
|
126
128
|
active
|
|
127
129
|
);
|
|
130
|
+
|
|
131
|
+
//初始化控制图提示框状态的函数
|
|
132
|
+
const initCtlTip = ()=>{
|
|
133
|
+
return {
|
|
134
|
+
show:false,
|
|
135
|
+
xName:"",
|
|
136
|
+
x:undefined,
|
|
137
|
+
indicatorList:axisX.ticks.map((tick) => {
|
|
138
|
+
return {
|
|
139
|
+
tick: tick,
|
|
140
|
+
isShow: false,
|
|
141
|
+
};
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const [ctlTip, setCtlTip] = useState(initCtlTip); //控制图的提示框
|
|
146
|
+
|
|
128
147
|
useEffect(()=>{
|
|
129
148
|
const handleAction=(e)=>{
|
|
130
149
|
const { dynamicData } = e;
|
|
@@ -169,12 +188,37 @@ const Chart = memo(
|
|
|
169
188
|
config: tooltipConfig,
|
|
170
189
|
active
|
|
171
190
|
});
|
|
191
|
+
const setTouchIndex = (e)=>{
|
|
192
|
+
e.preventDefault();
|
|
193
|
+
const touch = e.touches[0];
|
|
194
|
+
if(isControl){
|
|
195
|
+
const target = document.elementFromPoint(touch.clientX,touch.clientY);
|
|
196
|
+
const { mobile } = target.dataset;
|
|
197
|
+
if(mobile){
|
|
198
|
+
const { x, xName } = JSON.parse(mobile);
|
|
199
|
+
setCtlTip((pre)=>({
|
|
200
|
+
show:true, x, xName,
|
|
201
|
+
indicatorList:pre.indicatorList.map((item)=>{
|
|
202
|
+
if (item.tick === xName) {
|
|
203
|
+
return { ...item, isShow: true };
|
|
204
|
+
} else {
|
|
205
|
+
return item;
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
}))
|
|
209
|
+
}else{
|
|
210
|
+
setCtlTip(initCtlTip);
|
|
211
|
+
}
|
|
212
|
+
}else{
|
|
213
|
+
setIndex(touch);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
172
216
|
const tooltipData = useMemo(
|
|
173
217
|
() =>
|
|
174
218
|
tickName !== undefined && originData.filter((d) => d.x === tickName),
|
|
175
219
|
[tickName, originData]
|
|
176
220
|
);
|
|
177
|
-
|
|
221
|
+
|
|
178
222
|
const showTooltip = !!(
|
|
179
223
|
tooltipData &&
|
|
180
224
|
tooltipData.length &&
|
|
@@ -346,21 +390,7 @@ const Chart = memo(
|
|
|
346
390
|
};
|
|
347
391
|
}
|
|
348
392
|
}, [JSON.stringify(animation), control, cWidth, cHeight, cBarWidth, cPercent]);
|
|
349
|
-
|
|
350
|
-
const initCtlTip = ()=>{
|
|
351
|
-
return {
|
|
352
|
-
show:false,
|
|
353
|
-
xName:"",
|
|
354
|
-
x:undefined,
|
|
355
|
-
indicatorList:axisX.ticks.map((tick) => {
|
|
356
|
-
return {
|
|
357
|
-
tick: tick,
|
|
358
|
-
isShow: false,
|
|
359
|
-
};
|
|
360
|
-
})
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
const [ctlTip, setCtlTip] = useState(initCtlTip);
|
|
393
|
+
|
|
364
394
|
const { show:showCtl, xName:ctlXName, x:ctlX, indicatorList:ctlIndicatorList } = ctlTip;
|
|
365
395
|
const controlChartTooltipData = ctlXName && originData.filter((d) => d.x === ctlXName);
|
|
366
396
|
const bodyWidth = isVertical?xLineRange + 100 + marginRight + marginLeft:xLineRange,
|
|
@@ -380,7 +410,12 @@ const Chart = memo(
|
|
|
380
410
|
}
|
|
381
411
|
})
|
|
382
412
|
},[tooltipX, tickName]);
|
|
383
|
-
|
|
413
|
+
useEffect(()=>{
|
|
414
|
+
svg.current.addEventListener("touchmove", setTouchIndex, {passive:false});
|
|
415
|
+
return ()=>{
|
|
416
|
+
svg.current.removeEventListener("touchmove", setTouchIndex);
|
|
417
|
+
}
|
|
418
|
+
},[control]);
|
|
384
419
|
|
|
385
420
|
return (
|
|
386
421
|
<>
|
package/src/components/Chart.js
CHANGED
|
@@ -39,7 +39,7 @@ const Chart = memo(
|
|
|
39
39
|
emitEvent,
|
|
40
40
|
...props
|
|
41
41
|
}) => {
|
|
42
|
-
const isIOS = useRef(/iPad|iPhone|iPod|iOS|CriOS/i.test(navigator.userAgent));
|
|
42
|
+
const isIOS = useRef(/iPad|iPhone|iPod|iOS|CriOS|Mac OS/i.test(navigator.userAgent));
|
|
43
43
|
const svg = createRef();
|
|
44
44
|
const chartWidth = width - marginLeft - marginRight;
|
|
45
45
|
const chartHeight = height - marginTop - marginBottom;
|
|
@@ -49,7 +49,7 @@ const Chart = memo(
|
|
|
49
49
|
(action,data) => {
|
|
50
50
|
if (!interaction) return;
|
|
51
51
|
const { callbacks, remoteControls } = interaction;
|
|
52
|
-
const callbackData = getCallbackData(action,callbacks, data);
|
|
52
|
+
const callbackData = getCallbackData(action, callbacks, data);
|
|
53
53
|
if (JSON.stringify(callbackData)!="{}") {
|
|
54
54
|
onRelative && onRelative(id, callbackData);
|
|
55
55
|
remoteControls &&
|
|
@@ -97,7 +97,6 @@ const Chart = memo(
|
|
|
97
97
|
if(!isAnimation) setActive(false);
|
|
98
98
|
const activeHandler=(e)=>{
|
|
99
99
|
const { dynamicData = true } = e;
|
|
100
|
-
// console.log("当前组件(id="+id+")状态:",dynamicData?"唤醒":"休眠");
|
|
101
100
|
isAnimation && setActive(dynamicData);
|
|
102
101
|
}
|
|
103
102
|
getScreenScale();
|
|
@@ -110,19 +109,6 @@ const Chart = memo(
|
|
|
110
109
|
},[]);
|
|
111
110
|
|
|
112
111
|
let data = originData;
|
|
113
|
-
//对轴类图表进行自动排序
|
|
114
|
-
// if(axes){
|
|
115
|
-
// const xAxis = axes.find(d=>d.axisType=="x");
|
|
116
|
-
// if(xAxis){
|
|
117
|
-
// const { config:{ label:{ autoSort, format:{ type } } } } = xAxis;
|
|
118
|
-
// if(type=="date" && autoSort){
|
|
119
|
-
// const groupBySeries = group(data, (d) => d.s);
|
|
120
|
-
// data=[...groupBySeries].flatMap(d=>{
|
|
121
|
-
// return d[1].sort((a,b)=>a.x>b.x?1:-1)
|
|
122
|
-
// });
|
|
123
|
-
// }
|
|
124
|
-
// }
|
|
125
|
-
// }
|
|
126
112
|
|
|
127
113
|
return (
|
|
128
114
|
<chartContext.Provider value={context}>
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 轴类图表移上去的指示框背景
|
|
3
3
|
*/
|
|
4
|
-
import { useState } from "react";
|
|
5
4
|
export default ({
|
|
6
5
|
color,
|
|
7
6
|
height,
|
|
@@ -15,17 +14,20 @@ export default ({
|
|
|
15
14
|
manual,
|
|
16
15
|
auto
|
|
17
16
|
}) => {
|
|
17
|
+
|
|
18
18
|
let isShow = true;
|
|
19
19
|
if (isControlChart && ctlIndicatorList) {
|
|
20
20
|
isShow = ctlIndicatorList.find(
|
|
21
21
|
(item) => item.tick === xName
|
|
22
22
|
).isShow;
|
|
23
23
|
}
|
|
24
|
+
|
|
24
25
|
return manual?(
|
|
25
26
|
<rect
|
|
26
27
|
width={width}
|
|
27
28
|
height={height}
|
|
28
29
|
x={x}
|
|
30
|
+
data-mobile={JSON.stringify({x:x+width/2,xName})}
|
|
29
31
|
onMouseEnter={() => {
|
|
30
32
|
if (isControlChart) {
|
|
31
33
|
setCtlTip((pre)=>({
|
package/src/hooks/useAxes.js
CHANGED
|
@@ -6,7 +6,7 @@ import { getYTicksByStep, getYTicks } from "@easyv/utils/lib/common/utils";
|
|
|
6
6
|
const getCount = (num) => {
|
|
7
7
|
let i = 0,
|
|
8
8
|
num_ = Math.abs(num);
|
|
9
|
-
if (num_ < 1) return
|
|
9
|
+
if (num_ < 1) return 0;
|
|
10
10
|
while (num_ > 10) {
|
|
11
11
|
i++;
|
|
12
12
|
num_ = Math.floor(num_ / 10);
|
|
@@ -27,11 +27,12 @@ const getNewDomain = (
|
|
|
27
27
|
percentageExtent;
|
|
28
28
|
let bottom = defaultBottom,
|
|
29
29
|
top = defaultTop;
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
let newDomain = [];
|
|
32
32
|
//能进入这个函数,说明extent中min和max至少有一个是缺失的,如果max存在,意味着纵轴上限被固定
|
|
33
33
|
let min = domain[0],
|
|
34
34
|
max = domain[1];
|
|
35
|
+
|
|
35
36
|
let minCount = Math.pow(10, getCount(min)),
|
|
36
37
|
maxCount = Math.pow(10, getCount(max));
|
|
37
38
|
//轴标签,范围模式,百分比模式
|
|
@@ -41,13 +42,14 @@ const getNewDomain = (
|
|
|
41
42
|
bottom = (min * _min) / 100;
|
|
42
43
|
top = (max * _max) / 100;
|
|
43
44
|
}
|
|
44
|
-
|
|
45
45
|
switch (mode) {
|
|
46
46
|
case "count":
|
|
47
47
|
newDomain[0] =
|
|
48
48
|
bottom != "" ? bottom : Math.floor(domain[0] / minCount) * minCount;
|
|
49
49
|
newDomain[1] =
|
|
50
50
|
top != "" ? top : maxCount==1?domain[1]:Math.ceil(domain[1] / maxCount) * maxCount;
|
|
51
|
+
if(newDomain[0]>0 && newDomain[0]<10 && defaultBottom==="")newDomain[0] = 0;
|
|
52
|
+
if(newDomain[1]<0 && newDomain[1]>-10 && defaultTop==="")newDomain[1] = 0;
|
|
51
53
|
break;
|
|
52
54
|
case "step":
|
|
53
55
|
if (defaultTop != "") {
|