diff --git a/docs/old/dataset.html b/docs/old/dataset.html deleted file mode 100644 index 48007fad..00000000 --- a/docs/old/dataset.html +++ /dev/null @@ -1,949 +0,0 @@ - - - -
-- 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. -
- - -- 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); -- - - -
- 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:
-
Name | -Type | -Default value | -Description | -
---|---|---|---|
fieldId | -String | -"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.
- |
-
type | -Object.<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. - | -
queue | -Object | boolean | -none | -
- 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:
-
|
-
DataSet contains the following methods.
- -Method | -Return Type | -Description | -
---|---|---|
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) | -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. | -
flush() | -none | -Flush 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:
-
-
|
-
- 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.
- |
-
DataSet contains the following properties.
- -Property | -Type | -Description | -
---|---|---|
length | -Number | -The number of items in the DataSet. | -
- 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. 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.
- |
-
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 .
- |
-
- 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 a data item or an array with items. -
- -Syntax: -var addedIds = DataSet.add(data [, senderId])- -The argument
data
can contain:
-Object
containing a single item to be
- added. The item must contain an id.
- Array
containing a list with items to be added. Each item must contain an id.
-
- 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 a data item or an array with items. -
- -Syntax: -var updatedIds = DataSet.update(data [, senderId])- -The argument
data
can contain:
-Object
containing a single item to be
- updated. The item must contain an id.
- Array
containing a list with items to be updated. Each item must contain an id.
- - 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 a data item or an array with items. -
- -Syntax: -var removedIds = DataSet.remove(id [, senderId])- -
- The argument id
can be:
-
Number
or String
containing the id
- of a single item to be removed.
- Object
containing the item to be deleted.
- The item will be deleted by its id.
- - 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 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.
-
- 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:
-
Name | -Type | -Description | -
---|---|---|
fields | -String[ ] | Object.<String, String> | -
- 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.
- |
-
type | -Object.<String, String> | -- 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. - | -
filter | -Function | -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. - See section Data Filtering. | -
order | -String | Function | -Order the items by a field name or custom sort function. | -
returnType | -String | -Determine 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 - } -}); -- -
- 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); - } -}); - -- - -
- DataSet supports the following data types: -
- -Name | -Description | -Examples | -
---|---|---|
Boolean | -A JavaScript Boolean | -
- true - false
- |
-
Number | -A JavaScript Number | -
- 32 - 2.4
- |
-
String | -A JavaScript String | -
- "hello world" - "2013-06-28"
- |
-
Date | -A JavaScript Date object | -
- new Date() - new Date(2013, 5, 28) - new Date(1372370400000)
- |
-
Moment | -A Moment object, created with - moment.js | -
- moment() - moment('2013-06-28')
- |
-
ISODate | -A string containing an ISO Date | -
- new Date().toISOString() - "2013-06-27T22:00:00.000Z"
- |
-
ASPDate | -A string containing an ASP Date | -
- "/Date(1372370400000)/" - "/Date(1198908717056-0700)/"
- |
-
- All code and data is processed and rendered in the browser. - No data is sent to any server. -
- -- 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. -
- -- 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(); -- -
- A DataView can be constructed as: -
- --var data = new vis.DataView(dataset, options) -- -
- where: -
- -dataset
is a DataSet or DataView.
- options
is an object which can
- contain the following properties. Note that these properties
- are exactly the same as the properties available in methods
- DataSet.get
and DataView.get
.
-
- Name | -Type | -Description | -
---|---|---|
convert | -Object.<String, String> | -- 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. - | -
fields | -String[ ] | Object.<String, String> | -
- 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.
- |
-
filter | -function | -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. - See also section Data Filtering. | -
DataView contains the following methods.
- -Method | -Return Type | -Description | -
---|---|---|
- 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.
- |
-
DataView contains the following properties.
- -Property | -Type | -Description | -
---|---|---|
length | -Number | -The number of items in the DataView. | -
- 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); - } -}); -- - - -
- 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... -- - - -
- All code and data is processed and rendered in the browser. - No data is sent to any server. -
- -- Graph3d is an interactive visualization chart to draw data in a three dimensional - graph. You can freely move and zoom in the graph by dragging and scrolling in the - window. Graph3d also supports animation of a graph. -
-- Graph3d uses HTML canvas - to render graphs, and can render up to a few thousands of data points smoothly. -
- -- The following code shows how to create a Graph3d and provide it with data. - More examples can be found in the examples directory. -
- --<!DOCTYPE HTML> -<html> -<head> - <title>Graph 3D demo</title> - - <style> - body {font: 10pt arial;} - </style> - - <script type="text/javascript" src="../../dist/vis.js"></script> - - <script type="text/javascript"> - var data = null; - var graph = null; - - function custom(x, y) { - return (Math.sin(x/50) * Math.cos(y/50) * 50 + 50); - } - - // Called when the Visualization API is loaded. - function drawVisualization() { - // Create and populate a data table. - var data = new vis.DataSet(); - // create some nice looking data with sin/cos - var steps = 50; // number of datapoints will be steps*steps - var axisMax = 314; - var axisStep = axisMax / steps; - for (var x = 0; x < axisMax; x+=axisStep) { - for (var y = 0; y < axisMax; y+=axisStep) { - var value = custom(x, y); - data.add({ - x: x, - y: y, - z: value, - style: value - }); - } - } - - // specify options - var options = { - width: '600px', - height: '600px', - style: 'surface', - showPerspective: true, - showGrid: true, - showShadow: false, - keepAspectRatio: true, - verticalRatio: 0.5 - }; - - // create a graph3d - var container = document.getElementById('mygraph'); - graph3d = new vis.Graph3d(container, data, options); - } - </script> -</head> - -<body onload="drawVisualization();"> - <div id="mygraph"></div> -</body> -</html> - -- - -
- The class name of the Graph3d is vis.Graph3d
.
- When constructing a Graph3d, an HTML DOM container must be provided to attach
- the graph to. Optionally, data an options can be provided.
- Data is a vis DataSet
or an Array
, described in
- section Data Format.
- Options is a name-value map in the JSON format. The available options
- are described in section Configuration Options.
-
var graph = new vis.Graph3d(container [, data] [, options]);- -
- Data and options can be set or changed later on using the functions
- Graph3d.setData(data)
and Graph3d.setOptions(options)
.
-
- Graph3d can load data from an Array
, a DataSet
or a DataView
.
- JSON objects are added to this DataSet by using the add()
function.
- Data points must have properties x
, y
, and z
,
- and can optionally have a property style
and filter
.
-
-
- The DataSet JSON objects are defined as: -
- -Name | -Type | -Required | -Description | -
---|---|---|---|
x | -number | -yes | -Location on the x-axis. | -
y | -number | -yes | -Location on the y-axis. | -
z | -number | -yes | -Location on the z-axis. | -
style | -number | -no | -The data value, required for graph styles dot-color and
- dot-size .
- |
-
filter | -* | -no | -Filter values used for the animation. - This column may have any type, such as a number, string, or Date. | -
- Options can be used to customize the graph. Options are defined as a JSON object. - All options are optional. -
- --var options = { - width: '100%', - height: '400px', - style: 'surface' -}; -- -
- The following options are available. -
- -Name | -Type | -Default | -Description | -
---|---|---|---|
animationInterval | -number | -1000 | -The animation interval in milliseconds. This determines how fast - the animation runs. | -
animationPreload | -boolean | -false | -If false, the animation frames are loaded as soon as they are requested.
- if animationPreload is true, the graph will automatically load
- all frames in the background, resulting in a smoother animation as soon as
- all frames are loaded. The load progress is shown on screen. |
-
animationAutoStart | -boolean | -false | -If true, the animation starts playing automatically after the graph - is created. | -
backgroundColor | -string or Object | -'white' | -The background color for the main area of the chart. - Can be either a simple HTML color string, for example: 'red' or '#00cc00', - or an object with the following properties. | -
backgroundColor.stroke | -string | -'gray' | -The color of the chart border, as an HTML color string. | -
backgroundColor.strokeWidth | -number | -1 | -The border width, in pixels. | -
backgroundColor.fill | -string | -'white' | -The chart fill color, as an HTML color string. | -
cameraPosition | -Object | -{horizontal: 1.0, vertical: 0.5, distance: 1.7} | -Set the initial rotation and position of the camera.
- The object cameraPosition contains three parameters:
- horizontal , vertical , and distance .
- Parameter horizontal is a value in radians and can have any
- value (but normally in the range of 0 and 2*Pi).
- Parameter vertical is a value in radians between 0 and 0.5*Pi.
- Parameter distance is the (normalized) distance from the
- camera to the center of the graph, in the range of 0.71 to 5.0. A
- larger distance puts the graph further away, making it smaller.
- All parameters are optional.
- |
height | -string | -'400px' | -The height of the graph in pixels or as a percentage. | -
keepAspectRatio | -boolean | -true | -If keepAspectRatio is true, the x-axis and the y-axis
- keep their aspect ratio. If false, the axes are scaled such that they
- both have the same, maximum with. |
-
showAnimationControls | -boolean | -true | -If true, animation controls are created at the bottom of the Graph. - The animation controls consists of buttons previous, start/stop, next, - and a slider showing the current frame. - Only applicable when the provided data contains an animation. | -
showGrid | -boolean | -true | -If true, grid lines are draw in the x-y surface (the bottom of the 3d - graph). | -
showPerspective | -boolean | -true | -If true, the graph is drawn in perspective: points and lines which - are further away are drawn smaller. - Note that the graph currently does not support a gray colored bottom side - when drawn in perspective. - | -
showShadow | -boolean | -false | -Show shadow on the graph. | -
style | -string | -'dot' | -The style of the 3d graph. Available styles:
- bar ,
- bar-color ,
- bar-size ,
- dot ,
- dot-line ,
- dot-color ,
- dot-size ,
- line ,
- grid ,
- or surface |
-
tooltip | -boolean | function | -false | -Show a tooltip showing the values of the hovered data point.
- The contents of the tooltip can be customized by providing a callback
- function as tooltip . In this case the function is called
- with an object containing parameters x ,
- y , and z argument,
- and must return a string which may contain HTML.
- |
-
valueMax | -number | -none | -The maximum value for the value-axis. Only available in combination
- with the styles dot-color and dot-size . |
-
valueMin | -number | -none | -The minimum value for the value-axis. Only available in combination
- with the styles dot-color and dot-size . |
-
verticalRatio | -number | -0.5 | -A value between 0.1 and 1.0. This scales the vertical size of the graph - When keepAspectRatio is set to false, and verticalRatio is set to 1.0, - the graph will be a cube. | -
width | -string | -'400px' | -The width of the graph in pixels or as a percentage. | -
xBarWidth | -number | -none | -The width of bars in x direction. By default, the width is equal to the distance
- between the data points, such that bars adjoin each other.
- Only applicable for styles 'bar' and 'bar-color' . |
-
xCenter | -string | -'55%' | -The horizontal center position of the graph, as a percentage or in - pixels. | -
xMax | -number | -none | -The maximum value for the x-axis. | -
xMin | -number | -none | -The minimum value for the x-axis. | -
xStep | -number | -none | -Step size for the grid on the x-axis. | -
xValueLabel | -function | -none | -A function for custom formatting of the labels along the x-axis,
- for example function (x) {return (x * 100) + '%'} .
- |
-
yBarWidth | -number | -none | -The width of bars in y direction. By default, the width is equal to the distance
- between the data points, such that bars adjoin each other.
- Only applicable for styles 'bar' and 'bar-color' . |
-
yCenter | -string | -'45%' | -The vertical center position of the graph, as a percentage or in - pixels. | -
yMax | -number | -none | -The maximum value for the y-axis. | -
yMin | -number | -none | -The minimum value for the y-axis. | -
yStep | -number | -none | -Step size for the grid on the y-axis. | -
yValueLabel | -function | -none | -A function for custom formatting of the labels along the y-axis,
- for example function (y) {return (y * 100) + '%'} .
- |
-
zMin | -number | -none | -The minimum value for the z-axis. | -
zMax | -number | -none | -The maximum value for the z-axis. | -
zStep | -number | -none | -Step size for the grid on the z-axis. | -
zValueLabel | -function | -none | -A function for custom formatting of the labels along the z-axis,
- for example function (z) {return (z * 100) + '%'} .
- |
-
xLabel | -String | -x | -Label on the X axis. | -
yLabel | -String | -y | -Label on the Y axis. | -
zLabel | -String | -z | -Label on the Z axis. | -
filterLabel | -String | -time | -Label for the filter column. | -
legendLabel | -String | -value | -Label for the style description. | -
- Graph3d supports the following methods. -
- -Method | -Return Type | -Description | -
---|---|---|
animationStart() | -none | -Start playing the animation. - Only applicable when animation data is available. | -
animationStop() | -none | -Stop playing the animation. - Only applicable when animation data is available. | -
getCameraPosition() | -An object with parameters horizontal ,
- vertical and distance |
- Returns an object with parameters horizontal ,
- vertical and distance ,
- which each one of them is a number, representing the rotation and position
- of the camera. |
-
redraw() | -none | -Redraw the graph. Useful after the camera position is changed externally, - when data is changed, or when the layout of the webpage changed. | -
setData(data) | -none | -Replace the data in the Graph3d. | -
setOptions(options) | -none | -Update options of Graph3d. - The provided options will be merged with current options. | -
setSize(width, height) | -none | -Parameters width and height are strings,
- containing a new size for the graph. Size can be provided in pixels
- or in percentages. |
-
setCameraPosition (pos) | -{horizontal: 1.0, vertical: 0.5, distance: 1.7} | -Set the rotation and position of the camera. Parameter pos
- is an object which contains three parameters: horizontal ,
- vertical , and distance .
- Parameter horizontal is a value in radians and can have any
- value (but normally in the range of 0 and 2*Pi).
- Parameter vertical is a value in radians between 0 and 0.5*Pi.
- Parameter distance is the (normalized) distance from the
- camera to the center of the graph, in the range of 0.71 to 5.0. A
- larger distance puts the graph further away, making it smaller.
- All parameters are optional.
- |
-
- Graph3d fires events after the camera position has been changed.
- The event can be catched by creating a listener.
- Here an example on how to catch a cameraPositionChange
event.
-
-function onCameraPositionChange(event) { - alert('The camera position changed to:\n' + - 'Horizontal: ' + event.horizontal + '\n' + - 'Vertical: ' + event.vertical + '\n' + - 'Distance: ' + event.distance); -} -// assuming var graph3d = new vis.Graph3d(document.getElementById('mygraph')); -graph3d.on('cameraPositionChange', onCameraPositionChange); -- -
- The following events are available. -
- -name | -Description | -Properties | -
---|---|---|
cameraPositionChange | -The camera position changed. Fired after the user modified the camera position
- by moving (dragging) the graph, or by zooming (scrolling),
- but not after a call to setCameraPosition method.
- The new camera position can be retrieved by calling the method
- getCameraPosition . |
-
-
|
-
- All code and data are processed and rendered in the browser. No data is sent to any server. -
- -- Vis.js is a dynamic, browser based visualization library. - The library is designed to be easy to use, handle large amounts - of dynamic data, and enable manipulation of the data. -
- -- The library is developed by - Almende B.V.. - Vis.js runs fine on Chrome, Firefox, Opera, Safari, IE9+, and most mobile - browsers (with full touch support). -
- -- Vis.js contains of the following components: -
- - - --npm install vis -- -
-bower install vis -- -
- To load vis.js, include the javascript and css files of vis in your web page: -
- -<!DOCTYPE HTML> -<html> -<head> - <script src="components/vis/vis.js"></script> - <link href="components/vis/vis.css" rel="stylesheet" type="text/css" /> -</head> -<body> -<script type="text/javascript"> - // ... load a visualization -</script> -</body> -</html> -- -
- or load vis.js using require.js: -
- --require.config({ - paths: { - vis: 'path/to/vis', - } -}); - -require(['vis'], function (math) { - // ... load a visualization -}); -- -
- A timeline can be instantiated as follows. Other components can be - created in a similar way. -
- --var timeline = new vis.Timeline(container, data, options); -- -
- Where container
is an HTML element, data
is
- an Array with data or a DataSet, and options
is an optional
- object with configuration options for the component.
-
- A basic example on using a Timeline is shown below. More examples can be - found in the examples directory of the project. -
- --<!DOCTYPE HTML> -<html> -<head> - <title>Timeline basic demo</title> - - <script src="components/vis/vis.js"></script> - <link href="components/vis/vis.css" rel="stylesheet" type="text/css" /> - - <style type="text/css"> - body, html { - font-family: sans-serif; - } - </style> -</head> -<body> -<div id="visualization"></div> - -<script type="text/javascript"> - // DOM element where the Timeline will be attached - var container = document.getElementById('visualization'); - - // Create a DataSet (allows two way data-binding) - var data = new vis.DataSet([ - {id: 1, content: 'item 1', start: '2013-04-20'}, - {id: 2, content: 'item 2', start: '2013-04-14'}, - {id: 3, content: 'item 3', start: '2013-04-18'}, - {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'}, - {id: 5, content: 'item 5', start: '2013-04-25'}, - {id: 6, content: 'item 6', start: '2013-04-27'} - ]); - - // Configuration for the Timeline - var options = {}; - - // Create a Timeline - var timeline = new vis.Timeline(container, data, options); -</script> -</body> -</html> -- - -
- Copyright 2010-2014 Almende B.V. -
- -- Vis.js is dual licensed under both -
-- and -
-- Vis.js may be distributed under either license. -
- - -Handles the HTML part of the canvas.
- -The options for the canvas have to be contained in an object titled 'canvas'.
-Click on the options shown to show how these options are supposed to be used.
- -All of the individual options are explained here:
-name | -type | -default | -description | -
width | -String | -'100%' |
- the width of the canvas. Can be in percentages or pixels (ie. '400px' ). |
-
height | -String | -'100%' |
- the height of the canvas. Can be in percentages or pixels (ie. '400px' ). |
-
autoResize | -Boolean | -true |
- If true, the Network will automatically detect when its container is resized, and redraw itself - accordingly. If false, the Network can be forced to repaint after its container has been resized - using the function redraw() and setSize(). | -
This is a list of all the methods in the public API. Options can be set directly to the module or you can use the - setOptions method of the network itself and use the module name as an object name.
-name | -returns | -description | -
setSize(String width ,String
- height ) - |
- none | -Set the size of the canvas. This is automatically done on a window resize. | -
canvasToDOM({x: Number ,y:
- Number }) - |
- Object | -This function converts canvas coordinates to coordinates on the DOM. Input and output are in the form of
- {x:Number,y:Number} . The DOM values are relative to the network container.
- |
-
DOMtoCanvas({x: Number ,y:
- Number }) - |
- Object | -This function converts DOM coordinates to coordinates on the canvas. Input and output are in the form of
- {x:Number,y:Number} . The DOM values are relative to the network container.
- |
-
This is a list of all the events in the public API. They are collected here from all individual modules.
-name | -properties | -description | -
resize | -
--{ - width: Number // the new width of the canvas - height: Number // the new height of the canvas - oldWidth: Number // the old width of the canvas - oldHeight: Number // the old height of the canvas -} --
|
- Fired when the size of the canvas has been resized, either by a redraw call when the container div has - changed in size, a setSize() call with new values or a setOptions() with new width and/or height values. - | - -
Handles the HTML part of the canvas.
- -Clustering has no options, everything is done with methods.
- - -This is a list of all the methods in the public API. Options can be set directly to the module or you can use the setOptions method of the network itself and use the module name as an object name.
-name | returns | description |
findNode( - String nodeId ) | Array | Nodes can be in clusters. Clusters can also be in clusters. This function returns and array of nodeIds showing where the node is. Example: - cluster 'A' contains cluster 'B', - cluster 'B' contains cluster 'C', - cluster 'C' contains node 'fred'. - network.clustering.findNode('fred') will return ['A','B','C','fred'] .
- |
isCluster( - String nodeId ) | Boolean | Returns true if the node whose ID has been supplied is a cluster. |
openCluster( - String nodeId ) | none | Opens the cluster, releases the contained nodes and edges, removing the cluster node and cluster edges. |
cluster( - Object options ) | none | The options object is explained in full below. The joinCondition function is presented with all nodes. |
clusterByConnection( - String nodeId ,- [Object options] - ) | none | This method looks at the provided node and makes a cluster of it and all it's connected nodes. The behaviour can be customized by proving the options object. All options of this object are explained below. The joinCondition is only presented with the connected nodes. |
clusterByHubsize( - Number hubsize ,- [Object options] ) | none | This method checks all nodes in the network and those with a equal or higher amount of edges than specified with the hubsize qualify. Cluster by connection is performed on each of them. The options object is described for clusterByConnection and does the same here. |
clusterOutliers( - [Object options] ) | none | This method will cluster all nodes with 1 edge with their respective connected node. |
The options object supplied to the cluster functions can contain these properties:
-name | Type | description |
joinCondition(Object nodeOptions ) | Function | -Optional for all but the cluster method. The cluster module loops over all nodes that are selected to be in the cluster and calls this function with their data as argument.
- If this function returns true, this node will be added to the cluster. You have access to all options (including the default)
- as well as any custom fields you may have added to the node to determine whether or not to include it in the cluster. Example:
--var nodes = [ - {id: 4, label: 'Node 4'}, - {id: 5, label: 'Node 5'}, - {id: 6, label: 'Node 6', cid:1}, - {id: 7, label: 'Node 7', cid:1} -] - -var options = { - joinCondition:function(nodeOptions) { - return nodeOptions.cid === 1; - } -} - -network.clustering.cluster(options); - |
processProperties(Object nodeOptions ) | Function | Optional. Before creating the new cluster node, this (optional) function will be called with the properties supplied by you (clusterNodeProperties ), all contained nodes and all contained edges. You can use this to update the
- properties of the cluster based on which items it contains. The function should return the properties to create the cluster node. In the example below, we ensure preservation of mass and value when forming the cluster:
--var options = { - processProperties: function (clusterOptions, childNodes, childEdges) { - var totalMass = 0; - var totalValue = 0; - for (var i = 0; i < childNodes.length; i++) { - totalMass += childNodes[i].mass; - totalValue = childNodes[i].value ? totalValue + childNodes[i].value : totalValue; - } - clusterOptions.mass = totalMass; - if (totalValue > 0) { - clusterOptions.value = totalValue; - } - return clusterOptions; - }, -} - |
clusterNodeProperties | Object | Optional. This is an object containing the options for the cluster node. All options described in the nodes module are allowed. This allows you to style your cluster node any way you want. This is also the style object that is provided in the processProperties function for fine tuning. If undefined, default node options will be used. |
clusterEdgeProperties | Object | Optional. This is an object containing the options for the edges connected to the cluster. All options described in the edges module are allowed. Using this, you can style the edges connecting to the cluster any way you want. If none are provided, the optoins from the edges that are replaced are used. If undefined, default edge options will be used. |
- -
- -The clustering module does not have any events.
- -Handles the rendering aspect of vis. It governs the render loop, it draws the nodes and edges and provides events to allow users to hook into the drawing.
- -The options for the rendering have to be contained in an object titled 'rendering'.
-Click on the options shown to show how these options are supposed to be used.
- -All of the individual options are explained here:
-name | type | default | description |
hideEdgesOnDrag | Boolean | false | When true, the edges are not drawn when dragging the view. This can greatly speed up responsiveness on dragging, improving user experience. |
hideNodesOnDrag | Boolean | false | When true, the nodes are not drawn when dragging the view. This can greatly speed up responsiveness on dragging, improving user experience. |
This is a list of all the methods in the public API. Options can be set directly to the module or you can use the setOptions method of the network itself and use the module name as an object name.
-name | returns | description |
redraw() | none | Redraw the network. |
These events are fired by the renderer and can be used to move and draw custom elements on the same canvas as the rest of the network.
-name | properties | description |
initRedraw | none | Fired before the redrawing begins. The simulation step has completed at this point. Can be used to move custom elements before starting drawing the new frame. | -
beforeDrawing | canvas context | Fired after the canvas has been cleared, scaled and translated to the viewing position but before all edges and nodes are drawn. Can be used to draw behind the network. | -
initRedraw | canvas context | Fired after drawing on the canvas has been completed. Can be used to draw on top of the network. |
Handles the selection of nodes and edges.
- -The options for the selection have to be contained in an object titled 'selection'.
-Click on the options shown to show how these options are supposed to be used.
- -All of the individual options are explained here:
-name | type | default | description |
selectable | Boolean | true | When true, the nodes and edges can be selected by the user. |
selectConnectedEdges | Boolean | true | When true, on selecting a node, its connecting edges are highlighted. |
This is a list of all the methods in the public API. Options can be set directly to the module or you can use the setOptions method of the network itself and use the module name as an object name.
-name | returns | description |
getSelection() |
--{ - nodes: [Array of selected nodeIds], - edges: [Array of selected edgeIds] -} | Returns an object with selected nodes and edges ids. |
getSelectedNodes() | [nodeId1, nodeId2, ..] | Returns an array of selected node ids. |
getSelectedEdges() | [edgeId1, edgeId2, ..] | Returns an array of selected edge ids. |
getNodeAt({x: xPosition DOM, ) | nodeId | Returns a nodeId or undefined. The DOM positions are expected to be in pixels from the top left corner of the canvas. |
getEdgeAt({x: xPosition DOM, ) | edgeId | Returns a edgeId or undefined. The DOM positions are expected to be in pixels from the top left corner of the canvas.. |
selectNodes(Array with nodeIds ,[Boolean highlightEdges] ) | none | Selects the nodes corresponding to the id's in the input array. If highlightEdges is true or undefined, the neighbouring edges will also be selected. This method unselects all other objects before selecting its own objects. Does not fire events. |
selectEdges(Array with edgeIds ) | none | Selects the edges corresponding to the id's in the input array. This method unselects all other objects before selecting its own objects. Does not fire events. |
unselectAll() | none | Unselect all objects. Does not fire events. |
The selection handler does not fire events. All related events are fired by the interaction module because they are triggered by user interaction.
- -Acts as the camera that looks on the canvas. Does the animation, zooming and focusing.
- -The view has no options.
- -This is a list of all the methods in the public API. Options can be set directly to the module or you can use the setOptions method of the network itself and use the module name as an object name.
-name | returns | description |
getScale() | Number | Returns the current scale of the network. 1.0 is comparible to 100%, 0 is zoomed out infinitely. |
getPosition() | Number | Returns the current central focus point of the camera. |
fit([Object options] ) | none | Zooms out so all nodes fit on the canvas. You can supply options to customize this:
--{ - nodes:[Array of nodeIds], - animation: { // -------------------> can be a boolean too! - duration: Number - easingFunction: String - } -} -- The nodes can be used to zoom to fit only specific nodes in the view. - The other options are explained in the moveTo() description below.
- All options are optional for the fit method.
- |
focus( - String nodeId ,- [Object options] ) | none | -You can focus on a node with this function. What that means is the view will lock onto that node, if it is moving, the view will also move accordingly. If the view is dragged by the user, the focus is broken.
- You can supply options to customize the effect:
--{ - scale: Number, - offset: {x:Number, y:Number} - locked: boolean - animation: { // -------------------> can be a boolean too! - duration: Number - easingFunction: String - } -} -- All options except for locked are explained in the moveTo() description below. Locked denotes whether or not the view remains locked to the node once the zoom-in animation is finished. Default value is true. The options object is optional in the focus method. |
moveTo(Object options ) | none | You can animate or move the camera using the moveTo method. Options are:
--{ - position: {x:Number, y:Number}, - scale: Number, - offset: {x:Number, y:Number} - animation: { // -------------------> can be a boolean too! - duration: Number - easingFunction: String - } -} -- The position (in canvas units!) is the position of the central focus point of the camera. - The scale is the target zoomlevel. Default value is 1.0. - The offset (in DOM units) is how many pixels from the center the view is focussed. Default value is {x:0,y:0}. - For animation you can either use a Boolean to use it with the default options or disable it or you can define the duration (in milliseconds) and easing function manually. Available are: - linear, easeInQuad, easeOutQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic, easeInQuart, easeOutQuart, easeInOutQuart, easeInQuint, easeOutQuint, easeInOutQuint . - You will have to define at least a scale or a position. Otherwise, there is nothing to move to. - |
releaseNode() | none | Programatically release the focussed node. |
These events are fired by the renderer and can be used to move and draw custom elements on the same canvas as the rest of the network.
-name | properties | description |
animationFinished | none | Fired when an animation is finished. | -
- The Timeline is an interactive visualization chart to visualize data in time. - The data items can take place on a single date, or have a start and end date (a range). - You can freely move and zoom in the timeline by dragging and scrolling in the - Timeline. Items can be created, edited, and deleted in the timeline. - The time scale on the axis is adjusted automatically, and supports scales ranging - from milliseconds to years. -
-- Timeline uses regular HTML DOM to render the timeline and items put on the - timeline. This allows for flexible customization using css styling. -
- -- The following code shows how to create a Timeline and provide it with data. - More examples can be found in the examples directory. -
- -<!DOCTYPE HTML> -<html> -<head> - <title>Timeline | Basic demo</title> - - <style type="text/css"> - body, html { - font-family: sans-serif; - } - </style> - - <script src="../../dist/vis.js"></script> - <link href="../../dist/vis.css" rel="stylesheet" type="text/css" /> -</head> -<body> -<div id="visualization"></div> - -<script type="text/javascript"> - // DOM element where the Timeline will be attached - var container = document.getElementById('visualization'); - - // Create a DataSet (allows two way data-binding) - var items = new vis.DataSet([ - {id: 1, content: 'item 1', start: '2013-04-20'}, - {id: 2, content: 'item 2', start: '2013-04-14'}, - {id: 3, content: 'item 3', start: '2013-04-18'}, - {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'}, - {id: 5, content: 'item 5', start: '2013-04-25'}, - {id: 6, content: 'item 6', start: '2013-04-27'} - ]); - - // Configuration for the Timeline - var options = {}; - - // Create a Timeline - var timeline = new vis.Timeline(container, items, options); -</script> -</body> -</html> -- - -
- Install or download the vis.js library. - in a subfolder of your project. Include the libraries script and css files in the - head of your html code: -
- --<script src="vis/dist/vis.js"></script> -<link href="vis/dist/vis.css" rel="stylesheet" type="text/css" /> -- -The constructor of the Timeline is
vis.Timeline
-var timeline = new vis.Timeline(container, items, options);-or when using groups: -
var timeline = new vis.Timeline(container, items, groups, options);- -The constructor accepts four parameters: -
container
is the DOM element in which to create the timeline.
- items
is an Array containing items. The properties of an
- item are described in section Data Format, items.
- groups
is an Array containing groups. The properties of a
- group are described in section Data Format, groups.
- options
is an optional Object containing a name-value map
- with options. Options can also be set using the method
- setOptions
.
- - The timeline can be provided with two types of data: -
-
- The Timeline uses regular Arrays and Objects as data format.
- Data items can contain the properties start
,
- end
(optional), content
,
- group
(optional), className
(optional),
- and style
(optional).
-
- A table is constructed as: -
- --var items = [ - { - start: new Date(2010, 7, 15), - end: new Date(2010, 8, 2), // end is optional - content: 'Trajectory A' - // Optional: fields 'id', 'type', 'group', 'className', 'style' - } - // more items... -]); -- -
- The item properties are defined as: -
- -Name | -Type | -Required | -Description | -
---|---|---|---|
className | -String | -no | -This field is optional. A className can be used to give items
- an individual css style. For example, when an item has className
- 'red', one can define a css style like:
- -.vis.timeline .red { - color: white; - background-color: red; - border-color: darkred; -}- More details on how to style items can be found in the section - Styles. - |
-
content | -String | -yes | -The contents of the item. This can be plain text or html code. | -
end | -Date | number | string | Moment | -no | -The end date of the item. The end date is optional, and can be left null .
- If end date is provided, the item is displayed as a range.
- If not, the item is displayed as a box. |
-
group | -any type | -no | -This field is optional. When the group column is provided,
- all items with the same group are placed on one line.
- A vertical axis is displayed showing the groups.
- Grouping items can be useful for example when showing availability of multiple
- people, rooms, or other resources next to each other. - |
-
id | -String | Number | -no | -An id for the item. Using an id is not required but highly - recommended. An id is needed when dynamically adding, updating, - and removing items in a DataSet. | -
start | -Date | number | string | Moment | -yes | -The start date of the item, for example new Date(2010,9,23) . |
-
style | -String | -no | -
- A css text string to apply custom styling for an individual item, for
- example "color: red; background-color: pink;" .
- |
-
subgroup | -String | Number | -none | -The id of a subgroup.
- Groups all items within a group per subgroup, and positions them on the
- same height instead of staking them on top of each other. can be ordered
- by specifying the option subgroupOrder of a group.
- |
-
title | -String | -none | -Add a title for the item, displayed when holding the mouse on the item. - The title can only contain plain text. - | -
type | -String | -'box' | -The type of the item. Can be 'box' (default), 'point', 'range', or 'background'. - Types 'box' and 'point' need a start date, the types 'range' and 'background' needs both a start and end date. - | -
- Like the items, groups are regular JavaScript Arrays and Objects.
- Using groups, items can be grouped together.
- Items are filtered per group, and displayed as
-
- Group items can contain the properties id
,
- content
, and className
(optional).
-
- Groups can be applied to a timeline using the method setGroups
or supplied in the constructor.
- A table with groups can be created like:
-
-var groups = [ - { - id: 1, - content: 'Group 1' - // Optional: a field 'className', 'style' - } - // more groups... -]); -- - -
- Groups can have the following properties: -
- -Name | -Type | -Required | -Description | -
---|---|---|---|
className | -String | -no | -This field is optional. A className can be used to give groups
- an individual css style. For example, when a group has className
- 'red', one can define a css style
-
- .red {
- color: red;
- }
- .
- More details on how to style groups can be found in the section
- Styles.
- |
-
content | -String | -yes | -The contents of the group. This can be plain text or html code. | -
id | -String | Number | -yes | -An id for the group. The group will display all items having a
- property group which matches the id
- of the group. |
-
style | -String | -no | -
- A css text string to apply custom styling for an individual group label, for
- example "color: red; background-color: pink;" .
- |
-
subgroupOrder | -String | Function | -none | -Order the subgroups by a field name or custom sort function. - By default, groups are ordered by first-come, first-show. - | -
title | -String | -none | -A title for the group, displayed when holding the mouse on the groups label. - The title can only contain plain text. - | -
- Options can be used to customize the timeline. - Options are defined as a JSON object. All options are optional. -
- --var options = { - width: '100%', - height: '30px', - margin: { - item: 20 - } -}; -- -
- The following options are available. -
- -Name | -Type | -Default | -Description | -
---|---|---|---|
align | -String | -"center" | -Alignment of items with type 'box', 'range', and 'background'. Available values are 'auto' (default), 'center', 'left', or 'right'. For 'box' items, the 'auto' alignment is 'center'. For 'range' items, the auto alignment is dynamic: positioned left and shifted such that the contents is always visible on screen. | -
autoResize | -boolean | -true | -If true, the Timeline will automatically detect when its container is resized, and redraw itself accordingly. If false, the Timeline can be forced to repaint after its container has been resized using the function redraw() . |
-
clickToUse | -boolean | -false | -When a Timeline is configured to be clickToUse , it will react to mouse and touch events only when active.
- When active, a blue shadow border is displayed around the Timeline. The Timeline is set active by clicking on it, and is changed to inactive again by clicking outside the Timeline or by pressing the ESC key. |
-
dataAttributes | -Array[String] | 'all' | -false | -An array of fields optionally defined on the timeline items that will be appended as data- attributes to the DOM element of the items.- If value is 'all' then each field defined on the timeline item will become a data- attribute. |
-
editable | -Boolean | Object | -false | -If true, the items in the timeline can be manipulated. Only applicable when option selectable is true . See also the callbacks onAdd , onUpdate , onMove , and onRemove . When editable is an object, one can enable or disable individual manipulation actions.
- See section Editing Items for a detailed explanation.
- |
-
editable.add | -Boolean | -false | -If true, new items can be created by double tapping an empty space in the Timeline. See section Editing Items for a detailed explanation. | -
editable.remove | -Boolean | -false | -If true, items can be deleted by first selecting them, and then clicking the delete button on the top right of the item. See section Editing Items for a detailed explanation. | -
editable.updateGroup | -Boolean | -false | -If true, items can be dragged from one group to another. Only applicable when the Timeline has groups. See section Editing Items for a detailed explanation. | -
editable.updateTime | -Boolean | -false | -If true, items can be dragged to another moment in time. See section Editing Items for a detailed explanation. | -
end | -Date | Number | String | Moment | -none | -The initial end date for the axis of the timeline. - If not provided, the latest date present in the items set is taken as - end date. | -
format | -Object | -none | -
- Apply custom date formatting of the labels on the time axis. The default value of format is:
- { - minorLabels: { - millisecond:'SSS', - second: 's', - minute: 'HH:mm', - hour: 'HH:mm', - weekday: 'ddd D', - day: 'D', - month: 'MMM', - year: 'YYYY' - }, - majorLabels: { - millisecond:'HH:mm:ss', - second: 'D MMMM HH:mm', - minute: 'ddd D MMMM', - hour: 'ddd D MMMM', - weekday: 'MMMM YYYY', - day: 'MMMM YYYY', - month: 'YYYY', - year: '' - } -}- For values which not provided in the customized options.format , the default values will be used.
- All available formatting syntax is described in the docs of moment.js.
- |
-
groupOrder | -String | Function | -none | -Order the groups by a field name or custom sort function. - By default, groups are not ordered. - | -
height | -Number | String | -none | -The height of the timeline in pixels or as a percentage.
- When height is undefined or null, the height of the timeline is automatically
- adjusted to fit the contents.
- It is possible to set a maximum height using option maxHeight
- to prevent the timeline from getting too high in case of automatically
- calculated height.
- |
-
hiddenDates | -Object | -none | -This option allows you to hide specific timespans from the time axis. The dates can be supplied as an object:
- {start: '2014-03-21 00:00:00', end: '2014-03-28 00:00:00', [repeat:'daily']} or as an Array of these objects. The repeat argument is optional.
- The possible values are (case-sensitive): daily, weekly, monthly, yearly . To hide a weekend, pick any Saturday as start and the following Monday as end
- and set repeat to weekly.
- |
-
locale | -String | -none | -Select a locale for the Timeline. See section Localization for more information. | -
locales | -Object | -none | -A map with i18n locales. See section Localization for more information. | -
margin | -Number | Object | -Object | -When a number, applies the margin to margin.axis , margin.item.horizontal , and margin.item.vertical . |
-
margin.axis | -Number | -20 | -The minimal margin in pixels between items and the time axis. | -
margin.item | -Number | -10 | -The minimal margin in pixels between items in both horizontal and vertical direction. | -
margin.item.horizontal | -Number | -10 | -The minimal horizontal margin in pixels between items. | -
margin.item.vertical | -Number | -10 | -The minimal vertical margin in pixels between items. | -
max | -Date | Number | String | Moment | -none | -Set a maximum Date for the visible range. - It will not be possible to move beyond this maximum. - | -
maxHeight | -Number | String | -none | -Specifies the maximum height for the Timeline. Can be a number in pixels or a string like "300px". | -
min | -Date | Number | String | Moment | -none | -Set a minimum Date for the visible range. - It will not be possible to move beyond this minimum. - | -
minHeight | -Number | String | -none | -Specifies the minimum height for the Timeline. Can be a number in pixels or a string like "300px". | -
moveable | -Boolean | -true | -
- Specifies whether the Timeline can be moved and zoomed by dragging the window.
- See also option zoomable .
- |
-
onAdd | -Function | -none | -Callback function triggered when an item is about to be added: when the user double taps an empty space in the Timeline. See section Editing Items for more information. Only applicable when both options selectable and editable.add are set true .
- |
-
onUpdate | -Function | -none | -Callback function triggered when an item is about to be updated, when the user double taps an item in the Timeline. See section Editing Items for more information. Only applicable when both options selectable and editable.updateTime or editable.updateGroup are set true .
- |
-
onMove | -Function | -none | -Callback function triggered when an item has been moved: after the user has dragged the item to an other position. See section Editing Items for more information. Only applicable when both options selectable and editable.updateTime or editable.updateGroup are set true .
- |
-
onMoving | -Function | -none | -Callback function triggered repeatedly when an item is being moved. See section Editing Items for more information. Only applicable when both options selectable and editable.updateTime or editable.updateGroup are set true .
- |
-
onRemove | -Function | -none | -Callback function triggered when an item is about to be removed: when the user tapped the delete button on the top right of a selected item. See section Editing Items for more information. Only applicable when both options selectable and editable.remove are set true .
- |
-
order | -Function | -none | -
- Provide a custom sort function to order the items. The order of the - items is determining the way they are stacked. The function - order is called with two arguments containing the data of two items to be - compared. - -WARNING: Use with caution. Custom ordering is not suitable for large amounts of items. On load, the Timeline will render all items once to determine their width and height. Keep the number of items in this configuration limited to a maximum of a few hundred items. - |
-
orientation | -String | Object | -'bottom' | -Orientation of the timelines axis and items. When orientation is a string, the value is applied to both items and axis. Can be 'top', 'bottom' (default), or 'both'. | -
orientation.axis | -String | -'bottom' | -Orientation of the timeline axis: 'top', 'bottom' (default), or 'both'. If orientation is 'bottom', the time axis is drawn at the bottom. When 'top', the axis is drawn on top. When 'both', two axes are drawn, both on top and at the bottom. | -
orientation.item | -String | -'bottom' | -Orientation of the timeline items: 'top' or 'bottom' (default). Determines whether items are aligned to the top or bottom of the Timeline. | -
selectable | -Boolean | -true | -If true, the items on the timeline can be selected. Multiple items can be selected by long pressing them, or by using ctrl+click or shift+click. The event select is fired each time the selection has changed (see section Events). |
-
showCurrentTime | -boolean | -true | -Show a vertical bar at the current time. | -
showMajorLabels | -boolean | -true | -By default, the timeline shows both minor and major date labels on the
- time axis.
- For example the minor labels show minutes and the major labels show hours.
- When showMajorLabels is false , no major labels
- are shown. |
-
showMinorLabels | -boolean | -true | -By default, the timeline shows both minor and major date labels on the
- time axis.
- For example the minor labels show minutes and the major labels show hours.
- When showMinorLabels is false , no minor labels
- are shown. When both showMajorLabels and
- showMinorLabels are false, no horizontal axis will be
- visible. |
-
stack | -Boolean | -true | -If true (default), items will be stacked on top of each other such that they do not overlap. | -
snap | -function | null | -function | -When moving items on the Timeline, they will be snapped to nice dates like full hours or days, depending on the current scale. The snap function can be replaced with a custom function, or can be set to null to disable snapping. The signature of the snap function is:
- function snap(date: Date, scale: string, step: number) : Date | number- The parameter scale can be can be 'millisecond', 'second', 'minute', 'hour', 'weekday, 'day, 'month, or 'year'. The parameter step is a number like 1, 2, 4, 5.
- |
-
start | -Date | Number | String | Moment | -none | -The initial start date for the axis of the timeline. - If not provided, the earliest date present in the events is taken as start date. | -
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. |
-
timeAxis.scale | -string | -none | -Set a fixed scale for the time axis of the Timeline. Choose from 'millisecond' , 'second' , 'minute' , 'hour' , 'weekday' , 'day' , 'month' , 'year' . Example usage:
- var options = { - timeAxis: {scale: 'minute', step: 5} -}- |
-
timeAxis.step | -number | -1 | -
- Set a fixed step size for the time axis. Only applicable when used together with timeAxis.scale .
- Choose for example 1, 2, 5, or 10. |
-
type | -String | -none | -Specifies the default type for the timeline items. Choose from 'box', 'point', 'range', and 'background'. Note that individual items can override this default type. If undefined, the Timeline will auto detect the type from the items data: if a start and end date is available, a 'range' will be created, and else, a 'box' is created. Items of type 'background' are not editable. - | -
width | -String | -'100%' | -The width of the timeline in pixels or as a percentage. | -
zoomable | -Boolean | -true | -
- Specifies whether the Timeline can be zoomed by pinching or scrolling in the window.
- Only applicable when option moveable is set true .
- |
-
zoomMax | -Number | -315360000000000 | -Set a maximum zoom interval for the visible range in milliseconds. - It will not be possible to zoom out further than this maximum. - Default value equals about 10000 years. - | -
zoomMin | -Number | -10 | -Set a minimum zoom interval for the visible range in milliseconds. - It will not be possible to zoom in further than this minimum. - | -
- The Timeline supports the following methods. -
- -Method | -Return Type | -Description | -
---|---|---|
addCustomTime([time] [, id]) | -Number | String | -
- Add new vertical bar representing a custom time that can be dragged by the user.
- Parameter time can be a Date, Number, or String, and is new Date() by default.
- Parameter id can be Number or String and is undefined by default.- Returns id of the created bar. - |
-
destroy() | -none | -Destroy the Timeline. The timeline is removed from memory. all DOM elements and event listeners are cleaned up. - | -
fit([options]) | -none | -Adjust the visible window such that it fits all items. See also function focus(id) .
- Available options:
-
|
-
focus(id | ids [, options]) | -none | -Adjust the visible window such that the selected item (or multiple items) are centered on screen. See also function fit() . Available options:
-
|
-
getCurrentTime() | -Date | -Get the current time. Only applicable when option showCurrentTime is true.
- |
-
getCustomTime([id]) | -Date | -Retrieve the custom time from the custom time bar with given id. Id is undefined by default.
- |
-
getEventProperties(event) | -Object | -
- Returns an Object with relevant properties from an event:
-
|
-
getSelection() | -Number[] | -Get an array with the ids of the currently selected items. | -
getVisibleItems() | -Number[] | -Get an array with the ids of the currently visible items. | -
getWindow() | -Object | -Get the current visible window. Returns an object with properties start: Date and end: Date . |
-
moveTo(time [, options]) | -none | -Move the window such that given time is centered on screen. Parameter time can be a Date , Number , or String . Available options:
-
|
-
on(event, callback) | -none | -Create an event listener. The callback function is invoked every time the event is triggered. Avialable events: rangechange , rangechanged , select . The callback function is invoked as callback(properties) , where properties is an object containing event specific properties. See section Events for more information. |
-
off(event, callback) | -none | -Remove an event listener created before via function on(event, callback) . See section Events for more information. |
-
redraw() | -none | -Force a redraw of the Timeline. The size of all items will be recalculated.
- Can be useful to manually redraw when option autoResize=false and the window
- has been resized, or when the items CSS has been changed.
- |
-
removeCustomTime(id) | -none | -
- Remove vertical bars previously added to the timeline via addCustomTime method. Parameter id is the ID of the custom vertical bar returned by addCustomTime method.
- |
-
setCurrentTime(time) | -none | -Set a current time. This can be used for example to ensure that a client's time is synchronized with a shared server time.
- time can be a Date object, numeric timestamp, or ISO date string.
- Only applicable when option showCurrentTime is true. |
-
setCustomTime(time [, id]) | -none | -Adjust the time of a custom time bar.
- Parameter time can be a Date object, numeric timestamp, or ISO date string.
- Parameter id is the idof the custom time bar, and is undefined by default.
- |
-
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 | -Set a data set with groups for the Timeline.
- 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.
- |
-
setItems(items) | -none | -Set a data set with items for the Timeline.
- items can be an Array with Objects,
- a DataSet, or a DataView.
- |
-
setOptions(options) | -none | -Set or update options. It is possible to change any option of the timeline at any time. You can for example switch orientation on the fly. - | -
setSelection(id | ids [, options]) | -none | -Select one or multiple items by their id. The currently selected items will be unselected. To unselect all selected items, call `setSelection([])`. Available options:
-
|
-
setWindow(start, end [, options]) | -none | -Set the current visible window. The parameters start and end can be a Date , Number , or String . If the parameter value of start or end is null, the parameter will be left unchanged. Available options:
-
|
-
- Timeline fires events when changing the visible window by dragging, when - selecting items, and when dragging the custom time bar. -
- -
- Here an example on how to listen for a select
event.
-
-timeline.on('select', function (properties) { - alert('selected items: ' + properties.nodes); -}); -- -
- A listener can be removed via the function off
:
-
-function onSelect (properties) { - alert('selected items: ' + properties.nodes); -} - -// add event listener -timeline.on('select', onSelect); - -// do stuff... - -// remove event listener -timeline.off('select', onSelect); -- - -
- The following events are available. -
- -name | -Description | -Properties | -
---|---|---|
click | -Fired when clicked inside the Timeline. - | -
- Passes a properties object as returned by the method Timeline.getEventProperties(event) .
- |
-
contextmenu | -Fired when right-clicked inside the Timeline. Note that in order to prevent the context menu from showing up, default behavior of the event must be stopped:
-timeline.on('contextmenu', function (props) { - alert('Right click!'); - props.event.preventDefault(); -}); -- |
-
- Passes a properties object as returned by the method Timeline.getEventProperties(event) .
- |
-
doubleClick | -Fired when double clicked inside the Timeline. - | -
- Passes a properties object as returned by the method Timeline.getEventProperties(event) .
- |
-
rangechange | -Fired repeatedly when the timeline window is being changed. - | -
-
|
-
rangechanged | -Fired once after the timeline window has been changed. - | -
-
|
-
select | -Fired after the user selects or deselects items by tapping or holding them.
- When a use taps an already selected item, the select event is fired again.
- Not fired when the method setSelection is executed.
- |
-
-
|
-
timechange | -Fired repeatedly when the user is dragging the custom time bar. - Only available when the custom time bar is enabled. - | -
-
|
-
timechanged | -Fired once after the user has dragged the custom time bar. - Only available when the custom time bar is enabled. - | -
-
|
-
- When the Timeline is configured to be editable (both options selectable
and editable
are true
), the user can:
-
Option editable
accepts a boolean or an object. When editable
is a boolean, all manipulation actions will be either enabled or disabled. When editable
is an object, one can enable individual manipulation actions:
// enable or disable all manipulation actions -var options = { - editable: true // true or false -}; - -// enable or disable individual manipulation actions -var options = { - editable: { - add: true, // add new items by double tapping - updateTime: true, // drag items horizontally - updateGroup: true, // drag items from one group to another - remove: true // delete an item by tapping the delete button top right - } -};- - -
- One can specify callback functions to validate changes made by the user. There are a number of callback functions for this purpose: -
- -onAdd(item, callback)
Fired when a new item is about to be added. If not implemented, the item will be added with default text contents.onUpdate(item, callback)
Fired when an item is about to be updated. This function typically has to show a dialog where the user change the item. If not implemented, nothing happens.onMove(item, callback)
Fired when an item has been moved. If not implemented, the move action will be accepted.onMoving(item, callback)
Fired repeatedly while an item is being moved (dragged). Can be used to adjust the items start, end, and/or group to allowed regions.onRemove(item, callback)
Fired when an item is about to be deleted. If not implemented, the item will be always removed.- Each of the callbacks is invoked with two arguments: -
-item
: the item being manipulatedcallback
: a callback function which must be invoked to report back. The callback must be invoked as callback(item | null)
. Here, item
can contain changes to the passed item. Parameter `item` typically contains fields `content`, `start`, and optionally `end`. The type of `start` and `end` is determined by the DataSet type configuration and is `Date` by default. When invoked as callback(null)
, the action will be cancelled.- Example code: -
- -var options = { - onUpdate: function (item, callback) { - item.content = prompt('Edit items text:', item.content); - if (item.content != null) { - callback(item); // send back adjusted item - } - else { - callback(null); // cancel updating the item - } - } -}; -- -A full example is available here: 08_edit_items.html. - - -
- Timeline supports templates to format item contents. Any template engine (such as handlebars or mustache) can be used, and one can also manually build HTML. In the options, one can provide a template handler. This handler is a function accepting an items data as argument, and outputs formatted HTML: -
- -var options = { - template: function (item) { - var html = ... // generate HTML markup for this item - return html; - } -}; -- -
var options = { - template: function (item) { - return '<h1>' + item.header + '</h1><p>' + item.description + '</p>'; - } -}; -- -
-<script id="item-template" type="text/x-handlebars-template"> - <h1>{{header}}</h1> - <p>{{description}}</p> -</script> -- -Compile the template: - -
-var source = document.getElementById('item-template').innerHTML; -var template = Handlebars.compile(source); -- -And then specify the template in the Timeline options - -
var options = { - template: template -}; -- -
-var templates = { - template1: Handlebars.compile(...), - template2: Handlebars.compile(...), - template2: Handlebars.compile(...), - ... -}; - -var options = { - template: function (item) { - var template = templates[item.template]; // choose the right template - return template(item); // execute the template - } -}; -- -Now the items can be extended with a property
template
, specifying which template to use for the item.
-
-
-- Timeline can be localized. For localization, Timeline depends largely on the localization of moment.js. Locales are not included in vis.js by default. To enable localization, moment.js must be loaded with locales. Moment.js offers a bundle named "moment-with-locales.min.js" for this and there are various alternative ways to load locales. -
- -
- To set a locale for the Timeline, specify the option locale
:
-
var options = { - locale: 'nl' -}; -- -
locales
:
-
-var options = { - locales: { - // create a new locale (text strings should be replaced with localized strings) - mylocale: { - current: 'current', - time: 'time', - } - }, - - // use the new locale - locale: 'mylocale' -}; -- -
- Timeline comes with support for the following locales: -
- -Language | Code |
---|---|
English | -
- en - en_EN - en_US
- |
-
Dutch | -
- nl - nl_NL - nl_BE
- |
-
- All parts of the Timeline have a class name and a default css style. - The styles can be overwritten, which enables full customization of the layout - of the Timeline. -
- -For example, to change the border and background color of all items, include the - following code inside the head of your html code or in a separate stylesheet.
-<style> - .vis-item { - border-color: orange; - background-color: yellow; - } -</style> -- -
- The background grid of the time axis can be styled, for example to highlight - weekends or to create grids with an alternating white/lightgray background. -
-- Depending on the zoom level, the grids get certain css classes attached. - The following classes are available: -
- -Description | values | -
---|---|
Alternating columns | even , odd |
-
Current date | today , tomorrow , yesterday , current-week , current-month , current-year |
-
Hours | h0 , h1 , ..., h23 |
-
Grouped hours | h0-h4 to h20-h24 |
-
Weekday | monday , tuesday , wednesday , thursday , friday , saturday , sunday |
-
Days | date1 , date2 , ..., date31 |
-
Months | januari , februari , march , april , may , june , july , august , september , october , november , december |
-
Years | year2014 , year2015 , ... |
-
Examples:
- -<style> - /* alternating column backgrounds */ - .vis-time-axis .grid.odd { - background: #f5f5f5; - } - - /* gray background in weekends, white text color */ - .vis-time-axis .vis-grid.saturday, - .vis-time-axis .vis-grid.sunday { - background: gray; - } - .vis-time-axis .vis-text.saturday, - .vis-time-axis .vis-text.sunday { - color: white; - } -</style> -- - -
- All code and data is processed and rendered in the browser. - No data is sent to any server. -
- -