From f51c3640fe23669b4d0159d8960c9bf70f38e206 Mon Sep 17 00:00:00 2001 From: jos Date: Wed, 20 May 2015 12:32:42 +0200 Subject: [PATCH] DataSet and DataView now have new styling --- docs/css/style.css | 1 + docs/dataset/dataset.html | 1002 ++++++++++++++++++++++++++++++++++ docs/dataset/dataview.html | 392 +++++++++++++ docs/{ => old}/dataset.html | 0 docs/{ => old}/dataview.html | 0 5 files changed, 1395 insertions(+) create mode 100644 docs/dataset/dataset.html create mode 100644 docs/dataset/dataview.html rename docs/{ => old}/dataset.html (100%) rename docs/{ => old}/dataview.html (100%) diff --git a/docs/css/style.css b/docs/css/style.css index 45a7fd10..a91d3468 100644 --- a/docs/css/style.css +++ b/docs/css/style.css @@ -93,6 +93,7 @@ The following tables are used: - A table 'methods' with methods. Columns: Method, Return Type, Description - A table 'events' with events. Columns: Name, Properties, Description - A table 'styles' with styles. Columns: Description, Values +- A table 'datatypes' with data types. Columns: Name, Description, Examples */ table.properties td:nth-child(2), table.properties td:nth-child(3), diff --git a/docs/dataset/dataset.html b/docs/dataset/dataset.html new file mode 100644 index 00000000..c2d0c674 --- /dev/null +++ b/docs/dataset/dataset.html @@ -0,0 +1,1002 @@ + + + + + + + + + DataSet - vis.js - A dynamic, browser based visualization library. + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +

DataSet

+ +

Contents

+ + + +

Overview

+ +

+ Vis.js comes with a flexible DataSet, which can be used to hold and + manipulate unstructured data and listen for changes in the data. + The DataSet is key/value based. Data items can be added, updated and + removed from the DatSet, and one can subscribe to changes in the DataSet. + The data in the DataSet can be filtered and ordered, and fields (like + dates) can be converted to a specific type. Data can be normalized when + appending it to the DataSet as well. +

+ + +

Example

+ +

+ The following example shows how to use a DataSet. +

+ +
+// create a DataSet
+var options = {};
+var data = new vis.DataSet(options);
+
+// add items
+// note that the data items can contain different properties and data formats
+data.add([
+  {id: 1, text: 'item 1', date: new Date(2013, 6, 20), group: 1, first: true},
+  {id: 2, text: 'item 2', date: '2013-06-23', group: 2},
+  {id: 3, text: 'item 3', date: '2013-06-25', group: 2},
+  {id: 4, text: 'item 4'}
+]);
+
+// subscribe to any change in the DataSet
+data.on('*', function (event, properties, senderId) {
+  console.log('event', event, properties);
+});
+
+// update an existing item
+data.update({id: 2, group: 1});
+
+// remove an item
+data.remove(4);
+
+// get all ids
+var ids = data.getIds();
+console.log('ids', ids);
+
+// get a specific item
+var item1 = data.get(1);
+console.log('item1', item1);
+
+// retrieve a filtered subset of the data
+var items = data.get({
+  filter: function (item) {
+    return item.group == 1;
+  }
+});
+console.log('filtered items', items);
+
+// retrieve formatted items
+var items = data.get({
+  fields: ['id', 'date'],
+  type: {
+    date: 'ISODate'
+  }
+});
+console.log('formatted items', items);
+
+ + + +

Construction

+ +

+ A DataSet can be constructed as: +

+ +
+var data = new vis.DataSet([data] [, options])
+
+ +

+ After construction, data can be added to the DataSet using the methods + add and update, as described in section + Data Manipulation. +

+ +

+ The parameter data is optional and is an Array with items. +

+ +

