diff --git a/src/coord/axisDefault.js b/src/coord/axisDefault.js index 3167f19f57..3f058999a0 100644 --- a/src/coord/axisDefault.js +++ b/src/coord/axisDefault.js @@ -134,6 +134,7 @@ define(function (require) { splitNumber: 5 // Minimum interval // minInterval: null + // maxInterval: null }, defaultOption); // FIXME diff --git a/src/coord/axisHelper.js b/src/coord/axisHelper.js index 7af29db891..126c29ffc1 100644 --- a/src/coord/axisHelper.js +++ b/src/coord/axisHelper.js @@ -113,12 +113,16 @@ define(function (require) { scale.base = model.get('logBase'); } + var scaleType = scale.type; scale.setExtent(extent[0], extent[1]); scale.niceExtent({ splitNumber: splitNumber, fixMin: fixMin, fixMax: fixMax, - minInterval: scale.type === 'interval' ? model.get('minInterval') : null + minInterval: (scaleType === 'interval' || scaleType === 'time') + ? model.get('minInterval') : null, + maxInterval: (scaleType === 'interval' || scaleType === 'time') + ? model.get('maxInterval') : null }); // If some one specified the min, max. And the default calculated interval diff --git a/src/scale/Interval.js b/src/scale/Interval.js index 0b5e6b2ece..0cf58d141f 100644 --- a/src/scale/Interval.js +++ b/src/scale/Interval.js @@ -117,8 +117,9 @@ define(function (require) { * * @param {number} [splitNumber = 5] Desired number of ticks * @param {number} [minInterval] + * @param {number} [maxInterval] */ - niceTicks: function (splitNumber, minInterval) { + niceTicks: function (splitNumber, minInterval, maxInterval) { splitNumber = splitNumber || 5; var extent = this._extent; var span = extent[1] - extent[0]; @@ -132,7 +133,9 @@ define(function (require) { extent.reverse(); } - var result = helper.intervalScaleNiceTicks(extent, splitNumber, minInterval); + var result = helper.intervalScaleNiceTicks( + extent, splitNumber, minInterval, maxInterval + ); this._intervalPrecision = result.intervalPrecision; this._interval = result.interval; @@ -145,7 +148,8 @@ define(function (require) { * @param {number} [opt.splitNumber = 5] Given approx tick number * @param {boolean} [opt.fixMin=false] * @param {boolean} [opt.fixMax=false] - * @param {boolean} [opt.minInterval=false] + * @param {boolean} [opt.minInterval] + * @param {boolean} [opt.maxInterval] */ niceExtent: function (opt) { var extent = this._extent; @@ -178,7 +182,7 @@ define(function (require) { extent[1] = 1; } - this.niceTicks(opt.splitNumber, opt.minInterval); + this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval); // var extent = this._extent; var interval = this._interval; diff --git a/src/scale/Time.js b/src/scale/Time.js index baad527b69..ddfd2b4313 100644 --- a/src/scale/Time.js +++ b/src/scale/Time.js @@ -81,7 +81,7 @@ define(function (require) { extent[0] = extent[1] - ONE_DAY; } - this.niceTicks(opt.splitNumber); + this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval); // var extent = this._extent; var interval = this._interval; @@ -97,7 +97,7 @@ define(function (require) { /** * @override */ - niceTicks: function (approxTickNum) { + niceTicks: function (approxTickNum, minInterval, maxInterval) { var timezoneOffset = this.getSetting('useUTC') ? 0 : numberUtil.getTimezoneOffset() * 60 * 1000; approxTickNum = approxTickNum || 10; @@ -105,6 +105,14 @@ define(function (require) { var extent = this._extent; var span = extent[1] - extent[0]; var approxInterval = span / approxTickNum; + + if (minInterval != null && approxInterval < minInterval) { + approxInterval = minInterval; + } + if (maxInterval != null && approxInterval > maxInterval) { + approxInterval = maxInterval; + } + var scaleLevelsLen = scaleLevels.length; var idx = bisect(scaleLevels, approxInterval, 0, scaleLevelsLen); diff --git a/src/scale/helper.js b/src/scale/helper.js index c492ddc187..e1618dbd97 100644 --- a/src/scale/helper.js +++ b/src/scale/helper.js @@ -14,9 +14,10 @@ define(function (require) { * Should be extent[0] < extent[1]. * @param {number} splitNumber splitNumber should be >= 1. * @param {number} [minInterval] + * @param {number} [maxInterval] * @return {Object} {interval, intervalPrecision, niceTickExtent} */ - helper.intervalScaleNiceTicks = function (extent, splitNumber, minInterval) { + helper.intervalScaleNiceTicks = function (extent, splitNumber, minInterval, maxInterval) { var result = {}; var span = extent[1] - extent[0]; @@ -24,6 +25,9 @@ define(function (require) { if (minInterval != null && interval < minInterval) { interval = result.interval = minInterval; } + if (maxInterval != null && interval > maxInterval) { + interval = result.interval = maxInterval; + } // Tow more digital for tick. var precision = result.intervalPrecision = helper.getIntervalPrecision(interval); // Niced extent inside original extent diff --git a/test/timeScale.html b/test/timeScale.html index 4e54bb4086..bc984f6a20 100644 --- a/test/timeScale.html +++ b/test/timeScale.html @@ -134,6 +134,7 @@ boundaryGap : false, axisLine: {onZero: false}, splitNumber: 20, + // minInterval: 3600 * 1000 * 24 // min: 'dataMin', // max: 'dataMax' }