|
|
@ -280,9 +280,8 @@ exports.toScreen = function(Core, time, width) { |
|
|
|
time = hidden.startDate; |
|
|
|
} |
|
|
|
|
|
|
|
var res = exports.correctTimeForDuration(Core.body.hiddenDates, Core.range, time); |
|
|
|
var duration = res.duration; |
|
|
|
time = res.time; |
|
|
|
var duration = exports.getHiddenDuration(Core.body.hiddenDates, Core.range); |
|
|
|
time = exports.getHiddenTimeBefore(Core.body.hiddenDates, Core.range, time); |
|
|
|
|
|
|
|
var conversion = Core.range.conversion(width, duration); |
|
|
|
return (time.valueOf() - conversion.offset) * conversion.scale; |
|
|
@ -298,10 +297,13 @@ exports.toScreen = function(Core, time, width) { |
|
|
|
* @returns {Date} |
|
|
|
*/ |
|
|
|
exports.toTime = function(body, range, x, width) { |
|
|
|
var duration = exports.getHiddenDuration(body.hiddenDates, range); |
|
|
|
var conversion = range.conversion(width, duration); |
|
|
|
var hiddenDuration = exports.getHiddenDuration(body.hiddenDates, range); |
|
|
|
var totalDuration = range.end - range.start - hiddenDuration; |
|
|
|
var partialDuration = totalDuration * x / width; |
|
|
|
var accumulatedHiddenDuration = exports.getAccumulatedHiddenDuration(body.hiddenDates,range, partialDuration); |
|
|
|
|
|
|
|
return new Date(x / conversion.scale + conversion.offset); |
|
|
|
var newTime = new Date(accumulatedHiddenDuration + partialDuration + range.start); |
|
|
|
return newTime; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -328,32 +330,63 @@ exports.getHiddenDuration = function(hiddenTimes, range) { |
|
|
|
|
|
|
|
/** |
|
|
|
* Support function |
|
|
|
* @param hiddenTimes |
|
|
|
* @param hiddenDates |
|
|
|
* @param range |
|
|
|
* @param time |
|
|
|
* @returns {{duration: number, time: *, offset: number}} |
|
|
|
*/ |
|
|
|
exports.correctTimeForDuration = function(hiddenTimes, range, time) { |
|
|
|
var duration = 0; |
|
|
|
exports.getHiddenTimeBefore = function(hiddenDates, range, time) { |
|
|
|
var timeOffset = 0; |
|
|
|
time = moment(time).toDate().valueOf(); |
|
|
|
|
|
|
|
for (var i = 0; i < hiddenTimes.length; i++) { |
|
|
|
var startDate = hiddenTimes[i].start; |
|
|
|
var endDate = hiddenTimes[i].end; |
|
|
|
for (var i = 0; i < hiddenDates.length; i++) { |
|
|
|
var startDate = hiddenDates[i].start; |
|
|
|
var endDate = hiddenDates[i].end; |
|
|
|
// if time after the cutout, and the
|
|
|
|
if (startDate >= range.start && endDate < range.end) { |
|
|
|
duration += (endDate - startDate); |
|
|
|
if (time >= endDate) { |
|
|
|
timeOffset += (endDate - startDate); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
time -= timeOffset; |
|
|
|
return {duration: duration, time:time, offset: timeOffset}; |
|
|
|
return time; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Support function |
|
|
|
* @param hiddenDates |
|
|
|
* @param range |
|
|
|
* @param time |
|
|
|
* @returns {{duration: number, time: *, offset: number}} |
|
|
|
*/ |
|
|
|
exports.getAccumulatedHiddenDuration = function(hiddenDates, range, requiredDuration) { |
|
|
|
var hiddenDuration = 0; |
|
|
|
var duration = 0; |
|
|
|
var previousPoint = range.start; |
|
|
|
//exports.printDates(hiddenDates)
|
|
|
|
for (var i = 0; i < hiddenDates.length; i++) { |
|
|
|
var startDate = hiddenDates[i].start; |
|
|
|
var endDate = hiddenDates[i].end; |
|
|
|
// if time after the cutout, and the
|
|
|
|
if (startDate >= range.start && endDate < range.end) { |
|
|
|
duration += startDate - previousPoint; |
|
|
|
|
|
|
|
previousPoint = endDate; |
|
|
|
if (duration >= requiredDuration) { |
|
|
|
break; |
|
|
|
} |
|
|
|
else { |
|
|
|
hiddenDuration += endDate - startDate; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return hiddenDuration; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* used to step over to either side of a hidden block. Correction is disabled on tablets, might be set to true |
|
|
|
* @param hiddenTimes |
|
|
|