vis-rails 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vis/rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/vis.js +26 -26
  4. metadata +16 -85
  5. data/vendor/assets/vis/DataSet.js +0 -926
  6. data/vendor/assets/vis/DataView.js +0 -283
  7. data/vendor/assets/vis/graph/Edge.js +0 -957
  8. data/vendor/assets/vis/graph/Graph.js +0 -2291
  9. data/vendor/assets/vis/graph/Groups.js +0 -80
  10. data/vendor/assets/vis/graph/Images.js +0 -41
  11. data/vendor/assets/vis/graph/Node.js +0 -966
  12. data/vendor/assets/vis/graph/Popup.js +0 -132
  13. data/vendor/assets/vis/graph/css/graph-manipulation.css +0 -128
  14. data/vendor/assets/vis/graph/css/graph-navigation.css +0 -66
  15. data/vendor/assets/vis/graph/dotparser.js +0 -829
  16. data/vendor/assets/vis/graph/graphMixins/ClusterMixin.js +0 -1143
  17. data/vendor/assets/vis/graph/graphMixins/HierarchicalLayoutMixin.js +0 -311
  18. data/vendor/assets/vis/graph/graphMixins/ManipulationMixin.js +0 -576
  19. data/vendor/assets/vis/graph/graphMixins/MixinLoader.js +0 -199
  20. data/vendor/assets/vis/graph/graphMixins/NavigationMixin.js +0 -205
  21. data/vendor/assets/vis/graph/graphMixins/SectorsMixin.js +0 -552
  22. data/vendor/assets/vis/graph/graphMixins/SelectionMixin.js +0 -648
  23. data/vendor/assets/vis/graph/graphMixins/physics/BarnesHut.js +0 -398
  24. data/vendor/assets/vis/graph/graphMixins/physics/HierarchialRepulsion.js +0 -64
  25. data/vendor/assets/vis/graph/graphMixins/physics/PhysicsMixin.js +0 -697
  26. data/vendor/assets/vis/graph/graphMixins/physics/Repulsion.js +0 -66
  27. data/vendor/assets/vis/graph/img/acceptDeleteIcon.png +0 -0
  28. data/vendor/assets/vis/graph/img/addNodeIcon.png +0 -0
  29. data/vendor/assets/vis/graph/img/backIcon.png +0 -0
  30. data/vendor/assets/vis/graph/img/connectIcon.png +0 -0
  31. data/vendor/assets/vis/graph/img/cross.png +0 -0
  32. data/vendor/assets/vis/graph/img/cross2.png +0 -0
  33. data/vendor/assets/vis/graph/img/deleteIcon.png +0 -0
  34. data/vendor/assets/vis/graph/img/downArrow.png +0 -0
  35. data/vendor/assets/vis/graph/img/editIcon.png +0 -0
  36. data/vendor/assets/vis/graph/img/leftArrow.png +0 -0
  37. data/vendor/assets/vis/graph/img/minus.png +0 -0
  38. data/vendor/assets/vis/graph/img/plus.png +0 -0
  39. data/vendor/assets/vis/graph/img/rightArrow.png +0 -0
  40. data/vendor/assets/vis/graph/img/upArrow.png +0 -0
  41. data/vendor/assets/vis/graph/img/zoomExtends.png +0 -0
  42. data/vendor/assets/vis/graph/shapes.js +0 -225
  43. data/vendor/assets/vis/graph3d/Graph3d.js +0 -3306
  44. data/vendor/assets/vis/module/exports.js +0 -65
  45. data/vendor/assets/vis/module/header.js +0 -24
  46. data/vendor/assets/vis/module/imports.js +0 -31
  47. data/vendor/assets/vis/shim.js +0 -252
  48. data/vendor/assets/vis/timeline/Range.js +0 -532
  49. data/vendor/assets/vis/timeline/TimeStep.js +0 -466
  50. data/vendor/assets/vis/timeline/Timeline.js +0 -851
  51. data/vendor/assets/vis/timeline/component/Component.js +0 -52
  52. data/vendor/assets/vis/timeline/component/CurrentTime.js +0 -128
  53. data/vendor/assets/vis/timeline/component/CustomTime.js +0 -182
  54. data/vendor/assets/vis/timeline/component/Group.js +0 -470
  55. data/vendor/assets/vis/timeline/component/ItemSet.js +0 -1332
  56. data/vendor/assets/vis/timeline/component/TimeAxis.js +0 -389
  57. data/vendor/assets/vis/timeline/component/css/animation.css +0 -33
  58. data/vendor/assets/vis/timeline/component/css/currenttime.css +0 -5
  59. data/vendor/assets/vis/timeline/component/css/customtime.css +0 -6
  60. data/vendor/assets/vis/timeline/component/css/item.css +0 -107
  61. data/vendor/assets/vis/timeline/component/css/itemset.css +0 -33
  62. data/vendor/assets/vis/timeline/component/css/labelset.css +0 -36
  63. data/vendor/assets/vis/timeline/component/css/panel.css +0 -71
  64. data/vendor/assets/vis/timeline/component/css/timeaxis.css +0 -48
  65. data/vendor/assets/vis/timeline/component/css/timeline.css +0 -2
  66. data/vendor/assets/vis/timeline/component/item/Item.js +0 -139
  67. data/vendor/assets/vis/timeline/component/item/ItemBox.js +0 -230
  68. data/vendor/assets/vis/timeline/component/item/ItemPoint.js +0 -190
  69. data/vendor/assets/vis/timeline/component/item/ItemRange.js +0 -262
  70. data/vendor/assets/vis/timeline/component/item/ItemRangeOverflow.js +0 -57
  71. data/vendor/assets/vis/timeline/img/delete.png +0 -0
  72. data/vendor/assets/vis/timeline/stack.js +0 -112
  73. data/vendor/assets/vis/util.js +0 -990
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1002e56b0744e4169ce63ab556d257a94cac683c
4
- data.tar.gz: e3012aa0301eef513c00f21af009a1c2ff257108
3
+ metadata.gz: 7e26e8d73439c435c7cb51f91ae5d907817ddc96
4
+ data.tar.gz: df482a44d381096b3da2d69080253274dd1b0a70
5
5
  SHA512:
