@progress/kendo-charts 1.20.0-dev.202111121622 → 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,6 +3,13 @@ import toChartAxisRanges from './to-chart-axis-ranges';
3
3
 
4
4
  import { X, Y } from '../../common/constants';
5
5
  import { Class, deepExtend } from '../../common';
6
+ import { limitValue } from '../../drawing-utils';
7
+
8
+ // Limit the zoom rate between 1% and 90% per mousewheel event.
9
+ // At zoom rates close to 100% the axis range quickly becomes 0.
10
+ var MIN_RATE = 0.01;
11
+ var MAX_RATE = 0.9;
12
+ var DEFAULT_RATE = 0.3;
6
13
 
7
14
  var MousewheelZoom = (function (Class) {
8
15
  function MousewheelZoom(chart, options) {
@@ -10,7 +17,7 @@ var MousewheelZoom = (function (Class) {
10
17
 
11
18
  this.chart = chart;
12
19
  this.options = deepExtend({
13
- rate: 0.3
20
+ rate: DEFAULT_RATE
14
21
  }, this.options, options);
15
22
  }
16
23
 
@@ -30,7 +37,8 @@ var MousewheelZoom = (function (Class) {
30
37
  var vertical = axis.options.vertical;
31
38
 
32
39
  if (!(lock === X && !vertical) && !(lock === Y && vertical) && axis.zoomRange) {
33
- var range = axis.zoomRange(-delta * this$1.options.rate, coords);
40
+ var rate = limitValue(this$1.options.rate, MIN_RATE, MAX_RATE);
41
+ var range = axis.zoomRange(-delta * rate, coords);
34
42
 
35
43
  if (range) {
36
44
  axisRanges.push({
@@ -907,6 +907,26 @@ var Axis = (function (ChartElement) {
907
907
  return offset;
908
908
  };
909
909
 
910
+ // Computes the axis range change (delta) for a given scale factor.
911
+ // The delta is subtracted from the axis range:
912
+ // * delta > 0 reduces the axis range (zoom-in)
913
+ // * delta < 0 expands the axis range (zoom-out)
914
+ Axis.prototype.scaleToDelta = function scaleToDelta (rawScale, range) {
915
+ // Scale >= 1 would result in axis range of 0.
916
+ // Scale <= -1 would reverse the scale direction.
917
+ var MAX_SCALE = 0.999;
918
+ var scale = limitValue(rawScale, -MAX_SCALE, MAX_SCALE);
919
+
920
+ var delta;
921
+ if (scale > 0) {
922
+ delta = range * Math.min(1, scale);
923
+ } else {
924
+ delta = range - (range / (1 + scale));
925
+ }
926
+
927
+ return delta;
928
+ };
929
+
910
930
  Axis.prototype.labelsBetweenTicks = function labelsBetweenTicks () {
911
931
  return !this.options.justified;
912
932
  };
@@ -445,7 +445,8 @@ var CategoryAxis = (function (Axis) {
445
445
  CategoryAxis.prototype.scaleRange = function scaleRange (scale, cursor) {
446
446
  var position = Math.abs(this.pointOffset(cursor));
447
447
  var rangeIndices = this.totalRangeIndices();
448
- var delta = (rangeIndices.max - rangeIndices.min) * Math.min(1, scale);
448
+ var range = rangeIndices.max - rangeIndices.min;
449
+ var delta = this.scaleToDelta(scale, range);
449
450
  var minDelta = position * delta;
450
451
  var maxDelta = (1 - position) * delta;
451
452
  var min = rangeIndices.min + minDelta;
@@ -455,7 +456,6 @@ var CategoryAxis = (function (Axis) {
455
456
  max = min + MIN_CATEGORY_RANGE;
456
457
  }
457
458
 
458
-
459
459
  return {
460
460
  min: min,
461
461
  max: max
@@ -544,7 +544,8 @@ var DateCategoryAxis = (function (CategoryAxis) {
544
544
  var rangeMax = ref.max;
545
545
 
546
546
  var position = Math.abs(this.pointOffset(cursor));
547
- var delta = (rangeMax - rangeMin) * scale;
547
+ var range = rangeMax - rangeMin;
548
+ var delta = this.scaleToDelta(scale, range);
548
549
  var minDelta = Math.round(position * delta);
549
550
  var maxDelta = Math.round((1 - position) * delta);
550
551
 
@@ -180,7 +180,8 @@ var DateValueAxis = (function (Axis) {
180
180
 
181
181
  DateValueAxis.prototype.scaleRange = function scaleRange (scale, cursor) {
182
182
  var position = Math.abs(this.pointOffset(cursor));
183
- var delta = (this.options.max - this.options.min) * Math.min(1, scale);
183
+ var range = this.options.max - this.options.min;
184
+ var delta = this.scaleToDelta(scale, range);
184
185
  var minDelta = position * delta;
185
186
  var maxDelta = (1 - position) * delta;
186
187
  var min = toDate(toTime(this.options.min) + minDelta);
@@ -313,7 +313,8 @@ var LogarithmicAxis = (function (Axis) {
313
313
  var logMin = log(this.options.min, base);
314
314
  var logMax = log(this.options.max, base);
315
315
  var position = Math.abs(this.pointOffset(cursor));
316
- var delta = (logMax - logMin) * Math.min(1, scale);
316
+ var range = logMax - logMin;
317
+ var delta = this.scaleToDelta(scale, range);
317
318
  var min = Math.pow(base, logMin + position * delta);
318
319
  var max = Math.pow(base, logMax - (1 - position) * delta);
319
320
 
@@ -215,11 +215,12 @@ var NumericAxis = (function (Axis) {
215
215
 
216
216
  NumericAxis.prototype.scaleRange = function scaleRange (scale, cursor) {
217
217
  var position = Math.abs(this.pointOffset(cursor));
218
- var delta = (this.options.max - this.options.min) * Math.min(1, scale);
218
+ var range = this.options.max - this.options.min;
219
+ var delta = this.scaleToDelta(scale, range);
219
220
  var minDelta = position * delta;
220
221
  var maxDelta = (1 - position) * delta;
221
- var min = this.options.min + minDelta;
222
- var max = this.options.max - maxDelta;
222
+ var min = round(this.options.min + minDelta, DEFAULT_PRECISION);
223
+ var max = round(this.options.max - maxDelta, DEFAULT_PRECISION);
223
224
 
224
225
  if (max - min < MIN_VALUE_RANGE) {
225
226
  max = min + MIN_VALUE_RANGE;
@@ -3,6 +3,13 @@ import toChartAxisRanges from './to-chart-axis-ranges';
3
3
 
4
4
  import { X, Y } from '../../common/constants';
5
5
  import { Class, deepExtend } from '../../common';
6
+ import { limitValue } from '../../drawing-utils';
7
+
8
+ // Limit the zoom rate between 1% and 90% per mousewheel event.
9
+ // At zoom rates close to 100% the axis range quickly becomes 0.
10
+ const MIN_RATE = 0.01;
11
+ const MAX_RATE = 0.9;
12
+ const DEFAULT_RATE = 0.3;
6
13
 
7
14
  class MousewheelZoom extends Class {
8
15
  constructor(chart, options) {
@@ -10,7 +17,7 @@ class MousewheelZoom extends Class {
10
17
 
11
18
  this.chart = chart;
12
19
  this.options = deepExtend({
13
- rate: 0.3
20
+ rate: DEFAULT_RATE
14
21
  }, this.options, options);
15
22
  }
16
23
 
@@ -24,7 +31,8 @@ class MousewheelZoom extends Class {
24
31
  const vertical = axis.options.vertical;
25
32
 
26
33
  if (!(lock === X && !vertical) && !(lock === Y && vertical) && axis.zoomRange) {
27
- const range = axis.zoomRange(-delta * this.options.rate, coords);
34
+ const rate = limitValue(this.options.rate, MIN_RATE, MAX_RATE);
35
+ const range = axis.zoomRange(-delta * rate, coords);
28
36
 
29
37
  if (range) {
30
38
  axisRanges.push({
@@ -857,6 +857,26 @@ class Axis extends ChartElement {
857
857
  return offset;
858
858
  }
859
859
 
860
+ // Computes the axis range change (delta) for a given scale factor.
861
+ // The delta is subtracted from the axis range:
862
+ // * delta > 0 reduces the axis range (zoom-in)
863
+ // * delta < 0 expands the axis range (zoom-out)
864
+ scaleToDelta(rawScale, range) {
865
+ // Scale >= 1 would result in axis range of 0.
866
+ // Scale <= -1 would reverse the scale direction.
867
+ const MAX_SCALE = 0.999;
868
+ const scale = limitValue(rawScale, -MAX_SCALE, MAX_SCALE);
869
+
870
+ let delta;
871
+ if (scale > 0) {
872
+ delta = range * Math.min(1, scale);
873
+ } else {
874
+ delta = range - (range / (1 + scale));
875
+ }
876
+
877
+ return delta;
878
+ }
879
+
860
880
  labelsBetweenTicks() {
861
881
  return !this.options.justified;
862
882
  }
@@ -410,7 +410,8 @@ class CategoryAxis extends Axis {
410
410
  scaleRange(scale, cursor) {
411
411
  const position = Math.abs(this.pointOffset(cursor));
412
412
  const rangeIndices = this.totalRangeIndices();
413
- const delta = (rangeIndices.max - rangeIndices.min) * Math.min(1, scale);
413
+ const range = rangeIndices.max - rangeIndices.min;
414
+ const delta = this.scaleToDelta(scale, range);
414
415
  const minDelta = position * delta;
415
416
  const maxDelta = (1 - position) * delta;
416
417
  const min = rangeIndices.min + minDelta;
@@ -420,7 +421,6 @@ class CategoryAxis extends Axis {
420
421
  max = min + MIN_CATEGORY_RANGE;
421
422
  }
422
423
 
423
-
424
424
  return {
425
425
  min: min,
426
426
  max: max
@@ -528,7 +528,8 @@ class DateCategoryAxis extends CategoryAxis {
528
528
  const { min: rangeMin, max: rangeMax } = this.dataRange.displayRange();
529
529
 
530
530
  const position = Math.abs(this.pointOffset(cursor));
531
- const delta = (rangeMax - rangeMin) * scale;
531
+ const range = rangeMax - rangeMin;
532
+ const delta = this.scaleToDelta(scale, range);
532
533
  const minDelta = Math.round(position * delta);
533
534
  const maxDelta = Math.round((1 - position) * delta);
534
535
 
@@ -172,7 +172,8 @@ class DateValueAxis extends Axis {
172
172
 
173
173
  scaleRange(scale, cursor) {
174
174
  const position = Math.abs(this.pointOffset(cursor));
175
- const delta = (this.options.max - this.options.min) * Math.min(1, scale);
175
+ const range = this.options.max - this.options.min;
176
+ const delta = this.scaleToDelta(scale, range);
176
177
  const minDelta = position * delta;
177
178
  const maxDelta = (1 - position) * delta;
178
179
  const min = toDate(toTime(this.options.min) + minDelta);
@@ -268,7 +268,8 @@ class LogarithmicAxis extends Axis {
268
268
  const logMin = log(this.options.min, base);
269
269
  const logMax = log(this.options.max, base);
270
270
  const position = Math.abs(this.pointOffset(cursor));
271
- const delta = (logMax - logMin) * Math.min(1, scale);
271
+ const range = logMax - logMin;
272
+ const delta = this.scaleToDelta(scale, range);
272
273
  const min = Math.pow(base, logMin + position * delta);
273
274
  let max = Math.pow(base, logMax - (1 - position) * delta);
274
275
 
@@ -197,11 +197,12 @@ class NumericAxis extends Axis {
197
197
 
198
198
  scaleRange(scale, cursor) {
199
199
  const position = Math.abs(this.pointOffset(cursor));
200
- const delta = (this.options.max - this.options.min) * Math.min(1, scale);
200
+ const range = this.options.max - this.options.min;
201
+ const delta = this.scaleToDelta(scale, range);
201
202
  const minDelta = position * delta;
202
203
  const maxDelta = (1 - position) * delta;
203
- const min = this.options.min + minDelta;
204
- let max = this.options.max - maxDelta;
204
+ const min = round(this.options.min + minDelta, DEFAULT_PRECISION);
205
+ let max = round(this.options.max - maxDelta, DEFAULT_PRECISION);
205
206
 
206
207
  if (max - min < MIN_VALUE_RANGE) {
207
208
  max = min + MIN_VALUE_RANGE;