@easyv/charts 1.4.35 → 1.4.37

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.
@@ -10,15 +10,12 @@ export default ({
10
10
  y = 0,
11
11
  isControlChart = false,
12
12
  xName = null,
13
- setControlChartTooltipShow = null,
14
- setControlChartTooltipXName = null,
15
- setControlChartTooltipX = null,
16
- setControlChartIndicatorList = null,
17
- controlChartIndicatorList = null,
13
+ ctlIndicatorList,
14
+ setCtlTip
18
15
  }) => {
19
16
  let isShow = true;
20
- if (isControlChart && controlChartIndicatorList) {
21
- isShow = controlChartIndicatorList.find(
17
+ if (isControlChart && ctlIndicatorList) {
18
+ isShow = ctlIndicatorList.find(
22
19
  (item) => item.tick === xName
23
20
  ).isShow;
24
21
  }
@@ -29,28 +26,28 @@ export default ({
29
26
  x={x}
30
27
  onMouseEnter={() => {
31
28
  if (isControlChart) {
32
- setControlChartIndicatorList((v) => {
33
- return v.map((item) => {
29
+ setCtlTip((pre)=>({
30
+ show:true, x:x+width/2, xName,
31
+ indicatorList:pre.indicatorList.map((item)=>{
34
32
  if (item.tick === xName) {
35
33
  return { ...item, isShow: true };
36
34
  } else {
37
35
  return item;
38
36
  }
39
- });
40
- });
41
- setControlChartTooltipShow(true);
42
- setControlChartTooltipXName(xName);
43
- setControlChartTooltipX(x);
37
+ })
38
+ }))
44
39
  }
45
40
  }}
46
41
  onMouseLeave={() => {
47
42
  if (isControlChart) {
48
- setControlChartIndicatorList((v) =>
49
- v.map((item) => ({ ...item, isShow: false }))
50
- );
51
- setControlChartTooltipShow(false);
52
- setControlChartTooltipXName(undefined);
53
- setControlChartTooltipX(undefined);
43
+ setCtlTip((pre)=>({
44
+ show:false,
45
+ x:undefined,
46
+ xName:undefined,
47
+ indicatorList:pre.indicatorList.map((item)=>{
48
+ return { ...item, isShow:false }
49
+ })
50
+ }))
54
51
  }
55
52
  }}
56
53
  fill={isShow ? color : "transparent"}
@@ -18,14 +18,7 @@ export default memo(
18
18
  data,
19
19
  xAxis: { scaler: xScaler, step, direction },
20
20
  yAxis: { scaler: yScaler, isClipAxis, clipValue },
21
- triggerClick,
22
- //控制图相关
23
- indicatorWidth,
24
- setControlChartTooltipShow,
25
- setControlChartTooltipX,
26
- setControlChartTooltipXName,
27
- isControlChart = false,
28
- setControlChartIndicatorList = null,
21
+ triggerClick
29
22
  }) => {
30
23
  const lineType = config.hasOwnProperty("line"); // 堆叠处理
31
24
  const showIcon = icon && icon.show;
@@ -104,32 +97,6 @@ export default memo(
104
97
  <g
105
98
  key={i}
106
99
  onClick={triggerClick}
107
- onMouseEnter={() => {
108
- if (isControlChart) {
109
- setControlChartIndicatorList((v) => {
110
- return v.map((item) => {
111
- if (item.tick === data.x) {
112
- return { ...item, isShow: true };
113
- } else {
114
- return item;
115
- }
116
- });
117
- });
118
- setControlChartTooltipShow(true);
119
- setControlChartTooltipX(xScaler(x) - indicatorWidth / 2);
120
- setControlChartTooltipXName(data.x);
121
- }
122
- }}
123
- onMouseLeave={() => {
124
- if (isControlChart) {
125
- setControlChartIndicatorList((v) =>
126
- v.map((item) => ({ ...item, isShow: false }))
127
- );
128
- setControlChartTooltipShow(false);
129
- setControlChartTooltipXName(undefined);
130
- setControlChartTooltipX(undefined);
131
- }
132
- }}
133
100
  style={{ cursor: "pointer" }}
134
101
  data-data={JSON.stringify(data)}
135
102
  >
@@ -41,7 +41,6 @@ export default memo(
41
41
  ...translateTip,
42
42
  x: translateTip.x + position + marginLeft,
43
43
  };
44
-
45
44
  if (translate3d.x + tipWidth > width) {
46
45
  const newPositon = position + marginLeft - tipWidth - translateTip.x;
47
46
  translate3d.x = newPositon >= 0 ? newPositon : 0;
@@ -60,17 +60,19 @@ const scales = {
60
60
 
61
61
  export default ({
62
62
  axes,
63
- context: { width, height }, //是否为控制图
64
- isControlChart,
65
- control: controlConfig,
63
+ context: { width:chartWidth, height:chartHeight },
64
+ controlInfo, //是否为控制图
66
65
  }) => {
66
+ const { isC, cHeight, cWidth, cPercent } = controlInfo;
67
+ const width = chartWidth;
68
+ const height = chartHeight - cHeight;
67
69
  const _axes = useMemo(() => {
68
70
  const tmp = new Map();
69
71
  const xAxisPositions = [];
70
72
  axes.forEach((item) => {
71
73
  const {
72
74
  config: {
73
- label: { showLast = false, decimal = 0 },
75
+ label: { extent, showLast = false, decimal = 0 },
74
76
  },
75
77
  type,
76
78
  orientation,
@@ -91,19 +93,16 @@ export default ({
91
93
  bottomClipAxisStep,
92
94
  topClipAxisStep,
93
95
  clipValue,
94
- clipPosition,
95
- clipDifferenceValue,
96
- clipAxisMode,
96
+ clipPosition
97
97
  } = item;
98
98
  //如果是断轴类型,输出一套完全不同的values
99
-
100
99
  /**
101
100
  * 获取轴的:朝向direction,起点位置start,终点位置end
102
101
  * @param {*} orientation
103
102
  * @param {*} width
104
103
  * @param {*} height
105
104
  * @param {*} paddingOuter
106
- * @returns {start,end,direction}
105
+ * @returns { start, end, direction }
107
106
  */
108
107
  function getChartsConfig(orientation, width, height, paddingOuter) {
109
108
  const direction =
@@ -321,10 +320,8 @@ export default ({
321
320
  });
322
321
  } else {
323
322
  //计算真正需要的tickCount,如果domain区间太小,不能完全按照count来,需要减少count数
324
- const tickCount =
325
- type == "ordinal" ? _count : getTickCount(domain, _count, decimal);
326
- const { start, end, direction, _paddingOuter, length } =
327
- getChartsConfig(orientation, width, height, paddingOuter);
323
+ const tickCount = type == "ordinal" ? _count : getTickCount(domain, _count, decimal);
324
+ const { start, end, direction, _paddingOuter, length } = getChartsConfig(orientation, width, height, paddingOuter);
328
325
 
329
326
  let range =
330
327
  direction === "horizontal"
@@ -333,23 +330,24 @@ export default ({
333
330
  ? [end, start]
334
331
  : [0, 0];
335
332
  let newDomain = domain;
336
- if (type !== "ordinal" && !isNaN(domain[1]) && !auto) {
333
+ const fixedDomain = extent && extent.min!="" && extent.max!=""; //判断配置项中是否强制了最大最小值,如果已经被强制了,就不计算newDomain
334
+ if (type !== "ordinal" && !isNaN(domain[1]) && !auto && !fixedDomain) {
337
335
  newDomain = getNewDomain(domain, mode, _step);
338
336
  }
339
-
340
- const scaler = scales[type]().domain(newDomain).range(range);
337
+ let scaler = scales[type]().domain(newDomain).range(range);
341
338
 
342
339
  scaler.type = type;
343
- if (type !== "ordinal") scaler.clamp(true); //scaler.nice().clamp(true)
340
+ if (type !== "ordinal") scaler.clamp(true);
341
+
344
342
  const allTicks = ticks
345
343
  ? ticks
346
344
  : scaler.ticks
347
345
  ? scaler.ticks(tickCount)
348
346
  : scaler.domain();
349
347
  let _ticks = allTicks;
350
- //
348
+
351
349
  if (type === "ordinal") {
352
- if (carousel === false) {
350
+ if (carousel === false || isC) {
353
351
  _ticks = getTicksOfAxis(_ticks, +tickCount, showLast);
354
352
  }
355
353
  } else {
@@ -381,6 +379,25 @@ export default ({
381
379
  }
382
380
  }
383
381
  }
382
+ let step = lengthWithoutPaddingOuter / allTicks.length;
383
+ const controlCfg = {
384
+ controlStep:0,
385
+ controlDragScaler:null
386
+ }
387
+ if(isC){
388
+ controlCfg.controlStep = step / cPercent;
389
+ controlCfg.controlDragScaler = scaler.copy().range([start/cPercent, end/cPercent]);
390
+ const { start:start_, end:end_, direction:direction_, _paddingOuter:outer, length:len } = getChartsConfig(orientation, cWidth, height, paddingOuter);
391
+ let range = direction_ === "horizontal"
392
+ ? [start_, end_]
393
+ : direction_ === "vertical"
394
+ ? [end_, start_]
395
+ : [0, 0];
396
+ scaler = scales[type]().domain(newDomain).range(range);
397
+ scaler.type = type;
398
+ const controlOuter = len - outer;
399
+ step = controlOuter/allTicks.length;
400
+ }
384
401
  tmp.set(axisType, {
385
402
  ...item,
386
403
  count: _count,
@@ -393,13 +410,14 @@ export default ({
393
410
  start,
394
411
  end,
395
412
  lengthWithoutPaddingOuter,
396
- step: lengthWithoutPaddingOuter / allTicks.length,
413
+ step,
414
+ ...controlCfg,
397
415
  allTicks,
416
+ rawTicks: _ticks,
398
417
  ticks: _ticks,
399
418
  });
400
419
  }
401
420
  });
402
-
403
421
  tmp.get("x") && (tmp.get("x").positions = xAxisPositions);
404
422
  return tmp;
405
423
  }, [axes]);
@@ -17,14 +17,14 @@ export default (
17
17
  axis,
18
18
  config,
19
19
  isHover,
20
- isControlChart = false,
21
- controlConfig = null
20
+ controlInfo
22
21
  ) => {
23
22
  const { show, interval, duration, hover } = config;
23
+ const { isC, cPercent } = controlInfo;
24
24
  const time = duration + interval;
25
25
 
26
26
  const {
27
- tickCount,
27
+ tickCount:count,
28
28
  allTicks,
29
29
  scaler,
30
30
  start,
@@ -34,12 +34,11 @@ export default (
34
34
  lengthWithoutPaddingOuter,
35
35
  } = axis;
36
36
  const tickLength = ticks.length;
37
+ const tickCount = isC?allTicks.length:count;
37
38
 
38
- const _end =
39
- isControlChart && controlConfig
40
- ? end / (controlConfig.drag.width / 100)
41
- : end;
42
- const controlDragScaler = scaler.copy().range([start, end]);
39
+ const scale = isC?cPercent:1;
40
+ const _start = start/scale;
41
+ const _end = end/scale;
43
42
 
44
43
  const [state, setState] = useState({
45
44
  scaler,
@@ -86,7 +85,7 @@ export default (
86
85
  setState({
87
86
  step,
88
87
  ticks: _ticks,
89
- scaler: scaler.copy().domain(_ticks).range([start, _end]),
88
+ scaler: scaler.copy().domain(_ticks).range([_start, _end]),
90
89
  });
91
90
  } else {
92
91
  animation = animate({
@@ -107,7 +106,7 @@ export default (
107
106
  ticks: _ticks,
108
107
  scaler: scaler
109
108
  .copy()
110
- .range([start, _end + step])
109
+ .range([_start, _end + step])
111
110
  .domain(_ticks),
112
111
  };
113
112
  });
@@ -119,7 +118,7 @@ export default (
119
118
  ...axis,
120
119
  scaler: scaler
121
120
  .copy()
122
- .range([start + step * v, _end + step + step * v]),
121
+ .range([_start + step * v, _end + step + step * v]),
123
122
  };
124
123
  });
125
124
  },
@@ -130,7 +129,7 @@ export default (
130
129
  return {
131
130
  ...axis,
132
131
  ticks: _ticks,
133
- scaler: scaler.copy().range([start, _end]).domain(_ticks),
132
+ scaler: scaler.copy().range([_start, _end]).domain(_ticks),
134
133
  };
135
134
  });
136
135
  },
@@ -140,7 +139,7 @@ export default (
140
139
  const _ticks = scaler.type == "linear" ? scaler.domain() : allTicks;
141
140
  setState({
142
141
  step,
143
- scaler: scaler.copy().domain(_ticks).range([start, _end]),
142
+ scaler: scaler.copy().domain(_ticks).range([_start, _end]),
144
143
  ticks,
145
144
  });
146
145
  }
@@ -151,7 +150,7 @@ export default (
151
150
  tickCount,
152
151
  allTicks,
153
152
  scaler,
154
- start,
153
+ _start,
155
154
  _end,
156
155
  step,
157
156
  ticks,
@@ -163,10 +162,7 @@ export default (
163
162
  return {
164
163
  ...axis,
165
164
  ...state,
166
- rawTicks: axis.ticks,
167
- controlDragScaler,
168
- controlEnd: _end,
169
- isControlChart,
165
+ controlEnd: _end
170
166
  };
171
167
  };
172
168