|
|
@ -24,7 +24,7 @@ |
|
|
|
* @param {Date} [end] The end date |
|
|
|
* @param {Number} [minimumStep] Optional. Minimum step size in milliseconds |
|
|
|
*/ |
|
|
|
function DataStep(start, end, minimumStep, containerHeight, forcedStepSize) { |
|
|
|
function DataStep(start, end, minimumStep, containerHeight, customRange) { |
|
|
|
// variables
|
|
|
|
this.current = 0; |
|
|
|
|
|
|
@ -35,11 +35,12 @@ function DataStep(start, end, minimumStep, containerHeight, forcedStepSize) { |
|
|
|
|
|
|
|
this.marginStart; |
|
|
|
this.marginEnd; |
|
|
|
this.deadSpace = 0; |
|
|
|
|
|
|
|
this.majorSteps = [1, 2, 5, 10]; |
|
|
|
this.minorSteps = [0.25, 0.5, 1, 2]; |
|
|
|
|
|
|
|
this.setRange(start, end, minimumStep, containerHeight, forcedStepSize); |
|
|
|
this.setRange(start, end, minimumStep, containerHeight, customRange); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -54,9 +55,9 @@ function DataStep(start, end, minimumStep, containerHeight, forcedStepSize) { |
|
|
|
* @param {Number} [end] The end date and time. |
|
|
|
* @param {Number} [minimumStep] Optional. Minimum step size in milliseconds |
|
|
|
*/ |
|
|
|
DataStep.prototype.setRange = function(start, end, minimumStep, containerHeight, forcedStepSize) { |
|
|
|
this._start = start; |
|
|
|
this._end = end; |
|
|
|
DataStep.prototype.setRange = function(start, end, minimumStep, containerHeight, customRange) { |
|
|
|
this._start = customRange.min === undefined ? start : customRange.min; |
|
|
|
this._end = customRange.max === undefined ? end : customRange.max; |
|
|
|
|
|
|
|
if (start == end) { |
|
|
|
this._start = start - 0.75; |
|
|
@ -64,9 +65,9 @@ DataStep.prototype.setRange = function(start, end, minimumStep, containerHeight, |
|
|
|
} |
|
|
|
|
|
|
|
if (this.autoScale) { |
|
|
|
this.setMinimumStep(minimumStep, containerHeight, forcedStepSize); |
|
|
|
this.setMinimumStep(minimumStep, containerHeight); |
|
|
|
} |
|
|
|
this.setFirst(); |
|
|
|
this.setFirst(customRange); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
@ -76,7 +77,7 @@ DataStep.prototype.setRange = function(start, end, minimumStep, containerHeight, |
|
|
|
DataStep.prototype.setMinimumStep = function(minimumStep, containerHeight) { |
|
|
|
// round to floor
|
|
|
|
var size = this._end - this._start; |
|
|
|
var safeSize = size * 1.1; |
|
|
|
var safeSize = size * 1.2; |
|
|
|
var minimumStepValue = minimumStep * (safeSize / containerHeight); |
|
|
|
var orderOfMagnitude = Math.round(Math.log(safeSize)/Math.LN10); |
|
|
|
|
|
|
@ -109,23 +110,21 @@ DataStep.prototype.setMinimumStep = function(minimumStep, containerHeight) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Set the range iterator to the start date. |
|
|
|
*/ |
|
|
|
DataStep.prototype.first = function() { |
|
|
|
this.setFirst(); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Round the current date to the first minor date value |
|
|
|
* This must be executed once when the current date is set to start Date |
|
|
|
*/ |
|
|
|
DataStep.prototype.setFirst = function() { |
|
|
|
var niceStart = this._start - (this.scale * this.minorSteps[this.stepIndex]); |
|
|
|
var niceEnd = this._end + (this.scale * this.minorSteps[this.stepIndex]); |
|
|
|
DataStep.prototype.setFirst = function(customRange) { |
|
|
|
if (customRange === undefined) { |
|
|
|
customRange = {}; |
|
|
|
} |
|
|
|
var niceStart = customRange.min === undefined ? this._start - (this.scale * 2 * this.minorSteps[this.stepIndex]) : customRange.min; |
|
|
|
var niceEnd = customRange.max === undefined ? this._end + (this.scale * this.minorSteps[this.stepIndex]) : customRange.max; |
|
|
|
|
|
|
|
this.marginEnd = this.roundToMinor(niceEnd); |
|
|
|
this.marginStart = this.roundToMinor(niceStart); |
|
|
|
this.marginEnd = customRange.max === undefined ? this.roundToMinor(niceEnd) : customRange.max; |
|
|
|
this.marginStart = customRange.min === undefined ? this.roundToMinor(niceStart) : customRange.min; |
|
|
|
this.deadSpace = this.roundToMinor(niceEnd) - niceEnd + this.roundToMinor(niceStart) - niceStart; |
|
|
|
this.marginRange = this.marginEnd - this.marginStart; |
|
|
|
|
|
|
|
this.current = this.marginEnd; |
|
|
|