6
- metadata.gz: ff7655bf5bc3ba371b9ee010a5de16f3de2181c4bdc658b552ab91e18108ab6c9868329a41ec50abdfb6d4a52816498c9257c23ddd3785a5a0e0e4801a3a3d1f
7
- data.tar.gz: a70b60516ac5cd314bb23cc4ced33125bd0663d0471d849d347e24e995679f6f5d842c7bb8a866c2930b565f1a2e43fae1042546bf245dffc70ce4f8ff3adc23
6
+ metadata.gz: b5aca05a594565f770285fd032a79c43f92e737eb25ae1603d55a5ff283c86033672cdecf312bff6cac2baa11e1f9243439386f77972a0385874b6ddf0a6c5d1
7
+ data.tar.gz: a4bca7252c6657758993f574fd400ab468a781bcdb8e36031664a49ba525dfdae08df623839b33710eb0cf21232907246aceecf43ce0a460b6a6a05510dd6ed4
@@ -1,5 +1,5 @@
1
1
  module Vis
2
2
  module Rails
3
- VERSION = "2.0.0"
3
+ VERSION = "2.0.1"
4
4
  end
5
5
  end
@@ -1,35 +1,35 @@
1
- //= require ../vis/module/header
1
+ //= require_relative ../vis/module/header
2
2
  //= require moment
3
3
  //= require hammer
4
- //= require ../component/emitter
4
+ //= require_relative ../component/emitter
5
5
 
6
- //= require ../vis/shim
7
- //= require ../vis/util
8
- //= require ../vis/DataSet
9
- //= require ../vis/DataView
6
+ //= require_relative ../vis/shim
7
+ //= require_relative ../vis/util
8
+ //= require_relative ../vis/DataSet
9
+ //= require_relative ../vis/DataView
10
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
11
+ //= require_relative ../vis/timeline/stack
12
+ //= require_relative ../vis/timeline/TimeStep
13
+ //= require_relative ../vis/timeline/component/Component
14
+ //= require_relative ../vis/timeline/Range
15
+ //= require_relative ../vis/timeline/component/TimeAxis
16
+ //= require_relative ../vis/timeline/component/CurrentTime
17
+ //= require_relative ../vis/timeline/component/CustomTime
18
18
  //= require_tree ../vis/timeline/component/item
19
- //= require ../vis/timeline/component/ItemSet
20
- //= require ../vis/timeline/component/Group
21
- //= require ../vis/timeline/Timeline
19
+ //= require_relative ../vis/timeline/component/ItemSet
20
+ //= require_relative ../vis/timeline/component/Group
21
+ //= require_relative ../vis/timeline/Timeline
22
22
 
23
- //= require ../vis/graph/dotparser
24
- //= require ../vis/graph/shapes
25
- //= require ../vis/graph/Node
26
- //= require ../vis/graph/Edge
27
- //= require ../vis/graph/Popup
28
- //= require ../vis/graph/Groups
29
- //= require ../vis/graph/Images
23
+ //= require_relative ../vis/graph/dotparser
24
+ //= require_relative ../vis/graph/shapes
25
+ //= require_relative ../vis/graph/Node
26
+ //= require_relative ../vis/graph/Edge
27
+ //= require_relative ../vis/graph/Popup
28
+ //= require_relative ../vis/graph/Groups
29
+ //= require_relative ../vis/graph/Images
30
30
  //= require_tree ../vis/graph/graphMixins
31
- //= require ../vis/graph/Graph
31
+ //= require_relative ../vis/graph/Graph
32
32
 
33
- //= require ../vis/graph3d/Graph3d
33
+ //= require_relative ../vis/graph3d/Graph3d
34
34
 
35
- //= require ../vis/module/exports
35
+ //= require_relative ../vis/module/exports
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vis-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - AlexVangelov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-27 00:00:00.000000000 Z
11
+ date: 2015-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: momentjs-rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hammerjs-rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: This gem provides Rails driver for http://visjs.org browser-based visualization
@@ -74,9 +74,9 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - .gitignore
78
- - .gitmodules
79
- - .project
77
+ - ".gitignore"
78
+ - ".gitmodules"
79
+ - ".project"
80
80
  - CHANGELOG.md
81
81
  - Gemfile
82
82
  - LICENSE
@@ -92,75 +92,6 @@ files:
92
92
  - vendor/assets/javascripts/vis.js
93
93
  - vendor/assets/stylesheets/vis-only-timeline.css
94
94
  - vendor/assets/stylesheets/vis.css
