Browse Source

- Dropped support for Google DataTable.

- Dropped support for appending data returned by `DataSet.get()` to an existing Array or DataTable.
- Fixed a `window` issue in uuid.js.
flowchartTest
jos 9 years ago
parent
commit
7e0961ae73
9 changed files with 61 additions and 178 deletions
  1. +6
    -0
      HISTORY.md
  2. +8
    -15
      docs/dataset.html
  3. +2
    -2
      docs/dataview.html
  4. +19
    -124
      lib/DataSet.js
  5. +17
    -15
      lib/module/uuid.js
  6. +1
    -1
      lib/timeline/Core.js
  7. +3
    -3
      lib/timeline/Graph2d.js
  8. +5
    -5
      lib/timeline/Timeline.js
  9. +0
    -13
      lib/util.js

+ 6
- 0
HISTORY.md View File

@ -31,6 +31,12 @@ http://visjs.org
- Rebuilt the cluster system - Rebuilt the cluster system
### DataSet
- Dropped support for Google visualization DataTable.
- Dropped support for appending data returned by `DataSet.get()` to an existing
Array or DataTable.
## not yet released, version 3.12.1-SNAPSHOT ## not yet released, version 3.12.1-SNAPSHOT

+ 8
- 15
docs/dataset.html View File

@ -118,8 +118,7 @@ var data = new vis.DataSet([data] [, options])
</p> </p>
<p> <p>
The parameter <code>data</code> is optional and can be an Array or
<a href="https://developers.google.com/chart/interactive/docs/reference#DataTable" target="_blank">Google DataTable</a> with items.
The parameter <code>data</code> is optional and is an Array with items.
</p> </p>
<p> <p>
@ -245,10 +244,10 @@ var data = new vis.DataSet([data] [, options])
get(id [,options] [, data])<br> get(id [,options] [, data])<br>
get(ids [, options] [, data]) get(ids [, options] [, data])
</td> </td>
<td>Object | Array | DataTable</td>
<td>Object | Array</td>
<td> <td>
Get a single item, multiple items, or all items from the DataSet. Get a single item, multiple items, or all items from the DataSet.
Usage examples can be found in section <a href="#Getting_Data">Getting Data</a>, and the available <code>options</code> are described in section <a href="#Data_Selection">Data Selection</a>. If parameter <code>data</code> is provided, items will be appended to this array or table, which is required in case of Google DataTable.
Usage examples can be found in section <a href="#Getting_Data">Getting Data</a>, and the available <code>options</code> are described in section <a href="#Data_Selection">Data Selection</a>.
</td> </td>
</tr> </tr>
@ -600,10 +599,7 @@ The argument data can contain:
added. The item must contain an id. added. The item must contain an id.
</li> </li>
<li> <li>
An <code>Array</code> or
<code>google.visualization.DataTable</code> containing
a list with items to be added. Each item must contain
an id.
An <code>Array</code> containing a list with items to be added. Each item must contain an id.
</li> </li>
</ul> </ul>
@ -635,10 +631,7 @@ The argument data can contain:
updated. The item must contain an id. updated. The item must contain an id.
</li> </li>
<li> <li>
An <code>Array</code> or
<code>google.visualization.DataTable</code> containing
a list with items to be updated. Each item must contain
an id.
An <code>Array</code> containing a list with items to be updated. Each item must contain an id.
</li> </li>
</ul> </ul>
@ -720,7 +713,7 @@ Syntax:
</p> </p>
<pre class="prettyprint lang-js"> <pre class="prettyprint lang-js">
DataSet.get([id] [, options] [, data]);
DataSet.get([id] [, options]);
DataSet.getIds([options]); DataSet.getIds([options]);
DataSet.forEach(callback [, options]); DataSet.forEach(callback [, options]);
DataSet.map(callback [, options]); DataSet.map(callback [, options]);
@ -786,8 +779,8 @@ DataSet.map(callback [, options]);
<tr> <tr>
<td>returnType</td> <td>returnType</td>
<td>String</td> <td>String</td>
<td>Determine the type of output of the get function. Allowed values are <code>Array | Object | DataTable</code>.
The <code>DataTable</code> refers to a Google DataTable. The default returnType is an array. The object type will return a JSON object with the ID's as keys.</td>
<td>Determine the type of output of the get function. Allowed values are <code>'Array' | 'Object'</code>.
The default returnType is an Array. The Object type will return a JSON object with the ID's as keys.</td>
</tr> </tr>
</table> </table>

+ 2
- 2
docs/dataview.html View File

