Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Commit

Permalink
fixes strange behaviour in the time axis bar when hiddenDates are set (
Browse files Browse the repository at this point in the history
…#1944)

* fixes #1723
* better variable name
* fix wrong indentation
  • Loading branch information
nini-os authored and mojoaxel committed Aug 9, 2016
1 parent 6de24a2 commit e5e6a8b
Showing 1 changed file with 52 additions and 18 deletions.
70 changes: 52 additions & 18 deletions lib/timeline/DateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,24 +286,37 @@ exports.stepOverHiddenDates = function(moment, timeStep, previousTime) {
* @param width
* @returns {number}
*/
exports.toScreen = function(Core, time, width) {
if (Core.body.hiddenDates.length == 0) {
var conversion = Core.range.conversion(width);
return (time.valueOf() - conversion.offset) * conversion.scale;
}
else {
var hidden = exports.isHidden(time, Core.body.hiddenDates);
if (hidden.hidden == true) {
time = hidden.startDate;
}

var duration = exports.getHiddenDurationBetween(Core.body.hiddenDates, Core.range.start, Core.range.end);
time = exports.correctTimeForHidden(Core.options.moment, Core.body.hiddenDates, Core.range, time);
exports.toScreen = function (Core, time, width) {
if (Core.body.hiddenDates.length == 0) {
var conversion = Core.range.conversion(width);
return (time.valueOf() - conversion.offset) * conversion.scale;
} else {
var hidden = exports.isHidden(time, Core.body.hiddenDates);
if (hidden.hidden == true) {
time = hidden.startDate;
}

var conversion = Core.range.conversion(width, duration);
return (time.valueOf() - conversion.offset) * conversion.scale;
}
};
var duration = exports.getHiddenDurationBetween(Core.body.hiddenDates, Core.range.start, Core.range.end);
if (time < Core.range.start) {
var conversion = Core.range.conversion(width, duration);
var hiddenBeforeStart = exports.getHiddenDurationBeforeStart(Core.body.hiddenDates, time, conversion.offset);
time = Core.options.moment(time).toDate().valueOf();
time = time + hiddenBeforeStart;
return -(conversion.offset - time.valueOf()) * conversion.scale;

} else if (time > Core.range.end) {
var rangeAfterEnd = {start: Core.range.start, end: time};
time = exports.correctTimeForHidden(Core.options.moment, Core.body.hiddenDates, rangeAfterEnd, time);
var conversion = Core.range.conversion(width, duration);
return (time.valueOf() - conversion.offset) * conversion.scale;

} else {
time = exports.correctTimeForHidden(Core.options.moment, Core.body.hiddenDates, Core.range, time);
var conversion = Core.range.conversion(width, duration);
return (time.valueOf() - conversion.offset) * conversion.scale;
}
}
};


/**
Expand Down Expand Up @@ -351,6 +364,27 @@ exports.getHiddenDurationBetween = function(hiddenDates, start, end) {
return duration;
};

/**
* Support function
*
* @param hiddenDates
* @param start
* @param end
* @returns {number}
*/
exports.getHiddenDurationBeforeStart = function (hiddenDates, start, end) {
var duration = 0;
for (var i = 0; i < hiddenDates.length; i++) {
var startDate = hiddenDates[i].start;
var endDate = hiddenDates[i].end;

if (startDate >= start && endDate <= end) {
duration += endDate - startDate;
}
}
return duration;
};


/**
* Support function
Expand Down Expand Up @@ -470,4 +504,4 @@ exports.isHidden = function(time, hiddenDates) {
}
}
return {hidden: false, startDate: startDate, endDate: endDate};
}
}

0 comments on commit e5e6a8b

Please sign in to comment.