+ The parameter options is optional and is an object which can + contain the following properties: +

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefault valueDescription
fieldIdString"id" + The name of the field containing the id of the items. + + When data is fetched from a server which uses some specific + field to identify items, this field name can be specified + in the DataSet using the option fieldId. + For example CouchDB uses the field + "_id" to identify documents. +
typeObject.<String, String>none + An object containing field names as key, and data types as + value. By default, the type of the properties of items are left + unchanged. Item properties can be normalized by specifying a + field type. This is useful for example to automatically convert + stringified dates coming from a server into JavaScript Date + objects. The available data types are listed in section + Data Types. +
queueObject | booleannone + Queue data changes ('add', 'update', 'remove') and flush them at once. + The queue can be flushed manually by calling + DataSet.flush(), or can be flushed after a configured delay + or maximum number of entries. +
+
+ When queue is true, a queue is created + with default options. Options can be specified by providing an object: +
    +
  • delay: number
    + The queue will be flushed automatically after an inactivity of this + delay in milliseconds. Default value is null. +
  • max: number
    + When the queue exceeds the given maximum number + of entries, the queue is flushed automatically. + Default value is Infinity. +
  • +
+
+ + +

Methods

+ +

DataSet contains the following methods.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
MethodReturn TypeDescription
add(data [, senderId])Number[]Add one or multiple items to the DataSet. data can be a single item or an array with items. 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)ArrayFind 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.
flush()noneFlush queued changes. Only available when the DataSet is configured with the option queue, see section Construction.
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 + 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. +
+ getDataSet() + DataSet + Get the DataSet itself. In case of a DataView, this function does not + return the DataSet to which the DataView is connected. +
+ 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 type 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 one or multiple items by id or by the items themselves. Returns an array with the ids of the removed items. See section Data Manipulation. +
+ setOptions(options) + none + Set options for the DataSet. Available options: + +
    +
  • + queue
    + Queue data changes ('add', 'update', 'remove') and flush them at once. + The queue can be flushed manually by calling + DataSet.flush(), or can be flushed after a configured delay + or maximum number of entries. +
    +
    + When queue is true, a queue is created with default options. + When queue is false, an existing queue will be flushed and removed. + Options can be specified by providing an object: +
      +
    • delay: number
      + The queue will be flushed automatically after an inactivity of this + delay in milliseconds. Default value is null. +
    • max: number
      + When the queue exceeds the given maximum number + of entries, the queue is flushed automatically. + Default value is Infinity. +
    • +
    +
  • +
+
+ update(data [, senderId]) + Number[] + Update on ore multiple existing items. data can be a single item or an array with 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. +
+ + +

Properties

+ +

DataSet contains the following properties.

+ + + + + + + + + + + + + +
PropertyTypeDescription
lengthNumberThe number of items in the DataSet.
+ + +

Subscriptions

+ +

+ 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
+
+ + +

On

+ +

+ Subscribe to an event. +

+ + Syntax: +
DataSet.on(event, callback)
+ + Where: + + +

Off

+ +

+ Unsubscribe from an event. +

+ + Syntax: +
DataSet.off(event, callback)
+ + Where event and callback correspond with the + parameters used to subscribe to the event. + +

Events

+ +

+ The following events are available for subscription: +

+ + + + + + + + + + + + + + + + + + + + + + +
EventDescription
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. +
+ +

Callback

+ +

+ The callback functions of subscribers are called with the following + parameters: +

+ +
+function (event, properties, senderId) {
+  // handle the event
+});
+
+ +

+ where the parameters are defined as +

+ + + + + + + + + + + + + + + + + + + + + + +
ParameterTypeDescription
eventString + Any of the available events: add, + update, or remove. +
propertiesObject | 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. The update event has an extra field data + containing the original data of the updated items, i.e. the gives the + changed fields of the changed items. +
senderIdString | Number + An senderId, optionally provided by the application code + which triggered the event. If senderId is not provided, the + argument will be null. +
+ + +

Data Manipulation

+ +

+ The data in a DataSet can be manipulated using the methods + add, + update, + and remove. + The DataSet can be emptied using the method + clear. +

+ +
+// create a DataSet
+var data = new vis.DataSet();
+
+// add items
+data.add([
+  {id: 1, text: 'item 1'},
+  {id: 2, text: 'item 2'},
+  {id: 3, text: 'item 3'}
+]);
+
+// update an item
+data.update({id: 2, text: 'item 2 (updated)'});
+
+// remove an item
+data.remove(3);
+
+ +

Add

+ +

+ Add a data item or an array with items. +

+ + Syntax: +
var addedIds = DataSet.add(data [, senderId])
+ + The argument data can contain: + + +

+ After the items are added to the DataSet, the DataSet will + trigger an event add. When a senderId + is provided, this id will be passed with the triggered + event to all subscribers. +

+ +