@ -176,10 +176,10 @@ var data = new vis.DataView(dataset, options)
get(id [,options] [, data])<br> get(id [,options] [, data])<br>
get(ids [, options] [, data]) get(ids [, options] [, data])
</td> </td>
<td>Object | Array | DataTable</td>
<td>Object | Array</td>
<td> <td>
Get a single item, multiple items, or all items from the DataView. Get a single item, multiple items, or all items from the DataView.
Usage examples can be found in section <a href="#Getting_Data">Getting Data</a>, and the available <code>options</code> are described in section <a href="#Data_Selection">Data Selection</a>. If parameter <code>data</code> is provided, items will be appended to this array or table, which is required in case of Google DataTable.
Usage examples can be found in section <a href="#Getting_Data">Getting Data</a>, and the available <code>options</code> are described in section <a href="#Data_Selection">Data Selection</a>.
</td> </td>
</tr> </tr>

+ 19
- 124
lib/DataSet.js View File

@ -29,7 +29,7 @@ var Queue = require('./Queue');
* - gives triggers upon changes in the data * - gives triggers upon changes in the data
* - can import/export data in various data formats * - can import/export data in various data formats
* *
* @param {Array | DataTable} [data] Optional array with initial data
* @param {Array} [data] Optional array with initial data
* @param {Object} [options] Available options: * @param {Object} [options] Available options:
* {String} fieldId Field name of the id in the * {String} fieldId Field name of the id in the
* items, 'id' by default. * items, 'id' by default.
@ -46,7 +46,7 @@ var Queue = require('./Queue');
// TODO: add a DataSet constructor DataSet(data, options) // TODO: add a DataSet constructor DataSet(data, options)
function DataSet (data, options) { function DataSet (data, options) {
// correctly read optional arguments // correctly read optional arguments
if (data && !Array.isArray(data) && !util.isDataTable(data)) {
if (data && !Array.isArray(data)) {
options = data; options = data;
data = null; data = null;
} }
@ -191,7 +191,7 @@ DataSet.prototype._trigger = function (event, params, senderId) {
/** /**
* Add data. * Add data.
* Adding an item will fail when there already is an item with the same id. * Adding an item will fail when there already is an item with the same id.
* @param {Object | Array | DataTable} data
* @param {Object | Array} data
* @param {String} [senderId] Optional sender id * @param {String} [senderId] Optional sender id
* @return {Array} addedIds Array with the ids of the added items * @return {Array} addedIds Array with the ids of the added items
*/ */
@ -207,20 +207,6 @@ DataSet.prototype.add = function (data, senderId) {
addedIds.push(id); addedIds.push(id);
} }
} }
else if (util.isDataTable(data)) {
// Google DataTable
var columns = this._getColumnNames(data);
for (var row = 0, rows = data.getNumberOfRows(); row < rows; row++) {
var item = {};
for (var col = 0, cols = columns.length; col < cols; col++) {
var field = columns[col];
item[field] = data.getValue(row, col);
}
id = me._addItem(item);
addedIds.push(id);
}
}
else if (data instanceof Object) { else if (data instanceof Object) {
// Single item // Single item
id = me._addItem(data); id = me._addItem(data);
@ -239,7 +225,7 @@ DataSet.prototype.add = function (data, senderId) {
/** /**
* Update existing items. When an item does not exist, it will be created * Update existing items. When an item does not exist, it will be created
* @param {Object | Array | DataTable} data
* @param {Object | Array} data
* @param {String} [senderId] Optional sender id * @param {String} [senderId] Optional sender id
* @return {Array} updatedIds The ids of the added or updated items * @return {Array} updatedIds The ids of the added or updated items
*/ */
@ -271,19 +257,6 @@ DataSet.prototype.update = function (data, senderId) {
addOrUpdate(data[i]); addOrUpdate(data[i]);
} }
} }
else if (util.isDataTable(data)) {
// Google DataTable
var columns = this._getColumnNames(data);
for (var row = 0, rows = data.getNumberOfRows(); row < rows; row++) {
var item = {};
for (var col = 0, cols = columns.length; col < cols; col++) {
var field = columns[col];
item[field] = data.getValue(row, col);
}
addOrUpdate(item);
}
}
else if (data instanceof Object) { else if (data instanceof Object) {
// Single item // Single item
addOrUpdate(data); addOrUpdate(data);
@ -309,75 +282,52 @@ DataSet.prototype.update = function (data, senderId) {
* *
* get() * get()
* get(options: Object) * get(options: Object)
* get(options: Object, data: Array | DataTable)
* *
* get(id: Number | String) * get(id: Number | String)
* get(id: Number | String, options: Object) * get(id: Number | String, options: Object)
* get(id: Number | String, options: Object, data: Array | DataTable)
* *
* get(ids: Number[] | String[]) * get(ids: Number[] | String[])
* get(ids: Number[] | String[], options: Object) * get(ids: Number[] | String[], options: Object)
* get(ids: Number[] | String[], options: Object, data: Array | DataTable)
* *
* Where: * Where:
* *
* {Number | String} id The id of an item * {Number | String} id The id of an item
* {Number[] | String{}} ids An array with ids of items * {Number[] | String{}} ids An array with ids of items
* {Object} options An Object with options. Available options: * {Object} options An Object with options. Available options:
* {String} [returnType] Type of data to be
* returned. Can be 'DataTable' or 'Array' (default)
* {Object.<String, String>} [type]
* {String[]} [fields] field names to be returned
* {function} [filter] filter items
* {String | function} [order] Order the items by
* a field name or custom sort function.
* {Array | DataTable} [data] If provided, items will be appended to this
* array or table. Required in case of Google
* DataTable.
*
* {String} [returnType] Type of data to be returned.
* Can be 'Array' (default) or 'Object'.
* {Object.<String, String>} [type]
* {String[]} [fields] field names to be returned
* {function} [filter] filter items
* {String | function} [order] Order the items by a field name or custom sort function.
* @throws Error * @throws Error
*/ */
DataSet.prototype.get = function (args) { DataSet.prototype.get = function (args) {
var me = this; var me = this;
// parse the arguments // parse the arguments
var id, ids, options, data;
var id, ids, options;
var firstType = util.getType(arguments[0]); var firstType = util.getType(arguments[0]);
if (firstType == 'String' || firstType == 'Number') { if (firstType == 'String' || firstType == 'Number') {
// get(id [, options] [, data])
// get(id [, options])
id = arguments[0]; id = arguments[0];
options = arguments[1]; options = arguments[1];
data = arguments[2];
} }
else if (firstType == 'Array') { else if (firstType == 'Array') {
// get(ids [, options] [, data])
// get(ids [, options])
ids = arguments[0]; ids = arguments[0];
options = arguments[1]; options = arguments[1];
data = arguments[2];
} }
else { else {
// get([, options] [, data])
// get([, options])
options = arguments[0]; options = arguments[0];
data = arguments[1];
} }
// determine the return type // determine the return type
var returnType; var returnType;
if (options && options.returnType) { if (options && options.returnType) {
var allowedValues = ["DataTable", "Array", "Object"];
returnType = allowedValues.indexOf(options.returnType) == -1 ? "Array" : options.returnType;
if (data && (returnType != util.getType(data))) {
throw new Error('Type of parameter "data" (' + util.getType(data) + ') ' +
'does not correspond with specified options.type (' + options.type + ')');
}
if (returnType == 'DataTable' && !util.isDataTable(data)) {
throw new Error('Parameter "data" must be a DataTable ' +
'when options.type is "DataTable"');
}
}
else if (data) {
returnType = (util.getType(data) == 'DataTable') ? 'DataTable' : 'Array';
var allowedValues = ['Array', 'Object'];
returnType = allowedValues.indexOf(options.returnType) == -1 ? 'Array' : options.returnType;
} }
else { else {
returnType = 'Array'; returnType = 'Array';
@ -436,21 +386,7 @@ DataSet.prototype.get = function (args) {
} }
// return the results // return the results
if (returnType == 'DataTable') {
var columns = this._getColumnNames(data);
if (id != undefined) {
// append a single item to the data table
me._appendRow(data, columns, item);
}
else {
// copy the items to the provided data table
for (i = 0; i < items.length; i++) {
me._appendRow(data, columns, items[i]);
}
}
return data;
}
else if (returnType == "Object") {
if (returnType == 'Object') {
var result = {}; var result = {};
for (i = 0; i < items.length; i++) { for (i = 0; i < items.length; i++) {
result[items[i].id] = items[i]; result[items[i].id] = items[i];
@ -458,24 +394,13 @@ DataSet.prototype.get = function (args) {
return result; return result;
} }
else { else {
// return an array
if (id != undefined) { if (id != undefined) {
// a single item // a single item
return item; return item;
} }
else { else {
// multiple items
if (data) {
// copy the items to the provided array
for (i = 0, len = items.length; i < len; i++) {
data.push(items[i]);
}
return data;
}
else {
// just return our array
return items;
}
// just return our array
return items;
} }
} }
}; };
@ -971,34 +896,4 @@ DataSet.prototype._updateItem = function (item) {
return id; return id;
}; };
/**
* Get an array with the column names of a Google DataTable
* @param {DataTable} dataTable
* @return {String[]} columnNames
* @private
*/
DataSet.prototype._getColumnNames = function (dataTable) {
var columns = [];
for (var col = 0, cols = dataTable.getNumberOfColumns(); col < cols; col++) {
columns[col] = dataTable.getColumnId(col) || dataTable.getColumnLabel(col);
}
return columns;
};
/**
* Append an item as a row to the dataTable
* @param dataTable
* @param columns
* @param item
* @private
*/
DataSet.prototype._appendRow = function (dataTable, columns, item) {
var row = dataTable.addRow();
for (var col = 0, cols = columns.length; col < cols; col++) {
var field = columns[col];
dataTable.setValue(row, col, item[field]);
}
};
module.exports = DataSet; module.exports = DataSet;

+ 17
- 15
lib/module/uuid.js View File

@ -1,8 +1,10 @@
var _rng; var _rng;
var globalVar = window !== undefined ? window : global;
if (globalVar.crypto && crypto.getRandomValues) {
var globalVar = typeof window !== 'undefined'
? window
: typeof global !== 'undefined' ? global : null;
if (globalVar && globalVar.crypto && crypto.getRandomValues) {
// WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto // WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto
// Moderately fast, high quality // Moderately fast, high quality
var _rnds8 = new Uint8Array(16); var _rnds8 = new Uint8Array(16);
@ -17,8 +19,8 @@ if (!_rng) {
// //
// If all else fails, use Math.random(). It's fast, but is of unspecified // If all else fails, use Math.random(). It's fast, but is of unspecified
// quality. // quality.
var _rnds = new Array(16);
_rng = function() {
var _rnds = new Array(16);
_rng = function () {
for (var i = 0, r; i < 16; i++) { for (var i = 0, r; i < 16; i++) {
if ((i & 0x03) === 0) r = Math.random() * 0x100000000; if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
_rnds[i] = r >>> ((i & 0x03) << 3) & 0xff; _rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
@ -52,7 +54,7 @@ function parse(s, buf, offset) {
var i = (buf && offset) || 0, ii = 0; var i = (buf && offset) || 0, ii = 0;
buf = buf || []; buf = buf || [];
s.toLowerCase().replace(/[0-9a-f]{2}/g, function(oct) {
s.toLowerCase().replace(/[0-9a-f]{2}/g, function (oct) {
if (ii < 16) { // Don't overflow! if (ii < 16) { // Don't overflow!
buf[i + ii++] = _hexToByte[oct]; buf[i + ii++] = _hexToByte[oct];
} }
@ -69,14 +71,14 @@ function parse(s, buf, offset) {
// **`unparse()` - Convert UUID byte array (ala parse()) into a string** // **`unparse()` - Convert UUID byte array (ala parse()) into a string**
function unparse(buf, offset) { function unparse(buf, offset) {
var i = offset || 0, bth = _byteToHex; var i = offset || 0, bth = _byteToHex;
return bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]];
return bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]];
} }
// **`v1()` - Generate time-based UUID** // **`v1()` - Generate time-based UUID**
@ -119,7 +121,7 @@ function v1(options, buf, offset) {
var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1;
// Time since last uuid creation (in msecs) // Time since last uuid creation (in msecs)
var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;
var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs) / 10000;
// Per 4.2.1.2, Bump clockseq on clock regression // Per 4.2.1.2, Bump clockseq on clock regression
if (dt < 0 && options.clockseq === undefined) { if (dt < 0 && options.clockseq === undefined) {

+ 1
- 1
lib/timeline/Core.js View File

@ -14,7 +14,7 @@ var CustomTime = require('./component/CustomTime');
/** /**
* Create a timeline visualization * Create a timeline visualization
* @param {HTMLElement} container * @param {HTMLElement} container
* @param {vis.DataSet | Array | google.visualization.DataTable} [items]
* @param {vis.DataSet | Array} [items]
* @param {Object} [options] See Core.setOptions for the available options. * @param {Object} [options] See Core.setOptions for the available options.
* @constructor * @constructor
*/ */

+ 3
- 3
lib/timeline/Graph2d.js View File

@ -13,7 +13,7 @@ var LineGraph = require('./component/LineGraph');
/** /**
* Create a timeline visualization * Create a timeline visualization
* @param {HTMLElement} container * @param {HTMLElement} container
* @param {vis.DataSet | Array | google.visualization.DataTable} [items]
* @param {vis.DataSet | Array} [items]
* @param {Object} [options] See Graph2d.setOptions for the available options. * @param {Object} [options] See Graph2d.setOptions for the available options.
* @constructor * @constructor
* @extends Core * @extends Core
@ -119,7 +119,7 @@ Graph2d.prototype = new Core();
/** /**
* Set items * Set items
* @param {vis.DataSet | Array | google.visualization.DataTable | null} items
* @param {vis.DataSet | Array | null} items
*/ */
Graph2d.prototype.setItems = function(items) { Graph2d.prototype.setItems = function(items) {
var initialLoad = (this.itemsData == null); var initialLoad = (this.itemsData == null);
@ -161,7 +161,7 @@ Graph2d.prototype.setItems = function(items) {
/** /**
* Set groups * Set groups
* @param {vis.DataSet | Array | google.visualization.DataTable} groups
* @param {vis.DataSet | Array} groups
*/ */
Graph2d.prototype.setGroups = function(groups) { Graph2d.prototype.setGroups = function(groups) {
// convert to type DataSet when needed // convert to type DataSet when needed

+ 5
- 5
lib/timeline/Timeline.js View File

@ -13,8 +13,8 @@ var ItemSet = require('./component/ItemSet');
/** /**
* Create a timeline visualization * Create a timeline visualization
* @param {HTMLElement} container * @param {HTMLElement} container
* @param {vis.DataSet | vis.DataView | Array | google.visualization.DataTable} [items]
* @param {vis.DataSet | vis.DataView | Array | google.visualization.DataTable} [groups]
* @param {vis.DataSet | vis.DataView | Array} [items]
* @param {vis.DataSet | vis.DataView | Array} [groups]
* @param {Object} [options] See Timeline.setOptions for the available options. * @param {Object} [options] See Timeline.setOptions for the available options.
* @constructor * @constructor
* @extends Core * @extends Core
@ -141,7 +141,7 @@ Timeline.prototype.redraw = function() {
/** /**
* Set items * Set items
* @param {vis.DataSet | Array | google.visualization.DataTable | null} items
* @param {vis.DataSet | Array | null} items
*/ */
Timeline.prototype.setItems = function(items) { Timeline.prototype.setItems = function(items) {
var initialLoad = (this.itemsData == null); var initialLoad = (this.itemsData == null);
@ -187,7 +187,7 @@ Timeline.prototype.setItems = function(items) {
/** /**
* Set groups * Set groups
* @param {vis.DataSet | Array | google.visualization.DataTable} groups
* @param {vis.DataSet | Array} groups
*/ */
Timeline.prototype.setGroups = function(groups) { Timeline.prototype.setGroups = function(groups) {
// convert to type DataSet when needed // convert to type DataSet when needed
@ -209,7 +209,7 @@ Timeline.prototype.setGroups = function(groups) {
/** /**
* Set both items and groups in one go * Set both items and groups in one go
* @param {{items: Array | vis.DataSet | google.visualization.DataTable, groups: Array | vis.DataSet | google.visualization.DataTable}} data
* @param {{items: Array | vis.DataSet, groups: Array | vis.DataSet}} data
*/ */
Timeline.prototype.setData = function (data) { Timeline.prototype.setData = function (data) {
if (data && data.groups) { if (data && data.groups) {

+ 0
- 13
lib/util.js View File

@ -75,18 +75,6 @@ exports.isDate = function(object) {
return false; return false;
}; };
/**
* Test whether given object is an instance of google.visualization.DataTable
* @param {*} object
* @return {Boolean} isDataTable
*/
exports.isDataTable = function(object) {
return (typeof (google) !== 'undefined') &&
(google.visualization) &&
(google.visualization.DataTable) &&
(object instanceof google.visualization.DataTable);
};
/** /**
* Create a semi UUID * Create a semi UUID
* source: http://stackoverflow.com/a/105074/1262753 * source: http://stackoverflow.com/a/105074/1262753
@ -96,7 +84,6 @@ exports.randomUUID = function() {
return uuid.v4(); return uuid.v4();
}; };
/** /**
* assign all keys of an object that are not nested objects to a certain value (used for color objects). * assign all keys of an object that are not nested objects to a certain value (used for color objects).
* @param obj * @param obj

Loading…
Cancel
Save