vis-rails 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -1
  3. data/README.md +2 -0
  4. data/lib/vis/rails/version.rb +1 -1
  5. data/vendor/assets/javascripts/module/exports-only-timeline.js +55 -0
  6. data/vendor/assets/javascripts/vis-only-timeline.js +23 -0
  7. data/vendor/assets/javascripts/vis.js +3 -3
  8. data/vendor/assets/stylesheets/vis-only-timeline.css +3 -0
  9. data/vendor/assets/vis/DataSet.js +106 -130
  10. data/vendor/assets/vis/DataView.js +35 -37
  11. data/vendor/assets/vis/graph/Edge.js +225 -45
  12. data/vendor/assets/vis/graph/Graph.js +120 -24
  13. data/vendor/assets/vis/graph/Node.js +16 -16
  14. data/vendor/assets/vis/graph/graphMixins/HierarchicalLayoutMixin.js +1 -1
  15. data/vendor/assets/vis/graph/graphMixins/ManipulationMixin.js +143 -0
  16. data/vendor/assets/vis/graph/graphMixins/SelectionMixin.js +81 -3
  17. data/vendor/assets/vis/graph3d/Graph3d.js +3306 -0
  18. data/vendor/assets/vis/module/exports.js +2 -3
  19. data/vendor/assets/vis/timeline/Range.js +93 -80
  20. data/vendor/assets/vis/timeline/Timeline.js +525 -428
  21. data/vendor/assets/vis/timeline/component/Component.js +19 -53
  22. data/vendor/assets/vis/timeline/component/CurrentTime.js +57 -25
  23. data/vendor/assets/vis/timeline/component/CustomTime.js +55 -19
  24. data/vendor/assets/vis/timeline/component/Group.js +47 -50
  25. data/vendor/assets/vis/timeline/component/ItemSet.js +402 -206
  26. data/vendor/assets/vis/timeline/component/TimeAxis.js +112 -169
  27. data/vendor/assets/vis/timeline/component/css/animation.css +33 -0
  28. data/vendor/assets/vis/timeline/component/css/currenttime.css +1 -1
  29. data/vendor/assets/vis/timeline/component/css/customtime.css +1 -1
  30. data/vendor/assets/vis/timeline/component/css/item.css +1 -11
  31. data/vendor/assets/vis/timeline/component/css/itemset.css +13 -18
  32. data/vendor/assets/vis/timeline/component/css/labelset.css +8 -6
  33. data/vendor/assets/vis/timeline/component/css/panel.css +56 -13
  34. data/vendor/assets/vis/timeline/component/css/timeaxis.css +15 -8
  35. data/vendor/assets/vis/timeline/component/item/Item.js +16 -15
  36. data/vendor/assets/vis/timeline/component/item/ItemBox.js +30 -30
  37. data/vendor/assets/vis/timeline/component/item/ItemPoint.js +20 -21
  38. data/vendor/assets/vis/timeline/component/item/ItemRange.js +23 -24
  39. data/vendor/assets/vis/timeline/component/item/ItemRangeOverflow.js +10 -10
  40. data/vendor/assets/vis/timeline/stack.js +5 -5
  41. data/vendor/assets/vis/util.js +81 -35
  42. metadata +7 -4
  43. data/vendor/assets/vis/timeline/component/Panel.js +0 -170
  44. data/vendor/assets/vis/timeline/component/RootPanel.js +0 -176
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d28f18ffa726cedf2df18f07ed3f34a5881b8693
4
- data.tar.gz: 716adb84278baadcd222bbecf802759ddd0a9eb2
3
+ metadata.gz: 1002e56b0744e4169ce63ab556d257a94cac683c
4
+ data.tar.gz: e3012aa0301eef513c00f21af009a1c2ff257108
5
5
  SHA512:
