@easyv/charts 1.6.25 → 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.
@@ -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: "fixed",
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"
@@ -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"])({
@@ -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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.6.25",
3
+ "version": "1.6.26",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -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) => {
@@ -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: "fixed",
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
  <>
@@ -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)=>({