|
|
@ -15,14 +15,12 @@ var moment = require('../../module/moment'); |
|
|
|
function TimeAxis (body, options) { |
|
|
|
this.dom = { |
|
|
|
foreground: null, |
|
|
|
majorLines: [], |
|
|
|
lines: [], |
|
|
|
majorTexts: [], |
|
|
|
minorLines: [], |
|
|
|
minorTexts: [], |
|
|
|
redundant: { |
|
|
|
majorLines: [], |
|
|
|
lines: [], |
|
|
|
majorTexts: [], |
|
|
|
minorLines: [], |
|
|
|
minorTexts: [] |
|
|
|
} |
|
|
|
}; |
|
|
@ -198,29 +196,40 @@ TimeAxis.prototype._repaintLabels = function () { |
|
|
|
// can be picked for re-use, and clear the lists with lines and texts.
|
|
|
|
// At the end of the function _repaintLabels, left over elements will be cleaned up
|
|
|
|
var dom = this.dom; |
|
|
|
dom.redundant.majorLines = dom.majorLines; |
|
|
|
dom.redundant.lines = dom.lines; |
|
|
|
dom.redundant.majorTexts = dom.majorTexts; |
|
|
|
dom.redundant.minorLines = dom.minorLines; |
|
|
|
dom.redundant.minorTexts = dom.minorTexts; |
|
|
|
dom.majorLines = []; |
|
|
|
dom.lines = []; |
|
|
|
dom.majorTexts = []; |
|
|
|
dom.minorLines = []; |
|
|
|
dom.minorTexts = []; |
|
|
|
|
|
|
|
step.first(); |
|
|
|
var cur; |
|
|
|
var x = 0; |
|
|
|
var isMajor; |
|
|
|
var xPrev = 0; |
|
|
|
var width = 0; |
|
|
|
var prevLine; |
|
|
|
var xFirstMajorLabel = undefined; |
|
|
|
var max = 0; |
|
|
|
var className; |
|
|
|
|
|
|
|
step.first(); |
|
|
|
while (step.hasNext() && max < 1000) { |
|
|
|
max++; |
|
|
|
var cur = step.getCurrent(); |
|
|
|
var x = this.body.util.toScreen(cur); |
|
|
|
var isMajor = step.isMajor(); |
|
|
|
|
|
|
|
cur = step.getCurrent(); |
|
|
|
isMajor = step.isMajor(); |
|
|
|
className = step.getClassName(); |
|
|
|
|
|
|
|
// TODO: lines must have a width, such that we can create css backgrounds
|
|
|
|
xPrev = x; |
|
|
|
x = this.body.util.toScreen(cur); |
|
|
|
width = x - xPrev; |
|
|
|
if (prevLine) { |
|
|
|
prevLine.style.width = width + 'px'; |
|
|
|
} |
|
|
|
|
|
|
|
if (this.options.showMinorLabels) { |
|
|
|
this._repaintMinorText(x, step.getLabelMinor(), orientation); |
|
|
|
this._repaintMinorText(x, step.getLabelMinor(), orientation, className); |
|
|
|
} |
|
|
|
|
|
|
|
if (isMajor && this.options.showMajorLabels) { |
|
|
@ -228,12 +237,12 @@ TimeAxis.prototype._repaintLabels = function () { |
|
|
|
if (xFirstMajorLabel == undefined) { |
|
|
|
xFirstMajorLabel = x; |
|
|
|
} |
|
|
|
this._repaintMajorText(x, step.getLabelMajor(), orientation); |
|
|
|
this._repaintMajorText(x, step.getLabelMajor(), orientation, className); |
|
|
|
} |
|
|
|
this._repaintMajorLine(x, orientation); |
|
|
|
prevLine = this._repaintMajorLine(x, orientation, className); |
|
|
|
} |
|
|
|
else { |
|
|
|
this._repaintMinorLine(x, orientation); |
|
|
|
prevLine = this._repaintMinorLine(x, orientation, className); |
|
|
|
} |
|
|
|
|
|
|
|
step.next(); |
|
|
@ -246,7 +255,7 @@ TimeAxis.prototype._repaintLabels = function () { |
|
|
|
widthText = leftText.length * (this.props.majorCharWidth || 10) + 10; // upper bound estimation
|
|
|
|
|
|
|
|
if (xFirstMajorLabel == undefined || widthText < xFirstMajorLabel) { |
|
|
|
this._repaintMajorText(0, leftText, orientation); |
|
|
|
this._repaintMajorText(0, leftText, orientation, className); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -266,9 +275,10 @@ TimeAxis.prototype._repaintLabels = function () { |
|
|
|
* @param {Number} x |
|
|
|
* @param {String} text |
|
|
|
* @param {String} orientation "top" or "bottom" (default) |
|
|
|
* @param {String} className |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
TimeAxis.prototype._repaintMinorText = function (x, text, orientation) { |
|
|
|
TimeAxis.prototype._repaintMinorText = function (x, text, orientation, className) { |
|
|
|
// reuse redundant label
|
|
|
|
var label = this.dom.redundant.minorTexts.shift(); |
|
|
|
|
|
|
@ -277,7 +287,6 @@ TimeAxis.prototype._repaintMinorText = function (x, text, orientation) { |
|
|
|
var content = document.createTextNode(''); |
|
|
|
label = document.createElement('div'); |
|
|
|
label.appendChild(content); |
|
|
|
label.className = 'text minor'; |
|
|
|
this.dom.foreground.appendChild(label); |
|
|
|
} |
|
|
|
this.dom.minorTexts.push(label); |
|
|
@ -286,6 +295,7 @@ TimeAxis.prototype._repaintMinorText = function (x, text, orientation) { |
|
|
|
|
|
|
|
label.style.top = (orientation == 'top') ? (this.props.majorLabelHeight + 'px') : '0'; |
|
|
|
label.style.left = x + 'px'; |
|
|
|
label.className = 'text minor ' + className; |
|
|
|
//label.title = title; // TODO: this is a heavy operation
|
|
|
|
}; |
|
|
|
|
|
|
@ -294,9 +304,10 @@ TimeAxis.prototype._repaintMinorText = function (x, text, orientation) { |
|
|
|
* @param {Number} x |
|
|
|
* @param {String} text |
|
|
|
* @param {String} orientation "top" or "bottom" (default) |
|
|
|
* @param {String} className |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
TimeAxis.prototype._repaintMajorText = function (x, text, orientation) { |
|
|
|
TimeAxis.prototype._repaintMajorText = function (x, text, orientation, className) { |
|
|
|
// reuse redundant label
|
|
|
|
var label = this.dom.redundant.majorTexts.shift(); |
|
|
|
|
|
|
@ -304,13 +315,13 @@ TimeAxis.prototype._repaintMajorText = function (x, text, orientation) { |
|
|
|
// create label
|
|
|
|
var content = document.createTextNode(text); |
|
|
|
label = document.createElement('div'); |
|
|
|
label.className = 'text major'; |
|
|
|
label.appendChild(content); |
|
|
|
this.dom.foreground.appendChild(label); |
|
|
|
} |
|
|
|
this.dom.majorTexts.push(label); |
|
|
|
|
|
|
|
label.childNodes[0].nodeValue = text; |
|
|
|
label.className = 'text major ' + className; |
|
|
|
//label.title = title; // TODO: this is a heavy operation
|
|
|
|
|
|
|
|
label.style.top = (orientation == 'top') ? '0' : (this.props.minorLabelHeight + 'px'); |
|
|
@ -321,19 +332,19 @@ TimeAxis.prototype._repaintMajorText = function (x, text, orientation) { |
|
|
|
* Create a minor line for the axis at position x |
|
|
|
* @param {Number} x |
|
|
|
* @param {String} orientation "top" or "bottom" (default) |
|
|
|
* @param {String} className |
|
|
|
* @return {Element} Returns the created line |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
TimeAxis.prototype._repaintMinorLine = function (x, orientation) { |
|
|
|
TimeAxis.prototype._repaintMinorLine = function (x, orientation, className) { |
|
|
|
// reuse redundant line
|
|
|
|
var line = this.dom.redundant.minorLines.shift(); |
|
|
|
|
|
|
|
var line = this.dom.redundant.lines.shift(); |
|
|
|
if (!line) { |
|
|
|
// create vertical line
|
|
|
|
line = document.createElement('div'); |
|
|
|
line.className = 'grid vertical minor'; |
|
|
|
this.dom.background.appendChild(line); |
|
|
|
} |
|
|
|
this.dom.minorLines.push(line); |
|
|
|
this.dom.lines.push(line); |
|
|
|
|
|
|
|
var props = this.props; |
|
|
|
if (orientation == 'top') { |
|
|
@ -344,25 +355,29 @@ TimeAxis.prototype._repaintMinorLine = function (x, orientation) { |
|
|
|
} |
|
|
|
line.style.height = props.minorLineHeight + 'px'; |
|
|
|
line.style.left = (x - props.minorLineWidth / 2) + 'px'; |
|
|
|
|
|
|
|
line.className = 'grid vertical minor ' + className; |
|
|
|
|
|
|
|
return line; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Create a Major line for the axis at position x |
|
|
|
* @param {Number} x |
|
|
|
* @param {String} orientation "top" or "bottom" (default) |
|
|
|
* @param {String} className |
|
|
|
* @return {Element} Returns the created line |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
TimeAxis.prototype._repaintMajorLine = function (x, orientation) { |
|
|
|
TimeAxis.prototype._repaintMajorLine = function (x, orientation, className) { |
|
|
|
// reuse redundant line
|
|
|
|
var line = this.dom.redundant.majorLines.shift(); |
|
|
|
|
|
|
|
var line = this.dom.redundant.lines.shift(); |
|
|
|
if (!line) { |
|
|
|
// create vertical line
|
|
|
|
line = document.createElement('DIV'); |
|
|
|
line.className = 'grid vertical major'; |
|
|
|
line = document.createElement('div'); |
|
|
|
this.dom.background.appendChild(line); |
|
|
|
} |
|
|
|
this.dom.majorLines.push(line); |
|
|
|
this.dom.lines.push(line); |
|
|
|
|
|
|
|
var props = this.props; |
|
|
|
if (orientation == 'top') { |
|
|
@ -373,6 +388,10 @@ TimeAxis.prototype._repaintMajorLine = function (x, orientation) { |
|
|
|
} |
|
|
|
line.style.left = (x - props.majorLineWidth / 2) + 'px'; |
|
|
|
line.style.height = props.majorLineHeight + 'px'; |
|
|
|
|
|
|
|
line.className = 'grid vertical major ' + className; |
|
|
|
|
|
|
|
return line; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|