95
- - vendor/assets/vis/DataSet.js
96
- - vendor/assets/vis/DataView.js
97
- - vendor/assets/vis/graph/Edge.js
98
- - vendor/assets/vis/graph/Graph.js
99
- - vendor/assets/vis/graph/Groups.js
100
- - vendor/assets/vis/graph/Images.js
101
- - vendor/assets/vis/graph/Node.js
102
- - vendor/assets/vis/graph/Popup.js
103
- - vendor/assets/vis/graph/css/graph-manipulation.css
104
- - vendor/assets/vis/graph/css/graph-navigation.css
105
- - vendor/assets/vis/graph/dotparser.js
106
- - vendor/assets/vis/graph/graphMixins/ClusterMixin.js
107
- - vendor/assets/vis/graph/graphMixins/HierarchicalLayoutMixin.js
108
- - vendor/assets/vis/graph/graphMixins/ManipulationMixin.js
109
- - vendor/assets/vis/graph/graphMixins/MixinLoader.js
110
- - vendor/assets/vis/graph/graphMixins/NavigationMixin.js
111
- - vendor/assets/vis/graph/graphMixins/SectorsMixin.js
112
- - vendor/assets/vis/graph/graphMixins/SelectionMixin.js
113
- - vendor/assets/vis/graph/graphMixins/physics/BarnesHut.js
114
- - vendor/assets/vis/graph/graphMixins/physics/HierarchialRepulsion.js
115
- - vendor/assets/vis/graph/graphMixins/physics/PhysicsMixin.js
116
- - vendor/assets/vis/graph/graphMixins/physics/Repulsion.js
117
- - vendor/assets/vis/graph/img/acceptDeleteIcon.png
118
- - vendor/assets/vis/graph/img/addNodeIcon.png
119
- - vendor/assets/vis/graph/img/backIcon.png
120
- - vendor/assets/vis/graph/img/connectIcon.png
121
- - vendor/assets/vis/graph/img/cross.png
122
- - vendor/assets/vis/graph/img/cross2.png
123
- - vendor/assets/vis/graph/img/deleteIcon.png
124
- - vendor/assets/vis/graph/img/downArrow.png
125
- - vendor/assets/vis/graph/img/editIcon.png
126
- - vendor/assets/vis/graph/img/leftArrow.png
127
- - vendor/assets/vis/graph/img/minus.png
128
- - vendor/assets/vis/graph/img/plus.png
129
- - vendor/assets/vis/graph/img/rightArrow.png
130
- - vendor/assets/vis/graph/img/upArrow.png
131
- - vendor/assets/vis/graph/img/zoomExtends.png
132
- - vendor/assets/vis/graph/shapes.js
133
- - vendor/assets/vis/graph3d/Graph3d.js
134
- - vendor/assets/vis/module/exports.js
135
- - vendor/assets/vis/module/header.js
136
- - vendor/assets/vis/module/imports.js
137
- - vendor/assets/vis/shim.js
138
- - vendor/assets/vis/timeline/Range.js
139
- - vendor/assets/vis/timeline/TimeStep.js
140
- - vendor/assets/vis/timeline/Timeline.js
141
- - vendor/assets/vis/timeline/component/Component.js
142
- - vendor/assets/vis/timeline/component/CurrentTime.js
143
- - vendor/assets/vis/timeline/component/CustomTime.js
144
- - vendor/assets/vis/timeline/component/Group.js
145
- - vendor/assets/vis/timeline/component/ItemSet.js
146
- - vendor/assets/vis/timeline/component/TimeAxis.js
147
- - vendor/assets/vis/timeline/component/css/animation.css
148
- - vendor/assets/vis/timeline/component/css/currenttime.css
149
- - vendor/assets/vis/timeline/component/css/customtime.css
150
- - vendor/assets/vis/timeline/component/css/item.css
151
- - vendor/assets/vis/timeline/component/css/itemset.css
152
- - vendor/assets/vis/timeline/component/css/labelset.css
153
- - vendor/assets/vis/timeline/component/css/panel.css
154
- - vendor/assets/vis/timeline/component/css/timeaxis.css
155
- - vendor/assets/vis/timeline/component/css/timeline.css
156
- - vendor/assets/vis/timeline/component/item/Item.js
157
- - vendor/assets/vis/timeline/component/item/ItemBox.js
158
- - vendor/assets/vis/timeline/component/item/ItemPoint.js
159
- - vendor/assets/vis/timeline/component/item/ItemRange.js
160
- - vendor/assets/vis/timeline/component/item/ItemRangeOverflow.js
161
- - vendor/assets/vis/timeline/img/delete.png
162
- - vendor/assets/vis/timeline/stack.js
163
- - vendor/assets/vis/util.js
164
95
  - vis-rails.gemspec
165
96
  homepage: https://github.com/AlexVangelov/vis-rails
166
97
  licenses:
@@ -172,17 +103,17 @@ require_paths:
172
103
  - lib
173
104
  required_ruby_version: !ruby/object:Gem::Requirement
174
105
  requirements:
175
- - - '>='
106
+ - - ">="
176
107
  - !ruby/object:Gem::Version
177
108
  version: '0'
178
109
  required_rubygems_version: !ruby/object:Gem::Requirement
179
110
  requirements:
180
- - - '>='
111
+ - - ">="
181
112
  - !ruby/object:Gem::Version
182
113
  version: '0'
183
114
  requirements: []
184
115
  rubyforge_project:
185
- rubygems_version: 2.2.2
116
+ rubygems_version: 2.4.6
186
117
  signing_key:
