vis-rails 0.0.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vis/rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/vis.js +2 -9
  4. data/vendor/assets/vis/DataSet.js +17 -9
  5. data/vendor/assets/vis/graph/Edge.js +49 -24
  6. data/vendor/assets/vis/graph/Graph.js +268 -64
  7. data/vendor/assets/vis/graph/Groups.js +1 -1
  8. data/vendor/assets/vis/graph/Node.js +18 -67
  9. data/vendor/assets/vis/graph/Popup.js +40 -13
  10. data/vendor/assets/vis/graph/css/graph-navigation.css +18 -14
  11. data/vendor/assets/vis/graph/graphMixins/ClusterMixin.js +7 -5
  12. data/vendor/assets/vis/graph/graphMixins/HierarchicalLayoutMixin.js +20 -5
  13. data/vendor/assets/vis/graph/graphMixins/ManipulationMixin.js +33 -33
  14. data/vendor/assets/vis/graph/graphMixins/MixinLoader.js +30 -32
  15. data/vendor/assets/vis/graph/graphMixins/NavigationMixin.js +33 -1
  16. data/vendor/assets/vis/graph/graphMixins/SectorsMixin.js +2 -2
  17. data/vendor/assets/vis/graph/graphMixins/SelectionMixin.js +72 -60
  18. data/vendor/assets/vis/graph/graphMixins/physics/BarnesHut.js +43 -18
  19. data/vendor/assets/vis/graph/graphMixins/physics/HierarchialRepulsion.js +8 -8
  20. data/vendor/assets/vis/graph/graphMixins/physics/PhysicsMixin.js +309 -129
  21. data/vendor/assets/vis/graph/graphMixins/physics/Repulsion.js +10 -10
  22. data/vendor/assets/vis/module/exports.js +1 -2
  23. data/vendor/assets/vis/module/header.js +2 -2
  24. data/vendor/assets/vis/timeline/Range.js +53 -93
  25. data/vendor/assets/vis/timeline/Timeline.js +328 -224
  26. data/vendor/assets/vis/timeline/component/Component.js +17 -95
  27. data/vendor/assets/vis/timeline/component/CurrentTime.js +54 -59
  28. data/vendor/assets/vis/timeline/component/CustomTime.js +55 -83
  29. data/vendor/assets/vis/timeline/component/Group.js +398 -75
  30. data/vendor/assets/vis/timeline/component/ItemSet.js +662 -403
  31. data/vendor/assets/vis/timeline/component/Panel.js +118 -60
  32. data/vendor/assets/vis/timeline/component/RootPanel.js +80 -132
  33. data/vendor/assets/vis/timeline/component/TimeAxis.js +191 -277
  34. data/vendor/assets/vis/timeline/component/css/item.css +16 -23
  35. data/vendor/assets/vis/timeline/component/css/itemset.css +25 -4
  36. data/vendor/assets/vis/timeline/component/css/labelset.css +34 -0
  37. data/vendor/assets/vis/timeline/component/css/panel.css +15 -1
  38. data/vendor/assets/vis/timeline/component/css/timeaxis.css +8 -8
  39. data/vendor/assets/vis/timeline/component/item/Item.js +48 -26
  40. data/vendor/assets/vis/timeline/component/item/ItemBox.js +156 -230
  41. data/vendor/assets/vis/timeline/component/item/ItemPoint.js +118 -166
  42. data/vendor/assets/vis/timeline/component/item/ItemRange.js +135 -187
  43. data/vendor/assets/vis/timeline/component/item/ItemRangeOverflow.js +29 -92
  44. data/vendor/assets/vis/timeline/stack.js +112 -0
  45. data/vendor/assets/vis/util.js +136 -38
  46. metadata +4 -18
  47. data/vendor/assets/vis/.gitignore +0 -1
  48. data/vendor/assets/vis/EventBus.js +0 -89
  49. data/vendor/assets/vis/events.js +0 -116
  50. data/vendor/assets/vis/graph/ClusterMixin.js +0 -1019
  51. data/vendor/assets/vis/graph/NavigationMixin.js +0 -245
  52. data/vendor/assets/vis/graph/SectorsMixin.js +0 -547
  53. data/vendor/assets/vis/graph/SelectionMixin.js +0 -515
  54. data/vendor/assets/vis/graph/img/downarrow.png +0 -0
  55. data/vendor/assets/vis/graph/img/leftarrow.png +0 -0
  56. data/vendor/assets/vis/graph/img/rightarrow.png +0 -0
  57. data/vendor/assets/vis/graph/img/uparrow.png +0 -0
  58. data/vendor/assets/vis/timeline/Controller.js +0 -183
  59. data/vendor/assets/vis/timeline/Stack.js +0 -190
  60. data/vendor/assets/vis/timeline/component/ContentPanel.js +0 -113
  61. data/vendor/assets/vis/timeline/component/GroupSet.js +0 -580
  62. data/vendor/assets/vis/timeline/component/css/groupset.css +0 -59
