diff --git a/docs/dataset.html b/docs/dataset.html index 477d26a4..0828e37e 100644 --- a/docs/dataset.html +++ b/docs/dataset.html @@ -20,10 +20,10 @@
DataSet contains the following methods.
+ +Method | +Return Type | +Description | +
---|---|---|
add(data [, senderId]) | +Number[] | +Add data to the DataSet. Adding an item will fail when there already is an item with the same id. The function returns an array with the ids of the added items. See section Data Manipulation. | +
clear([senderId]) | +Number[] | +Clear all data from the DataSet. The function returns an array with the ids of the removed items. | +
distinct(field) | +Array | +Find all distinct values of a specified field. Returns an unordered array containing all distinct values. If data items do not contain the specified field are ignored. | +
forEach(callback [, options]) | +none | ++ Execute a callback function for every item in the dataset. + The available options are described in section Data Selection. + | +
+ get([options] [, data]) + get(id [,options] [, data]) + get(ids [, options] [, data]) + |
+ Object | Array | DataTable | +
+ Get a single item, multiple items, or all items from the DataSet.
+ Usage examples can be found in section Getting Data, and the available options are described in section Data Selection. If parameter data isprovided, items will be appended to this array or table, which is required in case of Google DataTable.
+ |
+
+ getIds([options]) + | +Number[] | +
+ Get ids of all items or of a filtered set of items.
+ Available options are described in section Data Selection, except that options fields and convert are not applicable in case of getIds .
+ |
+
map(callback [, options]) | +Array | ++ Map every item in the DataSet. + The available options are described in section Data Selection. + | +
max(field) | +Object | null | +
+ Find the item with maximum value of specified field. Returns null if no item is found.
+ |
+
min(field) | +Object | null | +
+ Find the item with minimum value of specified field. Returns null if no item is found.
+ |
+
off(event, callback) | +none | ++ Unsubscribe from an event, remove an event listener. See section Subscriptions. + | +
on(event, callback) | +none | ++ Subscribe to an event, add an event listener. See section Subscriptions. + | +
+ remove(id [, senderId]) + remove(ids [, senderId]) + |
+ Number[] | ++ Remove on ore multiple items by id or by the items themselves. Returns an array with the ids of the removed items. See section Data Manipulation. + | +
+ update(id [, senderId]) + update(ids [, senderId]) + |
+ Number[] | ++ Update on ore existing items. When an item doesn't exist, it will be created. Returns an array with the ids of the removed items. See section Data Manipulation. + | +
+ One can subscribe on changes in a DataSet.
+ A subscription can be created using the method on
,
+ and removed with off
.
+
+// create a DataSet +var data = new vis.DataSet(); + +// subscribe to any change in the DataSet +data.on('*', function (event, properties, senderId) { + console.log('event:', event, 'properties:', properties, 'senderId:', senderId); +}); + +// add an item +data.add({id: 1, text: 'item 1'}); // triggers an 'add' event +data.update({id: 1, text: 'item 1 (updated)'}); // triggers an 'update' event +data.remove(1); // triggers an 'remove' event ++ + +
+ Subscribe to an event. +
+ +Syntax: +DataSet.on(event, callback)+ +Where: +
event
is a String containing any of the events listed
+ in section Events.
+ callback
is a callback function which will be called
+ each time the event occurs. The callback function is described in
+ section Callback.
+ + Unsubscribe from an event. +
+ +Syntax: +DataSet.off(event, callback)+ +Where
event
and callback
correspond with the
+parameters used to subscribe to the event.
+
++ The following events are available for subscription: +
+ +Event | +Description | +
---|---|
add | +
+ The add event is triggered when an item
+ or a set of items is added, or when an item is updated while
+ not yet existing.
+ |
+
update | +
+ The update event is triggered when an existing item
+ or a set of existing items is updated.
+ |
+
remove | +
+ The remove event is triggered when an item
+ or a set of items is removed.
+ |
+
* | +
+ The * event is triggered when any of the events
+ add , update , and remove
+ occurs.
+ |
+
+ The callback functions of subscribers are called with the following + parameters: +
+ ++function (event, properties, senderId) { + // handle the event +}); ++ +
+ where the parameters are defined as +
+ +Parameter | +Type | +Description | +
---|---|---|
event | +String | +
+ Any of the available events: add ,
+ update , or remove .
+ |
+
properties | +Object | null | +
+ Optional properties providing more information on the event.
+ In case of the events add ,
+ update , and remove ,
+ properties is always an object containing a property
+ items, which contains an array with the ids of the affected
+ items.
+ |
+
senderId | +String | Number | +
+ An senderId, optionally provided by the application code
+ which triggered the event. If senderId is not provided, the
+ argument will be null .
+ |
+
@@ -322,70 +610,18 @@ Syntax:
-
- Data can be retrieved from the DataSet using the method get
.
- This method can return a single item or a list with items.
-
A single item can be retrieved by its id:
- --var item1 = dataset.get(1); -- -
A selection of items can be retrieved by providing an array with ids:
- --var items = dataset.get([1, 3, 4]); // retrieve items 1, 3, and 4 -- -
All items can be retrieved by simply calling get
without
- specifying an id:
-var items = dataset.get(); // retrieve all items -- -
- Items can be filtered on specific properties by providing a filter - function. A filter function is executed for each of the items in the - DataSet, and is called with the item as parameter. The function must - return a boolean. All items for which the filter function returns - true will be emitted. -
- --// retrieve all items having a property group with value 2 -var group2 = dataset.get({ - filter: function (item) { - return (item.group == 2); - } -}); - -// retrieve all items having a property balance with a value above zero -var positiveBalance = dataset.get({ - filter: function (item) { - return (item.balance > 0); - } -}); - -- - -
- The DataSet contains functionality to format data retrieved via the
- method get
. The method get
has the following
- syntax:
+ The DataSet contains functionality to format, filter, and sort data retrieved via the
+ methods get
, getIds
, forEach
, and map
. These methods have the following syntax:
-var item = DataSet.get(id, options); // retrieve a single item -var items = DataSet.get(ids, options); // retrieve a selection of items -var items = DataSet.get(options); // retrieve all items or a filtered set +DataSet.get([id] [, options] [, data]); +DataSet.getIds([options]); +DataSet.forEach(callback [, options]); +DataSet.map(callback [, options]);
@@ -471,6 +707,59 @@ var items = data.get({ }); +
+ Data can be retrieved from the DataSet using the method get
.
+ This method can return a single item or a list with items.
+
A single item can be retrieved by its id:
+ ++var item1 = dataset.get(1); ++ +
A selection of items can be retrieved by providing an array with ids:
+ ++var items = dataset.get([1, 3, 4]); // retrieve items 1, 3, and 4 ++ +
All items can be retrieved by simply calling get
without
+ specifying an id:
+var items = dataset.get(); // retrieve all items ++ + +
+ Items can be filtered on specific properties by providing a filter + function. A filter function is executed for each of the items in the + DataSet, and is called with the item as parameter. The function must + return a boolean. All items for which the filter function returns + true will be emitted. +
+ ++// retrieve all items having a property group with value 2 +var group2 = dataset.get({ + filter: function (item) { + return (item.group == 2); + } +}); + +// retrieve all items having a property balance with a value above zero +var positiveBalance = dataset.get({ + filter: function (item) { + return (item.balance > 0); + } +}); + +
- One can subscribe on changes in a DataSet.
- A subscription can be created using the method on
,
- and removed with off
.
-
-// create a DataSet -var data = new vis.DataSet(); - -// subscribe to any change in the DataSet -data.on('*', function (event, properties, senderId) { - console.log('event:', event, 'properties:', properties, 'senderId:', senderId); -}); - -// add an item -data.add({id: 1, text: 'item 1'}); // triggers an 'add' event -data.update({id: 1, text: 'item 1 (updated)'}); // triggers an 'update' event -data.remove(1); // triggers an 'remove' event -- - -
- Subscribe to an event. -
- -Syntax: -DataSet.on(event, callback)- -Where: -
event
is a String containing any of the events listed
- in section Events.
- callback
is a callback function which will be called
- each time the event occurs. The callback function is described in
- section Callback.
- - Unsubscribe from an event. -
- -Syntax: -DataSet.off(event, callback)- -Where
event
and callback
correspond with the
-parameters used to subscribe to the event.
-
-- The following events are available for subscription: -
- -Event | -Description | -
---|---|
add | -
- The add event is triggered when an item
- or a set of items is added, or when an item is updated while
- not yet existing.
- |
-
update | -
- The update event is triggered when an existing item
- or a set of existing items is updated.
- |
-
remove | -
- The remove event is triggered when an item
- or a set of items is removed.
- |
-
* | -
- The * event is triggered when any of the events
- add , update , and remove
- occurs.
- |
-
- The callback functions of subscribers are called with the following - parameters: -
- --function (event, properties, senderId) { - // handle the event -}); -- -
- where the parameters are defined as -
- -Parameter | -Type | -Description | -
---|---|---|
event | -String | -
- Any of the available events: add ,
- update , or remove .
- |
-
properties | -Object | null | -
- Optional properties providing more information on the event.
- In case of the events add ,
- update , and remove ,
- properties is always an object containing a property
- items, which contains an array with the ids of the affected
- items.
- |
-
senderId | -String | Number | -
- An senderId, optionally provided by the application code
- which triggered the event. If senderId is not provided, the
- argument will be null .
- |
-
All code and data is processed and rendered in the browser.
diff --git a/src/DataSet.js b/src/DataSet.js
index a7b95d04..ca93ade1 100644
--- a/src/DataSet.js
+++ b/src/DataSet.js
@@ -521,7 +521,6 @@ DataSet.prototype.getIds = function (options) {
/**
* Execute a callback function for every item in the dataset.
- * The order of the items is not determined.
* @param {function} callback
* @param {Object} [options] Available options:
* {Object.