From 66938d91c0651d877f4b0130e53cbcc1253400ce Mon Sep 17 00:00:00 2001 From: Jannis Giannantonio-Tillmann Date: Wed, 6 Feb 2019 12:20:49 +0100 Subject: [PATCH 1/2] Fix zooming clears logarithmic scale Existing error: Logarithmic scale gets cleared out by zooming out. Error diagnosis: Minimum value of scale was getting a negative value, logarithmic scales are not able to show negative values -> gets cleared out. Bug fixing: When the scale would get a negative value it will be substituted by 0. --- src/plugin.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/plugin.js b/src/plugin.js index 39c352768..fcc825e9b 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -132,6 +132,7 @@ function zoomTimeScale(scale, zoom, center, zoomOptions) { } function zoomNumericalScale(scale, zoom, center, zoomOptions) { + var tickOpts = scale.options.ticks; var range = scale.max - scale.min; var newDiff = range * (zoom - 1); @@ -142,6 +143,10 @@ function zoomNumericalScale(scale, zoom, center, zoomOptions) { var minDelta = newDiff * minPercent; var maxDelta = newDiff * maxPercent; + if (scale.type === 'logarithmic') { + tickOpts.min = tickOpts.min < 0 ? 0 : tickOpts.min; + } + scale.options.ticks.min = rangeMinLimiter(zoomOptions, scale.min + minDelta); scale.options.ticks.max = rangeMaxLimiter(zoomOptions, scale.max - maxDelta); } From e2c7d8dfb5acb90dc65a8ef60705b7f48f434f15 Mon Sep 17 00:00:00 2001 From: Jannis Giannantonio-Tillmann Date: Thu, 7 Feb 2019 15:13:23 +0100 Subject: [PATCH 2/2] fixup! Fix zooming clears logarithmic scale --- src/plugin.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/plugin.js b/src/plugin.js index fcc825e9b..5d2b158cb 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -143,12 +143,15 @@ function zoomNumericalScale(scale, zoom, center, zoomOptions) { var minDelta = newDiff * minPercent; var maxDelta = newDiff * maxPercent; + tickOpts.min = scale.min + minDelta; + tickOpts.max = scale.max - maxDelta; + if (scale.type === 'logarithmic') { tickOpts.min = tickOpts.min < 0 ? 0 : tickOpts.min; } - scale.options.ticks.min = rangeMinLimiter(zoomOptions, scale.min + minDelta); - scale.options.ticks.max = rangeMaxLimiter(zoomOptions, scale.max - maxDelta); + tickOpts.min = rangeMinLimiter(zoomOptions, tickOpts.min); + tickOpts.max = rangeMaxLimiter(zoomOptions, tickOpts.max); } function zoomScale(scale, zoom, center, zoomOptions) {