From 8cd847c6a1da750b6c91992a99a4431ce0257436 Mon Sep 17 00:00:00 2001 From: Nikola Gluhovic Date: Tue, 5 Jul 2016 11:24:05 +0200 Subject: [PATCH 1/3] fix #1723 --- lib/timeline/DateUtil.js | 70 +++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/lib/timeline/DateUtil.js b/lib/timeline/DateUtil.js index 1a8a9076..67bf2c20 100644 --- a/lib/timeline/DateUtil.js +++ b/lib/timeline/DateUtil.js @@ -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 durationAfter = exports.getHiddenDurationBeforeStart(Core.body.hiddenDates, time, conversion.offset); + time = Core.options.moment(time).toDate().valueOf(); + time = time + durationAfter; + 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; + } + } + }; /** @@ -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 @@ -470,4 +504,4 @@ exports.isHidden = function(time, hiddenDates) { } } return {hidden: false, startDate: startDate, endDate: endDate}; -} \ No newline at end of file +} From d07a3ec8e585f72fd1c8db14c9c3816f97cbf990 Mon Sep 17 00:00:00 2001 From: Nikola Gluhovic Date: Tue, 5 Jul 2016 11:26:10 +0200 Subject: [PATCH 2/3] better variable name --- lib/timeline/DateUtil.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/timeline/DateUtil.js b/lib/timeline/DateUtil.js index 67bf2c20..49e9a56f 100644 --- a/lib/timeline/DateUtil.js +++ b/lib/timeline/DateUtil.js @@ -299,9 +299,9 @@ exports.toScreen = function (Core, time, width) { 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 durationAfter = exports.getHiddenDurationBeforeStart(Core.body.hiddenDates, time, conversion.offset); + var hiddenBeforeStart = exports.getHiddenDurationBeforeStart(Core.body.hiddenDates, time, conversion.offset); time = Core.options.moment(time).toDate().valueOf(); - time = time + durationAfter; + time = time + hiddenBeforeStart; return -(conversion.offset - time.valueOf()) * conversion.scale; } else if (time > Core.range.end) { From 9ec77c622b08bad81a243344fd903bbe96b473ed Mon Sep 17 00:00:00 2001 From: Nikola Gluhovic Date: Tue, 5 Jul 2016 11:32:38 +0200 Subject: [PATCH 3/3] fix wrong indentation --- lib/timeline/DateUtil.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/timeline/DateUtil.js b/lib/timeline/DateUtil.js index 49e9a56f..5ff46f41 100644 --- a/lib/timeline/DateUtil.js +++ b/lib/timeline/DateUtil.js @@ -378,7 +378,7 @@ exports.getHiddenDurationBeforeStart = function (hiddenDates, start, end) { var startDate = hiddenDates[i].start; var endDate = hiddenDates[i].end; - if (startDate >= start && endDate <= end) { + if (startDate >= start && endDate <= end) { duration += endDate - startDate; } }