|
@ -1,8 +1,7 @@ |
|
|
var util = require('../../util'); |
|
|
var util = require('../../util'); |
|
|
var DOMutil = require('../../DOMutil'); |
|
|
var DOMutil = require('../../DOMutil'); |
|
|
var Component = require('./Component'); |
|
|
var Component = require('./Component'); |
|
|
var DataStep = require('../DataStep'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var DataScale = require('./DataScale'); |
|
|
/** |
|
|
/** |
|
|
* A horizontal time axis |
|
|
* A horizontal time axis |
|
|
* @param {Object} [options] See DataAxis.setOptions for the available |
|
|
* @param {Object} [options] See DataAxis.setOptions for the available |
|
@ -50,7 +49,7 @@ function DataAxis (body, options, svg, linegraphOptions) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
this.dom = {}; |
|
|
this.dom = {}; |
|
|
|
|
|
|
|
|
|
|
|
this.scale= undefined; |
|
|
this.range = {start:0, end:0}; |
|
|
this.range = {start:0, end:0}; |
|
|
|
|
|
|
|
|
this.options = util.extend({}, this.defaultOptions); |
|
|
this.options = util.extend({}, this.defaultOptions); |
|
@ -68,10 +67,10 @@ function DataAxis (body, options, svg, linegraphOptions) { |
|
|
|
|
|
|
|
|
this.lineOffset = 0; |
|
|
this.lineOffset = 0; |
|
|
this.master = true; |
|
|
this.master = true; |
|
|
|
|
|
this.masterAxis = null; |
|
|
this.svgElements = {}; |
|
|
this.svgElements = {}; |
|
|
this.iconsRemoved = false; |
|
|
this.iconsRemoved = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.groups = {}; |
|
|
this.groups = {}; |
|
|
this.amountOfGroups = 0; |
|
|
this.amountOfGroups = 0; |
|
|
|
|
|
|
|
@ -132,10 +131,9 @@ DataAxis.prototype.setOptions = function (options) { |
|
|
'right', |
|
|
'right', |
|
|
'alignZeros' |
|
|
'alignZeros' |
|
|
]; |
|
|
]; |
|
|
util.selectiveExtend(fields, this.options, options); |
|
|
|
|
|
|
|
|
util.selectiveDeepExtend(fields, this.options, options); |
|
|
|
|
|
|
|
|
this.minWidth = Number(('' + this.options.width).replace("px","")); |
|
|
this.minWidth = Number(('' + this.options.width).replace("px","")); |
|
|
|
|
|
|
|
|
if (redraw === true && this.dom.frame) { |
|
|
if (redraw === true && this.dom.frame) { |
|
|
this.hide(); |
|
|
this.hide(); |
|
|
this.show(); |
|
|
this.show(); |
|
@ -248,11 +246,6 @@ DataAxis.prototype.hide = function() { |
|
|
* @param end |
|
|
* @param end |
|
|
*/ |
|
|
*/ |
|
|
DataAxis.prototype.setRange = function (start, end) { |
|
|
DataAxis.prototype.setRange = function (start, end) { |
|
|
if (this.master === false && this.options.alignZeros === true && this.zeroCrossing != -1) { |
|
|
|
|
|
if (start > 0) { |
|
|
|
|
|
start = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
this.range.start = start; |
|
|
this.range.start = start; |
|
|
this.range.end = end; |
|
|
this.range.end = end; |
|
|
}; |
|
|
}; |
|
@ -264,7 +257,7 @@ DataAxis.prototype.setRange = function (start, end) { |
|
|
DataAxis.prototype.redraw = function () { |
|
|
DataAxis.prototype.redraw = function () { |
|
|
var resized = false; |
|
|
var resized = false; |
|
|
var activeGroups = 0; |
|
|
var activeGroups = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure the line container adheres to the vertical scrolling.
|
|
|
// Make sure the line container adheres to the vertical scrolling.
|
|
|
this.dom.lineContainer.style.top = this.body.domProps.scrollTop + 'px'; |
|
|
this.dom.lineContainer.style.top = this.body.domProps.scrollTop + 'px'; |
|
|
|
|
|
|
|
@ -352,103 +345,60 @@ DataAxis.prototype._redrawLabels = function () { |
|
|
DOMutil.prepareElements(this.DOMelements.lines); |
|
|
DOMutil.prepareElements(this.DOMelements.lines); |
|
|
DOMutil.prepareElements(this.DOMelements.labels); |
|
|
DOMutil.prepareElements(this.DOMelements.labels); |
|
|
var orientation = this.options['orientation']; |
|
|
var orientation = this.options['orientation']; |
|
|
|
|
|
var customRange = this.options[orientation].range != undefined? this.options[orientation].range:{}; |
|
|
|
|
|
|
|
|
// get the range for the slaved axis
|
|
|
|
|
|
var step, stepSize, rangeStart, rangeEnd; |
|
|
|
|
|
if (this.master === false) { |
|
|
|
|
|
if (this.zeroCrossing !== -1 && this.options.alignZeros === true) { |
|
|
|
|
|
if (this.range.end > 0) { |
|
|
|
|
|
stepSize = this.range.end / this.zeroCrossing; // size of one step
|
|
|
|
|
|
rangeStart = this.range.end - this.amountOfSteps * stepSize; |
|
|
|
|
|
rangeEnd = this.range.end; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
// all of the range (including start) has to be done before the zero crossing.
|
|
|
|
|
|
stepSize = -1 * this.range.start / (this.amountOfSteps - this.zeroCrossing); // absolute size of a step
|
|
|
|
|
|
rangeStart = this.range.start; |
|
|
|
|
|
rangeEnd = this.range.start + stepSize * this.amountOfSteps; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
rangeStart = this.range.start; |
|
|
|
|
|
rangeEnd = this.range.end; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//Override range with manual options:
|
|
|
|
|
|
var autoScaleEnd = true; |
|
|
|
|
|
if (customRange.max != undefined){ |
|
|
|
|
|
this.range.end = customRange.max; |
|
|
|
|
|
autoScaleEnd = false; |
|
|
} |
|
|
} |
|
|
else { |
|
|
|
|
|
// calculate range and step (step such that we have space for 7 characters per label)
|
|
|
|
|
|
rangeStart = this.range.start; |
|
|
|
|
|
rangeEnd = this.range.end; |
|
|
|
|
|
|
|
|
var autoScaleStart = true; |
|
|
|
|
|
if (customRange.min != undefined){ |
|
|
|
|
|
this.range.start = customRange.min; |
|
|
|
|
|
autoScaleStart = false; |
|
|
} |
|
|
} |
|
|
var minimumStep = this.props.majorCharHeight; |
|
|
|
|
|
|
|
|
|
|
|
this.step = step = new DataStep( |
|
|
|
|
|
rangeStart, |
|
|
|
|
|
rangeEnd, |
|
|
|
|
|
minimumStep, |
|
|
|
|
|
|
|
|
this.scale = new DataScale( |
|
|
|
|
|
this.range.start, |
|
|
|
|
|
this.range.end, |
|
|
|
|
|
autoScaleStart, |
|
|
|
|
|
autoScaleEnd, |
|
|
this.dom.frame.offsetHeight, |
|
|
this.dom.frame.offsetHeight, |
|
|
this.options[this.options.orientation].range, |
|
|
|
|
|
this.options[this.options.orientation].format, |
|
|
|
|
|
this.master === false && this.options.alignZeros // does the step have to align zeros? only if not master and the options is on
|
|
|
|
|
|
|
|
|
this.props.majorCharHeight, |
|
|
|
|
|
this.options.alignZeros, |
|
|
|
|
|
this.options[orientation].format |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
// the slave axis needs to use the same horizontal lines as the master axis.
|
|
|
|
|
|
if (this.master === true) { |
|
|
|
|
|
this.stepPixels = ((this.dom.frame.offsetHeight) / step.marginRange) * step.step; |
|
|
|
|
|
this.amountOfSteps = Math.ceil(this.dom.frame.offsetHeight / this.stepPixels); |
|
|
|
|
|
|
|
|
if (this.master === false && this.masterAxis != undefined){ |
|
|
|
|
|
this.scale.followScale(this.masterAxis.scale); |
|
|
} |
|
|
} |
|
|
else { |
|
|
|
|
|
// align with zero
|
|
|
|
|
|
if (this.options.alignZeros === true && this.zeroCrossing !== -1) { |
|
|
|
|
|
// distance is the amount of steps away from the zero crossing we are.
|
|
|
|
|
|
let distance = (step.current - this.zeroCrossing * step.step) / step.step; |
|
|
|
|
|
this.step.shift(distance); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// value at the bottom of the SVG
|
|
|
|
|
|
this.valueAtBottom = step.marginEnd; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Is updated in side-effect of _redrawLabel():
|
|
|
this.maxLabelSize = 0; |
|
|
this.maxLabelSize = 0; |
|
|
var y = 0; // init value
|
|
|
|
|
|
var stepIndex = 0; // init value
|
|
|
|
|
|
var isMajor = false; // init value
|
|
|
|
|
|
while (stepIndex < this.amountOfSteps) { |
|
|
|
|
|
y = Math.round(stepIndex * this.stepPixels); |
|
|
|
|
|
isMajor = step.isMajor(); |
|
|
|
|
|
|
|
|
|
|
|
if (stepIndex > 0 && stepIndex !== this.amountOfSteps) { |
|
|
|
|
|
if (this.options['showMinorLabels'] && isMajor === false || this.master === false && this.options['showMinorLabels'] === true) { |
|
|
|
|
|
this._redrawLabel(y - 2, step.getCurrent(), orientation, 'vis-y-axis vis-minor', this.props.minorCharHeight); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isMajor && this.options['showMajorLabels'] && this.master === true || |
|
|
|
|
|
this.options['showMinorLabels'] === false && this.master === false && isMajor === true) { |
|
|
|
|
|
|
|
|
var lines = this.scale.getLines(); |
|
|
|
|
|
lines.forEach( |
|
|
|
|
|
line=> { |
|
|
|
|
|
var y = line.y; |
|
|
|
|
|
var isMajor = line.major; |
|
|
|
|
|
if (this.options['showMinorLabels'] && isMajor === false) { |
|
|
|
|
|
this._redrawLabel(y - 2, line.val, orientation, 'vis-y-axis vis-minor', this.props.minorCharHeight); |
|
|
|
|
|
} |
|
|
|
|
|
if (isMajor) { |
|
|
if (y >= 0) { |
|
|
if (y >= 0) { |
|
|
this._redrawLabel(y - 2, step.getCurrent(), orientation, 'vis-y-axis vis-major', this.props.majorCharHeight); |
|
|
|
|
|
|
|
|
this._redrawLabel(y - 2, line.val, orientation, 'vis-y-axis vis-major', this.props.majorCharHeight); |
|
|
} |
|
|
} |
|
|
this._redrawLine(y, orientation, 'vis-grid vis-horizontal vis-major', this.options.majorLinesOffset, this.props.majorLineWidth); |
|
|
|
|
|
} |
|
|
} |
|
|
else { |
|
|
|
|
|
this._redrawLine(y, orientation, 'vis-grid vis-horizontal vis-minor', this.options.minorLinesOffset, this.props.minorLineWidth); |
|
|
|
|
|
|
|
|
if (this.master === true) { |
|
|
|
|
|
if (isMajor) { |
|
|
|
|
|
this._redrawLine(y, orientation, 'vis-grid vis-horizontal vis-major', this.options.majorLinesOffset, this.props.majorLineWidth); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
this._redrawLine(y, orientation, 'vis-grid vis-horizontal vis-minor', this.options.minorLinesOffset, this.props.minorLineWidth); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get zero crossing
|
|
|
|
|
|
if (this.master === true && step.current === 0) { |
|
|
|
|
|
this.zeroCrossing = stepIndex; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
step.next(); |
|
|
|
|
|
stepIndex += 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get zero crossing if it's the last step
|
|
|
|
|
|
if (this.master === true && step.current === 0) { |
|
|
|
|
|
this.zeroCrossing = stepIndex; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.conversionFactor = this.stepPixels / step.step; |
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
// Note that title is rotated, so we're using the height, not width!
|
|
|
// Note that title is rotated, so we're using the height, not width!
|
|
|
var titleWidth = 0; |
|
|
var titleWidth = 0; |
|
@ -485,13 +435,11 @@ DataAxis.prototype._redrawLabels = function () { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
DataAxis.prototype.convertValue = function (value) { |
|
|
DataAxis.prototype.convertValue = function (value) { |
|
|
var invertedValue = this.valueAtBottom - value; |
|
|
|
|
|
var convertedValue = invertedValue * this.conversionFactor; |
|
|
|
|
|
return convertedValue; |
|
|
|
|
|
|
|
|
return this.scale.convertValue(value); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
DataAxis.prototype.screenToValue = function (x) { |
|
|
DataAxis.prototype.screenToValue = function (x) { |
|
|
return this.valueAtBottom - (x / this.conversionFactor); |
|
|
|
|
|
|
|
|
return this.scale.screenToValue(x); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|