From 7f8bedf580f3a352bebc961eb5974c85f73ec5a7 Mon Sep 17 00:00:00 2001 From: jos Date: Mon, 4 May 2015 11:35:59 +0200 Subject: [PATCH] Added convenience method `setData({groups: groups, items: items})` --- HISTORY.md | 1 + docs/timeline.html | 11 +++++++++++ lib/timeline/Timeline.js | 14 ++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index d872a134..2f9d01d9 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -14,6 +14,7 @@ http://visjs.org ### Timeline +- Added method `setData({groups: groups, items: items})`. - Fixed range items not being displayed smaller than 10 pixels (twice the padding). In order to have overflowing text, one should now apply css style `.vis.timeline .item.range { overflow: visible; }` instead of diff --git a/docs/timeline.html b/docs/timeline.html index bfe0daf0..832044ca 100644 --- a/docs/timeline.html +++ b/docs/timeline.html @@ -1003,6 +1003,17 @@ var options = { + + setData({
  groups: groups,
  items: items
}) + none + Set both groups and items at once. Both properties are optional. This is a convenience method for individually calling both setItems(items) and setGroups(groups). + Both items and groups can be an Array with Objects, + a DataSet, or a DataView. For each of the groups, the items of the + timeline are filtered on the property group, which + must correspond with the id of the group. + + + setGroups(groups) none diff --git a/lib/timeline/Timeline.js b/lib/timeline/Timeline.js index a5dec563..7cc6445a 100644 --- a/lib/timeline/Timeline.js +++ b/lib/timeline/Timeline.js @@ -207,6 +207,20 @@ Timeline.prototype.setGroups = function(groups) { this.itemSet.setGroups(newDataSet); }; +/** + * Set both items and groups in one go + * @param {{items: Array | vis.DataSet | google.visualization.DataTable, groups: Array | vis.DataSet | google.visualization.DataTable}} data + */ +Timeline.prototype.setData = function (data) { + if (data && data.groups) { + this.setGroups(data.groups); + } + + if (data && data.items) { + this.setItems(data.items); + } +}; + /** * Set selected items by their id. Replaces the current selection * Unknown id's are silently ignored.