Skip to content

Commit

Permalink
fix(item-update): visibility of range spanning items not always correct
Browse files Browse the repository at this point in the history
Remove binary search for items having an end time because items starting before range and ending after it were left out.

Fixes visjs#1657
  • Loading branch information
ChristianKrebel committed Dec 16, 2024
1 parent 6586430 commit 1d48d75
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions lib/timeline/component/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ class Group {
*/
_resetSubgroups() {
for (const subgroup in this.subgroups) {
if (this.subgroups.hasOwnProperty(subgroup)) {
if (Object.prototype.hasOwnProperty.call(this.subgroups, subgroup)) {
this.subgroups[subgroup].visible = false;
this.subgroups[subgroup].height = 0;
}
Expand Down Expand Up @@ -924,14 +924,6 @@ class Group {
else {return 1;}
};

// this function is used to do the binary search for items having start and end dates (range).
const endSearchFunction = data => {
const {start, end} = data;
if (end < lowerBound) {return -1;}
else if (start <= upperBound) {return 0;}
else {return 1;}
}

// first check if the items that were in view previously are still in view.
// IMPORTANT: this handles the case for the items with startdate before the window and enddate after the window!
// also cleans up invisible items.
Expand All @@ -947,20 +939,9 @@ class Group {
// trace the visible items from the inital start pos both ways until an invisible item is found, we only look at the start values.
this._traceVisible(initialPosByStart, orderedItems.byStart, visibleItems, visibleItemsLookup, item => item.data.start < lowerBound || item.data.start > upperBound);

// if the window has changed programmatically without overlapping the old window, the ranged items with start < lowerBound and end > upperbound are not shown.
// We therefore have to brute force check all items in the byEnd list
if (this.checkRangedItems == true) {
this.checkRangedItems = false;
for (let i = 0; i < orderedItems.byEnd.length; i++) {
this._checkIfVisibleWithReference(orderedItems.byEnd[i], visibleItems, visibleItemsLookup, range);
}
}
else {
// we do a binary search for the items that have defined end times.
const initialPosByEnd = util.binarySearchCustom(orderedItems.byEnd, endSearchFunction, 'data');

// trace the visible items from the inital start pos both ways until an invisible item is found, we only look at the end values.
this._traceVisible(initialPosByEnd, orderedItems.byEnd, visibleItems, visibleItemsLookup, item => item.data.end < lowerBound || item.data.start > upperBound);
// check every item with end date if is visible. Binary search would be the most efficient, but it would leave out items that start before the range and end after the range.
for (let i = 0; i < orderedItems.byEnd.length; i++) {
this._checkIfVisibleWithReference(orderedItems.byEnd[i], visibleItems, visibleItemsLookup, range);
}

const redrawQueue = {};
Expand Down

0 comments on commit 1d48d75

Please sign in to comment.