From f5f0585ce9b0a3a5c8ae1a0ce07e17418aed4f78 Mon Sep 17 00:00:00 2001 From: susiwen8 Date: Mon, 2 Mar 2020 11:40:34 +0800 Subject: [PATCH 1/3] Feat: use auto calculate if min /max is null --- src/coord/axisHelper.js | 52 ++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/coord/axisHelper.js b/src/coord/axisHelper.js index a0e2a13608..2e457930f9 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; @@ -87,17 +85,6 @@ export function getScaleExtent(scale, model) { // (2) When `needCrossZero` and all data is positive/negative, should it be ensured // that the results processed by boundaryGap are positive/negative? - if (min == null) { - min = scaleType === 'ordinal' - ? (axisDataLen ? 0 : NaN) - : originalExtent[0] - boundaryGap[0] * span; - } - if (max == null) { - max = scaleType === 'ordinal' - ? (axisDataLen ? axisDataLen - 1 : NaN) - : originalExtent[1] + boundaryGap[1] * span; - } - if (min === 'dataMin') { min = originalExtent[0]; } @@ -118,6 +105,17 @@ export function getScaleExtent(scale, model) { }); } + if (min == null) { + min = scaleType === 'ordinal' + ? (axisDataLen ? 0 : NaN) + : originalExtent[0] - boundaryGap[0] * span; + } + if (max == null) { + max = scaleType === 'ordinal' + ? (axisDataLen ? axisDataLen - 1 : NaN) + : originalExtent[1] + boundaryGap[1] * span; + } + (min == null || !isFinite(min)) && (min = NaN); (max == null || !isFinite(max)) && (max = NaN); @@ -130,11 +128,11 @@ export function getScaleExtent(scale, model) { // Evaluate if axis needs cross zero if (model.getNeedCrossZero()) { // Axis is over zero and min is not set - if (min > 0 && max > 0 && !fixMin) { + if (min > 0 && max > 0 && !(min != null)) { min = 0; } // Axis is under zero and max is not set - if (min < 0 && max < 0 && !fixMax) { + if (min < 0 && max < 0 && !(max != null)) { max = 0; } } @@ -208,8 +206,24 @@ function adjustScaleForOverflow(min, max, model, barWidthAndOffset) { export function niceScaleExtent(scale, model) { var extent = getScaleExtent(scale, model); - var fixMin = model.getMin() != null; - var fixMax = model.getMax() != null; + 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 splitNumber = model.get('splitNumber'); if (scale.type === 'log') { @@ -220,8 +234,8 @@ export function niceScaleExtent(scale, model) { scale.setExtent(extent[0], extent[1]); scale.niceExtent({ splitNumber: splitNumber, - fixMin: fixMin, - fixMax: fixMax, + fixMin: min != null, + fixMax: max != null, minInterval: (scaleType === 'interval' || scaleType === 'time') ? model.get('minInterval') : null, maxInterval: (scaleType === 'interval' || scaleType === 'time') From 12d1c0e5e46eaa299de7ff7747d986dc518ed1ea Mon Sep 17 00:00:00 2001 From: susiwen8 Date: Mon, 2 Mar 2020 12:35:58 +0800 Subject: [PATCH 2/3] add test case --- src/echarts.js | 2 +- test/axis-extrema.html | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/echarts.js b/src/echarts.js index b35ae3b3ee..bc90768bda 100644 --- a/src/echarts.js +++ b/src/echarts.js @@ -601,7 +601,7 @@ echartsProto.getConnectedDataURL = function (opts) { each(canvasList, function (item) { var x = item.left - left; var y = item.top - top; - content += '' + item.dom + ''; }); zr.painter.getSvgRoot().innerHTML = content; diff --git a/test/axis-extrema.html b/test/axis-extrema.html index 80821b30f7..4a0777a38c 100644 --- a/test/axis-extrema.html +++ b/test/axis-extrema.html @@ -68,6 +68,9 @@

cartesian value axis | xAxis: {min: -10, max: 10}

cartesian value axis | xAxis: {min: function, max: function}

+

cartesian value axis | xAxis: {min: function, max: function}

+
+

cartesian time axis | xAxis: {min: 'dataMin', max: 'dataMax'}

@@ -463,6 +466,42 @@

single category axis | singleAxis: {min: function, max: function}

}); + From c928a9399954feddb76edb376c4d6900507847b6 Mon Sep 17 00:00:00 2001 From: susiwen8 Date: Mon, 2 Mar 2020 14:27:09 +0800 Subject: [PATCH 3/3] Revert some code due to failed test case --- src/coord/axisHelper.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/coord/axisHelper.js b/src/coord/axisHelper.js index 2e457930f9..75a424070a 100644 --- a/src/coord/axisHelper.js +++ b/src/coord/axisHelper.js @@ -42,6 +42,8 @@ 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; @@ -128,11 +130,11 @@ export function getScaleExtent(scale, model) { // Evaluate if axis needs cross zero if (model.getNeedCrossZero()) { // Axis is over zero and min is not set - if (min > 0 && max > 0 && !(min != null)) { + if (min > 0 && max > 0 && !fixMin) { min = 0; } // Axis is under zero and max is not set - if (min < 0 && max < 0 && !(max != null)) { + if (min < 0 && max < 0 && !fixMax) { max = 0; } }