@@ -1,8 +1,5 @@
1
1
  /**
2
2
  * A panel can contain components
3
- * @param {Component} [parent]
4
- * @param {Component[]} [depends] Components on which this components depends
5
- * (except for the parent)
6
3
  * @param {Object} [options] Available parameters:
7
4
  * {String | Number | function} [left]
8
5
  * {String | Number | function} [top]
@@ -12,12 +9,15 @@
12
9
  * @constructor Panel
13
10
  * @extends Component
14
11
  */
15
- function Panel(parent, depends, options) {
12
+ function Panel(options) {
16
13
  this.id = util.randomUUID();
17
- this.parent = parent;
18
- this.depends = depends;
14
+ this.parent = null;
15
+ this.childs = [];
19
16
 
20
17
  this.options = options || {};
18
+
19
+ // create frame
20
+ this.frame = (typeof document !== 'undefined') ? document.createElement('div') : null;
21
21
  }
22
22
 
23
23
  Panel.prototype = new Component();
@@ -34,79 +34,137 @@ Panel.prototype = new Component();
34
34
  Panel.prototype.setOptions = Component.prototype.setOptions;
35
35
 
36
36
  /**
37
- * Get the container element of the panel, which can be used by a child to
38
- * add its own widgets.
39
- * @returns {HTMLElement} container
37
+ * Get the outer frame of the panel
38
+ * @returns {HTMLElement} frame
40
39
  */
41
- Panel.prototype.getContainer = function () {
40
+ Panel.prototype.getFrame = function () {
42
41
  return this.frame;
43
42
  };
44
43
 
45
44
  /**
46
- * Repaint the component
47
- * @return {Boolean} changed
45
+ * Append a child to the panel
46
+ * @param {Component} child
48
47
  */
49
- Panel.prototype.repaint = function () {
50
- var changed = 0,
51
- update = util.updateProperty,
52
- asSize = util.option.asSize,
53
- options = this.options,
54
- frame = this.frame;
55
- if (!frame) {
56
- frame = document.createElement('div');
57
- frame.className = 'vpanel';
58
-
59
- var className = options.className;
60
- if (className) {
61
- if (typeof className == 'function') {
62
- util.addClassName(frame, String(className()));
48
+ Panel.prototype.appendChild = function (child) {
49
+ this.childs.push(child);
50
+ child.parent = this;
51
+
52
+ // attach to the DOM
53
+ var frame = child.getFrame();
54
+ if (frame) {
55
+ if (frame.parentNode) {
56
+ frame.parentNode.removeChild(frame);
57
+ }
58
+ this.frame.appendChild(frame);
59
+ }
60
+ };
61
+
62
+ /**
63
+ * Insert a child to the panel
64
+ * @param {Component} child
65
+ * @param {Component} beforeChild
66
+ */
67
+ Panel.prototype.insertBefore = function (child, beforeChild) {
68
+ var index = this.childs.indexOf(beforeChild);
69
+ if (index != -1) {
70
+ this.childs.splice(index, 0, child);
71
+ child.parent = this;
72
+
73
+ // attach to the DOM
74
+ var frame = child.getFrame();
75
+ if (frame) {
76
+ if (frame.parentNode) {
77
+ frame.parentNode.removeChild(frame);
78
+ }
79
+
80
+ var beforeFrame = beforeChild.getFrame();
81
+ if (beforeFrame) {
82
+ this.frame.insertBefore(frame, beforeFrame);
63
83
  }
64
84
  else {
65
- util.addClassName(frame, String(className));
85
+ this.frame.appendChild(frame);
66
86
  }
67
87
  }
68
-
69
- this.frame = frame;
70
- changed += 1;
71
88
  }
72
- if (!frame.parentNode) {
73
- if (!this.parent) {
74
- throw new Error('Cannot repaint panel: no parent attached');
75
- }
76
- var parentContainer = this.parent.getContainer();
77
- if (!parentContainer) {
78
- throw new Error('Cannot repaint panel: parent has no container element');
89
+ };
90
+
91
+ /**
92
+ * Remove a child from the panel
93
+ * @param {Component} child
94
+ */
95
+ Panel.prototype.removeChild = function (child) {
96
+ var index = this.childs.indexOf(child);
97
+ if (index != -1) {
98
+ this.childs.splice(index, 1);
99
+ child.parent = null;
100
+
101
+ // remove from the DOM
102
+ var frame = child.getFrame();
103
+ if (frame && frame.parentNode) {
104
+ this.frame.removeChild(frame);
79
105
  }
80
- parentContainer.appendChild(frame);
81
- changed += 1;
82
106
  }
107
+ };
83
108
 
84
- changed += update(frame.style, 'top', asSize(options.top, '0px'));
85
- changed += update(frame.style, 'left', asSize(options.left, '0px'));
86
- changed += update(frame.style, 'width', asSize(options.width, '100%'));
87
- changed += update(frame.style, 'height', asSize(options.height, '100%'));
88
-
89
- return (changed > 0);
109
+ /**
110
+ * Test whether the panel contains given child
111
+ * @param {Component} child
112
+ */
113
+ Panel.prototype.hasChild = function (child) {
114
+ var index = this.childs.indexOf(child);
115
+ return (index != -1);
90
116
  };
91
117
 
92
118
  /**
93
- * Reflow the component
94
- * @return {Boolean} resized
119
+ * Repaint the component
120
+ * @return {boolean} Returns true if the component was resized since previous repaint
95
121
  */
96
- Panel.prototype.reflow = function () {
97
- var changed = 0,
98
- update = util.updateProperty,
99
- frame = this.frame;
122
+ Panel.prototype.repaint = function () {
123
+ var asString = util.option.asString,
124
+ options = this.options,
125
+ frame = this.getFrame();
100
126
 
101
- if (frame) {
102
- changed += update(this, 'top', frame.offsetTop);
103
- changed += update(this, 'left', frame.offsetLeft);
104
- changed += update(this, 'width', frame.offsetWidth);
105
- changed += update(this, 'height', frame.offsetHeight);
106
- }
107
- else {
108
- changed += 1;
127
+ // update className
128
+ frame.className = 'vpanel' + (options.className ? (' ' + asString(options.className)) : '');
129
+
130
+ // repaint the child components
131
+ var childsResized = this._repaintChilds();
132
+
133
+ // update frame size
134
+ this._updateSize();
135
+
136
+ return this._isResized() || childsResized;
137
+ };
138
+
139
+ /**
140
+ * Repaint all childs of the panel
141
+ * @return {boolean} Returns true if the component is resized
142
+ * @private
143
+ */
144
+ Panel.prototype._repaintChilds = function () {
145
+ var resized = false;
146
+ for (var i = 0, ii = this.childs.length; i < ii; i++) {
147
+ resized = this.childs[i].repaint() || resized;
109
148
  }
149
+ return resized;
150
+ };
151
+
152
+ /**
153
+ * Apply the size from options to the panel, and recalculate it's actual size.
154
+ * @private
155
+ */
156
+ Panel.prototype._updateSize = function () {
157
+ // apply size
158
+ this.frame.style.top = util.option.asSize(this.options.top);
159
+ this.frame.style.bottom = util.option.asSize(this.options.bottom);
160
+ this.frame.style.left = util.option.asSize(this.options.left);
161
+ this.frame.style.right = util.option.asSize(this.options.right);
162
+ this.frame.style.width = util.option.asSize(this.options.width, '100%');
163
+ this.frame.style.height = util.option.asSize(this.options.height, '');
110
164
 
111
- return (changed > 0);
165
+ // get actual size
166
+ this.top = this.frame.offsetTop;
167
+ this.left = this.frame.offsetLeft;
168
+ this.width = this.frame.offsetWidth;
169
+ this.height = this.frame.offsetHeight;
112
170
  };
@@ -10,32 +10,53 @@ function RootPanel(container, options) {
10
10
  this.id = util.randomUUID();
11
11
  this.container = container;
12
12
 
13
- // create functions to be used as DOM event listeners
14
- var me = this;
15
- this.hammer = null;
13
+ this.options = options || {};
14
+ this.defaultOptions = {
15
+ autoResize: true
16
+ };
17
+
18
+ // create the HTML DOM
19
+ this._create();
20
+
21
+ // attach the root panel to the provided container
22
+ if (!this.container) throw new Error('Cannot repaint root panel: no container attached');
23
+ this.container.appendChild(this.getFrame());
24
+
25
+
26
+ this._initWatch();
27
+ }
28
+
29
+ RootPanel.prototype = new Panel();
16
30
 
17
- // create listeners for all interesting events, these events will be emitted
18
- // via the controller
31
+ /**
32
+ * Create the HTML DOM for the root panel
33
+ */
34
+ RootPanel.prototype._create = function _create() {
35
+ // create frame
36
+ this.frame = document.createElement('div');
37
+
38
+ // create event listeners for all interesting events, these events will be
39
+ // emitted via emitter
40
+ this.hammer = Hammer(this.frame, {
41
+ prevent_default: true
42
+ });
43
+ this.listeners = {};
44
+
45
+ var me = this;
19
46
  var events = [
20
47
  'touch', 'pinch', 'tap', 'doubletap', 'hold',
21
48
  'dragstart', 'drag', 'dragend',
22
49
  'mousewheel', 'DOMMouseScroll' // DOMMouseScroll is for Firefox
23
50
  ];
24
- this.listeners = {};
25
51
  events.forEach(function (event) {
26
- me.listeners[event] = function () {
52
+ var listener = function () {
27
53
  var args = [event].concat(Array.prototype.slice.call(arguments, 0));
28
- me.controller.emit.apply(me.controller, args);
54
+ me.emit.apply(me, args);
29
55
  };
56
+ me.hammer.on(event, listener);
57
+ me.listeners[event] = listener;
30
58
  });
31
-
32
- this.options = options || {};
33
- this.defaultOptions = {
34
- autoResize: true
35
- };
36
- }
37
-
38
- RootPanel.prototype = new Panel();
59
+ };
39
60
 
40
61
  /**
41
62
  * Set options. Will extend the current options.
@@ -47,80 +68,54 @@ RootPanel.prototype = new Panel();
47
68
  * {String | Number | function} [height]
48
69
  * {Boolean | function} [autoResize]
49
70
  */
50
- RootPanel.prototype.setOptions = Component.prototype.setOptions;
51
-
52
- /**
53
- * Repaint the component
54
- * @return {Boolean} changed
55
- */
56
- RootPanel.prototype.repaint = function () {
57
- var changed = 0,
58
- update = util.updateProperty,
59
- asSize = util.option.asSize,
60
- options = this.options,
61
- frame = this.frame;
71
+ RootPanel.prototype.setOptions = function setOptions(options) {
72
+ if (options) {
73
+ util.extend(this.options, options);
62
74
 
63
- if (!frame) {
64
- frame = document.createElement('div');
65
-
66
- this.frame = frame;
67
-
68
- this._registerListeners();
69
-
70
- changed += 1;
71
- }
72
- if (!frame.parentNode) {
73
- if (!this.container) {
74
- throw new Error('Cannot repaint root panel: no container attached');
75
- }
76
- this.container.appendChild(frame);
77
- changed += 1;
78
- }
75
+ this.repaint();
79
76
 
80
- frame.className = 'vis timeline rootpanel ' + options.orientation +
81
- (options.editable ? ' editable' : '');
82
- var className = options.className;
83
- if (className) {
84
- util.addClassName(frame, util.option.asString(className));
77
+ this._initWatch();
85
78
  }
79
+ };
86
80
 
87
- changed += update(frame.style, 'top', asSize(options.top, '0px'));
88
- changed += update(frame.style, 'left', asSize(options.left, '0px'));
89
- changed += update(frame.style, 'width', asSize(options.width, '100%'));
90
- changed += update(frame.style, 'height', asSize(options.height, '100%'));
91
-
92
- this._updateWatch();
93
-
94
- return (changed > 0);
81
+ /**
82
+ * Get the frame of the root panel
83
+ */
84
+ RootPanel.prototype.getFrame = function getFrame() {
85
+ return this.frame;
95
86
  };
96
87
 
97
88
  /**
98
- * Reflow the component
99
- * @return {Boolean} resized
89
+ * Repaint the root panel
100
90
  */
101
- RootPanel.prototype.reflow = function () {
102
- var changed = 0,
103
- update = util.updateProperty,
104
- frame = this.frame;
105
-
106
- if (frame) {
107
- changed += update(this, 'top', frame.offsetTop);
108
- changed += update(this, 'left', frame.offsetLeft);
109
- changed += update(this, 'width', frame.offsetWidth);
110
- changed += update(this, 'height', frame.offsetHeight);
111
- }
112
- else {
113
- changed += 1;
91
+ RootPanel.prototype.repaint = function repaint() {
92
+ // update class name
93
+ var options = this.options;
94
+ var editable = options.editable.updateTime || options.editable.updateGroup;
95
+ var className = 'vis timeline rootpanel ' + options.orientation + (editable ? ' editable' : '');
96
+ if (options.className) className += ' ' + util.option.asString(className);
97
+ this.frame.className = className;
98
+
99
+ // repaint the child components
100
+ var childsResized = this._repaintChilds();
101
+
102
+ // update frame size
103
+ this.frame.style.maxHeight = util.option.asSize(this.options.maxHeight, '');
104
+ this._updateSize();
105
+
106
+ // if the root panel or any of its childs is resized, repaint again,
107
+ // as other components may need to be resized accordingly
108
+ var resized = this._isResized() || childsResized;
109
+ if (resized) {
110
+ setTimeout(this.repaint.bind(this), 0);
114
111
  }
115
-
116
- return (changed > 0);
117
112
  };
118
113
 
119
114
  /**
120
- * Update watching for resize, depending on the current option
115
+ * Initialize watching when option autoResize is true
121
116
  * @private
122
117
  */
123
- RootPanel.prototype._updateWatch = function () {
118
+ RootPanel.prototype._initWatch = function _initWatch() {
124
119
  var autoResize = this.getOption('autoResize');
125
120
  if (autoResize) {
126
121
  this._watch();
@@ -135,12 +130,12 @@ RootPanel.prototype._updateWatch = function () {
135
130
  * automatically redraw itself.
136
131
  * @private
137
132
  */
138
- RootPanel.prototype._watch = function () {
133
+ RootPanel.prototype._watch = function _watch() {
139
134
  var me = this;
140
135
 
141
136
  this._unwatch();
142
137
 
143
- var checkSize = function () {
138
+ var checkSize = function checkSize() {
144
139
  var autoResize = me.getOption('autoResize');
145
140
  if (!autoResize) {
146
141
  // stop watching when the option autoResize is changed to false
@@ -150,9 +145,12 @@ RootPanel.prototype._watch = function () {
150
145
 
151
146
  if (me.frame) {
152
147
  // check whether the frame is resized
153
- if ((me.frame.clientWidth != me.width) ||
154
- (me.frame.clientHeight != me.height)) {
155
- me.requestReflow();
148
+ if ((me.frame.clientWidth != me.lastWidth) ||
149
+ (me.frame.clientHeight != me.lastHeight)) {
150
+ me.lastWidth = me.frame.clientWidth;
151
+ me.lastHeight = me.frame.clientHeight;
152
+ me.repaint();
153
+ // TODO: emit a resize event instead?
156
154
  }
157
155
  }
158
156
  };
@@ -167,7 +165,7 @@ RootPanel.prototype._watch = function () {
167
165
  * Stop watching for a resize of the frame.
168
166
  * @private
169
167
  */
170
- RootPanel.prototype._unwatch = function () {
168
+ RootPanel.prototype._unwatch = function _unwatch() {
171
169
  if (this.watchTimer) {
172
170
  clearInterval(this.watchTimer);
173
171
  this.watchTimer = undefined;
@@ -175,53 +173,3 @@ RootPanel.prototype._unwatch = function () {
175
173
 
176
174
  // TODO: remove event listener on window.resize
177
175
  };
178
-
179
- /**
180
- * Set controller for this component, or remove current controller by passing
181
- * null as parameter value.
182
- * @param {Controller | null} controller
183
- */
184
- RootPanel.prototype.setController = function setController (controller) {
185
- this.controller = controller || null;
186
-
187
- if (this.controller) {
188
- this._registerListeners();
189
- }
190
- else {
191
- this._unregisterListeners();
192
- }
193
- };
194
-
195
- /**
196
- * Register event emitters emitted by the rootpanel
197
- * @private
198
- */
199
- RootPanel.prototype._registerListeners = function () {
200
- if (this.frame && this.controller && !this.hammer) {
201
- this.hammer = Hammer(this.frame, {
202
- prevent_default: true
203
- });
204
-
205
- for (var event in this.listeners) {
206
- if (this.listeners.hasOwnProperty(event)) {
207
- this.hammer.on(event, this.listeners[event]);
208
- }
209
- }
210
- }
211
- };
212
-
213
- /**
214
- * Unregister event emitters from the rootpanel
215
- * @private
216
- */
217
- RootPanel.prototype._unregisterListeners = function () {
218
- if (this.hammer) {
219
- for (var event in this.listeners) {
220
- if (this.listeners.hasOwnProperty(event)) {
221
- this.hammer.off(event, this.listeners[event]);
222
- }
223
- }
224
-
225
- this.hammer = null;
226
- }
227
- };