6
- metadata.gz: 90d77f98a4d5d2379703b87f96341180716d49e0e124bcc4d2fed368518255b5861863bf5efdd890ee8df7c98ecb753ccb89c40492928695959612cc1c0b38be
7
- data.tar.gz: 56d1c95072854f202bda9c12dcd197cba4c005009b05cce79f4250d096da5c346ce488d0f6bbd2b01508591074fcdc45e4fa457be32490106400d1b0b68fcd09
6
+ metadata.gz: ff7655bf5bc3ba371b9ee010a5de16f3de2181c4bdc658b552ab91e18108ab6c9868329a41ec50abdfb6d4a52816498c9257c23ddd3785a5a0e0e4801a3a3d1f
7
+ data.tar.gz: a70b60516ac5cd314bb23cc4ced33125bd0663d0471d849d347e24e995679f6f5d842c7bb8a866c2930b565f1a2e43fae1042546bf245dffc70ce4f8ff3adc23
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ## X.X.X
1
+ ## 1.0.2
2
2
  - https://github.com/almende/vis/blob/master/HISTORY.md
3
3
 
4
4
  ## 0.0.4
data/README.md CHANGED
@@ -25,6 +25,8 @@ Add to `app/assets/javascripts/application.js`:
25
25
  Add to `app/assets/stylesheets/application.css`:
26
26
 
27
27
  *= require vis
28
+
29
+ To load only Timeline component use `vis-only-timeline` instead of `vis` for both js and css
28
30
 
29
31
  Vis.js documentation:
30
32
 
@@ -1,5 +1,5 @@
1
1
  module Vis
2
2
  module Rails
3
- VERSION = "1.0.2"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -0,0 +1,55 @@
1
+ /**
2
+ * vis.js module exports
3
+ */
4
+ var vis = {
5
+ util: util,
6
+ moment: moment,
7
+
8
+ DataSet: DataSet,
9
+ DataView: DataView,
10
+ Range: Range,
11
+ stack: stack,
12
+ TimeStep: TimeStep,
13
+
14
+ components: {
15
+ items: {
16
+ Item: Item,
17
+ ItemBox: ItemBox,
18
+ ItemPoint: ItemPoint,
19
+ ItemRange: ItemRange
20
+ },
21
+
22
+ Component: Component,
23
+ ItemSet: ItemSet,
24
+ TimeAxis: TimeAxis
25
+ },
26
+
27
+ Timeline: Timeline
28
+ };
29
+
30
+ /**
31
+ * CommonJS module exports
32
+ */
33
+ if (typeof exports !== 'undefined') {
34
+ exports = vis;
35
+ }
36
+ if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
37
+ module.exports = vis;
38
+ }
39
+
40
+ /**
41
+ * AMD module exports
42
+ */
43
+ if (typeof(define) === 'function') {
44
+ define(function () {
45
+ return vis;
46
+ });
47
+ }
48
+
49
+ /**
50
+ * Window exports
51
+ */
52
+ if (typeof window !== 'undefined') {
53
+ // attach the module to the window, load as a regular javascript file
54
+ window['vis'] = vis;
55
+ }
@@ -0,0 +1,23 @@
1
+ //= require ../vis/module/header
2
+ //= require moment
3
+ //= require hammer
4
+ //= require ../component/emitter
5
+
6
+ //= require ../vis/shim
7
+ //= require ../vis/util
8
+ //= require ../vis/DataSet
9
+ //= require ../vis/DataView
10
+
11
+ //= require ../vis/timeline/stack
12
+ //= require ../vis/timeline/TimeStep
13
+ //= require ../vis/timeline/component/Component
14
+ //= require ../vis/timeline/Range
15
+ //= require ../vis/timeline/component/TimeAxis
16
+ //= require ../vis/timeline/component/CurrentTime
17
+ //= require ../vis/timeline/component/CustomTime
18
+ //= require_tree ../vis/timeline/component/item
19
+ //= require ../vis/timeline/component/ItemSet
20
+ //= require ../vis/timeline/component/Group
21
+ //= require ../vis/timeline/Timeline
22
+
23
+ //= require ./module/exports-only-timeline
@@ -10,10 +10,8 @@
10
10
 
11
11
  //= require ../vis/timeline/stack
12
12
  //= require ../vis/timeline/TimeStep
13
- //= require ../vis/timeline/Range
14
13
  //= require ../vis/timeline/component/Component
15
- //= require ../vis/timeline/component/Panel
16
- //= require ../vis/timeline/component/RootPanel
14
+ //= require ../vis/timeline/Range
17
15
  //= require ../vis/timeline/component/TimeAxis
18
16
  //= require ../vis/timeline/component/CurrentTime
19
17
  //= require ../vis/timeline/component/CustomTime
