From f1cb7320aac5756ef66a71468778b3eaa8668d5b Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sat, 3 Sep 2016 01:08:28 +0300 Subject: [PATCH 01/12] Hide vertically hidden ranged items in groups that are not visible --- lib/timeline/component/Group.js | 27 ++++++++++++++++++++++++ lib/timeline/component/item/RangeItem.js | 10 +++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/timeline/component/Group.js b/lib/timeline/component/Group.js index c11d7cce..5dcc2e49 100644 --- a/lib/timeline/component/Group.js +++ b/lib/timeline/component/Group.js @@ -14,6 +14,7 @@ function Group (groupId, data, itemSet) { this.subgroupIndex = 0; this.subgroupOrderer = data && data.subgroupOrder; this.itemSet = itemSet; + this.isVisible = null; this.dom = {}; this.props = { @@ -180,6 +181,8 @@ Group.prototype.redraw = function(range, margin, restack) { // recalculate the height of the subgroups this._calculateSubGroupHeights(); + this.isVisible = this._isGroupVisible(range); + // reposition visible items vertically if (typeof this.itemSet.options.order === 'function') { // a custom order function @@ -219,6 +222,10 @@ Group.prototype.redraw = function(range, margin, restack) { } } + if (!this.isVisible && this.height) { + return resized = false; + } + // recalculate the height of the group var height = this._calculateHeight(margin); @@ -265,6 +272,17 @@ Group.prototype._calculateSubGroupHeights = function () { } }; +/** + * check if group is visible + * @private + */ +Group.prototype._isGroupVisible = function (range) { + var isVisible = + (this.top < range.body.domProps.centerContainer.height - range.body.domProps.scrollTop) && + (this.top + this.height > - range.body.domProps.scrollTop); + return isVisible; +} + /** * recalculate the height of the group * @param {{item: {horizontal: number, vertical: number}, axis: number}} margin @@ -475,6 +493,15 @@ Group.prototype.order = function() { Group.prototype._updateVisibleItems = function(orderedItems, oldVisibleItems, range) { var visibleItems = []; var visibleItemsLookup = {}; // we keep this to quickly look up if an item already exists in the list without using indexOf on visibleItems + + if (!this.isVisible) { + for (i = 0; i < oldVisibleItems.length; i++) { + item = oldVisibleItems[i]; + if (item.displayed) item.hide(); + } + return visibleItems; + } + var interval = (range.end - range.start) / 4; var lowerBound = range.start - interval; var upperBound = range.end + interval; diff --git a/lib/timeline/component/item/RangeItem.js b/lib/timeline/component/item/RangeItem.js index 694d21b6..bfd6f7ee 100644 --- a/lib/timeline/component/item/RangeItem.js +++ b/lib/timeline/component/item/RangeItem.js @@ -43,8 +43,14 @@ RangeItem.prototype.baseClassName = 'vis-item vis-range'; */ RangeItem.prototype.isVisible = function(range) { // determine visibility - return (this.data.start < range.end) && (this.data.end > range.start); -}; +var isVisible = +// determine horizontal visibillity + (this.data.start < range.end) && + (this.data.end > range.start) && +// determine verticaltal visibillity + (this.parent.top < range.body.domProps.centerContainer.height - range.body.domProps.scrollTop) && + (this.parent.top + this.parent.height > - range.body.domProps.scrollTop) +return isVisible;}; /** * Repaint the item From 89a0bfd36a833579f4e0f05bf1e153f584753cd4 Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sun, 16 Oct 2016 11:54:01 +0300 Subject: [PATCH 02/12] Add element to templates options --- lib/timeline/component/Group.js | 2 +- lib/timeline/component/item/Item.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/timeline/component/Group.js b/lib/timeline/component/Group.js index 512fac58..4927e034 100644 --- a/lib/timeline/component/Group.js +++ b/lib/timeline/component/Group.js @@ -88,7 +88,7 @@ Group.prototype.setData = function(data) { // update contents var content; if (this.itemSet.options && this.itemSet.options.groupTemplate) { - content = this.itemSet.options.groupTemplate(data); + content = this.itemSet.options.groupTemplate(data, this.dom.inner); } else { content = data && data.content; diff --git a/lib/timeline/component/item/Item.js b/lib/timeline/component/item/Item.js index ea5c7cbb..743e5944 100644 --- a/lib/timeline/component/item/Item.js +++ b/lib/timeline/component/item/Item.js @@ -190,7 +190,7 @@ Item.prototype._updateContents = function (element) { var content; if (this.options.template) { var itemData = this.parent.itemSet.itemsData.get(this.id); // get a clone of the data from the dataset - content = this.options.template(itemData); + content = this.options.template(itemData, element); } else { content = this.data.content; From b32f9428ff7725bc14e4e11ef5f8dc16336516a1 Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sun, 16 Oct 2016 12:20:49 +0300 Subject: [PATCH 03/12] Fix comment typo --- lib/timeline/component/item/RangeItem.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/timeline/component/item/RangeItem.js b/lib/timeline/component/item/RangeItem.js index 98614607..01c94ed2 100644 --- a/lib/timeline/component/item/RangeItem.js +++ b/lib/timeline/component/item/RangeItem.js @@ -45,11 +45,11 @@ RangeItem.prototype.isVisible = function(range) { // determine visibility var isVisible = // determine horizontal visibillity - (this.data.start < range.end) && - (this.data.end > range.start) && -// determine verticaltal visibillity - (this.parent.top < range.body.domProps.centerContainer.height - range.body.domProps.scrollTop) && - (this.parent.top + this.parent.height > - range.body.domProps.scrollTop) +(this.data.start < range.end) && +(this.data.end > range.start) && +// determine vertical visibillity +(this.parent.top < range.body.domProps.centerContainer.height - range.body.domProps.scrollTop) && +(this.parent.top + this.parent.height > - range.body.domProps.scrollTop) return isVisible;}; /** From 092186857b8a35388f50911152d1cd373e9ae578 Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sun, 16 Oct 2016 12:33:42 +0300 Subject: [PATCH 04/12] Add documentation for react mounting --- docs/timeline/index.html | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/timeline/index.html b/docs/timeline/index.html index f11d1c89..4ca5975e 100644 --- a/docs/timeline/index.html +++ b/docs/timeline/index.html @@ -640,7 +640,7 @@ function (option, path) { groupTemplate function none - A template function used to generate the contents of the groups. The function is called by the Timeline with a groups data as argument, and must return HTML code as result. When the option groupTemplate is specified, the groups do not need to have a field content. See section Templates for a detailed explanation. + A template function used to generate the contents of the groups. The function is called by the Timeline with a groups data as the first argument and the group element as the second, and must return HTML code as result. When the option groupTemplate is specified, the groups do not need to have a field content. See section Templates for a detailed explanation. @@ -970,7 +970,7 @@ function (option, path) { template function none - A template function used to generate the contents of the items. The function is called by the Timeline with an items data as argument, and must return HTML code as result. When the option template is specified, the items do not need to have a field content. See section Templates for a detailed explanation. + A template function used to generate the contents of the items. The function is called by the Timeline with an items data as the first argument and the item element as the second, and must return HTML code as result. When the option template is specified, the items do not need to have a field content. See section Templates for a detailed explanation. @@ -1629,6 +1629,17 @@ var template = Handlebars.compile(source); }; +

React templates

+ +You can use a React component for the templates by rendering them to the templates' element directly: + +
+  template: function (item, element) {
+    return ReactDOM.render(<b>{item.content}</b>, element);
+  },
+
+ +

Multiple templates

In order to support multiple templates, the template handler can be extended to switch between different templates, depending on a specific item property: From 06c264e5b627c320f2d7474b251b1ccaa285e04c Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sat, 22 Oct 2016 13:07:29 +0300 Subject: [PATCH 05/12] add react example --- examples/timeline/other/usingReact.html | 131 ++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 examples/timeline/other/usingReact.html diff --git a/examples/timeline/other/usingReact.html b/examples/timeline/other/usingReact.html new file mode 100644 index 00000000..2e59d418 --- /dev/null +++ b/examples/timeline/other/usingReact.html @@ -0,0 +1,131 @@ + + + + + React Hello World + + + +
+ + + + + + + + + + + + + \ No newline at end of file From 17c48c7967d2a5c3995133ae61d19173458dfeab Mon Sep 17 00:00:00 2001 From: yotamberk Date: Sat, 22 Oct 2016 13:13:04 +0300 Subject: [PATCH 06/12] Fix typo --- examples/timeline/other/usingReact.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/timeline/other/usingReact.html b/examples/timeline/other/usingReact.html index 2e59d418..dea32d95 100644 --- a/examples/timeline/other/usingReact.html +++ b/examples/timeline/other/usingReact.html @@ -113,7 +113,7 @@ render: function() { return

Vis timline with React

-

Using react components for items ang group templates

+

Using react components for items and group templates

@@ -128,4 +128,4 @@ ReactDOM.render(, document.getElementById('root')); - \ No newline at end of file + From 42c054ff540b15db8f91d01c7824b3f73b7c4208 Mon Sep 17 00:00:00 2001 From: yotamberk Date: Sat, 22 Oct 2016 13:37:57 +0300 Subject: [PATCH 07/12] fix title --- examples/timeline/other/usingReact.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/timeline/other/usingReact.html b/examples/timeline/other/usingReact.html index dea32d95..4f7c2470 100644 --- a/examples/timeline/other/usingReact.html +++ b/examples/timeline/other/usingReact.html @@ -2,7 +2,7 @@ - React Hello World + React Components in templates From 342091d180ff6badfe2a1631adf809c3d326cb22 Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sat, 22 Oct 2016 17:51:52 +0300 Subject: [PATCH 08/12] Fix review comments --- examples/timeline/other/usingReact.html | 50 +++++++++++-------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/examples/timeline/other/usingReact.html b/examples/timeline/other/usingReact.html index 2e59d418..1d276499 100644 --- a/examples/timeline/other/usingReact.html +++ b/examples/timeline/other/usingReact.html @@ -2,7 +2,7 @@ - React Hello World + React Components in templates @@ -17,8 +17,8 @@ to compile JSX into JavaScript. Also, check out: http://facebook.github.io/react/docs/tooling-integration.html --> - - + + @@ -30,7 +30,7 @@ -->