vis-rails 2.0.0 → 2.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.
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
@@ -1,65 +0,0 @@
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
- graph: {
28
- Node: Node,
29
- Edge: Edge,
30
- Popup: Popup,
31
- Groups: Groups,
32
- Images: Images
33
- },
34
-
35
- Timeline: Timeline,
36
- Graph: Graph,
37
- Graph3d: Graph3d
38
- };
39
-
40
- /**
41
- * CommonJS module exports
42
- */
43
- if (typeof exports !== 'undefined') {
44
- exports = vis;
45
- }
46
- if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
47
- module.exports = vis;
48
- }
49
-
50
- /**
51
- * AMD module exports
52
- */
53
- if (typeof(define) === 'function') {
54
- define(function () {
55
- return vis;
56
- });
57
- }
58
-
59
- /**
60
- * Window exports
61
- */
62
- if (typeof window !== 'undefined') {
63
- // attach the module to the window, load as a regular javascript file
64
- window['vis'] = vis;
65
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * vis.js
3
- * https://github.com/almende/vis
4
- *
5
- * A dynamic, browser-based visualization library.
6
- *
7
- * @version @@version
8
- * @date @@date
9
- *
10
- * @license
11
- * Copyright (C) 2011-2014 Almende B.V, http://almende.com
12
- *
13
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
14
- * use this file except in compliance with the License. You may obtain a copy
15
- * of the License at
16
- *
17
- * http://www.apache.org/licenses/LICENSE-2.0
18
- *
19
- * Unless required by applicable law or agreed to in writing, software
20
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
21
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
22
- * License for the specific language governing permissions and limitations under
23
- * the License.
24
- */
@@ -1,31 +0,0 @@
1
- /**
2
- * vis.js module imports
3
- */
4
-
5
- // Try to load dependencies from the global window object.
6
- // If not available there, load via require.
7
-
8
- var moment = (typeof window !== 'undefined') && window['moment'] || require('moment');
9
- var Emitter = require('emitter-component');
10
-
11
- var Hammer;
12
- if (typeof window !== 'undefined') {
13
- // load hammer.js only when running in a browser (where window is available)
14
- Hammer = window['Hammer'] || require('hammerjs');
15
- }
16
- else {
17
- Hammer = function () {
18
- throw Error('hammer.js is only available in a browser, not in node.js.');
19
- }
20
- }
21
-
22
- var mousetrap;
23
- if (typeof window !== 'undefined') {
24
- // load mousetrap.js only when running in a browser (where window is available)
25
- mousetrap = window['mousetrap'] || require('mousetrap');
26
- }
27
- else {
28
- mousetrap = function () {
29
- throw Error('mouseTrap is only available in a browser, not in node.js.');
30
- }
31
- }
@@ -1,252 +0,0 @@
1
-
2
- // Internet Explorer 8 and older does not support Array.indexOf, so we define
3
- // it here in that case.
4
- // http://soledadpenades.com/2007/05/17/arrayindexof-in-internet-explorer/
5
- if(!Array.prototype.indexOf) {
6
- Array.prototype.indexOf = function(obj){
7
- for(var i = 0; i < this.length; i++){
8
- if(this[i] == obj){
9
- return i;
10
- }
11
- }
12
- return -1;
13
- };
14
-
15
- try {
16
- console.log("Warning: Ancient browser detected. Please update your browser");
17
- }
18
- catch (err) {
19
- }
20
- }
21
-
22
- // Internet Explorer 8 and older does not support Array.forEach, so we define
23
- // it here in that case.
24
- // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach
25
- if (!Array.prototype.forEach) {
26
- Array.prototype.forEach = function(fn, scope) {
27
- for(var i = 0, len = this.length; i < len; ++i) {
28
- fn.call(scope || this, this[i], i, this);
29
- }
30
- }
31
- }
32
-
33
- // Internet Explorer 8 and older does not support Array.map, so we define it
34
- // here in that case.
35
- // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map
36
- // Production steps of ECMA-262, Edition 5, 15.4.4.19
37
- // Reference: http://es5.github.com/#x15.4.4.19
38
- if (!Array.prototype.map) {
39
- Array.prototype.map = function(callback, thisArg) {
40
-
41
- var T, A, k;
42
-
43
- if (this == null) {
44
- throw new TypeError(" this is null or not defined");
45
- }
46
-
47
- // 1. Let O be the result of calling ToObject passing the |this| value as the argument.
48
- var O = Object(this);
49
-
50
- // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
51
- // 3. Let len be ToUint32(lenValue).
52
- var len = O.length >>> 0;
53
-
54
- // 4. If IsCallable(callback) is false, throw a TypeError exception.
55
- // See: http://es5.github.com/#x9.11
56
- if (typeof callback !== "function") {
57
- throw new TypeError(callback + " is not a function");
58
- }
59
-
60
- // 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
61
- if (thisArg) {
62
- T = thisArg;
63
- }
64
-
65
- // 6. Let A be a new array created as if by the expression new Array(len) where Array is
66
- // the standard built-in constructor with that name and len is the value of len.
67
- A = new Array(len);
68
-
69
- // 7. Let k be 0
70
- k = 0;
71
-
72
- // 8. Repeat, while k < len
73
- while(k < len) {
74
-
75
- var kValue, mappedValue;
76
-
77
- // a. Let Pk be ToString(k).
78
- // This is implicit for LHS operands of the in operator
79
- // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
80
- // This step can be combined with c
81
- // c. If kPresent is true, then
82
- if (k in O) {
83
-
84
- // i. Let kValue be the result of calling the Get internal method of O with argument Pk.
85
- kValue = O[ k ];
86
-
87
- // ii. Let mappedValue be the result of calling the Call internal method of callback
88
- // with T as the this value and argument list containing kValue, k, and O.
89
- mappedValue = callback.call(T, kValue, k, O);
90
-
91
- // iii. Call the DefineOwnProperty internal method of A with arguments
92
- // Pk, Property Descriptor {Value: mappedValue, : true, Enumerable: true, Configurable: true},
93
- // and false.
94
-
95
- // In browsers that support Object.defineProperty, use the following:
96
- // Object.defineProperty(A, Pk, { value: mappedValue, writable: true, enumerable: true, configurable: true });
97
-
98
- // For best browser support, use the following:
99
- A[ k ] = mappedValue;
100
- }
101
- // d. Increase k by 1.
102
- k++;
103
- }
104
-
105
- // 9. return A
106
- return A;
107
- };
108
- }
109
-
110
- // Internet Explorer 8 and older does not support Array.filter, so we define it
111
- // here in that case.
112
- // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/filter
113
- if (!Array.prototype.filter) {
114
- Array.prototype.filter = function(fun /*, thisp */) {
115
- "use strict";
116
-
117
- if (this == null) {
118
- throw new TypeError();
119
- }
120
-
121
- var t = Object(this);
122
- var len = t.length >>> 0;
123
- if (typeof fun != "function") {
124
- throw new TypeError();
125
- }
126
-
127
- var res = [];
128
- var thisp = arguments[1];
129
- for (var i = 0; i < len; i++) {
130
- if (i in t) {
131
- var val = t[i]; // in case fun mutates this
132
- if (fun.call(thisp, val, i, t))
133
- res.push(val);
134
- }
135
- }
136
-
137
- return res;
138
- };
139
- }
140
-
141
-
142
- // Internet Explorer 8 and older does not support Object.keys, so we define it
143
- // here in that case.
144
- // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/keys
145
- if (!Object.keys) {
146
- Object.keys = (function () {
147
- var hasOwnProperty = Object.prototype.hasOwnProperty,
148
- hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
149
- dontEnums = [
150
- 'toString',
151
- 'toLocaleString',
152
- 'valueOf',
153
- 'hasOwnProperty',
154
- 'isPrototypeOf',
155
- 'propertyIsEnumerable',
156
- 'constructor'
157
- ],
158
- dontEnumsLength = dontEnums.length;
159
-
160
- return function (obj) {
161
- if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) {
162
- throw new TypeError('Object.keys called on non-object');
163
- }
164
-
165
- var result = [];
166
-
167
- for (var prop in obj) {
168
- if (hasOwnProperty.call(obj, prop)) result.push(prop);
169
- }
170
-
171
- if (hasDontEnumBug) {
172
- for (var i=0; i < dontEnumsLength; i++) {
173
- if (hasOwnProperty.call(obj, dontEnums[i])) result.push(dontEnums[i]);
174
- }
175
- }
176
- return result;
177
- }
178
- })()
179
- }
180
-
181
- // Internet Explorer 8 and older does not support Array.isArray,
182
- // so we define it here in that case.
183
- // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/isArray
184
- if(!Array.isArray) {
185
- Array.isArray = function (vArg) {
186
- return Object.prototype.toString.call(vArg) === "[object Array]";
187
- };
188
- }
189
-
190
- // Internet Explorer 8 and older does not support Function.bind,
191
- // so we define it here in that case.
192
- // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/bind
193
- if (!Function.prototype.bind) {
194
- Function.prototype.bind = function (oThis) {
195
- if (typeof this !== "function") {
196
- // closest thing possible to the ECMAScript 5 internal IsCallable function
197
- throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
198
- }
199
-
200
- var aArgs = Array.prototype.slice.call(arguments, 1),
201
- fToBind = this,
202
- fNOP = function () {},
203
- fBound = function () {
204
- return fToBind.apply(this instanceof fNOP && oThis
205
- ? this
206
- : oThis,
207
- aArgs.concat(Array.prototype.slice.call(arguments)));
208
- };
209
-
210
- fNOP.prototype = this.prototype;
211
- fBound.prototype = new fNOP();
212
-
213
- return fBound;
214
- };
215
- }
216
-
217
- // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/create
218
- if (!Object.create) {
219
- Object.create = function (o) {
220
- if (arguments.length > 1) {
221
- throw new Error('Object.create implementation only accepts the first parameter.');
222
- }
223
- function F() {}
224
- F.prototype = o;
225
- return new F();
226
- };
227
- }
228
-
229
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
230
- if (!Function.prototype.bind) {
231
- Function.prototype.bind = function (oThis) {
232
- if (typeof this !== "function") {
233
- // closest thing possible to the ECMAScript 5 internal IsCallable function
234
- throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
235
- }
236
-
237
- var aArgs = Array.prototype.slice.call(arguments, 1),
238
- fToBind = this,
239
- fNOP = function () {},
240
- fBound = function () {
241
- return fToBind.apply(this instanceof fNOP && oThis
242
- ? this
243
- : oThis,
244
- aArgs.concat(Array.prototype.slice.call(arguments)));
245
- };
246
-
247
- fNOP.prototype = this.prototype;
248
- fBound.prototype = new fNOP();
249
-
250
- return fBound;
251
- };
252
- }
@@ -1,532 +0,0 @@
1
- /**
2
- * @constructor Range
3
- * A Range controls a numeric range with a start and end value.
4
- * The Range adjusts the range based on mouse events or programmatic changes,
5
- * and triggers events when the range is changing or has been changed.
6
- * @param {{dom: Object, domProps: Object, emitter: Emitter}} body
7
- * @param {Object} [options] See description at Range.setOptions
8
- */
9
- function Range(body, options) {
10
- var now = moment().hours(0).minutes(0).seconds(0).milliseconds(0);
11
- this.start = now.clone().add('days', -3).valueOf(); // Number
12
- this.end = now.clone().add('days', 4).valueOf(); // Number
13
-
14
- this.body = body;
15
-
16
- // default options
17
- this.defaultOptions = {
18
- start: null,
19
- end: null,
20
- direction: 'horizontal', // 'horizontal' or 'vertical'
21
- moveable: true,
22
- zoomable: true,
23
- min: null,
24
- max: null,
25
- zoomMin: 10, // milliseconds
26
- zoomMax: 1000 * 60 * 60 * 24 * 365 * 10000 // milliseconds
27
- };
28
- this.options = util.extend({}, this.defaultOptions);
29
-
30
- this.props = {
31
- touch: {}
32
- };
33
-
34
- // drag listeners for dragging
35
- this.body.emitter.on('dragstart', this._onDragStart.bind(this));
36
- this.body.emitter.on('drag', this._onDrag.bind(this));
37
- this.body.emitter.on('dragend', this._onDragEnd.bind(this));
38
-
39
- // ignore dragging when holding
40
- this.body.emitter.on('hold', this._onHold.bind(this));
41
-
42
- // mouse wheel for zooming
43
- this.body.emitter.on('mousewheel', this._onMouseWheel.bind(this));
44
- this.body.emitter.on('DOMMouseScroll', this._onMouseWheel.bind(this)); // For FF
45
-
46
- // pinch to zoom
47
- this.body.emitter.on('touch', this._onTouch.bind(this));
48
- this.body.emitter.on('pinch', this._onPinch.bind(this));
49
-
50
- this.setOptions(options);
51
- }
52
-
53
- Range.prototype = new Component();
54
-
55
- /**
56
- * Set options for the range controller
57
- * @param {Object} options Available options:
58
- * {Number | Date | String} start Start date for the range
59
- * {Number | Date | String} end End date for the range
60
- * {Number} min Minimum value for start
61
- * {Number} max Maximum value for end
62
- * {Number} zoomMin Set a minimum value for
63
- * (end - start).
64
- * {Number} zoomMax Set a maximum value for
65
- * (end - start).
66
- * {Boolean} moveable Enable moving of the range
67
- * by dragging. True by default
68
- * {Boolean} zoomable Enable zooming of the range
69
- * by pinching/scrolling. True by default
70
- */
71
- Range.prototype.setOptions = function (options) {
72
- if (options) {
73
- // copy the options that we know
74
- var fields = ['direction', 'min', 'max', 'zoomMin', 'zoomMax', 'moveable', 'zoomable'];
75
- util.selectiveExtend(fields, this.options, options);
76
-
77
- if ('start' in options || 'end' in options) {
78
- // apply a new range. both start and end are optional
79
- this.setRange(options.start, options.end);
80
- }
81
- }
82
- };
83
-
84
- /**
85
- * Test whether direction has a valid value
86
- * @param {String} direction 'horizontal' or 'vertical'
87
- */
88
- function validateDirection (direction) {
89
- if (direction != 'horizontal' && direction != 'vertical') {
90
- throw new TypeError('Unknown direction "' + direction + '". ' +
91
- 'Choose "horizontal" or "vertical".');
92
- }
93
- }
94
-
95
- /**
96
- * Set a new start and end range
97
- * @param {Number} [start]
98
- * @param {Number} [end]
99
- */
100
- Range.prototype.setRange = function(start, end) {
101
- var changed = this._applyRange(start, end);
102
- if (changed) {
103
- var params = {
104
- start: new Date(this.start),
105
- end: new Date(this.end)
106
- };
107
- this.body.emitter.emit('rangechange', params);
108
- this.body.emitter.emit('rangechanged', params);
109
- }
110
- };
111
-
112
- /**
113
- * Set a new start and end range. This method is the same as setRange, but
114
- * does not trigger a range change and range changed event, and it returns
115
- * true when the range is changed
116
- * @param {Number} [start]
117
- * @param {Number} [end]
118
- * @return {Boolean} changed
119
- * @private
120
- */
121
- Range.prototype._applyRange = function(start, end) {
122
- var newStart = (start != null) ? util.convert(start, 'Date').valueOf() : this.start,
123
- newEnd = (end != null) ? util.convert(end, 'Date').valueOf() : this.end,
124
- max = (this.options.max != null) ? util.convert(this.options.max, 'Date').valueOf() : null,
125
- min = (this.options.min != null) ? util.convert(this.options.min, 'Date').valueOf() : null,
126
- diff;
127
-
128
- // check for valid number
129
- if (isNaN(newStart) || newStart === null) {
130
- throw new Error('Invalid start "' + start + '"');
131
- }
132
- if (isNaN(newEnd) || newEnd === null) {
133
- throw new Error('Invalid end "' + end + '"');
134
- }
135
-
136
- // prevent start < end
137
- if (newEnd < newStart) {
138
- newEnd = newStart;
139
- }
140
-
141
- // prevent start < min
142
- if (min !== null) {
143
- if (newStart < min) {
144
- diff = (min - newStart);
145
- newStart += diff;
146
- newEnd += diff;
147
-
148
- // prevent end > max
149
- if (max != null) {
150
- if (newEnd > max) {
151
- newEnd = max;
152
- }
153
- }
154
- }
155
- }
156
-
157
- // prevent end > max
158
- if (max !== null) {
159
- if (newEnd > max) {
160
- diff = (newEnd - max);
161
- newStart -= diff;
162
- newEnd -= diff;
163
-
164
- // prevent start < min
165
- if (min != null) {
166
- if (newStart < min) {
167
- newStart = min;
168
- }
169
- }
170
- }
171
- }
172
-
173
- // prevent (end-start) < zoomMin
174
- if (this.options.zoomMin !== null) {
175
- var zoomMin = parseFloat(this.options.zoomMin);
176
- if (zoomMin < 0) {
177
- zoomMin = 0;
178
- }
179
- if ((newEnd - newStart) < zoomMin) {
180
- if ((this.end - this.start) === zoomMin) {
181
- // ignore this action, we are already zoomed to the minimum
182
- newStart = this.start;
183
- newEnd = this.end;
184
- }
185
- else {
186
- // zoom to the minimum
187
- diff = (zoomMin - (newEnd - newStart));
188
- newStart -= diff / 2;
189
- newEnd += diff / 2;
190
- }
191
- }
192
- }
193
-
194
- // prevent (end-start) > zoomMax
195
- if (this.options.zoomMax !== null) {
196
- var zoomMax = parseFloat(this.options.zoomMax);
197
- if (zoomMax < 0) {
198
- zoomMax = 0;
199
- }
200
- if ((newEnd - newStart) > zoomMax) {
201
- if ((this.end - this.start) === zoomMax) {
202
- // ignore this action, we are already zoomed to the maximum
203
- newStart = this.start;
204
- newEnd = this.end;
205
- }
206
- else {
207
- // zoom to the maximum
208
- diff = ((newEnd - newStart) - zoomMax);
209
- newStart += diff / 2;
210
- newEnd -= diff / 2;
211
- }
212
- }
213
- }
214
-
215
- var changed = (this.start != newStart || this.end != newEnd);
216
-
217
- this.start = newStart;
218
- this.end = newEnd;
219
-
220
- return changed;
221
- };
222
-
223
- /**
224
- * Retrieve the current range.
225
- * @return {Object} An object with start and end properties
226
- */
227
- Range.prototype.getRange = function() {
228
- return {
229
- start: this.start,
230
- end: this.end
231
- };
232
- };
233
-
234
- /**
235
- * Calculate the conversion offset and scale for current range, based on
236
- * the provided width
237
- * @param {Number} width
238
- * @returns {{offset: number, scale: number}} conversion
239
- */
240
- Range.prototype.conversion = function (width) {
241
- return Range.conversion(this.start, this.end, width);
242
- };
243
-
244
- /**
245
- * Static method to calculate the conversion offset and scale for a range,
246
- * based on the provided start, end, and width
247
- * @param {Number} start
248
- * @param {Number} end
249
- * @param {Number} width
250
- * @returns {{offset: number, scale: number}} conversion
251
- */
252
- Range.conversion = function (start, end, width) {
253
- if (width != 0 && (end - start != 0)) {
254
- return {
255
- offset: start,
256
- scale: width / (end - start)
257
- }
258
- }
259
- else {
260
- return {
261
- offset: 0,
262
- scale: 1
263
- };
264
- }
265
- };
266
-
267
- /**
268
- * Start dragging horizontally or vertically
269
- * @param {Event} event
270
- * @private
271
- */
272
- Range.prototype._onDragStart = function(event) {
273
- // only allow dragging when configured as movable
274
- if (!this.options.moveable) return;
275
-
276
- // refuse to drag when we where pinching to prevent the timeline make a jump
277
- // when releasing the fingers in opposite order from the touch screen
278
- if (!this.props.touch.allowDragging) return;
279
-
280
- this.props.touch.start = this.start;
281
- this.props.touch.end = this.end;
282
-
283
- if (this.body.dom.root) {
284
- this.body.dom.root.style.cursor = 'move';
285
- }
286
- };
287
-
288
- /**
289
- * Perform dragging operation
290
- * @param {Event} event
291
- * @private
292
- */
293
- Range.prototype._onDrag = function (event) {
294
- // only allow dragging when configured as movable
295
- if (!this.options.moveable) return;
296
-
297
- var direction = this.options.direction;
298
- validateDirection(direction);
299
-
300
- // refuse to drag when we where pinching to prevent the timeline make a jump
301
- // when releasing the fingers in opposite order from the touch screen
302
- if (!this.props.touch.allowDragging) return;
303
-
304
- var delta = (direction == 'horizontal') ? event.gesture.deltaX : event.gesture.deltaY,
305
- interval = (this.props.touch.end - this.props.touch.start),
306
- width = (direction == 'horizontal') ? this.body.domProps.center.width : this.body.domProps.center.height,
307
- diffRange = -delta / width * interval;
308
-
309
- this._applyRange(this.props.touch.start + diffRange, this.props.touch.end + diffRange);
310
-
311
- this.body.emitter.emit('rangechange', {
312
- start: new Date(this.start),
313
- end: new Date(this.end)
314
- });
315
- };
316
-
317
- /**
318
- * Stop dragging operation
319
- * @param {event} event
320
- * @private
321
- */
322
- Range.prototype._onDragEnd = function (event) {
323
- // only allow dragging when configured as movable
324
- if (!this.options.moveable) return;
325
-
326
- // refuse to drag when we where pinching to prevent the timeline make a jump
327
- // when releasing the fingers in opposite order from the touch screen
328
- if (!this.props.touch.allowDragging) return;
329
-
330
- if (this.body.dom.root) {
331
- this.body.dom.root.style.cursor = 'auto';
332
- }
333
-
334
- // fire a rangechanged event
335
- this.body.emitter.emit('rangechanged', {
336
- start: new Date(this.start),
337
- end: new Date(this.end)
338
- });
339
- };
340
-
341
- /**
342
- * Event handler for mouse wheel event, used to zoom
343
- * Code from http://adomas.org/javascript-mouse-wheel/
344
- * @param {Event} event
345
- * @private
346
- */
347
- Range.prototype._onMouseWheel = function(event) {
348
- // only allow zooming when configured as zoomable and moveable
349
- if (!(this.options.zoomable && this.options.moveable)) return;
350
-
351
- // retrieve delta
352
- var delta = 0;
353
- if (event.wheelDelta) { /* IE/Opera. */
354
- delta = event.wheelDelta / 120;
355
- } else if (event.detail) { /* Mozilla case. */
356
- // In Mozilla, sign of delta is different than in IE.
357
- // Also, delta is multiple of 3.
358
- delta = -event.detail / 3;
359
- }
360
-
361
- // If delta is nonzero, handle it.
362
- // Basically, delta is now positive if wheel was scrolled up,
363
- // and negative, if wheel was scrolled down.
364
- if (delta) {
365
- // perform the zoom action. Delta is normally 1 or -1
366
-
367
- // adjust a negative delta such that zooming in with delta 0.1
368
- // equals zooming out with a delta -0.1
369
- var scale;
370
- if (delta < 0) {
371
- scale = 1 - (delta / 5);
372
- }
373
- else {
374
- scale = 1 / (1 + (delta / 5)) ;
375
- }
376
-
377
- // calculate center, the date to zoom around
378
- var gesture = util.fakeGesture(this, event),
379
- pointer = getPointer(gesture.center, this.body.dom.center),
380
- pointerDate = this._pointerToDate(pointer);
381
-
382
- this.zoom(scale, pointerDate);
383
- }
384
-
385
- // Prevent default actions caused by mouse wheel
386
- // (else the page and timeline both zoom and scroll)
387
- event.preventDefault();
388
- };
389
-
390
- /**
391
- * Start of a touch gesture
392
- * @private
393
- */
394
- Range.prototype._onTouch = function (event) {
395
- this.props.touch.start = this.start;
396
- this.props.touch.end = this.end;
397
- this.props.touch.allowDragging = true;
398
- this.props.touch.center = null;
399
- };
400
-
401
- /**
402
- * On start of a hold gesture
403
- * @private
404
- */
405
- Range.prototype._onHold = function () {
406
- this.props.touch.allowDragging = false;
407
- };
408
-
409
- /**
410
- * Handle pinch event
411
- * @param {Event} event
412
- * @private
413
- */
414
- Range.prototype._onPinch = function (event) {
415
- // only allow zooming when configured as zoomable and moveable
416
- if (!(this.options.zoomable && this.options.moveable)) return;
417
-
418
- this.props.touch.allowDragging = false;
419
-
420
- if (event.gesture.touches.length > 1) {
421
- if (!this.props.touch.center) {
422
- this.props.touch.center = getPointer(event.gesture.center, this.body.dom.center);
423
- }
424
-
425
- var scale = 1 / event.gesture.scale,
426
- initDate = this._pointerToDate(this.props.touch.center);
427
-
428
- // calculate new start and end
429
- var newStart = parseInt(initDate + (this.props.touch.start - initDate) * scale);
430
- var newEnd = parseInt(initDate + (this.props.touch.end - initDate) * scale);
431
-
432
- // apply new range
433
- this.setRange(newStart, newEnd);
434
- }
435
- };
436
-
437
- /**
438
- * Helper function to calculate the center date for zooming
439
- * @param {{x: Number, y: Number}} pointer
440
- * @return {number} date
441
- * @private
442
- */
443
- Range.prototype._pointerToDate = function (pointer) {
444
- var conversion;
445
- var direction = this.options.direction;
446
-
447
- validateDirection(direction);
448
-
449
- if (direction == 'horizontal') {
450
- var width = this.body.domProps.center.width;
451
- conversion = this.conversion(width);
452
- return pointer.x / conversion.scale + conversion.offset;
453
- }
454
- else {
455
- var height = this.body.domProps.center.height;
456
- conversion = this.conversion(height);
457
- return pointer.y / conversion.scale + conversion.offset;
458
- }
459
- };
460
-
461
- /**
462
- * Get the pointer location relative to the location of the dom element
463
- * @param {{pageX: Number, pageY: Number}} touch
464
- * @param {Element} element HTML DOM element
465
- * @return {{x: Number, y: Number}} pointer
466
- * @private
467
- */
468
- function getPointer (touch, element) {
469
- return {
470
- x: touch.pageX - vis.util.getAbsoluteLeft(element),
471
- y: touch.pageY - vis.util.getAbsoluteTop(element)
472
- };
473
- }
474
-
475
- /**
476
- * Zoom the range the given scale in or out. Start and end date will
477
- * be adjusted, and the timeline will be redrawn. You can optionally give a
478
- * date around which to zoom.
479
- * For example, try scale = 0.9 or 1.1
480
- * @param {Number} scale Scaling factor. Values above 1 will zoom out,
481
- * values below 1 will zoom in.
482
- * @param {Number} [center] Value representing a date around which will
483
- * be zoomed.
484
- */
485
- Range.prototype.zoom = function(scale, center) {
486
- // if centerDate is not provided, take it half between start Date and end Date
487
- if (center == null) {
488
- center = (this.start + this.end) / 2;
489
- }
490
-
491
- // calculate new start and end
492
- var newStart = center + (this.start - center) * scale;
493
- var newEnd = center + (this.end - center) * scale;
494
-
495
- this.setRange(newStart, newEnd);
496
- };
497
-
498
- /**
499
- * Move the range with a given delta to the left or right. Start and end
500
- * value will be adjusted. For example, try delta = 0.1 or -0.1
501
- * @param {Number} delta Moving amount. Positive value will move right,
502
- * negative value will move left
503
- */
504
- Range.prototype.move = function(delta) {
505
- // zoom start Date and end Date relative to the centerDate
506
- var diff = (this.end - this.start);
507
-
508
- // apply new values
509
- var newStart = this.start + diff * delta;
510
- var newEnd = this.end + diff * delta;
511
-
512
- // TODO: reckon with min and max range
513
-
514
- this.start = newStart;
515
- this.end = newEnd;
516
- };
517
-
518
- /**
519
- * Move the range to a new center point
520
- * @param {Number} moveTo New center point of the range
521
- */
522
- Range.prototype.moveTo = function(moveTo) {
523
- var center = (this.start + this.end) / 2;
524
-
525
- var diff = center - moveTo;
526
-
527
- // calculate new start and end
528
- var newStart = this.start - diff;
529
- var newEnd = this.end - diff;
530
-
531
- this.setRange(newStart, newEnd);
532
- };