@@ -32,4 +30,6 @@
32
30
  //= require_tree ../vis/graph/graphMixins
33
31
  //= require ../vis/graph/Graph
34
32
 
33
+ //= require ../vis/graph3d/Graph3d
34
+
35
35
  //= require ../vis/module/exports
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require_tree ../vis/timeline/component/css
3
+ */
@@ -4,7 +4,7 @@
4
4
  * Usage:
5
5
  * var dataSet = new DataSet({
6
6
  * fieldId: '_id',
7
- * convert: {
7
+ * type: {
8
8
  * // ...
9
9
  * }
10
10
  * });
@@ -30,43 +30,46 @@
30
30
  * @param {Object} [options] Available options:
31
31
  * {String} fieldId Field name of the id in the
32
32
  * items, 'id' by default.
33
- * {Object.<String, String} convert
33
+ * {Object.<String, String} type
34
34
  * A map with field names as key,
35
35
  * and the field type as value.
36
36
  * @constructor DataSet
37
37
  */
38
38
  // TODO: add a DataSet constructor DataSet(data, options)
39
39
  function DataSet (data, options) {
40
- this.id = util.randomUUID();
41
-
42
40
  // correctly read optional arguments
43
41
  if (data && !Array.isArray(data) && !util.isDataTable(data)) {
44
42
  options = data;
45
43
  data = null;
46
44
  }
47
45
 
48
- this.options = options || {};
49
- this.data = {}; // map with data indexed by id
50
- this.fieldId = this.options.fieldId || 'id'; // name of the field containing id
51
- this.convert = {}; // field types by field name
52
- this.showInternalIds = this.options.showInternalIds || false; // show internal ids with the get function
46
+ this._options = options || {};
47
+ this._data = {}; // map with data indexed by id
48
+ this._fieldId = this._options.fieldId || 'id'; // name of the field containing id
49
+ this._type = {}; // internal field types (NOTE: this can differ from this._options.type)
53
50
 
54
- if (this.options.convert) {
55
- for (var field in this.options.convert) {
56
- if (this.options.convert.hasOwnProperty(field)) {
57
- var value = this.options.convert[field];
51
+ // all variants of a Date are internally stored as Date, so we can convert
52
+ // from everything to everything (also from ISODate to Number for example)
53
+ if (this._options.type) {
54
+ for (var field in this._options.type) {
55
+ if (this._options.type.hasOwnProperty(field)) {
56
+ var value = this._options.type[field];
58
57
  if (value == 'Date' || value == 'ISODate' || value == 'ASPDate') {
59
- this.convert[field] = 'Date';
58
+ this._type[field] = 'Date';
60
59
  }
61
60
  else {
62
- this.convert[field] = value;
61
+ this._type[field] = value;
63
62
  }
64
63
  }
65
64
  }
66
65
  }
67
66
 
68
- this.subscribers = {}; // event subscribers
69
- this.internalIds = {}; // internally generated id's
67
+ // TODO: deprecated since version 1.1.1 (or 2.0.0?)
68
+ if (this._options.convert) {
69
+ throw new Error('Option "convert" is deprecated. Use "type" instead.');
70
+ }
71
+
72
+ this._subscribers = {}; // event subscribers
70
73
 
71
74
  // add initial data when provided
72
75
  if (data) {
@@ -83,11 +86,11 @@ function DataSet (data, options) {
83
86
  * {Object | null} params
84
87
  * {String | Number} senderId
85
88
  */
86
- DataSet.prototype.on = function on (event, callback) {
87
- var subscribers = this.subscribers[event];
89
+ DataSet.prototype.on = function(event, callback) {
90
+ var subscribers = this._subscribers[event];
88
91
  if (!subscribers) {
89
92
  subscribers = [];
90
- this.subscribers[event] = subscribers;
93
+ this._subscribers[event] = subscribers;
91
94
  }
92
95
 
93
96
  subscribers.push({
@@ -103,10 +106,10 @@ DataSet.prototype.subscribe = DataSet.prototype.on;
103
106
  * @param {String} event
104
107
  * @param {function} callback
105
108
  */
106
- DataSet.prototype.off = function off(event, callback) {
107
- var subscribers = this.subscribers[event];
109
+ DataSet.prototype.off = function(event, callback) {
110
+ var subscribers = this._subscribers[event];
108
111
  if (subscribers) {
109
- this.subscribers[event] = subscribers.filter(function (listener) {
112
+ this._subscribers[event] = subscribers.filter(function (listener) {
110
113
  return (listener.callback != callback);
111
114
  });
112
115
  }
@@ -128,11 +131,11 @@ DataSet.prototype._trigger = function (event, params, senderId) {
128
131
  }
129
132
 
130
133
  var subscribers = [];
131
- if (event in this.subscribers) {
132
- subscribers = subscribers.concat(this.subscribers[event]);
134
+ if (event in this._subscribers) {
135
+ subscribers = subscribers.concat(this._subscribers[event]);
133
136
  }
134
- if ('*' in this.subscribers) {
135
- subscribers = subscribers.concat(this.subscribers['*']);
137
+ if ('*' in this._subscribers) {
138
+ subscribers = subscribers.concat(this._subscribers['*']);
136
139
  }
137
140
 
138
141
  for (var i = 0; i < subscribers.length; i++) {
@@ -155,7 +158,7 @@ DataSet.prototype.add = function (data, senderId) {
155
158
  id,
156
159
  me = this;
157
160
 
158
- if (data instanceof Array) {
161
+ if (Array.isArray(data)) {
159
162
  // Array
160
163
  for (var i = 0, len = data.length; i < len; i++) {
161
164
  id = me._addItem(data[i]);
@@ -202,11 +205,11 @@ DataSet.prototype.update = function (data, senderId) {
202
205
  var addedIds = [],
203
206
  updatedIds = [],
204
207
  me = this,
205
- fieldId = me.fieldId;
208
+ fieldId = me._fieldId;
206
209
 
207
210
  var addOrUpdate = function (item) {
208
211
  var id = item[fieldId];
209
- if (me.data[id]) {
212
+ if (me._data[id]) {
210
213
  // update item
211
214
  id = me._updateItem(item);
212
215
  updatedIds.push(id);
@@ -218,7 +221,7 @@ DataSet.prototype.update = function (data, senderId) {
218
221
  }
219
222
  };
220
223
 
221
- if (data instanceof Array) {
224
+ if (Array.isArray(data)) {
222
225
  // Array
223
226
  for (var i = 0, len = data.length; i < len; i++) {
224
227
  addOrUpdate(data[i]);
@@ -277,9 +280,9 @@ DataSet.prototype.update = function (data, senderId) {
277
280
  * {Number | String} id The id of an item
278
281
  * {Number[] | String{}} ids An array with ids of items
279
282
  * {Object} options An Object with options. Available options:
280
- * {String} [type] Type of data to be returned. Can
281
- * be 'DataTable' or 'Array' (default)
282
- * {Object.<String, String>} [convert]
283
+ * {String} [returnType] Type of data to be
284
+ * returned. Can be 'DataTable' or 'Array' (default)
285
+ * {Object.<String, String>} [type]
283
286
  * {String[]} [fields] field names to be returned
284
287
  * {function} [filter] filter items
285
288
  * {String | function} [order] Order the items by
@@ -292,7 +295,6 @@ DataSet.prototype.update = function (data, senderId) {
292
295
  */
293
296
  DataSet.prototype.get = function (args) {
294
297
  var me = this;
295
- var globalShowInternalIds = this.showInternalIds;
296
298
 
297
299
  // parse the arguments
298
300
  var id, ids, options, data;
@@ -316,42 +318,35 @@ DataSet.prototype.get = function (args) {
316
318
  }
317
319
 
318
320
  // determine the return type
319
- var type;
320
- if (options && options.type) {
321
- type = (options.type == 'DataTable') ? 'DataTable' : 'Array';
321
+ var returnType;
322
+ if (options && options.returnType) {
323
+ returnType = (options.returnType == 'DataTable') ? 'DataTable' : 'Array';
322
324
 
323
- if (data && (type != util.getType(data))) {
325
+ if (data && (returnType != util.getType(data))) {
324
326
  throw new Error('Type of parameter "data" (' + util.getType(data) + ') ' +
325
327
  'does not correspond with specified options.type (' + options.type + ')');
326
328
  }
327
- if (type == 'DataTable' && !util.isDataTable(data)) {
329
+ if (returnType == 'DataTable' && !util.isDataTable(data)) {
328
330
  throw new Error('Parameter "data" must be a DataTable ' +
329
331
  'when options.type is "DataTable"');
330
332
  }
331
333
  }
332
334
  else if (data) {
333
- type = (util.getType(data) == 'DataTable') ? 'DataTable' : 'Array';
335
+ returnType = (util.getType(data) == 'DataTable') ? 'DataTable' : 'Array';
334
336
  }
335
337
  else {
336
- type = 'Array';
337
- }
338
-
339
- // we allow the setting of this value for a single get request.
340
- if (options != undefined) {
341
- if (options.showInternalIds != undefined) {
342
- this.showInternalIds = options.showInternalIds;
343
- }
338
+ returnType = 'Array';
344
339
  }
345
340
 
346
341
  // build options
347
- var convert = options && options.convert || this.options.convert;
342
+ var type = options && options.type || this._options.type;
348
343
  var filter = options && options.filter;
349
344
  var items = [], item, itemId, i, len;
350
345
 
351
346
  // convert items
352
347
  if (id != undefined) {
353
348
  // return a single item
354
- item = me._getItem(id, convert);
349
+ item = me._getItem(id, type);
355
350
  if (filter && !filter(item)) {
356
351
  item = null;
357
352
  }
@@ -359,7 +354,7 @@ DataSet.prototype.get = function (args) {
359
354
  else if (ids != undefined) {
360
355
  // return a subset of items
361
356
  for (i = 0, len = ids.length; i < len; i++) {
362
- item = me._getItem(ids[i], convert);
357
+ item = me._getItem(ids[i], type);
363
358
  if (!filter || filter(item)) {
364
359
  items.push(item);
365
360
  }
@@ -367,9 +362,9 @@ DataSet.prototype.get = function (args) {
367
362
  }
368
363
  else {
369
364
  // return all items
370
- for (itemId in this.data) {
371
- if (this.data.hasOwnProperty(itemId)) {
372
- item = me._getItem(itemId, convert);
365
+ for (itemId in this._data) {
366
+ if (this._data.hasOwnProperty(itemId)) {
367
+ item = me._getItem(itemId, type);
373
368
  if (!filter || filter(item)) {
374
369
  items.push(item);
375
370
  }
@@ -377,9 +372,6 @@ DataSet.prototype.get = function (args) {
377
372
  }
378
373
  }
379
374
 
380
- // restore the global value of showInternalIds
381
- this.showInternalIds = globalShowInternalIds;
382
-
383
375
  // order the results
384
376
  if (options && options.order && id == undefined) {
385
377
  this._sort(items, options.order);
@@ -399,7 +391,7 @@ DataSet.prototype.get = function (args) {
399
391
  }
400
392
 
401
393
  // return the results
402
- if (type == 'DataTable') {
394
+ if (returnType == 'DataTable') {
403
395
  var columns = this._getColumnNames(data);
404
396
  if (id != undefined) {
405
397
  // append a single item to the data table
@@ -445,10 +437,10 @@ DataSet.prototype.get = function (args) {
445
437
  * @return {Array} ids
446
438
  */
447
439
  DataSet.prototype.getIds = function (options) {
448
- var data = this.data,
440
+ var data = this._data,
449
441
  filter = options && options.filter,
450
442
  order = options && options.order,
451
- convert = options && options.convert || this.options.convert,
443
+ type = options && options.type || this._options.type,
452
444
  i,
453
445
  len,
454
446
  id,
@@ -463,7 +455,7 @@ DataSet.prototype.getIds = function (options) {
463
455
  items = [];
464
456
  for (id in data) {
465
457
  if (data.hasOwnProperty(id)) {
466
- item = this._getItem(id, convert);
458
+ item = this._getItem(id, type);
467
459
  if (filter(item)) {
468
460
  items.push(item);
469
461
  }
@@ -473,16 +465,16 @@ DataSet.prototype.getIds = function (options) {
473
465
  this._sort(items, order);
474
466
 
475
467
  for (i = 0, len = items.length; i < len; i++) {
476
- ids[i] = items[i][this.fieldId];
468
+ ids[i] = items[i][this._fieldId];
477
469
  }
478
470
  }
479
471
  else {
480
472
  // create unordered list
481
473
  for (id in data) {
482
474
  if (data.hasOwnProperty(id)) {
483
- item = this._getItem(id, convert);
475
+ item = this._getItem(id, type);
484
476
  if (filter(item)) {
485
- ids.push(item[this.fieldId]);
477
+ ids.push(item[this._fieldId]);
486
478
  }
487
479
  }
488
480
  }
@@ -502,7 +494,7 @@ DataSet.prototype.getIds = function (options) {
502
494
  this._sort(items, order);
503
495
 
504
496
  for (i = 0, len = items.length; i < len; i++) {
505
- ids[i] = items[i][this.fieldId];
497
+ ids[i] = items[i][this._fieldId];
506
498
  }
507
499
  }
508
500
  else {
@@ -510,7 +502,7 @@ DataSet.prototype.getIds = function (options) {
510
502
  for (id in data) {
511
503
  if (data.hasOwnProperty(id)) {
512
504
  item = data[id];
513
- ids.push(item[this.fieldId]);
505
+ ids.push(item[this._fieldId]);
514
506
  }
515
507
  }
516
508
  }
@@ -523,7 +515,7 @@ DataSet.prototype.getIds = function (options) {
523
515
  * Execute a callback function for every item in the dataset.
524
516
  * @param {function} callback
525
517
  * @param {Object} [options] Available options:
526
- * {Object.<String, String>} [convert]
518
+ * {Object.<String, String>} [type]
527
519
  * {String[]} [fields] filter fields
528
520
  * {function} [filter] filter items
529
521
  * {String | function} [order] Order the items by
@@ -531,8 +523,8 @@ DataSet.prototype.getIds = function (options) {
531
523
  */
532
524
  DataSet.prototype.forEach = function (callback, options) {
533
525
  var filter = options && options.filter,
534
- convert = options && options.convert || this.options.convert,
535
- data = this.data,
526
+ type = options && options.type || this._options.type,
527
+ data = this._data,
536
528
  item,
537
529
  id;
538
530
 
@@ -542,7 +534,7 @@ DataSet.prototype.forEach = function (callback, options) {
542
534
 
543
535
  for (var i = 0, len = items.length; i < len; i++) {
544
536
  item = items[i];
545
- id = item[this.fieldId];
537
+ id = item[this._fieldId];
546
538
  callback(item, id);
547
539
  }
548
540
  }
@@ -550,7 +542,7 @@ DataSet.prototype.forEach = function (callback, options) {
550
542
  // unordered
551
543
  for (id in data) {
552
544
  if (data.hasOwnProperty(id)) {
553
- item = this._getItem(id, convert);
545
+ item = this._getItem(id, type);
554
546
  if (!filter || filter(item)) {
555
547
  callback(item, id);
556
548
  }
@@ -563,7 +555,7 @@ DataSet.prototype.forEach = function (callback, options) {
563
555
  * Map every item in the dataset.
564
556
  * @param {function} callback
565
557
  * @param {Object} [options] Available options:
566
- * {Object.<String, String>} [convert]
558
+ * {Object.<String, String>} [type]
567
559
  * {String[]} [fields] filter fields
568
560
  * {function} [filter] filter items
569
561
  * {String | function} [order] Order the items by
@@ -572,15 +564,15 @@ DataSet.prototype.forEach = function (callback, options) {
572
564
  */
573
565
  DataSet.prototype.map = function (callback, options) {
574
566
  var filter = options && options.filter,
575
- convert = options && options.convert || this.options.convert,
567
+ type = options && options.type || this._options.type,
576
568
  mappedItems = [],
577
- data = this.data,
569
+ data = this._data,
578
570
  item;
579
571
 
580
572
  // convert and filter items
581
573
  for (var id in data) {
582
574
  if (data.hasOwnProperty(id)) {
583
- item = this._getItem(id, convert);
575
+ item = this._getItem(id, type);
584
576
  if (!filter || filter(item)) {
585
577
  mappedItems.push(callback(item, id));
586
578
  }
@@ -652,7 +644,7 @@ DataSet.prototype.remove = function (id, senderId) {
652
644
  var removedIds = [],
653
645
  i, len, removedId;
654
646
 
655
- if (id instanceof Array) {
647
+ if (Array.isArray(id)) {
656
648
  for (i = 0, len = id.length; i < len; i++) {
657
649
  removedId = this._remove(id[i]);
658
650
  if (removedId != null) {
@@ -682,17 +674,15 @@ DataSet.prototype.remove = function (id, senderId) {
682
674
  */
683
675
  DataSet.prototype._remove = function (id) {
684
676
  if (util.isNumber(id) || util.isString(id)) {
685
- if (this.data[id]) {
686
- delete this.data[id];
687
- delete this.internalIds[id];
677
+ if (this._data[id]) {
678
+ delete this._data[id];
688
679
  return id;
689
680
  }
690
681
  }
691
682
  else if (id instanceof Object) {
692
- var itemId = id[this.fieldId];
693
- if (itemId && this.data[itemId]) {
694
- delete this.data[itemId];
695
- delete this.internalIds[itemId];
683
+ var itemId = id[this._fieldId];
684
+ if (itemId && this._data[itemId]) {
685
+ delete this._data[itemId];
696
686
  return itemId;
697
687
  }
698
688
  }
@@ -705,10 +695,9 @@ DataSet.prototype._remove = function (id) {
705
695
  * @return {Array} removedIds The ids of all removed items
706
696
  */
707
697
  DataSet.prototype.clear = function (senderId) {
708
- var ids = Object.keys(this.data);
698
+ var ids = Object.keys(this._data);
709
699
 
710
- this.data = {};
711
- this.internalIds = {};
700
+ this._data = {};
712
701
 
713
702
  this._trigger('remove', {items: ids}, senderId);
714
703
 
@@ -721,7 +710,7 @@ DataSet.prototype.clear = function (senderId) {
721
710
  * @return {Object | null} item Item containing max value, or null if no items
722
711
  */
723
712
  DataSet.prototype.max = function (field) {
724
- var data = this.data,
713
+ var data = this._data,
725
714
  max = null,
726
715
  maxField = null;
727
716
 
@@ -745,7 +734,7 @@ DataSet.prototype.max = function (field) {
745
734
  * @return {Object | null} item Item containing max value, or null if no items
746
735
  */
747
736
  DataSet.prototype.min = function (field) {
748
- var data = this.data,
737
+ var data = this._data,
749
738
  min = null,
750
739
  minField = null;
751
740
 
@@ -771,17 +760,18 @@ DataSet.prototype.min = function (field) {
771
760
  * The returned array is unordered.
772
761
  */
773
762
  DataSet.prototype.distinct = function (field) {
774
- var data = this.data,
775
- values = [],
776
- fieldType = this.options.convert[field],
777
- count = 0;
763
+ var data = this._data;
764
+ var values = [];
765
+ var fieldType = this._options.type && this._options.type[field] || null;
766
+ var count = 0;
767
+ var i;
778
768
 
779
769
  for (var prop in data) {
780
770
  if (data.hasOwnProperty(prop)) {
781
771
  var item = data[prop];
782
- var value = util.convert(item[field], fieldType);
772
+ var value = item[field];
783
773
  var exists = false;
784
- for (var i = 0; i < count; i++) {
774
+ for (i = 0; i < count; i++) {
785
775
  if (values[i] == value) {
786
776
  exists = true;
787
777
  break;
@@ -794,6 +784,12 @@ DataSet.prototype.distinct = function (field) {
794
784
  }
795
785
  }
796
786
 
787
+ if (fieldType) {
788
+ for (i = 0; i < values.length; i++) {
789
+ values[i] = util.convert(values[i], fieldType);
790
+ }
791
+ }
792
+
797
793
  return values;
798
794
  };
799
795
 
@@ -804,11 +800,11 @@ DataSet.prototype.distinct = function (field) {
804
800
  * @private
805
801
  */
806
802
  DataSet.prototype._addItem = function (item) {
807
- var id = item[this.fieldId];
803
+ var id = item[this._fieldId];
808
804
 
809
805
  if (id != undefined) {
810
806
  // check whether this id is already taken
811
- if (this.data[id]) {
807
+ if (this._data[id]) {
812
808
  // item already exists
813
809
  throw new Error('Cannot add item: item with id ' + id + ' already exists');
814
810
  }
@@ -816,18 +812,17 @@ DataSet.prototype._addItem = function (item) {
816
812
  else {
817
813
  // generate an id
818
814
  id = util.randomUUID();
819
- item[this.fieldId] = id;
820
- this.internalIds[id] = item;
815
+ item[this._fieldId] = id;
821
816
  }
822
817
 
823
818
  var d = {};
824
819
  for (var field in item) {
825
820
  if (item.hasOwnProperty(field)) {
826
- var fieldType = this.convert[field]; // type may be undefined
821
+ var fieldType = this._type[field]; // type may be undefined
827
822
  d[field] = util.convert(item[field], fieldType);
828
823
  }
829
824
  }
830
- this.data[id] = d;
825
+ this._data[id] = d;
831
826
 
832
827
  return id;
833
828
  };
@@ -835,31 +830,26 @@ DataSet.prototype._addItem = function (item) {
835
830
  /**
836
831
  * Get an item. Fields can be converted to a specific type
837
832
  * @param {String} id
838
- * @param {Object.<String, String>} [convert] field types to convert
833
+ * @param {Object.<String, String>} [types] field types to convert
839
834
  * @return {Object | null} item
840
835
  * @private
841
836
  */
842
- DataSet.prototype._getItem = function (id, convert) {
837
+ DataSet.prototype._getItem = function (id, types) {
843
838
  var field, value;
844
839
 
845
840
  // get the item from the dataset
846
- var raw = this.data[id];
841
+ var raw = this._data[id];
847
842
  if (!raw) {
848
843
  return null;
849
844
  }
850
845
 
851
846
  // convert the items field types
852
- var converted = {},
853
- fieldId = this.fieldId,
854
- internalIds = this.internalIds;
855
- if (convert) {
847
+ var converted = {};
848
+ if (types) {
856
849
  for (field in raw) {
857
850
  if (raw.hasOwnProperty(field)) {
858
851
  value = raw[field];
859
- // output all fields, except internal ids
860
- if ((field != fieldId) || (!(value in internalIds) || this.showInternalIds)) {
861
- converted[field] = util.convert(value, convert[field]);
862
- }
852
+ converted[field] = util.convert(value, types[field]);
863
853
  }
864
854
  }
865
855
  }
@@ -868,10 +858,7 @@ DataSet.prototype._getItem = function (id, convert) {
868
858
  for (field in raw) {
869
859
  if (raw.hasOwnProperty(field)) {
870
860
  value = raw[field];
871
- // output all fields, except internal ids
872
- if ((field != fieldId) || (!(value in internalIds) || this.showInternalIds)) {
873
- converted[field] = value;
874
- }
861
+ converted[field] = value;
875
862
  }
876
863
  }
877
864
  }
@@ -887,11 +874,11 @@ DataSet.prototype._getItem = function (id, convert) {
887
874
  * @private
888
875
  */
889
876
  DataSet.prototype._updateItem = function (item) {
890
- var id = item[this.fieldId];
877
+ var id = item[this._fieldId];
891
878
  if (id == undefined) {
892
879
  throw new Error('Cannot update item: item has no id (item: ' + JSON.stringify(item) + ')');
893
880
  }
894
- var d = this.data[id];
881
+ var d = this._data[id];
895
882
  if (!d) {
896
883
  // item doesn't exist
897
884
  throw new Error('Cannot update item: no item with id ' + id + ' found');
@@ -900,7 +887,7 @@ DataSet.prototype._updateItem = function (item) {
900
887
  // merge with current item
901
888
  for (var field in item) {
902
889
  if (item.hasOwnProperty(field)) {
903
- var fieldType = this.convert[field]; // type may be undefined
890
+ var fieldType = this._type[field]; // type may be undefined
904
891
  d[field] = util.convert(item[field], fieldType);
905
892
  }
906
893
  }
@@ -908,17 +895,6 @@ DataSet.prototype._updateItem = function (item) {
908
895
  return id;
909
896
  };
910
897
 
911
- /**
912
- * check if an id is an internal or external id
913
- * @param id
914
- * @returns {boolean}
915
- * @private
916
- */
917
- DataSet.prototype.isInternalId = function(id) {
918
- return (id in this.internalIds);
919
- };
920
-
921
-
922
898
  /**
923
899
  * Get an array with the column names of a Google DataTable
924
900
  * @param {DataTable} dataTable