@progress/kendo-charts 1.20.0-dev.202110131408 → 1.20.0-dev.202111190958

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.
@@ -3,8 +3,8 @@ import Axis from './axis';
3
3
  import AxisLabel from './axis-label';
4
4
  import Box from './box';
5
5
 
6
- import { BLACK, DEFAULT_PRECISION, COORD_PRECISION, X, Y } from '../common/constants';
7
- import { deepExtend, defined, limitValue, round, setDefaultOptions } from '../common';
6
+ import { BLACK, DEFAULT_PRECISION, COORD_PRECISION } from '../common/constants';
7
+ import { deepExtend, defined, limitValue, round, setDefaultOptions, valueOrDefault } from '../common';
8
8
 
9
9
  import autoMajorUnit from './utils/auto-major-unit';
10
10
  import autoAxisMin from './utils/auto-axis-min';
@@ -70,17 +70,13 @@ class NumericAxis extends Axis {
70
70
 
71
71
  getTickPositions(unit, skipUnit) {
72
72
  const options = this.options;
73
- const { vertical, reverse } = options;
74
- const lineBox = this.lineBox();
75
- const lineSize = vertical ? lineBox.height() : lineBox.width();
73
+ const { axisDir, axisOrigin, lineBox, lineSize } = this.lineInfo();
76
74
  const range = options.max - options.min;
77
75
  const scale = lineSize / range;
78
76
  const step = unit * scale;
79
77
  const divisions = this.getDivisions(unit);
80
- const dir = (vertical ? -1 : 1) * (reverse ? -1 : 1);
81
- const startEdge = dir === 1 ? 1 : 2;
82
78
  const positions = [];
83
- let pos = lineBox[(vertical ? Y : X) + startEdge];
79
+ let pos = lineBox[axisOrigin];
84
80
  let skipStep = 0;
85
81
 
86
82
  if (skipUnit) {
@@ -92,7 +88,7 @@ class NumericAxis extends Axis {
92
88
  positions.push(round(pos, COORD_PRECISION));
93
89
  }
94
90
 
95
- pos = pos + step * dir;
91
+ pos = pos + step * axisDir;
96
92
  }
97
93
 
98
94
  return positions;
@@ -108,79 +104,48 @@ class NumericAxis extends Axis {
108
104
 
109
105
  getSlot(a, b, limit = false) {
110
106
  const options = this.options;
111
- const { vertical, reverse } = options;
112
- const valueAxis = vertical ? Y : X;
113
- const lineBox = this.lineBox();
114
- const lineStart = lineBox[valueAxis + (reverse ? 2 : 1)];
115
- const lineSize = vertical ? lineBox.height() : lineBox.width();
116
- const dir = reverse ? -1 : 1;
117
- const step = dir * (lineSize / (options.max - options.min));
118
- const slotBox = new Box(lineBox.x1, lineBox.y1, lineBox.x1, lineBox.y1);
119
-
120
- let start = a;
121
- let end = b;
122
-
123
- if (!defined(start)) {
124
- start = end || 0;
125
- }
107
+ const { axis, axisDir, lineBox, lineSize, lineStart } = this.lineInfo();
108
+ const step = axisDir * (lineSize / (options.max - options.min));
126
109
 
127
- if (!defined(end)) {
128
- end = start || 0;
129
- }
110
+ let start = valueOrDefault(a, b || 0);
111
+ let end = valueOrDefault(b, a || 0);
130
112
 
131
113
  if (limit) {
132
- start = Math.max(Math.min(start, options.max), options.min);
133
- end = Math.max(Math.min(end, options.max), options.min);
114
+ start = limitValue(start, options.min, options.max);
115
+ end = limitValue(end, options.min, options.max);
134
116
  }
135
117
 
136
- let p1, p2;
137
-
138
- if (vertical) {
139
- p1 = options.max - Math.max(start, end);
140
- p2 = options.max - Math.min(start, end);
141
- } else {
142
- p1 = Math.min(start, end) - options.min;
143
- p2 = Math.max(start, end) - options.min;
144
- }
118
+ const p1 = Math.min(start, end) - options.min;
119
+ const p2 = Math.max(start, end) - options.min;
145
120
 
146
- slotBox[valueAxis + 1] = limitCoordinate(lineStart + step * (reverse ? p2 : p1));
147
- slotBox[valueAxis + 2] = limitCoordinate(lineStart + step * (reverse ? p1 : p2));
121
+ const slotBox = new Box(lineBox.x1, lineBox.y1, lineBox.x1, lineBox.y1);
122
+ slotBox[axis + 1] = limitCoordinate(lineStart + step * (axisDir > 0 ? p1 : p2));
123
+ slotBox[axis + 2] = limitCoordinate(lineStart + step * (axisDir > 0 ? p2 : p1));
148
124
 
149
125
  return slotBox;
150
126
  }
151
127
 
152
128
  getValue(point) {
153
129
  const options = this.options;
154
- const { vertical, reverse } = options;
155
130
  const max = Number(options.max);
156
131
  const min = Number(options.min);
157
- const valueAxis = vertical ? Y : X;
158
- const lineBox = this.lineBox();
159
- const lineStart = lineBox[valueAxis + (reverse ? 2 : 1)];
160
- const lineSize = vertical ? lineBox.height() : lineBox.width();
161
- const dir = reverse ? -1 : 1;
162
- const offset = dir * (point[valueAxis] - lineStart);
163
- const step = (max - min) / lineSize;
164
- const valueOffset = offset * step;
165
-
166
- if (offset < 0 || offset > lineSize) {
132
+ const offset = this.pointOffset(point);
133
+ const valueOffset = offset * (max - min);
134
+
135
+ if (offset < 0 || offset > 1) {
167
136
  return null;
168
137
  }
169
138
 
170
- const value = vertical ?
171
- max - valueOffset :
172
- min + valueOffset;
173
-
139
+ const value = min + valueOffset;
174
140
  return round(value, DEFAULT_PRECISION);
175
141
  }
176
142
 
177
143
  translateRange(delta) {
178
144
  const options = this.options;
179
145
  const { vertical, reverse, max, min } = options;
180
- const lineBox = this.lineBox();
181
- const size = vertical ? lineBox.height() : lineBox.width();
146
+ const { lineSize } = this.lineInfo();
182
147
  const range = max - min;
183
- const scale = size / range;
148
+ const scale = lineSize / range;
184
149
  let offset = round(delta / scale, DEFAULT_PRECISION);
185
150
 
186
151
  if ((vertical || reverse) && !(vertical && reverse )) {
@@ -194,16 +159,6 @@ class NumericAxis extends Axis {
194
159
  };
195
160
  }
196
161
 
197
- scaleRange(delta) {
198
- const options = this.options;
199
- const offset = -delta * options.majorUnit;
200
-
201
- return {
202
- min: options.min - offset,
203
- max: options.max + offset
204
- };
205
- }
206
-
207
162
  labelsCount() {
208
163
  return this.getDivisions(this.options.majorUnit);
209
164
  }
@@ -240,18 +195,33 @@ class NumericAxis extends Axis {
240
195
  }
241
196
  }
242
197
 
243
- zoomRange(delta) {
198
+ scaleRange(scale, cursor) {
199
+ const position = Math.abs(this.pointOffset(cursor));
200
+ const range = this.options.max - this.options.min;
201
+ const delta = this.scaleToDelta(scale, range);
202
+ const minDelta = position * delta;
203
+ const maxDelta = (1 - position) * delta;
204
+ const min = round(this.options.min + minDelta, DEFAULT_PRECISION);
205
+ let max = round(this.options.max - maxDelta, DEFAULT_PRECISION);
206
+
207
+ if (max - min < MIN_VALUE_RANGE) {
208
+ max = min + MIN_VALUE_RANGE;
209
+ }
210
+
211
+ return {
212
+ min: min,
213
+ max: max
214
+ };
215
+ }
216
+
217
+ zoomRange(scale, cursor) {
244
218
  const { totalMin, totalMax } = this;
245
- const newRange = this.scaleRange(delta);
246
- const min = limitValue(newRange.min, totalMin, totalMax);
247
- const max = limitValue(newRange.max, totalMin, totalMax);
219
+ const range = this.scaleRange(scale, cursor);
248
220
 
249
- if (this.isValidRange(min, max)) {
250
- return {
251
- min: min,
252
- max: max
253
- };
254
- }
221
+ return {
222
+ min: limitValue(range.min, totalMin, totalMax),
223
+ max: limitValue(range.max, totalMin, totalMax)
224
+ };
255
225
  }
256
226
 
257
227
  isValidRange(min, max) {
@@ -260,6 +260,7 @@ class Navigator extends Class {
260
260
 
261
261
  const fromIx = mainAxis.categoryIndex(selection.options.from);
262
262
  const toIx = mainAxis.categoryIndex(selection.options.to);
263
+ const coords = this.chart._eventCoordinates(e.originalEvent);
263
264
 
264
265
  e.originalEvent.preventDefault();
265
266
 
@@ -268,11 +269,11 @@ class Navigator extends Class {
268
269
  }
269
270
 
270
271
  if (toIx - fromIx > 1) {
271
- selection.expand(delta);
272
+ selection.zoom(delta, coords);
272
273
  this.readSelection();
273
274
  } else {
274
275
  axis.options.min = select.from;
275
- select.from = axis.scaleRange(-e.delta).min;
276
+ select.from = axis.scaleRange(-e.delta * this.chart._mousewheelZoomRate(), coords).min;
276
277
  }
277
278
 
278
279
  if (liveDrag) {