+ The method will throw an Error when an item with the same id + as any of the added items already exists. +

+ +

Update

+ +

+ Update a data item or an array with items. +

+ + Syntax: +
var updatedIds = DataSet.update(data [, senderId])
+ + The argument data can contain: + + +

+ The provided properties will be merged in the existing item. + When an item does not exist, it will be created. +

+ +

+ After the items are updated, the DataSet will + trigger an event add for the added items, and + an event update. When a senderId + is provided, this id will be passed with the triggered + event to all subscribers. +

+ +

Remove

+ +

+ Remove a data item or an array with items. +

+ + Syntax: +
var removedIds = DataSet.remove(id [, senderId])
+ +

+ The argument id can be: +

+ + +

+ The method ignores removal of non-existing items, and returns an array + containing the ids of the items which are actually removed from the + DataSet. +

+ +

+ After the items are removed, the DataSet will + trigger an event remove for the removed items. + When a senderId is provided, this id will be passed with + the triggered event to all subscribers. +

+ + +

Clear

+ +

+ Clear the complete DataSet. +

+ + Syntax: +
var removedIds = DataSet.clear([senderId])
+ +

+ After the items are removed, the DataSet will + trigger an event remove for all removed items. + When a senderId is provided, this id will be passed with + the triggered event to all subscribers. +

+ + +

Data Selection

+ +

+ 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: +

+ +
+DataSet.get([id] [, options]);
+DataSet.getIds([options]);
+DataSet.forEach(callback [, options]);
+DataSet.map(callback [, options]);
+
+ +

+ Where options is an Object which can have the following + properties: +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeRequiredDescription
fieldsString[ ] | Object.<String, String>no + An array with field names, or an object with current field name and + new field name that the field is returned as. + By default, all properties of the items are emitted. + When fields is defined, only the properties + whose name is specified in fields will be included + in the returned items. +
typeObject.<String, String>no + An object containing field names as key, and data types as value. + By default, the type of the properties of an item are left + unchanged. When a field type is specified, this field in the + items will be converted to the specified type. This can be used + for example to convert ISO strings containing a date to a + JavaScript Date object, or convert strings to numbers or vice + versa. The available data types are listed in section + Data Types. +
filterFunctionnoItems 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. + See section Data Filtering.
orderString | FunctionnoOrder the items by a field name or custom sort function.
returnTypeStringnoDetermine the type of output of the get function. Allowed values are 'Array' | 'Object'. + The default returnType is an Array. The Object type will return a JSON object with the ID's as keys.
+ +

+ The following example demonstrates formatting properties and filtering + properties from items. +

+ +
+// create a DataSet
+var data = new vis.DataSet();
+data.add([
+  {id: 1, text: 'item 1', date: '2013-06-20', group: 1, first: true},
+  {id: 2, text: 'item 2', date: '2013-06-23', group: 2},
+  {id: 3, text: 'item 3', date: '2013-06-25', group: 2},
+  {id: 4, text: 'item 4'}
+]);
+
+// retrieve formatted items
+var items = data.get({
+  fields: ['id', 'date', 'group'],    // output the specified fields only
+  type: {
+    date: 'Date',                   // convert the date fields to Date objects
+    group: 'String'                 // convert the group fields to Strings
+  }
+});
+
+ +

Getting Data

+ +

+ 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
+
+ + +

Data Filtering

+ +

+ 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);
+  }
+});
+
+
+ + +

Data Types

+ +

+ DataSet supports the following data types: +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameDescriptionExamples
BooleanA JavaScript Boolean + true
+ false +
NumberA JavaScript Number + 32
+ 2.4 +
StringA JavaScript String + "hello world"
+ "2013-06-28" +
DateA JavaScript Date object + new Date()
+ new Date(2013, 5, 28)
+ new Date(1372370400000) +
MomentA Moment object, created with + moment.js + moment()
+ moment('2013-06-28') +
ISODateA string containing an ISO Date + new Date().toISOString()
+ "2013-06-27T22:00:00.000Z" +
ASPDateA string containing an ASP Date + "/Date(1372370400000)/"
+ "/Date(1198908717056-0700)/" +
+ +
+ + + + + + + \ No newline at end of file diff --git a/docs/dataset/dataview.html b/docs/dataset/dataview.html new file mode 100644 index 00000000..dff732d4 --- /dev/null +++ b/docs/dataset/dataview.html @@ -0,0 +1,392 @@ + + + + + + + + + DataView - vis.js - A dynamic, browser based visualization library. + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +

