Browse Source

fixed all problems with hiddenDates EXCEPT moment on firefox

v3_develop
Alex de Mulder 10 years ago
parent
commit
d35dbef594
4 changed files with 26119 additions and 26087 deletions
  1. +26045
    -26029
      dist/vis.js
  2. +1
    -1
      examples/timeline/29_hiding_times.html
  3. +55
    -37
      lib/timeline/DateUtil.js
  4. +18
    -20
      lib/timeline/Range.js

+ 26045
- 26029
dist/vis.js
File diff suppressed because it is too large
View File


+ 1
- 1
examples/timeline/29_hiding_times.html View File

@ -32,7 +32,7 @@
var options = {
hiddenDates: [
{start: '2014-03-21 00:00:00', end: '2014-03-28 00:00:00'},
{start: '2014-03-29 00:00:00', end: '2014-03-31 00:00:00', repeat: 'weekly'}, // daily weekly monthly yearly
{start: '2013-10-26 00:00:00', end: '2013-10-28 00:00:00', repeat: 'weekly'}, // daily weekly monthly yearly
{start: '2013-03-29 20:00:00', end: '2013-03-30 9:00:00', repeat: 'daily'} // daily weekly monthly yearly
],
start: '2014-04-17',

+ 55
- 37
lib/timeline/DateUtil.js View File

@ -53,6 +53,7 @@ exports.updateHiddenDates = function (body, hiddenDates) {
var duration = endDate - startDate;
if (duration >= 4 * pixelTime) {
var offset = 0;
var runUntil = end.clone();
switch (hiddenDates[i].repeat) {
case "daily": // case of time
if (startDate.day() != endDate.day()) {
@ -64,44 +65,62 @@ exports.updateHiddenDates = function (body, hiddenDates) {
endDate.dayOfYear(start.dayOfYear());
endDate.year(start.year());
endDate.subtract(7,'days');
endDate.add(offset,'days');
endDate.subtract(7 - offset,'days');
runUntil.add(1, 'weeks');
break;
case "weekly":
if (startDate.week() != endDate.week()) {
offset = 1;
}
startDate.week(start.week() - 1);
var dayOffset = endDate.diff(startDate,'days')
var day = startDate.day();
// set the start date to the range.start
startDate.date(start.date());
startDate.month(start.month());
startDate.year(start.year());
endDate = startDate.clone();
endDate.week(start.week() - 1);
endDate.year(start.year());
endDate.add(offset,'weeks');
// force
startDate.day(day);
endDate.day(day);
endDate.add(dayOffset,'days');
startDate.subtract(1,'weeks');
endDate.subtract(1,'weeks');
runUntil.add(1, 'weeks');
break
case "monthly":
if (startDate.month() != endDate.month()) {
offset = 1;
}
startDate.month(start.month() - 1)
startDate.month(start.month());
startDate.year(start.year());
startDate.subtract(1,'months');
endDate.month(start.month() - 1);
endDate.month(start.month());
endDate.year(start.year());
endDate.subtract(1,'months');
endDate.add(offset,'months');
runUntil.add(1, 'months');
break;
case "yearly":
if (startDate.year() != endDate.year()) {
offset = 1;
}
startDate.year(start.year() - 1);
endDate.year(start.year() - 1);
startDate.year(start.year());
startDate.subtract(1,'years');
endDate.year(start.year());
endDate.subtract(1,'years');
endDate.add(offset,'years');
runUntil.add(1, 'years');
break;
default:
console.log("Wrong repeat format, allowed are: daily, weekly, monthly, yearly. Given:", hiddenDates[i].repeat);
return;
}
while (startDate < end) {
while (startDate < runUntil) {
body.hiddenDates.push({start: startDate.valueOf(), end: endDate.valueOf()});
switch (hiddenDates[i].repeat) {
case "daily":
@ -109,8 +128,8 @@ exports.updateHiddenDates = function (body, hiddenDates) {
endDate.add(1, 'days');
break;
case "weekly":
startDate.add(7, 'days');
endDate.add(7, 'days');
startDate.add(1, 'weeks');
endDate.add(1, 'weeks');
break
case "monthly":
startDate.add(1, 'months');
@ -129,10 +148,9 @@ exports.updateHiddenDates = function (body, hiddenDates) {
}
}
}
// remove duplicates, merge where possible
exports.removeDuplicates(body);
//exports.printDates(body.hiddenDates)
// ensure the new positions are not on hidden dates
var startHidden = exports.isHidden(body.range.start, body.hiddenDates);
var endHidden = exports.isHidden(body.range.end,body.hiddenDates);
@ -144,6 +162,7 @@ exports.updateHiddenDates = function (body, hiddenDates) {
body.range._applyRange(rangeStart, rangeEnd);
}
}
}
@ -260,7 +279,7 @@ exports.toScreen = function(Core, time, width) {
time = hidden.startDate;
}
var duration = exports.getHiddenDuration(Core.body.hiddenDates, Core.range);
var duration = exports.getHiddenDurationBetween(Core.body.hiddenDates, Core.range.start, Core.range.end);
time = exports.correctTimeForHidden(Core.body.hiddenDates, Core.range, time);
var conversion = Core.range.conversion(width, duration);
@ -277,7 +296,7 @@ exports.toScreen = function(Core, time, width) {
* @returns {Date}
*/
exports.toTime = function(body, range, x, width) {
var hiddenDuration = exports.getHiddenDuration(body.hiddenDates, range);
var hiddenDuration = exports.getHiddenDurationBetween(body.hiddenDates, range.start, range.end);
var totalDuration = range.end - range.start - hiddenDuration;
var partialDuration = totalDuration * x / width;
var accumulatedHiddenDuration = exports.getAccumulatedHiddenDuration(body.hiddenDates,range, partialDuration);
@ -290,17 +309,17 @@ exports.toTime = function(body, range, x, width) {
/**
* Support function
*
* @param hiddenTimes
* @param hiddenDates
* @param range
* @returns {number}
*/
exports.getHiddenDuration = function(hiddenTimes, range) {
exports.getHiddenDurationBetween = function(hiddenDates, start, end) {
var duration = 0;
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) {
if (startDate >= start && endDate < end) {
duration += endDate - startDate;
}
}
@ -374,14 +393,14 @@ exports.getAccumulatedHiddenDuration = function(hiddenDates, range, requiredDura
/**
* used to step over to either side of a hidden block. Correction is disabled on tablets, might be set to true
* @param hiddenTimes
* @param hiddenDates
* @param time
* @param direction
* @param correctionEnabled
* @returns {*}
*/
exports.snapAwayFromHidden = function(hiddenTimes, time, direction, correctionEnabled) {
var isHidden = exports.isHidden(time, hiddenTimes);
exports.snapAwayFromHidden = function(hiddenDates, time, direction, correctionEnabled) {
var isHidden = exports.isHidden(time, hiddenDates);
if (isHidden.hidden == true) {
if (direction < 0) {
if (correctionEnabled == true) {
@ -411,19 +430,18 @@ exports.snapAwayFromHidden = function(hiddenTimes, time, direction, correctionEn
* Check if a time is hidden
*
* @param time
* @param hiddenTimes
* @param hiddenDates
* @returns {{hidden: boolean, startDate: Window.start, endDate: *}}
*/
exports.isHidden = function(time, hiddenTimes) {
var isHidden = false;
for (var i = 0; i < hiddenTimes.length; i++) {
var startDate = hiddenTimes[i].start;
var endDate = hiddenTimes[i].end;
exports.isHidden = function(time, hiddenDates) {
for (var i = 0; i < hiddenDates.length; i++) {
var startDate = hiddenDates[i].start;
var endDate = hiddenDates[i].end;
if (time >= startDate && time < endDate) { // if the start is entering a hidden zone
isHidden = true;
return {hidden: true, startDate: startDate, endDate: endDate};
break;
}
}
return {hidden: isHidden, startDate: startDate, endDate: endDate};
return {hidden: false, startDate: startDate, endDate: endDate};
}

+ 18
- 20
lib/timeline/Range.js View File

@ -286,7 +286,6 @@ Range.prototype._applyRange = function(start, end) {
this.start = newStart;
this.end = newEnd;
return changed;
};
@ -369,20 +368,19 @@ Range.prototype._onDragStart = function(event) {
Range.prototype._onDrag = function (event) {
// only allow dragging when configured as movable
if (!this.options.moveable) return;
var direction = this.options.direction;
validateDirection(direction);
// refuse to drag when we where pinching to prevent the timeline make a jump
// when releasing the fingers in opposite order from the touch screen
if (!this.props.touch.allowDragging) return;
var direction = this.options.direction;
validateDirection(direction);
var delta = (direction == 'horizontal') ? event.gesture.deltaX : event.gesture.deltaY;
delta -= this.deltaDifference;
var interval = (this.props.touch.end - this.props.touch.start);
// normalize dragging speed if cutout is in between.
var duration = DateUtil.getHiddenDuration(this.body.hiddenDates, this);
var duration = DateUtil.getHiddenDurationBetween(this.body.hiddenDates, this.start, this.end);
interval -= duration;
var width = (direction == 'horizontal') ? this.body.domProps.center.width : this.body.domProps.center.height;
@ -526,18 +524,20 @@ Range.prototype._onPinch = function (event) {
var scale = 1 / (event.gesture.scale + this.scaleOffset);
var center = this._pointerToDate(this.props.touch.center);
var hiddenDuration = DateUtil.getHiddenDuration(this.body.hiddenDates, this);
var hiddenDuration = DateUtil.getHiddenDurationBetween(this.body.hiddenDates, this.start, this.end);
var hiddenDurationBefore = DateUtil.getHiddenDurationBefore(this.body.hiddenDates, this, center);
var hiddenDurationAfter = hiddenDuration - hiddenDurationBefore;
// calculate new start and end
var newStart = center + (this.props.touch.start - center) * scale;
var newEnd = (center+hiddenDuration) + (this.props.touch.end - (center+hiddenDuration)) * scale;
var newStart = (center-hiddenDurationBefore) + (this.start - (center-hiddenDurationBefore)) * scale;
var newEnd = (center+hiddenDurationAfter) + (this.end - (center+hiddenDurationAfter)) * scale;
// snapping times away from hidden zones
this.startToFront = 1 - scale > 0 ? false : true; // used to do the right autocorrection with periodic hidden times
this.endToFront = scale - 1 > 0 ? false : true; // used to do the right autocorrection with periodic hidden times
var safeStart = DateUtil.snapAwayFromHidden(this.body.hiddenDates, newStart, 1 - scale, false);
var safeEnd = DateUtil.snapAwayFromHidden(this.body.hiddenDates, newEnd, scale - 1, false);
var safeStart = DateUtil.snapAwayFromHidden(this.body.hiddenDates, newStart, 1 - scale, true);
var safeEnd = DateUtil.snapAwayFromHidden(this.body.hiddenDates, newEnd, scale - 1, true);
if (safeStart != newStart || safeEnd != newEnd) {
this.props.touch.start = safeStart;
this.props.touch.end = safeEnd;
@ -566,12 +566,7 @@ Range.prototype._pointerToDate = function (pointer) {
validateDirection(direction);
if (direction == 'horizontal') {
var width = this.body.domProps.center.width;
var duration = DateUtil.getHiddenDuration(this.body.hiddenDates, this);
//return DateUtil.toTime(this.body, this, pointer.x, width);
conversion = this.conversion(width, duration);
//console.log(new Date(pointer.x / conversion.scale + conversion.offset + duration));
return pointer.x / conversion.scale + conversion.offset;
return this.body.util.toTime(pointer.x).valueOf();
}
else {
var height = this.body.domProps.center.height;
@ -610,11 +605,14 @@ Range.prototype.zoom = function(scale, center, delta) {
center = (this.start + this.end) / 2;
}
var hiddenDuration = DateUtil.getHiddenDuration(this.body.hiddenDates, this);
var hiddenDuration = DateUtil.getHiddenDurationBetween(this.body.hiddenDates, this.start, this.end);
var hiddenDurationBefore = DateUtil.getHiddenDurationBefore(this.body.hiddenDates, this, center);
var hiddenDurationAfter = hiddenDuration - hiddenDurationBefore;
// calculate new start and end
var newStart = center + (this.start - center) * scale;
var newEnd = (center+hiddenDuration) + (this.end - (center+hiddenDuration)) * scale;
var newStart = (center-hiddenDurationBefore) + (this.start - (center-hiddenDurationBefore)) * scale;
var newEnd = (center+hiddenDurationAfter) + (this.end - (center+hiddenDurationAfter)) * scale;
// snapping times away from hidden zones
this.startToFront = delta > 0 ? false : true; // used to do the right autocorrection with periodic hidden times
this.endToFront = -delta > 0 ? false : true; // used to do the right autocorrection with periodic hidden times

Loading…
Cancel
Save