diff --git a/HISTORY.md b/HISTORY.md index 75d98f06..343f0f39 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -31,6 +31,12 @@ http://visjs.org - 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 diff --git a/docs/dataset.html b/docs/dataset.html index 81152644..1a7c5d8b 100644 --- a/docs/dataset.html +++ b/docs/dataset.html @@ -118,8 +118,7 @@ var data = new vis.DataSet([data] [, options])
- The parameter data
is optional and can be an Array or
- Google DataTable with items.
+ The parameter data
is optional and is an Array with items.
@@ -245,10 +244,10 @@ var data = new vis.DataSet([data] [, options])
get(id [,options] [, data])
get(ids [, options] [, data])
-
options
are described in section Data Selection. If parameter data
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 Getting Data, and the available options
are described in section Data Selection.
data
can contain:
added. The item must contain an id.
Array
or
- google.visualization.DataTable
containing
- a list with items to be added. Each item must contain
- an id.
+ An Array
containing a list with items to be added. Each item must contain an id.
data
can contain:
updated. The item must contain an id.
Array
or
- google.visualization.DataTable
containing
- a list with items to be updated. Each item must contain
- an id.
+ An Array
containing a list with items to be updated. Each item must contain an id.
-DataSet.get([id] [, options] [, data]); +DataSet.get([id] [, options]); DataSet.getIds([options]); DataSet.forEach(callback [, options]); DataSet.map(callback [, options]); @@ -786,8 +779,8 @@ DataSet.map(callback [, options]);diff --git a/docs/dataview.html b/docs/dataview.html index 28e3ec6c..df20795f 100644 --- a/docs/dataview.html +++ b/docs/dataview.html @@ -176,10 +176,10 @@ var data = new vis.DataView(dataset, options) get(id [,options] [, data]) returnType String -Determine the type of output of the get function. Allowed values are +Array | Object | DataTable
. - TheDataTable
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.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.
get(ids [, options] [, data]) -Object | Array | DataTable +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 diff --git a/lib/DataSet.js b/lib/DataSet.js index 5675beff..98558bee 100644 --- a/lib/DataSet.js +++ b/lib/DataSet.js @@ -29,7 +29,7 @@ var Queue = require('./Queue'); * - gives triggers upon changes in the data * - 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: * {String} fieldId Field name of the id in the * items, 'id' by default. @@ -46,7 +46,7 @@ var Queue = require('./Queue'); // TODO: add a DataSet constructor DataSet(data, options) function DataSet (data, options) { // correctly read optional arguments - if (data && !Array.isArray(data) && !util.isDataTable(data)) { + if (data && !Array.isArray(data)) { options = data; data = null; } @@ -191,7 +191,7 @@ DataSet.prototype._trigger = function (event, params, senderId) { /** * Add data. * 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 * @return {Array} addedIds Array with the ids of the added items */ @@ -207,20 +207,6 @@ DataSet.prototype.add = function (data, senderId) { 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) { // Single item 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 - * @param {Object | Array | DataTable} data + * @param {Object | Array} data * @param {String} [senderId] Optional sender id * @return {Array} updatedIds The ids of the added or updated items */ @@ -271,19 +257,6 @@ DataSet.prototype.update = function (data, senderId) { 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) { // Single item addOrUpdate(data); @@ -309,75 +282,52 @@ DataSet.prototype.update = function (data, senderId) { * * get() * get(options: Object) - * get(options: Object, data: Array | DataTable) * * get(id: Number | String) * get(id: Number | String, options: Object) - * get(id: Number | String, options: Object, data: Array | DataTable) * * get(ids: Number[] | String[]) * get(ids: Number[] | String[], options: Object) - * get(ids: Number[] | String[], options: Object, data: Array | DataTable) * * Where: * * {Number | String} id The id of an item * {Number[] | String{}} ids An array with ids of items * {Object} options An Object with options. Available options: - * {String} [returnType] Type of data to be - * returned. Can be 'DataTable' or 'Array' (default) - * {Object.options
are described in section Data Selection. If parameterdata
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 Getting Data, and the availableoptions
are described in section Data Selection.} [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. } [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 */ DataSet.prototype.get = function (args) { var me = this; // parse the arguments - var id, ids, options, data; + var id, ids, options; var firstType = util.getType(arguments[0]); if (firstType == 'String' || firstType == 'Number') { - // get(id [, options] [, data]) + // get(id [, options]) id = arguments[0]; options = arguments[1]; - data = arguments[2]; } else if (firstType == 'Array') { - // get(ids [, options] [, data]) + // get(ids [, options]) ids = arguments[0]; options = arguments[1]; - data = arguments[2]; } else { - // get([, options] [, data]) + // get([, options]) options = arguments[0]; - data = arguments[1]; } // determine the return type var 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 { returnType = 'Array'; @@ -436,21 +386,7 @@ DataSet.prototype.get = function (args) { } // 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 = {}; for (i = 0; i < items.length; i++) { result[items[i].id] = items[i]; @@ -458,24 +394,13 @@ DataSet.prototype.get = function (args) { return result; } else { - // return an array if (id != undefined) { // a single item return item; } 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; }; -/** - * 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; diff --git a/lib/module/uuid.js b/lib/module/uuid.js index eedbd934..e44dd84b 100644 --- a/lib/module/uuid.js +++ b/lib/module/uuid.js @@ -1,8 +1,10 @@ - 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 // Moderately fast, high quality 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 // quality. - var _rnds = new Array(16); - _rng = function() { + var _rnds = new Array(16); + _rng = function () { for (var i = 0, r; i < 16; i++) { if ((i & 0x03) === 0) r = Math.random() * 0x100000000; _rnds[i] = r >>> ((i & 0x03) << 3) & 0xff; @@ -52,7 +54,7 @@ function parse(s, buf, offset) { var i = (buf && offset) || 0, ii = 0; 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! buf[i + ii++] = _hexToByte[oct]; } @@ -69,14 +71,14 @@ function parse(s, buf, offset) { // **`unparse()` - Convert UUID byte array (ala parse()) into a string** function unparse(buf, offset) { 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** @@ -119,7 +121,7 @@ function v1(options, buf, offset) { var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; // 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 if (dt < 0 && options.clockseq === undefined) { diff --git a/lib/timeline/Core.js b/lib/timeline/Core.js index e255251f..f5b8428c 100644 --- a/lib/timeline/Core.js +++ b/lib/timeline/Core.js @@ -14,7 +14,7 @@ var CustomTime = require('./component/CustomTime'); /** * Create a timeline visualization * @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. * @constructor */ diff --git a/lib/timeline/Graph2d.js b/lib/timeline/Graph2d.js index 75b3c3f5..80e720aa 100644 --- a/lib/timeline/Graph2d.js +++ b/lib/timeline/Graph2d.js @@ -13,7 +13,7 @@ var LineGraph = require('./component/LineGraph'); /** * Create a timeline visualization * @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. * @constructor * @extends Core @@ -119,7 +119,7 @@ Graph2d.prototype = new Core(); /** * Set items - * @param {vis.DataSet | Array | google.visualization.DataTable | null} items + * @param {vis.DataSet | Array | null} items */ Graph2d.prototype.setItems = function(items) { var initialLoad = (this.itemsData == null); @@ -161,7 +161,7 @@ Graph2d.prototype.setItems = function(items) { /** * Set groups - * @param {vis.DataSet | Array | google.visualization.DataTable} groups + * @param {vis.DataSet | Array} groups */ Graph2d.prototype.setGroups = function(groups) { // convert to type DataSet when needed diff --git a/lib/timeline/Timeline.js b/lib/timeline/Timeline.js index 99714624..ef27b5e5 100644 --- a/lib/timeline/Timeline.js +++ b/lib/timeline/Timeline.js @@ -13,8 +13,8 @@ var ItemSet = require('./component/ItemSet'); /** * Create a timeline visualization * @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. * @constructor * @extends Core @@ -141,7 +141,7 @@ Timeline.prototype.redraw = function() { /** * Set items - * @param {vis.DataSet | Array | google.visualization.DataTable | null} items + * @param {vis.DataSet | Array | null} items */ Timeline.prototype.setItems = function(items) { var initialLoad = (this.itemsData == null); @@ -187,7 +187,7 @@ Timeline.prototype.setItems = function(items) { /** * Set groups - * @param {vis.DataSet | Array | google.visualization.DataTable} groups + * @param {vis.DataSet | Array} groups */ Timeline.prototype.setGroups = function(groups) { // convert to type DataSet when needed @@ -209,7 +209,7 @@ Timeline.prototype.setGroups = function(groups) { /** * 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) { if (data && data.groups) { diff --git a/lib/util.js b/lib/util.js index 6b8ca6d4..59158666 100644 --- a/lib/util.js +++ b/lib/util.js @@ -75,18 +75,6 @@ exports.isDate = function(object) { 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 * source: http://stackoverflow.com/a/105074/1262753 @@ -96,7 +84,6 @@ exports.randomUUID = function() { return uuid.v4(); }; - /** * assign all keys of an object that are not nested objects to a certain value (used for color objects). * @param obj