Skip to content

Commit

Permalink
support minInterval to time scale, and support maxInterval to time sc…
Browse files Browse the repository at this point in the history
…ale and interval scale.
  • Loading branch information
100pah committed Jun 29, 2017
1 parent 15e5c05 commit 64b5801
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/coord/axisDefault.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ define(function (require) {
splitNumber: 5
// Minimum interval
// minInterval: null
// maxInterval: null
}, defaultOption);

// FIXME
Expand Down
6 changes: 5 additions & 1 deletion src/coord/axisHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/scale/Interval.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions src/scale/Time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -97,14 +97,22 @@ 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;

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);

Expand Down
6 changes: 5 additions & 1 deletion src/scale/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ 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];

var interval = result.interval = numberUtil.nice(span / splitNumber, true);
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
Expand Down
1 change: 1 addition & 0 deletions test/timeScale.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
boundaryGap : false,
axisLine: {onZero: false},
splitNumber: 20,
// minInterval: 3600 * 1000 * 24
// min: 'dataMin',
// max: 'dataMax'
}
Expand Down

0 comments on commit 64b5801

Please sign in to comment.