187
118
  specification_version: 4
188
119
  summary: Using http://visjs.org visualization library with Rails
@@ -1,926 +0,0 @@
1
- /**
2
- * DataSet
3
- *
4
- * Usage:
5
- * var dataSet = new DataSet({
6
- * fieldId: '_id',
7
- * type: {
8
- * // ...
9
- * }
10
- * });
11
- *
12
- * dataSet.add(item);
13
- * dataSet.add(data);
14
- * dataSet.update(item);
15
- * dataSet.update(data);
16
- * dataSet.remove(id);
17
- * dataSet.remove(ids);
18
- * var data = dataSet.get();
19
- * var data = dataSet.get(id);
20
- * var data = dataSet.get(ids);
21
- * var data = dataSet.get(ids, options, data);
22
- * dataSet.clear();
23
- *
24
- * A data set can:
25
- * - add/remove/update data
26
- * - gives triggers upon changes in the data
27
- * - can import/export data in various data formats
28
- *
29
- * @param {Array | DataTable} [data] Optional array with initial data
30
- * @param {Object} [options] Available options:
31
- * {String} fieldId Field name of the id in the
32
- * items, 'id' by default.
33
- * {Object.<String, String} type
34
- * A map with field names as key,
35
- * and the field type as value.
36
- * @constructor DataSet
37
- */
38
- // TODO: add a DataSet constructor DataSet(data, options)
39
- function DataSet (data, options) {
40
- // correctly read optional arguments
41
- if (data && !Array.isArray(data) && !util.isDataTable(data)) {
42
- options = data;
43
- data = null;
44
- }
45
-
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)
50
-
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];
57
- if (value == 'Date' || value == 'ISODate' || value == 'ASPDate') {
58
- this._type[field] = 'Date';
59
- }
60
- else {
61
- this._type[field] = value;
62
- }
63
- }
64
- }
65
- }
66
-
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
73
-
74
- // add initial data when provided
75
- if (data) {
76
- this.add(data);
77
- }
78
- }
79
-
80
- /**
81
- * Subscribe to an event, add an event listener
82
- * @param {String} event Event name. Available events: 'put', 'update',
83
- * 'remove'
84
- * @param {function} callback Callback method. Called with three parameters:
85
- * {String} event
86
- * {Object | null} params
87
- * {String | Number} senderId
88
- */
89
- DataSet.prototype.on = function(event, callback) {
90
- var subscribers = this._subscribers[event];
91
- if (!subscribers) {
92
- subscribers = [];
93
- this._subscribers[event] = subscribers;
94
- }
95
-
96
- subscribers.push({
97
- callback: callback
98
- });
99
- };
100
-
101
- // TODO: make this function deprecated (replaced with `on` since version 0.5)
102
- DataSet.prototype.subscribe = DataSet.prototype.on;
103
-
104
- /**
105
- * Unsubscribe from an event, remove an event listener
106
- * @param {String} event
107
- * @param {function} callback
108
- */
109
- DataSet.prototype.off = function(event, callback) {
110
- var subscribers = this._subscribers[event];
111
- if (subscribers) {
112
- this._subscribers[event] = subscribers.filter(function (listener) {
113
- return (listener.callback != callback);
114
- });
115
- }
116
- };
117
-
118
- // TODO: make this function deprecated (replaced with `on` since version 0.5)
119
- DataSet.prototype.unsubscribe = DataSet.prototype.off;
120
-
121
- /**
122
- * Trigger an event
123
- * @param {String} event
124
- * @param {Object | null} params
125
- * @param {String} [senderId] Optional id of the sender.
126
- * @private
127
- */
128
- DataSet.prototype._trigger = function (event, params, senderId) {
129
- if (event == '*') {
130
- throw new Error('Cannot trigger event *');
131
- }
132
-
133
- var subscribers = [];
134
- if (event in this._subscribers) {
135
- subscribers = subscribers.concat(this._subscribers[event]);
136
- }
137
- if ('*' in this._subscribers) {
138
- subscribers = subscribers.concat(this._subscribers['*']);
139
- }
140
-
141
- for (var i = 0; i < subscribers.length; i++) {
142
- var subscriber = subscribers[i];
143
- if (subscriber.callback) {
144
- subscriber.callback(event, params, senderId || null);
145
- }
146
- }
147
- };
148
-
149
- /**
150
- * Add data.
151
- * Adding an item will fail when there already is an item with the same id.
152
- * @param {Object | Array | DataTable} data
153
- * @param {String} [senderId] Optional sender id
154
- * @return {Array} addedIds Array with the ids of the added items
155
- */
156
- DataSet.prototype.add = function (data, senderId) {
157
- var addedIds = [],
158
- id,
159
- me = this;
160
-
161
- if (Array.isArray(data)) {
162
- // Array
163
- for (var i = 0, len = data.length; i < len; i++) {
164
- id = me._addItem(data[i]);
165
- addedIds.push(id);
166
- }
167
- }
168
- else if (util.isDataTable(data)) {
169
- // Google DataTable
170
- var columns = this._getColumnNames(data);
171
- for (var row = 0, rows = data.getNumberOfRows(); row < rows; row++) {
172
- var item = {};
173
- for (var col = 0, cols = columns.length; col < cols; col++) {
174
- var field = columns[col];
175
- item[field] = data.getValue(row, col);
176
- }
177
-
178
- id = me._addItem(item);
179
- addedIds.push(id);
180
- }
181
- }
182
- else if (data instanceof Object) {
183
- // Single item
184
- id = me._addItem(data);
185
- addedIds.push(id);
186
- }
187
- else {
188
- throw new Error('Unknown dataType');
189
- }
190
-
191
- if (addedIds.length) {
192
- this._trigger('add', {items: addedIds}, senderId);
193
- }
194
-
195
- return addedIds;
196
- };
197
-
198
- /**
199
- * Update existing items. When an item does not exist, it will be created
200
- * @param {Object | Array | DataTable} data
201
- * @param {String} [senderId] Optional sender id
202
- * @return {Array} updatedIds The ids of the added or updated items
203
- */
204
- DataSet.prototype.update = function (data, senderId) {
205
- var addedIds = [],
206
- updatedIds = [],
207
- me = this,
208
- fieldId = me._fieldId;
209
-
210
- var addOrUpdate = function (item) {
211
- var id = item[fieldId];
212
- if (me._data[id]) {
213
- // update item
214
- id = me._updateItem(item);
215
- updatedIds.push(id);
216
- }
217
- else {
218
- // add new item
219
- id = me._addItem(item);
220
- addedIds.push(id);
221
- }
222
- };
223
-
224
- if (Array.isArray(data)) {
225
- // Array
226
- for (var i = 0, len = data.length; i < len; i++) {
227
- addOrUpdate(data[i]);
228
- }
229
- }
230
- else if (util.isDataTable(data)) {
231
- // Google DataTable
232
- var columns = this._getColumnNames(data);
233
- for (var row = 0, rows = data.getNumberOfRows(); row < rows; row++) {
234
- var item = {};
235
- for (var col = 0, cols = columns.length; col < cols; col++) {
236
- var field = columns[col];
237
- item[field] = data.getValue(row, col);
238
- }
239
-
240
- addOrUpdate(item);
241
- }
242
- }
243
- else if (data instanceof Object) {
244
- // Single item
245
- addOrUpdate(data);
246
- }
247
- else {
248
- throw new Error('Unknown dataType');
249
- }
250
-
251
- if (addedIds.length) {
252
- this._trigger('add', {items: addedIds}, senderId);
253
- }
254
- if (updatedIds.length) {
255
- this._trigger('update', {items: updatedIds}, senderId);
256
- }
257
-
258
- return addedIds.concat(updatedIds);
259
- };
260
-
261
- /**
262
- * Get a data item or multiple items.
263
- *
264
- * Usage:
265
- *
266
- * get()
267
- * get(options: Object)
268
- * get(options: Object, data: Array | DataTable)
269
- *
270
- * get(id: Number | String)
271
- * get(id: Number | String, options: Object)
272
- * get(id: Number | String, options: Object, data: Array | DataTable)
273
- *
274
- * get(ids: Number[] | String[])
275
- * get(ids: Number[] | String[], options: Object)
276
- * get(ids: Number[] | String[], options: Object, data: Array | DataTable)
277
- *
278
- * Where:
279
- *
280
- * {Number | String} id The id of an item
281
- * {Number[] | String{}} ids An array with ids of items
282
- * {Object} options An Object with options. Available options:
283
- * {String} [returnType] Type of data to be
284
- * returned. Can be 'DataTable' or 'Array' (default)
285
- * {Object.<String, String>} [type]
286
- * {String[]} [fields] field names to be returned
287
- * {function} [filter] filter items
288
- * {String | function} [order] Order the items by
289
- * a field name or custom sort function.
290
- * {Array | DataTable} [data] If provided, items will be appended to this
291
- * array or table. Required in case of Google
292
- * DataTable.
293
- *
294
- * @throws Error
295
- */
296
- DataSet.prototype.get = function (args) {
297
- var me = this;
298
-
299
- // parse the arguments
300
- var id, ids, options, data;
301
- var firstType = util.getType(arguments[0]);
302
- if (firstType == 'String' || firstType == 'Number') {
303
- // get(id [, options] [, data])
304
- id = arguments[0];
305
- options = arguments[1];
306
- data = arguments[2];
307
- }
308
- else if (firstType == 'Array') {
309
- // get(ids [, options] [, data])
310
- ids = arguments[0];
311
- options = arguments[1];
312
- data = arguments[2];
313
- }
314
- else {
315
- // get([, options] [, data])
316
- options = arguments[0];
317
- data = arguments[1];
318
- }
319
-
320
- // determine the return type
321
- var returnType;
322
- if (options && options.returnType) {
323
- returnType = (options.returnType == 'DataTable') ? 'DataTable' : 'Array';
324
-
325
- if (data && (returnType != util.getType(data))) {
326
- throw new Error('Type of parameter "data" (' + util.getType(data) + ') ' +
327
- 'does not correspond with specified options.type (' + options.type + ')');
328
- }
329
- if (returnType == 'DataTable' && !util.isDataTable(data)) {
330
- throw new Error('Parameter "data" must be a DataTable ' +
331
- 'when options.type is "DataTable"');
332
- }
333
- }
334
- else if (data) {
335
- returnType = (util.getType(data) == 'DataTable') ? 'DataTable' : 'Array';
336
- }
337
- else {
338
- returnType = 'Array';
339
- }
340
-
341
- // build options
342
- var type = options && options.type || this._options.type;
343
- var filter = options && options.filter;
344
- var items = [], item, itemId, i, len;
345
-
346
- // convert items
347
- if (id != undefined) {
348
- // return a single item
349
- item = me._getItem(id, type);
350
- if (filter && !filter(item)) {
351
- item = null;
352
- }
353
- }
354
- else if (ids != undefined) {
355
- // return a subset of items
356
- for (i = 0, len = ids.length; i < len; i++) {
357
- item = me._getItem(ids[i], type);
358
- if (!filter || filter(item)) {
359
- items.push(item);
360
- }
361
- }
362
- }
363
- else {
364
- // return all items
365
- for (itemId in this._data) {
366
- if (this._data.hasOwnProperty(itemId)) {
367
- item = me._getItem(itemId, type);
368
- if (!filter || filter(item)) {
369
- items.push(item);
370
- }
371
- }
372
- }
373
- }
374
-
375
- // order the results
376
- if (options && options.order && id == undefined) {
377
- this._sort(items, options.order);
378
- }
379
-
380
- // filter fields of the items
381
- if (options && options.fields) {
382
- var fields = options.fields;
383
- if (id != undefined) {
384
- item = this._filterFields(item, fields);
385
- }
386
- else {
387
- for (i = 0, len = items.length; i < len; i++) {
388
- items[i] = this._filterFields(items[i], fields);
389
- }
390
- }
391
- }
392
-
393
- // return the results
394
- if (returnType == 'DataTable') {
395
- var columns = this._getColumnNames(data);
396
- if (id != undefined) {
397
- // append a single item to the data table
398
- me._appendRow(data, columns, item);
399
- }
400
- else {
401
- // copy the items to the provided data table
402
- for (i = 0, len = items.length; i < len; i++) {
403
- me._appendRow(data, columns, items[i]);
404
- }
405
- }
406
- return data;
407
- }
408
- else {
409
- // return an array
410
- if (id != undefined) {
411
- // a single item
412
- return item;
413
- }
414
- else {
415
- // multiple items
416
- if (data) {
417
- // copy the items to the provided array
418
- for (i = 0, len = items.length; i < len; i++) {
419
- data.push(items[i]);
420
- }
421
- return data;
422
- }
423
- else {
424
- // just return our array
425
- return items;
426
- }
427
- }
428
- }
429
- };
430
-
431
- /**
432
- * Get ids of all items or from a filtered set of items.
433
- * @param {Object} [options] An Object with options. Available options:
434
- * {function} [filter] filter items
435
- * {String | function} [order] Order the items by
436
- * a field name or custom sort function.
437
- * @return {Array} ids
438
- */
439
- DataSet.prototype.getIds = function (options) {
440
- var data = this._data,
441
- filter = options && options.filter,
442
- order = options && options.order,
443
- type = options && options.type || this._options.type,
444
- i,
445
- len,
446
- id,
447
- item,
448
- items,
449
- ids = [];
450
-
451
- if (filter) {
452
- // get filtered items
453
- if (order) {
454
- // create ordered list
455
- items = [];
456
- for (id in data) {
457
- if (data.hasOwnProperty(id)) {
458
- item = this._getItem(id, type);
459
- if (filter(item)) {
460
- items.push(item);
461
- }
462
- }
463
- }
464
-
465
- this._sort(items, order);
466
-
467
- for (i = 0, len = items.length; i < len; i++) {
468
- ids[i] = items[i][this._fieldId];
469
- }
470
- }
471
- else {
472
- // create unordered list
473
- for (id in data) {
474
- if (data.hasOwnProperty(id)) {
475
- item = this._getItem(id, type);
476
- if (filter(item)) {
477
- ids.push(item[this._fieldId]);
478
- }
479
- }
480
- }
481
- }
482
- }
483
- else {
484
- // get all items
485
- if (order) {
486
- // create an ordered list
487
- items = [];
488
- for (id in data) {
489
- if (data.hasOwnProperty(id)) {
490
- items.push(data[id]);
491
- }
492
- }
493
-
494
- this._sort(items, order);
495
-
496
- for (i = 0, len = items.length; i < len; i++) {
497
- ids[i] = items[i][this._fieldId];
498
- }
499
- }
500
- else {
501
- // create unordered list
502
- for (id in data) {
503
- if (data.hasOwnProperty(id)) {
504
- item = data[id];
505
- ids.push(item[this._fieldId]);
506
- }
507
- }
508
- }
509
- }
510
-
511
- return ids;
512
- };
513
-
514
- /**
515
- * Execute a callback function for every item in the dataset.
516
- * @param {function} callback
517
- * @param {Object} [options] Available options:
518
- * {Object.<String, String>} [type]
519
- * {String[]} [fields] filter fields
520
- * {function} [filter] filter items
521
- * {String | function} [order] Order the items by
522
- * a field name or custom sort function.
523
- */
524
- DataSet.prototype.forEach = function (callback, options) {
525
- var filter = options && options.filter,
526
- type = options && options.type || this._options.type,
527
- data = this._data,
528
- item,
529
- id;
530
-
531
- if (options && options.order) {
532
- // execute forEach on ordered list
533
- var items = this.get(options);
534
-
535
- for (var i = 0, len = items.length; i < len; i++) {
536
- item = items[i];
537
- id = item[this._fieldId];
538
- callback(item, id);
539
- }
540
- }
541
- else {
542
- // unordered
543
- for (id in data) {
544
- if (data.hasOwnProperty(id)) {
545
- item = this._getItem(id, type);
546
- if (!filter || filter(item)) {
547
- callback(item, id);
548
- }
549
- }
550
- }
551
- }
552
- };
553
-
554
- /**
555
- * Map every item in the dataset.
556
- * @param {function} callback
557
- * @param {Object} [options] Available options:
558
- * {Object.<String, String>} [type]
559
- * {String[]} [fields] filter fields
560
- * {function} [filter] filter items
561
- * {String | function} [order] Order the items by
562
- * a field name or custom sort function.
563
- * @return {Object[]} mappedItems
564
- */
565
- DataSet.prototype.map = function (callback, options) {
566
- var filter = options && options.filter,
567
- type = options && options.type || this._options.type,
568
- mappedItems = [],
569
- data = this._data,
570
- item;
571
-
572
- // convert and filter items
573
- for (var id in data) {
574
- if (data.hasOwnProperty(id)) {
575
- item = this._getItem(id, type);
576
- if (!filter || filter(item)) {
577
- mappedItems.push(callback(item, id));
578
- }
579
- }
580
- }
581
-
582
- // order items
583
- if (options && options.order) {
584
- this._sort(mappedItems, options.order);
585
- }
586
-
587
- return mappedItems;
588
- };
589
-
590
- /**
591
- * Filter the fields of an item
592
- * @param {Object} item
593
- * @param {String[]} fields Field names
594
- * @return {Object} filteredItem
595
- * @private
596
- */
597
- DataSet.prototype._filterFields = function (item, fields) {
598
- var filteredItem = {};
599
-
600
- for (var field in item) {
601
- if (item.hasOwnProperty(field) && (fields.indexOf(field) != -1)) {
602
- filteredItem[field] = item[field];
603
- }
604
- }
605
-
606
- return filteredItem;
607
- };
608
-
609
- /**
610
- * Sort the provided array with items
611
- * @param {Object[]} items
612
- * @param {String | function} order A field name or custom sort function.
613
- * @private
614
- */
615
- DataSet.prototype._sort = function (items, order) {
616
- if (util.isString(order)) {
617
- // order by provided field name
618
- var name = order; // field name
619
- items.sort(function (a, b) {
620
- var av = a[name];
621
- var bv = b[name];
622
- return (av > bv) ? 1 : ((av < bv) ? -1 : 0);
623
- });
624
- }
625
- else if (typeof order === 'function') {
626
- // order by sort function
627
- items.sort(order);
628
- }
629
- // TODO: extend order by an Object {field:String, direction:String}
630
- // where direction can be 'asc' or 'desc'
631
- else {
632
- throw new TypeError('Order must be a function or a string');
633
- }
634
- };
635
-
636
- /**
637
- * Remove an object by pointer or by id
638
- * @param {String | Number | Object | Array} id Object or id, or an array with
639
- * objects or ids to be removed
640
- * @param {String} [senderId] Optional sender id
641
- * @return {Array} removedIds
642
- */
643
- DataSet.prototype.remove = function (id, senderId) {
644
- var removedIds = [],
645
- i, len, removedId;
646
-
647
- if (Array.isArray(id)) {
648
- for (i = 0, len = id.length; i < len; i++) {
649
- removedId = this._remove(id[i]);
650
- if (removedId != null) {
651
- removedIds.push(removedId);
652
- }
653
- }
654
- }
655
- else {
656
- removedId = this._remove(id);
657
- if (removedId != null) {
658
- removedIds.push(removedId);
659
- }
660
- }
661
-
662
- if (removedIds.length) {
663
- this._trigger('remove', {items: removedIds}, senderId);
664
- }
665
-
666
- return removedIds;
667
- };
668
-
669
- /**
670
- * Remove an item by its id
671
- * @param {Number | String | Object} id id or item
672
- * @returns {Number | String | null} id
673
- * @private
674
- */
675
- DataSet.prototype._remove = function (id) {
676
- if (util.isNumber(id) || util.isString(id)) {
677
- if (this._data[id]) {
678
- delete this._data[id];
679
- return id;
680
- }
681
- }
682
- else if (id instanceof Object) {
683
- var itemId = id[this._fieldId];
684
- if (itemId && this._data[itemId]) {
685
- delete this._data[itemId];
686
- return itemId;
687
- }
688
- }
689
- return null;
690
- };
691
-
692
- /**
693
- * Clear the data
694
- * @param {String} [senderId] Optional sender id
695
- * @return {Array} removedIds The ids of all removed items
696
- */
697
- DataSet.prototype.clear = function (senderId) {
698
- var ids = Object.keys(this._data);
699
-
700
- this._data = {};
701
-
702
- this._trigger('remove', {items: ids}, senderId);
703
-
704
- return ids;
705
- };
706
-
707
- /**
708
- * Find the item with maximum value of a specified field
709
- * @param {String} field
710
- * @return {Object | null} item Item containing max value, or null if no items
711
- */
712
- DataSet.prototype.max = function (field) {
713
- var data = this._data,
714
- max = null,
715
- maxField = null;
716
-
717
- for (var id in data) {
718
- if (data.hasOwnProperty(id)) {
719
- var item = data[id];
720
- var itemField = item[field];
721
- if (itemField != null && (!max || itemField > maxField)) {
722
- max = item;
723
- maxField = itemField;
724
- }
725
- }
726
- }
727
-
728
- return max;
729
- };
730
-
731
- /**
732
- * Find the item with minimum value of a specified field
733
- * @param {String} field
734
- * @return {Object | null} item Item containing max value, or null if no items
735
- */
736
- DataSet.prototype.min = function (field) {
737
- var data = this._data,
738
- min = null,
739
- minField = null;
740
-
741
- for (var id in data) {
742
- if (data.hasOwnProperty(id)) {
743
- var item = data[id];
744
- var itemField = item[field];
745
- if (itemField != null && (!min || itemField < minField)) {
746
- min = item;
747
- minField = itemField;
748
- }
749
- }
750
- }
751
-
752
- return min;
753
- };
754
-
755
- /**
756
- * Find all distinct values of a specified field
757
- * @param {String} field
758
- * @return {Array} values Array containing all distinct values. If data items
759
- * do not contain the specified field are ignored.
760
- * The returned array is unordered.
761
- */
762
- DataSet.prototype.distinct = function (field) {
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;
768
-
769
- for (var prop in data) {
770
- if (data.hasOwnProperty(prop)) {
771
- var item = data[prop];
772
- var value = item[field];
773
- var exists = false;
774
- for (i = 0; i < count; i++) {
775
- if (values[i] == value) {
776
- exists = true;
777
- break;
778
- }
779
- }
780
- if (!exists && (value !== undefined)) {
781
- values[count] = value;
782
- count++;
783
- }
784
- }
785
- }
786
-
787
- if (fieldType) {
788
- for (i = 0; i < values.length; i++) {
789
- values[i] = util.convert(values[i], fieldType);
790
- }
791
- }
792
-
793
- return values;
794
- };
795
-
796
- /**
797
- * Add a single item. Will fail when an item with the same id already exists.
798
- * @param {Object} item
799
- * @return {String} id
800
- * @private
801
- */
802
- DataSet.prototype._addItem = function (item) {
803
- var id = item[this._fieldId];
804
-
805
- if (id != undefined) {
806
- // check whether this id is already taken
807
- if (this._data[id]) {
808
- // item already exists
809
- throw new Error('Cannot add item: item with id ' + id + ' already exists');
810
- }
811
- }
812
- else {
813
- // generate an id
814
- id = util.randomUUID();
815
- item[this._fieldId] = id;
816
- }
817
-
818
- var d = {};
819
- for (var field in item) {
820
- if (item.hasOwnProperty(field)) {
821
- var fieldType = this._type[field]; // type may be undefined
822
- d[field] = util.convert(item[field], fieldType);
823
- }
824
- }
825
- this._data[id] = d;
826
-
827
- return id;
828
- };
829
-
830
- /**
831
- * Get an item. Fields can be converted to a specific type
832
- * @param {String} id
833
- * @param {Object.<String, String>} [types] field types to convert
834
- * @return {Object | null} item
835
- * @private
836
- */
837
- DataSet.prototype._getItem = function (id, types) {
838
- var field, value;
839
-
840
- // get the item from the dataset
841
- var raw = this._data[id];
842
- if (!raw) {
843
- return null;
844
- }
845
-
846
- // convert the items field types
847
- var converted = {};
848
- if (types) {
849
- for (field in raw) {
850
- if (raw.hasOwnProperty(field)) {
851
- value = raw[field];
852
- converted[field] = util.convert(value, types[field]);
853
- }
854
- }
855
- }
856
- else {
857
- // no field types specified, no converting needed
858
- for (field in raw) {
859
- if (raw.hasOwnProperty(field)) {
860
- value = raw[field];
861
- converted[field] = value;
862
- }
863
- }
864
- }
865
- return converted;
866
- };
867
-
868
- /**
869
- * Update a single item: merge with existing item.
870
- * Will fail when the item has no id, or when there does not exist an item
871
- * with the same id.
872
- * @param {Object} item
873
- * @return {String} id
874
- * @private
875
- */
876
- DataSet.prototype._updateItem = function (item) {
877
- var id = item[this._fieldId];
878
- if (id == undefined) {
879
- throw new Error('Cannot update item: item has no id (item: ' + JSON.stringify(item) + ')');
880
- }
881
- var d = this._data[id];
882
- if (!d) {
883
- // item doesn't exist
884
- throw new Error('Cannot update item: no item with id ' + id + ' found');
885
- }
886
-
887
- // merge with current item
888
- for (var field in item) {
889
- if (item.hasOwnProperty(field)) {
890
- var fieldType = this._type[field]; // type may be undefined
891
- d[field] = util.convert(item[field], fieldType);
892
- }
893
- }
894
-
895
- return id;
896
- };
897
-
898
- /**
899
- * Get an array with the column names of a Google DataTable
900
- * @param {DataTable} dataTable
901
- * @return {String[]} columnNames
902
- * @private
903
- */
904
- DataSet.prototype._getColumnNames = function (dataTable) {
905
- var columns = [];
906
- for (var col = 0, cols = dataTable.getNumberOfColumns(); col < cols; col++) {
907
- columns[col] = dataTable.getColumnId(col) || dataTable.getColumnLabel(col);
908
- }
909
- return columns;
910
- };
911
-
912
- /**
913
- * Append an item as a row to the dataTable
914
- * @param dataTable
915
- * @param columns
916
- * @param item
917
- * @private
918
- */
919
- DataSet.prototype._appendRow = function (dataTable, columns, item) {
920
- var row = dataTable.addRow();
921
-
922
- for (var col = 0, cols = columns.length; col < cols; col++) {
923
- var field = columns[col];
924
- dataTable.setValue(row, col, item[field]);
925
- }
926
- };