vis-rails 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.gitmodules +3 -0
- data/.project +11 -0
- data/Gemfile +4 -0
- data/LICENSE +202 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/vis/rails/engine.rb +6 -0
- data/lib/vis/rails/version.rb +5 -0
- data/lib/vis/rails.rb +7 -0
- data/vendor/assets/javascripts/vis.js +1 -0
- data/vendor/assets/stylesheets/vis.css +3 -0
- data/vendor/assets/vis/DataSet.js +936 -0
- data/vendor/assets/vis/DataView.js +281 -0
- data/vendor/assets/vis/EventBus.js +89 -0
- data/vendor/assets/vis/events.js +116 -0
- data/vendor/assets/vis/graph/ClusterMixin.js +1019 -0
- data/vendor/assets/vis/graph/Edge.js +620 -0
- data/vendor/assets/vis/graph/Graph.js +2111 -0
- data/vendor/assets/vis/graph/Groups.js +80 -0
- data/vendor/assets/vis/graph/Images.js +41 -0
- data/vendor/assets/vis/graph/NavigationMixin.js +245 -0
- data/vendor/assets/vis/graph/Node.js +978 -0
- data/vendor/assets/vis/graph/Popup.js +105 -0
- data/vendor/assets/vis/graph/SectorsMixin.js +547 -0
- data/vendor/assets/vis/graph/SelectionMixin.js +515 -0
- data/vendor/assets/vis/graph/dotparser.js +829 -0
- data/vendor/assets/vis/graph/img/downarrow.png +0 -0
- data/vendor/assets/vis/graph/img/leftarrow.png +0 -0
- data/vendor/assets/vis/graph/img/minus.png +0 -0
- data/vendor/assets/vis/graph/img/plus.png +0 -0
- data/vendor/assets/vis/graph/img/rightarrow.png +0 -0
- data/vendor/assets/vis/graph/img/uparrow.png +0 -0
- data/vendor/assets/vis/graph/img/zoomExtends.png +0 -0
- data/vendor/assets/vis/graph/shapes.js +225 -0
- data/vendor/assets/vis/module/exports.js +68 -0
- data/vendor/assets/vis/module/header.js +24 -0
- data/vendor/assets/vis/module/imports.js +32 -0
- data/vendor/assets/vis/shim.js +252 -0
- data/vendor/assets/vis/timeline/Controller.js +172 -0
- data/vendor/assets/vis/timeline/Range.js +553 -0
- data/vendor/assets/vis/timeline/Stack.js +192 -0
- data/vendor/assets/vis/timeline/TimeStep.js +449 -0
- data/vendor/assets/vis/timeline/Timeline.js +476 -0
- data/vendor/assets/vis/timeline/component/Component.js +148 -0
- data/vendor/assets/vis/timeline/component/ContentPanel.js +113 -0
- data/vendor/assets/vis/timeline/component/CurrentTime.js +101 -0
- data/vendor/assets/vis/timeline/component/CustomTime.js +255 -0
- data/vendor/assets/vis/timeline/component/Group.js +129 -0
- data/vendor/assets/vis/timeline/component/GroupSet.js +546 -0
- data/vendor/assets/vis/timeline/component/ItemSet.js +612 -0
- data/vendor/assets/vis/timeline/component/Panel.js +112 -0
- data/vendor/assets/vis/timeline/component/RootPanel.js +215 -0
- data/vendor/assets/vis/timeline/component/TimeAxis.js +522 -0
- data/vendor/assets/vis/timeline/component/css/currenttime.css +5 -0
- data/vendor/assets/vis/timeline/component/css/customtime.css +6 -0
- data/vendor/assets/vis/timeline/component/css/groupset.css +59 -0
- data/vendor/assets/vis/timeline/component/css/item.css +93 -0
- data/vendor/assets/vis/timeline/component/css/itemset.css +17 -0
- data/vendor/assets/vis/timeline/component/css/panel.css +14 -0
- data/vendor/assets/vis/timeline/component/css/timeaxis.css +41 -0
- data/vendor/assets/vis/timeline/component/css/timeline.css +2 -0
- data/vendor/assets/vis/timeline/component/item/Item.js +81 -0
- data/vendor/assets/vis/timeline/component/item/ItemBox.js +302 -0
- data/vendor/assets/vis/timeline/component/item/ItemPoint.js +237 -0
- data/vendor/assets/vis/timeline/component/item/ItemRange.js +251 -0
- data/vendor/assets/vis/timeline/component/item/ItemRangeOverflow.js +91 -0
- data/vendor/assets/vis/util.js +673 -0
- data/vis-rails.gemspec +47 -0
- metadata +142 -0
@@ -0,0 +1,215 @@
|
|
1
|
+
/**
|
2
|
+
* A root panel can hold components. The root panel must be initialized with
|
3
|
+
* a DOM element as container.
|
4
|
+
* @param {HTMLElement} container
|
5
|
+
* @param {Object} [options] Available parameters: see RootPanel.setOptions.
|
6
|
+
* @constructor RootPanel
|
7
|
+
* @extends Panel
|
8
|
+
*/
|
9
|
+
function RootPanel(container, options) {
|
10
|
+
this.id = util.randomUUID();
|
11
|
+
this.container = container;
|
12
|
+
|
13
|
+
this.options = options || {};
|
14
|
+
this.defaultOptions = {
|
15
|
+
autoResize: true
|
16
|
+
};
|
17
|
+
|
18
|
+
this.listeners = {}; // event listeners
|
19
|
+
}
|
20
|
+
|
21
|
+
RootPanel.prototype = new Panel();
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Set options. Will extend the current options.
|
25
|
+
* @param {Object} [options] Available parameters:
|
26
|
+
* {String | function} [className]
|
27
|
+
* {String | Number | function} [left]
|
28
|
+
* {String | Number | function} [top]
|
29
|
+
* {String | Number | function} [width]
|
30
|
+
* {String | Number | function} [height]
|
31
|
+
* {Boolean | function} [autoResize]
|
32
|
+
*/
|
33
|
+
RootPanel.prototype.setOptions = Component.prototype.setOptions;
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Repaint the component
|
37
|
+
* @return {Boolean} changed
|
38
|
+
*/
|
39
|
+
RootPanel.prototype.repaint = function () {
|
40
|
+
var changed = 0,
|
41
|
+
update = util.updateProperty,
|
42
|
+
asSize = util.option.asSize,
|
43
|
+
options = this.options,
|
44
|
+
frame = this.frame;
|
45
|
+
|
46
|
+
if (!frame) {
|
47
|
+
frame = document.createElement('div');
|
48
|
+
|
49
|
+
this.frame = frame;
|
50
|
+
|
51
|
+
changed += 1;
|
52
|
+
}
|
53
|
+
if (!frame.parentNode) {
|
54
|
+
if (!this.container) {
|
55
|
+
throw new Error('Cannot repaint root panel: no container attached');
|
56
|
+
}
|
57
|
+
this.container.appendChild(frame);
|
58
|
+
changed += 1;
|
59
|
+
}
|
60
|
+
|
61
|
+
frame.className = 'vis timeline rootpanel ' + options.orientation;
|
62
|
+
var className = options.className;
|
63
|
+
if (className) {
|
64
|
+
util.addClassName(frame, util.option.asString(className));
|
65
|
+
}
|
66
|
+
|
67
|
+
changed += update(frame.style, 'top', asSize(options.top, '0px'));
|
68
|
+
changed += update(frame.style, 'left', asSize(options.left, '0px'));
|
69
|
+
changed += update(frame.style, 'width', asSize(options.width, '100%'));
|
70
|
+
changed += update(frame.style, 'height', asSize(options.height, '100%'));
|
71
|
+
|
72
|
+
this._updateEventEmitters();
|
73
|
+
this._updateWatch();
|
74
|
+
|
75
|
+
return (changed > 0);
|
76
|
+
};
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Reflow the component
|
80
|
+
* @return {Boolean} resized
|
81
|
+
*/
|
82
|
+
RootPanel.prototype.reflow = function () {
|
83
|
+
var changed = 0,
|
84
|
+
update = util.updateProperty,
|
85
|
+
frame = this.frame;
|
86
|
+
|
87
|
+
if (frame) {
|
88
|
+
changed += update(this, 'top', frame.offsetTop);
|
89
|
+
changed += update(this, 'left', frame.offsetLeft);
|
90
|
+
changed += update(this, 'width', frame.offsetWidth);
|
91
|
+
changed += update(this, 'height', frame.offsetHeight);
|
92
|
+
}
|
93
|
+
else {
|
94
|
+
changed += 1;
|
95
|
+
}
|
96
|
+
|
97
|
+
return (changed > 0);
|
98
|
+
};
|
99
|
+
|
100
|
+
/**
|
101
|
+
* Update watching for resize, depending on the current option
|
102
|
+
* @private
|
103
|
+
*/
|
104
|
+
RootPanel.prototype._updateWatch = function () {
|
105
|
+
var autoResize = this.getOption('autoResize');
|
106
|
+
if (autoResize) {
|
107
|
+
this._watch();
|
108
|
+
}
|
109
|
+
else {
|
110
|
+
this._unwatch();
|
111
|
+
}
|
112
|
+
};
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Watch for changes in the size of the frame. On resize, the Panel will
|
116
|
+
* automatically redraw itself.
|
117
|
+
* @private
|
118
|
+
*/
|
119
|
+
RootPanel.prototype._watch = function () {
|
120
|
+
var me = this;
|
121
|
+
|
122
|
+
this._unwatch();
|
123
|
+
|
124
|
+
var checkSize = function () {
|
125
|
+
var autoResize = me.getOption('autoResize');
|
126
|
+
if (!autoResize) {
|
127
|
+
// stop watching when the option autoResize is changed to false
|
128
|
+
me._unwatch();
|
129
|
+
return;
|
130
|
+
}
|
131
|
+
|
132
|
+
if (me.frame) {
|
133
|
+
// check whether the frame is resized
|
134
|
+
if ((me.frame.clientWidth != me.width) ||
|
135
|
+
(me.frame.clientHeight != me.height)) {
|
136
|
+
me.requestReflow();
|
137
|
+
}
|
138
|
+
}
|
139
|
+
};
|
140
|
+
|
141
|
+
// TODO: automatically cleanup the event listener when the frame is deleted
|
142
|
+
util.addEventListener(window, 'resize', checkSize);
|
143
|
+
|
144
|
+
this.watchTimer = setInterval(checkSize, 1000);
|
145
|
+
};
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Stop watching for a resize of the frame.
|
149
|
+
* @private
|
150
|
+
*/
|
151
|
+
RootPanel.prototype._unwatch = function () {
|
152
|
+
if (this.watchTimer) {
|
153
|
+
clearInterval(this.watchTimer);
|
154
|
+
this.watchTimer = undefined;
|
155
|
+
}
|
156
|
+
|
157
|
+
// TODO: remove event listener on window.resize
|
158
|
+
};
|
159
|
+
|
160
|
+
/**
|
161
|
+
* Event handler
|
162
|
+
* @param {String} event name of the event, for example 'click', 'mousemove'
|
163
|
+
* @param {function} callback callback handler, invoked with the raw HTML Event
|
164
|
+
* as parameter.
|
165
|
+
*/
|
166
|
+
RootPanel.prototype.on = function (event, callback) {
|
167
|
+
// register the listener at this component
|
168
|
+
var arr = this.listeners[event];
|
169
|
+
if (!arr) {
|
170
|
+
arr = [];
|
171
|
+
this.listeners[event] = arr;
|
172
|
+
}
|
173
|
+
arr.push(callback);
|
174
|
+
|
175
|
+
this._updateEventEmitters();
|
176
|
+
};
|
177
|
+
|
178
|
+
/**
|
179
|
+
* Update the event listeners for all event emitters
|
180
|
+
* @private
|
181
|
+
*/
|
182
|
+
RootPanel.prototype._updateEventEmitters = function () {
|
183
|
+
if (this.listeners) {
|
184
|
+
var me = this;
|
185
|
+
util.forEach(this.listeners, function (listeners, event) {
|
186
|
+
if (!me.emitters) {
|
187
|
+
me.emitters = {};
|
188
|
+
}
|
189
|
+
if (!(event in me.emitters)) {
|
190
|
+
// create event
|
191
|
+
var frame = me.frame;
|
192
|
+
if (frame) {
|
193
|
+
//console.log('Created a listener for event ' + event + ' on component ' + me.id); // TODO: cleanup logging
|
194
|
+
var callback = function(event) {
|
195
|
+
listeners.forEach(function (listener) {
|
196
|
+
// TODO: filter on event target!
|
197
|
+
listener(event);
|
198
|
+
});
|
199
|
+
};
|
200
|
+
me.emitters[event] = callback;
|
201
|
+
|
202
|
+
if (!me.hammer) {
|
203
|
+
me.hammer = Hammer(frame, {
|
204
|
+
prevent_default: true
|
205
|
+
});
|
206
|
+
}
|
207
|
+
me.hammer.on(event, callback);
|
208
|
+
}
|
209
|
+
}
|
210
|
+
});
|
211
|
+
|
212
|
+
// TODO: be able to delete event listeners
|
213
|
+
// TODO: be able to move event listeners to a parent when available
|
214
|
+
}
|
215
|
+
};
|