diff --git a/src/timeline/component/ItemSet.js b/src/timeline/component/ItemSet.js index f2219b83..6f1fc3aa 100644 --- a/src/timeline/component/ItemSet.js +++ b/src/timeline/component/ItemSet.js @@ -301,11 +301,11 @@ ItemSet.prototype.repaint = function repaint() { // find start of visible items var start = Math.min(this.visibleItemsStart, Math.max(this.orderedItems.length - 1, 0)); var item = this.orderedItems[start]; - while (item && item.isVisible() && start > 0) { + while (item && item.isVisible(this.range) && start > 0) { start--; item = this.orderedItems[start]; } - while (item && !item.isVisible()) { + while (item && !item.isVisible(this.range)) { if (item.displayed) item.hide(); start++; @@ -316,12 +316,12 @@ ItemSet.prototype.repaint = function repaint() { // find end of visible items var end = Math.max(Math.min(this.visibleItemsEnd, this.orderedItems.length), this.visibleItemsStart); item = this.orderedItems[end]; - while (item && item.isVisible()) { + while (item && item.isVisible(this.range)) { end++; item = this.orderedItems[end]; } item = this.orderedItems[end - 1]; - while (item && !item.isVisible() && end > 0) { + while (item && !item.isVisible(this.range) && end > 0) { if (item.displayed) item.hide(); end--; diff --git a/src/timeline/component/item/ItemBox.js b/src/timeline/component/item/ItemBox.js index 7e68572c..9c19a19c 100644 --- a/src/timeline/component/item/ItemBox.js +++ b/src/timeline/component/item/ItemBox.js @@ -33,23 +33,16 @@ function ItemBox (parent, data, options, defaultOptions) { ItemBox.prototype = new Item (null, null); /** - * Check whether this item is visible in the current time window + * Check whether this item is visible inside given range + * @returns {{start: Number, end: Number}} range with a timestamp for start and end * @returns {boolean} True if visible */ -ItemBox.prototype.isVisible = function isVisible () { +ItemBox.prototype.isVisible = function isVisible (range) { // determine visibility - var data = this.data; - var range = this.parent && this.parent.range; - - if (data && range) { - // TODO: account for the width of the item. Right now we add 1/4 to the window - var interval = (range.end - range.start) / 4; - interval = 0; // TODO: remove - return (data.start > range.start - interval) && (data.start < range.end + interval); - } - else { - return false; - } + // TODO: account for the width of the item. Right now we add 1/4 to the window + var interval = (range.end - range.start) / 4; + interval = 0; // TODO: remove + return (this.data.start > range.start - interval) && (this.data.start < range.end + interval); } /** diff --git a/src/timeline/component/item/ItemPoint.js b/src/timeline/component/item/ItemPoint.js index f1726f93..6d0e5ea5 100644 --- a/src/timeline/component/item/ItemPoint.js +++ b/src/timeline/component/item/ItemPoint.js @@ -34,21 +34,14 @@ function ItemPoint (parent, data, options, defaultOptions) { ItemPoint.prototype = new Item (null, null); /** - * Check whether this item is visible in the current time window + * Check whether this item is visible inside given range + * @returns {{start: Number, end: Number}} range with a timestamp for start and end * @returns {boolean} True if visible */ -ItemPoint.prototype.isVisible = function isVisible () { +ItemPoint.prototype.isVisible = function isVisible (range) { // determine visibility - var data = this.data; - var range = this.parent && this.parent.range; - - if (data && range) { - var interval = (range.end - range.start); - return (data.start > range.start - interval) && (data.start < range.end); - } - else { - return false; - } + var interval = (range.end - range.start); + return (this.data.start > range.start - interval) && (this.data.start < range.end); } /** diff --git a/src/timeline/component/item/ItemRange.js b/src/timeline/component/item/ItemRange.js index 96e68fa9..bfd41ad0 100644 --- a/src/timeline/component/item/ItemRange.js +++ b/src/timeline/component/item/ItemRange.js @@ -33,20 +33,13 @@ ItemRange.prototype = new Item (null, null); ItemRange.prototype.baseClassName = 'item range'; /** - * Check whether this item is visible in the current time window + * Check whether this item is visible inside given range + * @returns {{start: Number, end: Number}} range with a timestamp for start and end * @returns {boolean} True if visible */ -ItemRange.prototype.isVisible = function isVisible () { +ItemRange.prototype.isVisible = function isVisible (range) { // determine visibility - var data = this.data; - var range = this.parent && this.parent.range; - - if (data && range) { - return (data.start < range.end) && (data.end > range.start); - } - else { - return false; - } + return (this.data.start < range.end) && (this.data.end > range.start); } /**