DataView documentation

+ +

Contents

+ + + +

Overview

+ +

+ A DataView offers a filtered and/or formatted view on a + DataSet. + One can subscribe on changes in a DataView, and easily get filtered or + formatted data without having to specify filters and field types all + the time. +

+ +

Example

+ +

+ The following example shows how to use a DataView. +

+ +
+// create a DataSet
+var data = new vis.DataSet();
+data.add([
+  {id: 1, text: 'item 1', date: new Date(2013, 6, 20), group: 1, first: true},
+  {id: 2, text: 'item 2', date: '2013-06-23', group: 2},
+  {id: 3, text: 'item 3', date: '2013-06-25', group: 2},
+  {id: 4, text: 'item 4'}
+]);
+
+// create a DataView
+// the view will only contain items having a property group with value 1,
+// and will only output fields id, text, and date.
+var view = new vis.DataView(data, {
+  filter: function (item) {
+    return (item.group == 1);
+  },
+  fields: ['id', 'text', 'date']
+});
+
+// subscribe to any change in the DataView
+view.on('*', function (event, properties, senderId) {
+  console.log('event', event, properties);
+});
+
+// update an item in the data set
+data.update({id: 2, group: 1});
+
+// get all ids in the view
+var ids = view.getIds();
+console.log('ids', ids); // will output [1, 2]
+
+// get all items in the view
+var items = view.get();
+
+ +

Construction

+ + +

+ A DataView can be constructed as: +

+ +
+var data = new vis.DataView(dataset, options)
+
+ +

+ where: +

+ + + +

Methods

+ +

DataView contains the following methods.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
MethodReturn TypeDescription
+ get([options] [, data])
+ get(id [,options] [, data])
+ get(ids [, options] [, data]) +
Object | Array + Get a single item, multiple items, or all items from the DataView. + Usage examples can be found in section Getting Data, and the available options are described in section Data Selection. +
+ getDataSet() + DataSet + Get the DataSet to which the DataView is connected. +
+ 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 type are not applicable in case of getIds. +
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. +
refresh()none + Refresh the filter results of a DataView. Useful when the filter function contains dynamic properties, like: + +
var data = new vis.DataSet(...);
+var view = new vis.DataView(data, {
+  filter: function (item) {
+    return item.value > threshold;
+  }
+});
+ In this example, threshold is an external parameter. When the value of threshold changes, the DataView must be notified that the filter results may have changed by calling DataView.refresh(). +
+ setDataSet(data) + none + Replace the DataSet of the DataView. Parameter data can be a DataSet or a DataView. +
+ + +

Properties

+ +

DataView contains the following properties.

+ + + + + + + + + + + + + + + + + +
PropertyTypeDescription
lengthNumberThe number of items in the DataView.
+ +

Getting Data

+ +

+ Data of the DataView can be retrieved using the method get. +

+ +
+var items = view.get();
+
+ +

+ Data of a DataView can be filtered and formatted again, in exactly the + same way as in a DataSet. See sections + Data Manipulation and + Data Selection for more + information. +

+ +
+var items = view.get({
+  fields: ['id', 'score'],
+  filter: function (item) {
+    return (item.score > 50);
+  }
+});
+
+ + + +

Subscriptions

+

+ One can subscribe on changes in the DataView. Subscription works exactly + the same as for DataSets. See the documentation on + subscriptions in a DataSet + for more information. +

+ +
+// create a DataSet and a view on the data set
+var data = new vis.DataSet();
+var view = new vis.DataView({
+  filter: function (item) {
+    return (item.group == 2);
+  }
+});
+
+// subscribe to any change in the DataView
+view.on('*', function (event, properties, senderId) {
+  console.log('event:', event, 'properties:', properties, 'senderId:', senderId);
+});
+
+// add, update, and remove data in the DataSet...
+
+ +
+ + + + + + + \ No newline at end of file diff --git a/docs/dataset.html b/docs/old/dataset.html similarity index 100% rename from docs/dataset.html rename to docs/old/dataset.html diff --git a/docs/dataview.html b/docs/old/dataview.html similarity index 100% rename from docs/dataview.html rename to docs/old/dataview.html