From f3a6b9aa8bab16701c1085c0b20a07aa397fbe39 Mon Sep 17 00:00:00 2001 From: 100pah Date: Thu, 2 Apr 2020 18:35:11 +0800 Subject: [PATCH] fix: axis min/max function return null: The original PR is: #12215 cf5812f6aad64e433c0de89c62bd0d84b7f3f0cf Fix from that: (1) The min/max function call should not be called twice (necessary and probably wrong input params). (2) `fixMin` `fixMax` should cover function return. (3) Add more test cases. --- src/coord/axisHelper.js | 37 +++++------- src/coord/radar/Radar.js | 2 +- test/min-max-function.html | 117 ++++++++++++++++++++++++++++++++----- 3 files changed, 119 insertions(+), 37 deletions(-) diff --git a/src/coord/axisHelper.js b/src/coord/axisHelper.js index 75a424070a..d6f7cd39c7 100644 --- a/src/coord/axisHelper.js +++ b/src/coord/axisHelper.js @@ -42,8 +42,6 @@ export function getScaleExtent(scale, model) { var min = model.getMin(); var max = model.getMax(); - var fixMin = min != null; - var fixMax = max != null; var originalExtent = scale.getExtent(); var axisDataLen; @@ -107,6 +105,9 @@ export function getScaleExtent(scale, model) { }); } + var fixMin = min != null; + var fixMax = max != null; + if (min == null) { min = scaleType === 'ordinal' ? (axisDataLen ? 0 : NaN) @@ -168,7 +169,13 @@ export function getScaleExtent(scale, model) { } } - return [min, max]; + return { + extent: [min, max], + // "fix" means "fixed", the value should not be + // changed in the subsequent steps. + fixMin: fixMin, + fixMax: fixMax + }; } function adjustScaleForOverflow(min, max, model, barWidthAndOffset) { @@ -207,24 +214,8 @@ function adjustScaleForOverflow(min, max, model, barWidthAndOffset) { } export function niceScaleExtent(scale, model) { - var extent = getScaleExtent(scale, model); - var min = model.getMin(); - var max = model.getMax(); - var originalExtent = scale.getExtent(); - - if (typeof min === 'function') { - min = min({ - min: originalExtent[0], - max: originalExtent[1] - }); - } - - if (typeof max === 'function') { - max = max({ - min: originalExtent[0], - max: originalExtent[1] - }); - } + var extentInfo = getScaleExtent(scale, model); + var extent = extentInfo.extent; var splitNumber = model.get('splitNumber'); @@ -236,8 +227,8 @@ export function niceScaleExtent(scale, model) { scale.setExtent(extent[0], extent[1]); scale.niceExtent({ splitNumber: splitNumber, - fixMin: min != null, - fixMax: max != null, + fixMin: extentInfo.fixMin, + fixMax: extentInfo.fixMin, minInterval: (scaleType === 'interval' || scaleType === 'time') ? model.get('minInterval') : null, maxInterval: (scaleType === 'interval' || scaleType === 'time') diff --git a/src/coord/radar/Radar.js b/src/coord/radar/Radar.js index 818e036a09..5ddf23a2cf 100644 --- a/src/coord/radar/Radar.js +++ b/src/coord/radar/Radar.js @@ -186,7 +186,7 @@ Radar.prototype.update = function (ecModel, api) { } // Force all the axis fixing the maxSplitNumber. zrUtil.each(indicatorAxes, function (indicatorAxis, idx) { - var rawExtent = getScaleExtent(indicatorAxis.scale, indicatorAxis.model); + var rawExtent = getScaleExtent(indicatorAxis.scale, indicatorAxis.model).extent; niceScaleExtent(indicatorAxis.scale, indicatorAxis.model); var axisModel = indicatorAxis.model; diff --git a/test/min-max-function.html b/test/min-max-function.html index f1d7821b34..b4d51c3743 100644 --- a/test/min-max-function.html +++ b/test/min-max-function.html @@ -21,33 +21,29 @@ + - + + + + +
+
+ + + + + + + + + + \ No newline at end of file