|
|
@ -39,6 +39,7 @@ function TimeAxis (body, options) { |
|
|
|
}, // axis orientation: 'top' or 'bottom'
|
|
|
|
showMinorLabels: true, |
|
|
|
showMajorLabels: true, |
|
|
|
maxMinorChars: 7, |
|
|
|
format: TimeStep.FORMAT, |
|
|
|
moment: moment, |
|
|
|
timeAxis: null |
|
|
@ -69,6 +70,7 @@ TimeAxis.prototype.setOptions = function(options) { |
|
|
|
util.selectiveExtend([ |
|
|
|
'showMinorLabels', |
|
|
|
'showMajorLabels', |
|
|
|
'maxMinorChars', |
|
|
|
'hiddenDates', |
|
|
|
'timeAxis', |
|
|
|
'moment' |
|
|
@ -195,7 +197,7 @@ TimeAxis.prototype._repaintLabels = function () { |
|
|
|
// calculate range and step (step such that we have space for 7 characters per label)
|
|
|
|
var start = util.convert(this.body.range.start, 'Number'); |
|
|
|
var end = util.convert(this.body.range.end, 'Number'); |
|
|
|
var timeLabelsize = this.body.util.toTime((this.props.minorCharWidth || 10) * 7).valueOf(); |
|
|
|
var timeLabelsize = this.body.util.toTime((this.props.minorCharWidth || 10) * this.options.maxMinorChars).valueOf(); |
|
|
|
var minimumStep = timeLabelsize - DateUtil.getHiddenDurationBefore(this.options.moment, this.body.hiddenDates, this.body.range, timeLabelsize); |
|
|
|
minimumStep -= this.body.util.toTime(0).valueOf(); |
|
|
|
|
|
|
@ -224,19 +226,20 @@ TimeAxis.prototype._repaintLabels = function () { |
|
|
|
var next; |
|
|
|
var x; |
|
|
|
var xNext; |
|
|
|
var isMajor; |
|
|
|
var width; |
|
|
|
var isMajor, nextIsMajor; |
|
|
|
var width = 0, prevWidth; |
|
|
|
var line; |
|
|
|
var labelMinor; |
|
|
|
var xFirstMajorLabel = undefined; |
|
|
|
var max = 0; |
|
|
|
var count = 0; |
|
|
|
const MAX = 1000; |
|
|
|
var className; |
|
|
|
|
|
|
|
step.start(); |
|
|
|
next = step.getCurrent(); |
|
|
|
xNext = this.body.util.toScreen(next); |
|
|
|
while (step.hasNext() && max < 1000) { |
|
|
|
max++; |
|
|
|
while (step.hasNext() && count < MAX) { |
|
|
|
count++; |
|
|
|
|
|
|
|
isMajor = step.isMajor(); |
|
|
|
className = step.getClassName(); |
|
|
@ -247,13 +250,16 @@ TimeAxis.prototype._repaintLabels = function () { |
|
|
|
|
|
|
|
step.next(); |
|
|
|
next = step.getCurrent(); |
|
|
|
nextIsMajor = step.isMajor(); |
|
|
|
xNext = this.body.util.toScreen(next); |
|
|
|
|
|
|
|
prevWidth = width; |
|
|
|
width = xNext - x; |
|
|
|
var labelFits = (labelMinor.length + 1) * this.props.minorCharWidth < width; |
|
|
|
var showMinorGrid = (width >= prevWidth * 0.4); // prevent displaying of the 31th of the month on a scale of 5 days
|
|
|
|
|
|
|
|
if (this.options.showMinorLabels && labelFits) { |
|
|
|
this._repaintMinorText(x, labelMinor, orientation, className); |
|
|
|
if (this.options.showMinorLabels && showMinorGrid) { |
|
|
|
var label = this._repaintMinorText(x, labelMinor, orientation, className); |
|
|
|
label.style.width = width + 'px'; // set width to prevent overflow
|
|
|
|
} |
|
|
|
|
|
|
|
if (isMajor && this.options.showMajorLabels) { |
|
|
@ -261,22 +267,28 @@ TimeAxis.prototype._repaintLabels = function () { |
|
|
|
if (xFirstMajorLabel == undefined) { |
|
|
|
xFirstMajorLabel = x; |
|
|
|
} |
|
|
|
this._repaintMajorText(x, step.getLabelMajor(), orientation, className); |
|
|
|
label = this._repaintMajorText(x, step.getLabelMajor(), orientation, className); |
|
|
|
} |
|
|
|
line = this._repaintMajorLine(x, width, orientation, className); |
|
|
|
} |
|
|
|
else { |
|
|
|
if (labelFits) { |
|
|
|
else { // minor line
|
|
|
|
if (showMinorGrid) { |
|
|
|
line = this._repaintMinorLine(x, width, orientation, className); |
|
|
|
} |
|
|
|
else { |
|
|
|
if (line) { |
|
|
|
line.style.width = (parseInt (line.style.width) + width) + 'px' |
|
|
|
// adjust the width of the previous grid
|
|
|
|
line.style.width = (parseInt (line.style.width) + width) + 'px'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (count === MAX && !warnedForOverflow) { |
|
|
|
console.warn(`Something is wrong with the Timeline scale. Limited drawing of grid lines to ${MAX} lines.`); |
|
|
|
warnedForOverflow = true; |
|
|
|
} |
|
|
|
|
|
|
|
// create a major label on the left when needed
|
|
|
|
if (this.options.showMajorLabels) { |
|
|
|
var leftTime = this.body.util.toTime(0), |
|
|
@ -467,4 +479,7 @@ TimeAxis.prototype._calculateCharSize = function () { |
|
|
|
this.props.majorCharWidth = this.dom.measureCharMajor.clientWidth; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var warnedForOverflow = false; |
|
|
|
|
|
|
|
module.exports = TimeAxis; |