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.
- checksums.yaml +4 -4
- data/lib/vis/rails/version.rb +1 -1
- data/vendor/assets/javascripts/vis.js +26 -26
- metadata +16 -85
- data/vendor/assets/vis/DataSet.js +0 -926
- data/vendor/assets/vis/DataView.js +0 -283
- data/vendor/assets/vis/graph/Edge.js +0 -957
- data/vendor/assets/vis/graph/Graph.js +0 -2291
- data/vendor/assets/vis/graph/Groups.js +0 -80
- data/vendor/assets/vis/graph/Images.js +0 -41
- data/vendor/assets/vis/graph/Node.js +0 -966
- data/vendor/assets/vis/graph/Popup.js +0 -132
- data/vendor/assets/vis/graph/css/graph-manipulation.css +0 -128
- data/vendor/assets/vis/graph/css/graph-navigation.css +0 -66
- data/vendor/assets/vis/graph/dotparser.js +0 -829
- data/vendor/assets/vis/graph/graphMixins/ClusterMixin.js +0 -1143
- data/vendor/assets/vis/graph/graphMixins/HierarchicalLayoutMixin.js +0 -311
- data/vendor/assets/vis/graph/graphMixins/ManipulationMixin.js +0 -576
- data/vendor/assets/vis/graph/graphMixins/MixinLoader.js +0 -199
- data/vendor/assets/vis/graph/graphMixins/NavigationMixin.js +0 -205
- data/vendor/assets/vis/graph/graphMixins/SectorsMixin.js +0 -552
- data/vendor/assets/vis/graph/graphMixins/SelectionMixin.js +0 -648
- data/vendor/assets/vis/graph/graphMixins/physics/BarnesHut.js +0 -398
- data/vendor/assets/vis/graph/graphMixins/physics/HierarchialRepulsion.js +0 -64
- data/vendor/assets/vis/graph/graphMixins/physics/PhysicsMixin.js +0 -697
- data/vendor/assets/vis/graph/graphMixins/physics/Repulsion.js +0 -66
- data/vendor/assets/vis/graph/img/acceptDeleteIcon.png +0 -0
- data/vendor/assets/vis/graph/img/addNodeIcon.png +0 -0
- data/vendor/assets/vis/graph/img/backIcon.png +0 -0
- data/vendor/assets/vis/graph/img/connectIcon.png +0 -0
- data/vendor/assets/vis/graph/img/cross.png +0 -0
- data/vendor/assets/vis/graph/img/cross2.png +0 -0
- data/vendor/assets/vis/graph/img/deleteIcon.png +0 -0
- data/vendor/assets/vis/graph/img/downArrow.png +0 -0
- data/vendor/assets/vis/graph/img/editIcon.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 +0 -225
- data/vendor/assets/vis/graph3d/Graph3d.js +0 -3306
- data/vendor/assets/vis/module/exports.js +0 -65
- data/vendor/assets/vis/module/header.js +0 -24
- data/vendor/assets/vis/module/imports.js +0 -31
- data/vendor/assets/vis/shim.js +0 -252
- data/vendor/assets/vis/timeline/Range.js +0 -532
- data/vendor/assets/vis/timeline/TimeStep.js +0 -466
- data/vendor/assets/vis/timeline/Timeline.js +0 -851
- data/vendor/assets/vis/timeline/component/Component.js +0 -52
- data/vendor/assets/vis/timeline/component/CurrentTime.js +0 -128
- data/vendor/assets/vis/timeline/component/CustomTime.js +0 -182
- data/vendor/assets/vis/timeline/component/Group.js +0 -470
- data/vendor/assets/vis/timeline/component/ItemSet.js +0 -1332
- data/vendor/assets/vis/timeline/component/TimeAxis.js +0 -389
- data/vendor/assets/vis/timeline/component/css/animation.css +0 -33
- data/vendor/assets/vis/timeline/component/css/currenttime.css +0 -5
- data/vendor/assets/vis/timeline/component/css/customtime.css +0 -6
- data/vendor/assets/vis/timeline/component/css/item.css +0 -107
- data/vendor/assets/vis/timeline/component/css/itemset.css +0 -33
- data/vendor/assets/vis/timeline/component/css/labelset.css +0 -36
- data/vendor/assets/vis/timeline/component/css/panel.css +0 -71
- data/vendor/assets/vis/timeline/component/css/timeaxis.css +0 -48
- data/vendor/assets/vis/timeline/component/css/timeline.css +0 -2
- data/vendor/assets/vis/timeline/component/item/Item.js +0 -139
- data/vendor/assets/vis/timeline/component/item/ItemBox.js +0 -230
- data/vendor/assets/vis/timeline/component/item/ItemPoint.js +0 -190
- data/vendor/assets/vis/timeline/component/item/ItemRange.js +0 -262
- data/vendor/assets/vis/timeline/component/item/ItemRangeOverflow.js +0 -57
- data/vendor/assets/vis/timeline/img/delete.png +0 -0
- data/vendor/assets/vis/timeline/stack.js +0 -112
- data/vendor/assets/vis/util.js +0 -990
@@ -1,466 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @constructor TimeStep
|
3
|
-
* The class TimeStep is an iterator for dates. You provide a start date and an
|
4
|
-
* end date. The class itself determines the best scale (step size) based on the
|
5
|
-
* provided start Date, end Date, and minimumStep.
|
6
|
-
*
|
7
|
-
* If minimumStep is provided, the step size is chosen as close as possible
|
8
|
-
* to the minimumStep but larger than minimumStep. If minimumStep is not
|
9
|
-
* provided, the scale is set to 1 DAY.
|
10
|
-
* The minimumStep should correspond with the onscreen size of about 6 characters
|
11
|
-
*
|
12
|
-
* Alternatively, you can set a scale by hand.
|
13
|
-
* After creation, you can initialize the class by executing first(). Then you
|
14
|
-
* can iterate from the start date to the end date via next(). You can check if
|
15
|
-
* the end date is reached with the function hasNext(). After each step, you can
|
16
|
-
* retrieve the current date via getCurrent().
|
17
|
-
* The TimeStep has scales ranging from milliseconds, seconds, minutes, hours,
|
18
|
-
* days, to years.
|
19
|
-
*
|
20
|
-
* Version: 1.2
|
21
|
-
*
|
22
|
-
* @param {Date} [start] The start date, for example new Date(2010, 9, 21)
|
23
|
-
* or new Date(2010, 9, 21, 23, 45, 00)
|
24
|
-
* @param {Date} [end] The end date
|
25
|
-
* @param {Number} [minimumStep] Optional. Minimum step size in milliseconds
|
26
|
-
*/
|
27
|
-
function TimeStep(start, end, minimumStep) {
|
28
|
-
// variables
|
29
|
-
this.current = new Date();
|
30
|
-
this._start = new Date();
|
31
|
-
this._end = new Date();
|
32
|
-
|
33
|
-
this.autoScale = true;
|
34
|
-
this.scale = TimeStep.SCALE.DAY;
|
35
|
-
this.step = 1;
|
36
|
-
|
37
|
-
// initialize the range
|
38
|
-
this.setRange(start, end, minimumStep);
|
39
|
-
}
|
40
|
-
|
41
|
-
/// enum scale
|
42
|
-
TimeStep.SCALE = {
|
43
|
-
MILLISECOND: 1,
|
44
|
-
SECOND: 2,
|
45
|
-
MINUTE: 3,
|
46
|
-
HOUR: 4,
|
47
|
-
DAY: 5,
|
48
|
-
WEEKDAY: 6,
|
49
|
-
MONTH: 7,
|
50
|
-
YEAR: 8
|
51
|
-
};
|
52
|
-
|
53
|
-
|
54
|
-
/**
|
55
|
-
* Set a new range
|
56
|
-
* If minimumStep is provided, the step size is chosen as close as possible
|
57
|
-
* to the minimumStep but larger than minimumStep. If minimumStep is not
|
58
|
-
* provided, the scale is set to 1 DAY.
|
59
|
-
* The minimumStep should correspond with the onscreen size of about 6 characters
|
60
|
-
* @param {Date} [start] The start date and time.
|
61
|
-
* @param {Date} [end] The end date and time.
|
62
|
-
* @param {int} [minimumStep] Optional. Minimum step size in milliseconds
|
63
|
-
*/
|
64
|
-
TimeStep.prototype.setRange = function(start, end, minimumStep) {
|
65
|
-
if (!(start instanceof Date) || !(end instanceof Date)) {
|
66
|
-
throw "No legal start or end date in method setRange";
|
67
|
-
}
|
68
|
-
|
69
|
-
this._start = (start != undefined) ? new Date(start.valueOf()) : new Date();
|
70
|
-
this._end = (end != undefined) ? new Date(end.valueOf()) : new Date();
|
71
|
-
|
72
|
-
if (this.autoScale) {
|
73
|
-
this.setMinimumStep(minimumStep);
|
74
|
-
}
|
75
|
-
};
|
76
|
-
|
77
|
-
/**
|
78
|
-
* Set the range iterator to the start date.
|
79
|
-
*/
|
80
|
-
TimeStep.prototype.first = function() {
|
81
|
-
this.current = new Date(this._start.valueOf());
|
82
|
-
this.roundToMinor();
|
83
|
-
};
|
84
|
-
|
85
|
-
/**
|
86
|
-
* Round the current date to the first minor date value
|
87
|
-
* This must be executed once when the current date is set to start Date
|
88
|
-
*/
|
89
|
-
TimeStep.prototype.roundToMinor = function() {
|
90
|
-
// round to floor
|
91
|
-
// IMPORTANT: we have no breaks in this switch! (this is no bug)
|
92
|
-
//noinspection FallthroughInSwitchStatementJS
|
93
|
-
switch (this.scale) {
|
94
|
-
case TimeStep.SCALE.YEAR:
|
95
|
-
this.current.setFullYear(this.step * Math.floor(this.current.getFullYear() / this.step));
|
96
|
-
this.current.setMonth(0);
|
97
|
-
case TimeStep.SCALE.MONTH: this.current.setDate(1);
|
98
|
-
case TimeStep.SCALE.DAY: // intentional fall through
|
99
|
-
case TimeStep.SCALE.WEEKDAY: this.current.setHours(0);
|
100
|
-
case TimeStep.SCALE.HOUR: this.current.setMinutes(0);
|
101
|
-
case TimeStep.SCALE.MINUTE: this.current.setSeconds(0);
|
102
|
-
case TimeStep.SCALE.SECOND: this.current.setMilliseconds(0);
|
103
|
-
//case TimeStep.SCALE.MILLISECOND: // nothing to do for milliseconds
|
104
|
-
}
|
105
|
-
|
106
|
-
if (this.step != 1) {
|
107
|
-
// round down to the first minor value that is a multiple of the current step size
|
108
|
-
switch (this.scale) {
|
109
|
-
case TimeStep.SCALE.MILLISECOND: this.current.setMilliseconds(this.current.getMilliseconds() - this.current.getMilliseconds() % this.step); break;
|
110
|
-
case TimeStep.SCALE.SECOND: this.current.setSeconds(this.current.getSeconds() - this.current.getSeconds() % this.step); break;
|
111
|
-
case TimeStep.SCALE.MINUTE: this.current.setMinutes(this.current.getMinutes() - this.current.getMinutes() % this.step); break;
|
112
|
-
case TimeStep.SCALE.HOUR: this.current.setHours(this.current.getHours() - this.current.getHours() % this.step); break;
|
113
|
-
case TimeStep.SCALE.WEEKDAY: // intentional fall through
|
114
|
-
case TimeStep.SCALE.DAY: this.current.setDate((this.current.getDate()-1) - (this.current.getDate()-1) % this.step + 1); break;
|
115
|
-
case TimeStep.SCALE.MONTH: this.current.setMonth(this.current.getMonth() - this.current.getMonth() % this.step); break;
|
116
|
-
case TimeStep.SCALE.YEAR: this.current.setFullYear(this.current.getFullYear() - this.current.getFullYear() % this.step); break;
|
117
|
-
default: break;
|
118
|
-
}
|
119
|
-
}
|
120
|
-
};
|
121
|
-
|
122
|
-
/**
|
123
|
-
* Check if the there is a next step
|
124
|
-
* @return {boolean} true if the current date has not passed the end date
|
125
|
-
*/
|
126
|
-
TimeStep.prototype.hasNext = function () {
|
127
|
-
return (this.current.valueOf() <= this._end.valueOf());
|
128
|
-
};
|
129
|
-
|
130
|
-
/**
|
131
|
-
* Do the next step
|
132
|
-
*/
|
133
|
-
TimeStep.prototype.next = function() {
|
134
|
-
var prev = this.current.valueOf();
|
135
|
-
|
136
|
-
// Two cases, needed to prevent issues with switching daylight savings
|
137
|
-
// (end of March and end of October)
|
138
|
-
if (this.current.getMonth() < 6) {
|
139
|
-
switch (this.scale) {
|
140
|
-
case TimeStep.SCALE.MILLISECOND:
|
141
|
-
|
142
|
-
this.current = new Date(this.current.valueOf() + this.step); break;
|
143
|
-
case TimeStep.SCALE.SECOND: this.current = new Date(this.current.valueOf() + this.step * 1000); break;
|
144
|
-
case TimeStep.SCALE.MINUTE: this.current = new Date(this.current.valueOf() + this.step * 1000 * 60); break;
|
145
|
-
case TimeStep.SCALE.HOUR:
|
146
|
-
this.current = new Date(this.current.valueOf() + this.step * 1000 * 60 * 60);
|
147
|
-
// in case of skipping an hour for daylight savings, adjust the hour again (else you get: 0h 5h 9h ... instead of 0h 4h 8h ...)
|
148
|
-
var h = this.current.getHours();
|
149
|
-
this.current.setHours(h - (h % this.step));
|
150
|
-
break;
|
151
|
-
case TimeStep.SCALE.WEEKDAY: // intentional fall through
|
152
|
-
case TimeStep.SCALE.DAY: this.current.setDate(this.current.getDate() + this.step); break;
|
153
|
-
case TimeStep.SCALE.MONTH: this.current.setMonth(this.current.getMonth() + this.step); break;
|
154
|
-
case TimeStep.SCALE.YEAR: this.current.setFullYear(this.current.getFullYear() + this.step); break;
|
155
|
-
default: break;
|
156
|
-
}
|
157
|
-
}
|
158
|
-
else {
|
159
|
-
switch (this.scale) {
|
160
|
-
case TimeStep.SCALE.MILLISECOND: this.current = new Date(this.current.valueOf() + this.step); break;
|
161
|
-
case TimeStep.SCALE.SECOND: this.current.setSeconds(this.current.getSeconds() + this.step); break;
|
162
|
-
case TimeStep.SCALE.MINUTE: this.current.setMinutes(this.current.getMinutes() + this.step); break;
|
163
|
-
case TimeStep.SCALE.HOUR: this.current.setHours(this.current.getHours() + this.step); break;
|
164
|
-
case TimeStep.SCALE.WEEKDAY: // intentional fall through
|
165
|
-
case TimeStep.SCALE.DAY: this.current.setDate(this.current.getDate() + this.step); break;
|
166
|
-
case TimeStep.SCALE.MONTH: this.current.setMonth(this.current.getMonth() + this.step); break;
|
167
|
-
case TimeStep.SCALE.YEAR: this.current.setFullYear(this.current.getFullYear() + this.step); break;
|
168
|
-
default: break;
|
169
|
-
}
|
170
|
-
}
|
171
|
-
|
172
|
-
if (this.step != 1) {
|
173
|
-
// round down to the correct major value
|
174
|
-
switch (this.scale) {
|
175
|
-
case TimeStep.SCALE.MILLISECOND: if(this.current.getMilliseconds() < this.step) this.current.setMilliseconds(0); break;
|
176
|
-
case TimeStep.SCALE.SECOND: if(this.current.getSeconds() < this.step) this.current.setSeconds(0); break;
|
177
|
-
case TimeStep.SCALE.MINUTE: if(this.current.getMinutes() < this.step) this.current.setMinutes(0); break;
|
178
|
-
case TimeStep.SCALE.HOUR: if(this.current.getHours() < this.step) this.current.setHours(0); break;
|
179
|
-
case TimeStep.SCALE.WEEKDAY: // intentional fall through
|
180
|
-
case TimeStep.SCALE.DAY: if(this.current.getDate() < this.step+1) this.current.setDate(1); break;
|
181
|
-
case TimeStep.SCALE.MONTH: if(this.current.getMonth() < this.step) this.current.setMonth(0); break;
|
182
|
-
case TimeStep.SCALE.YEAR: break; // nothing to do for year
|
183
|
-
default: break;
|
184
|
-
}
|
185
|
-
}
|
186
|
-
|
187
|
-
// safety mechanism: if current time is still unchanged, move to the end
|
188
|
-
if (this.current.valueOf() == prev) {
|
189
|
-
this.current = new Date(this._end.valueOf());
|
190
|
-
}
|
191
|
-
};
|
192
|
-
|
193
|
-
|
194
|
-
/**
|
195
|
-
* Get the current datetime
|
196
|
-
* @return {Date} current The current date
|
197
|
-
*/
|
198
|
-
TimeStep.prototype.getCurrent = function() {
|
199
|
-
return this.current;
|
200
|
-
};
|
201
|
-
|
202
|
-
/**
|
203
|
-
* Set a custom scale. Autoscaling will be disabled.
|
204
|
-
* For example setScale(SCALE.MINUTES, 5) will result
|
205
|
-
* in minor steps of 5 minutes, and major steps of an hour.
|
206
|
-
*
|
207
|
-
* @param {TimeStep.SCALE} newScale
|
208
|
-
* A scale. Choose from SCALE.MILLISECOND,
|
209
|
-
* SCALE.SECOND, SCALE.MINUTE, SCALE.HOUR,
|
210
|
-
* SCALE.WEEKDAY, SCALE.DAY, SCALE.MONTH,
|
211
|
-
* SCALE.YEAR.
|
212
|
-
* @param {Number} newStep A step size, by default 1. Choose for
|
213
|
-
* example 1, 2, 5, or 10.
|
214
|
-
*/
|
215
|
-
TimeStep.prototype.setScale = function(newScale, newStep) {
|
216
|
-
this.scale = newScale;
|
217
|
-
|
218
|
-
if (newStep > 0) {
|
219
|
-
this.step = newStep;
|
220
|
-
}
|
221
|
-
|
222
|
-
this.autoScale = false;
|
223
|
-
};
|
224
|
-
|
225
|
-
/**
|
226
|
-
* Enable or disable autoscaling
|
227
|
-
* @param {boolean} enable If true, autoascaling is set true
|
228
|
-
*/
|
229
|
-
TimeStep.prototype.setAutoScale = function (enable) {
|
230
|
-
this.autoScale = enable;
|
231
|
-
};
|
232
|
-
|
233
|
-
|
234
|
-
/**
|
235
|
-
* Automatically determine the scale that bests fits the provided minimum step
|
236
|
-
* @param {Number} [minimumStep] The minimum step size in milliseconds
|
237
|
-
*/
|
238
|
-
TimeStep.prototype.setMinimumStep = function(minimumStep) {
|
239
|
-
if (minimumStep == undefined) {
|
240
|
-
return;
|
241
|
-
}
|
242
|
-
|
243
|
-
var stepYear = (1000 * 60 * 60 * 24 * 30 * 12);
|
244
|
-
var stepMonth = (1000 * 60 * 60 * 24 * 30);
|
245
|
-
var stepDay = (1000 * 60 * 60 * 24);
|
246
|
-
var stepHour = (1000 * 60 * 60);
|
247
|
-
var stepMinute = (1000 * 60);
|
248
|
-
var stepSecond = (1000);
|
249
|
-
var stepMillisecond= (1);
|
250
|
-
|
251
|
-
// find the smallest step that is larger than the provided minimumStep
|
252
|
-
if (stepYear*1000 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 1000;}
|
253
|
-
if (stepYear*500 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 500;}
|
254
|
-
if (stepYear*100 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 100;}
|
255
|
-
if (stepYear*50 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 50;}
|
256
|
-
if (stepYear*10 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 10;}
|
257
|
-
if (stepYear*5 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 5;}
|
258
|
-
if (stepYear > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 1;}
|
259
|
-
if (stepMonth*3 > minimumStep) {this.scale = TimeStep.SCALE.MONTH; this.step = 3;}
|
260
|
-
if (stepMonth > minimumStep) {this.scale = TimeStep.SCALE.MONTH; this.step = 1;}
|
261
|
-
if (stepDay*5 > minimumStep) {this.scale = TimeStep.SCALE.DAY; this.step = 5;}
|
262
|
-
if (stepDay*2 > minimumStep) {this.scale = TimeStep.SCALE.DAY; this.step = 2;}
|
263
|
-
if (stepDay > minimumStep) {this.scale = TimeStep.SCALE.DAY; this.step = 1;}
|
264
|
-
if (stepDay/2 > minimumStep) {this.scale = TimeStep.SCALE.WEEKDAY; this.step = 1;}
|
265
|
-
if (stepHour*4 > minimumStep) {this.scale = TimeStep.SCALE.HOUR; this.step = 4;}
|
266
|
-
if (stepHour > minimumStep) {this.scale = TimeStep.SCALE.HOUR; this.step = 1;}
|
267
|
-
if (stepMinute*15 > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 15;}
|
268
|
-
if (stepMinute*10 > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 10;}
|
269
|
-
if (stepMinute*5 > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 5;}
|
270
|
-
if (stepMinute > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 1;}
|
271
|
-
if (stepSecond*15 > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 15;}
|
272
|
-
if (stepSecond*10 > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 10;}
|
273
|
-
if (stepSecond*5 > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 5;}
|
274
|
-
if (stepSecond > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 1;}
|
275
|
-
if (stepMillisecond*200 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 200;}
|
276
|
-
if (stepMillisecond*100 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 100;}
|
277
|
-
if (stepMillisecond*50 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 50;}
|
278
|
-
if (stepMillisecond*10 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 10;}
|
279
|
-
if (stepMillisecond*5 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 5;}
|
280
|
-
if (stepMillisecond > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 1;}
|
281
|
-
};
|
282
|
-
|
283
|
-
/**
|
284
|
-
* Snap a date to a rounded value.
|
285
|
-
* The snap intervals are dependent on the current scale and step.
|
286
|
-
* @param {Date} date the date to be snapped.
|
287
|
-
* @return {Date} snappedDate
|
288
|
-
*/
|
289
|
-
TimeStep.prototype.snap = function(date) {
|
290
|
-
var clone = new Date(date.valueOf());
|
291
|
-
|
292
|
-
if (this.scale == TimeStep.SCALE.YEAR) {
|
293
|
-
var year = clone.getFullYear() + Math.round(clone.getMonth() / 12);
|
294
|
-
clone.setFullYear(Math.round(year / this.step) * this.step);
|
295
|
-
clone.setMonth(0);
|
296
|
-
clone.setDate(0);
|
297
|
-
clone.setHours(0);
|
298
|
-
clone.setMinutes(0);
|
299
|
-
clone.setSeconds(0);
|
300
|
-
clone.setMilliseconds(0);
|
301
|
-
}
|
302
|
-
else if (this.scale == TimeStep.SCALE.MONTH) {
|
303
|
-
if (clone.getDate() > 15) {
|
304
|
-
clone.setDate(1);
|
305
|
-
clone.setMonth(clone.getMonth() + 1);
|
306
|
-
// important: first set Date to 1, after that change the month.
|
307
|
-
}
|
308
|
-
else {
|
309
|
-
clone.setDate(1);
|
310
|
-
}
|
311
|
-
|
312
|
-
clone.setHours(0);
|
313
|
-
clone.setMinutes(0);
|
314
|
-
clone.setSeconds(0);
|
315
|
-
clone.setMilliseconds(0);
|
316
|
-
}
|
317
|
-
else if (this.scale == TimeStep.SCALE.DAY) {
|
318
|
-
//noinspection FallthroughInSwitchStatementJS
|
319
|
-
switch (this.step) {
|
320
|
-
case 5:
|
321
|
-
case 2:
|
322
|
-
clone.setHours(Math.round(clone.getHours() / 24) * 24); break;
|
323
|
-
default:
|
324
|
-
clone.setHours(Math.round(clone.getHours() / 12) * 12); break;
|
325
|
-
}
|
326
|
-
clone.setMinutes(0);
|
327
|
-
clone.setSeconds(0);
|
328
|
-
clone.setMilliseconds(0);
|
329
|
-
}
|
330
|
-
else if (this.scale == TimeStep.SCALE.WEEKDAY) {
|
331
|
-
//noinspection FallthroughInSwitchStatementJS
|
332
|
-
switch (this.step) {
|
333
|
-
case 5:
|
334
|
-
case 2:
|
335
|
-
clone.setHours(Math.round(clone.getHours() / 12) * 12); break;
|
336
|
-
default:
|
337
|
-
clone.setHours(Math.round(clone.getHours() / 6) * 6); break;
|
338
|
-
}
|
339
|
-
clone.setMinutes(0);
|
340
|
-
clone.setSeconds(0);
|
341
|
-
clone.setMilliseconds(0);
|
342
|
-
}
|
343
|
-
else if (this.scale == TimeStep.SCALE.HOUR) {
|
344
|
-
switch (this.step) {
|
345
|
-
case 4:
|
346
|
-
clone.setMinutes(Math.round(clone.getMinutes() / 60) * 60); break;
|
347
|
-
default:
|
348
|
-
clone.setMinutes(Math.round(clone.getMinutes() / 30) * 30); break;
|
349
|
-
}
|
350
|
-
clone.setSeconds(0);
|
351
|
-
clone.setMilliseconds(0);
|
352
|
-
} else if (this.scale == TimeStep.SCALE.MINUTE) {
|
353
|
-
//noinspection FallthroughInSwitchStatementJS
|
354
|
-
switch (this.step) {
|
355
|
-
case 15:
|
356
|
-
case 10:
|
357
|
-
clone.setMinutes(Math.round(clone.getMinutes() / 5) * 5);
|
358
|
-
clone.setSeconds(0);
|
359
|
-
break;
|
360
|
-
case 5:
|
361
|
-
clone.setSeconds(Math.round(clone.getSeconds() / 60) * 60); break;
|
362
|
-
default:
|
363
|
-
clone.setSeconds(Math.round(clone.getSeconds() / 30) * 30); break;
|
364
|
-
}
|
365
|
-
clone.setMilliseconds(0);
|
366
|
-
}
|
367
|
-
else if (this.scale == TimeStep.SCALE.SECOND) {
|
368
|
-
//noinspection FallthroughInSwitchStatementJS
|
369
|
-
switch (this.step) {
|
370
|
-
case 15:
|
371
|
-
case 10:
|
372
|
-
clone.setSeconds(Math.round(clone.getSeconds() / 5) * 5);
|
373
|
-
clone.setMilliseconds(0);
|
374
|
-
break;
|
375
|
-
case 5:
|
376
|
-
clone.setMilliseconds(Math.round(clone.getMilliseconds() / 1000) * 1000); break;
|
377
|
-
default:
|
378
|
-
clone.setMilliseconds(Math.round(clone.getMilliseconds() / 500) * 500); break;
|
379
|
-
}
|
380
|
-
}
|
381
|
-
else if (this.scale == TimeStep.SCALE.MILLISECOND) {
|
382
|
-
var step = this.step > 5 ? this.step / 2 : 1;
|
383
|
-
clone.setMilliseconds(Math.round(clone.getMilliseconds() / step) * step);
|
384
|
-
}
|
385
|
-
|
386
|
-
return clone;
|
387
|
-
};
|
388
|
-
|
389
|
-
/**
|
390
|
-
* Check if the current value is a major value (for example when the step
|
391
|
-
* is DAY, a major value is each first day of the MONTH)
|
392
|
-
* @return {boolean} true if current date is major, else false.
|
393
|
-
*/
|
394
|
-
TimeStep.prototype.isMajor = function() {
|
395
|
-
switch (this.scale) {
|
396
|
-
case TimeStep.SCALE.MILLISECOND:
|
397
|
-
return (this.current.getMilliseconds() == 0);
|
398
|
-
case TimeStep.SCALE.SECOND:
|
399
|
-
return (this.current.getSeconds() == 0);
|
400
|
-
case TimeStep.SCALE.MINUTE:
|
401
|
-
return (this.current.getHours() == 0) && (this.current.getMinutes() == 0);
|
402
|
-
// Note: this is no bug. Major label is equal for both minute and hour scale
|
403
|
-
case TimeStep.SCALE.HOUR:
|
404
|
-
return (this.current.getHours() == 0);
|
405
|
-
case TimeStep.SCALE.WEEKDAY: // intentional fall through
|
406
|
-
case TimeStep.SCALE.DAY:
|
407
|
-
return (this.current.getDate() == 1);
|
408
|
-
case TimeStep.SCALE.MONTH:
|
409
|
-
return (this.current.getMonth() == 0);
|
410
|
-
case TimeStep.SCALE.YEAR:
|
411
|
-
return false;
|
412
|
-
default:
|
413
|
-
return false;
|
414
|
-
}
|
415
|
-
};
|
416
|
-
|
417
|
-
|
418
|
-
/**
|
419
|
-
* Returns formatted text for the minor axislabel, depending on the current
|
420
|
-
* date and the scale. For example when scale is MINUTE, the current time is
|
421
|
-
* formatted as "hh:mm".
|
422
|
-
* @param {Date} [date] custom date. if not provided, current date is taken
|
423
|
-
*/
|
424
|
-
TimeStep.prototype.getLabelMinor = function(date) {
|
425
|
-
if (date == undefined) {
|
426
|
-
date = this.current;
|
427
|
-
}
|
428
|
-
|
429
|
-
switch (this.scale) {
|
430
|
-
case TimeStep.SCALE.MILLISECOND: return moment(date).format('SSS');
|
431
|
-
case TimeStep.SCALE.SECOND: return moment(date).format('s');
|
432
|
-
case TimeStep.SCALE.MINUTE: return moment(date).format('HH:mm');
|
433
|
-
case TimeStep.SCALE.HOUR: return moment(date).format('HH:mm');
|
434
|
-
case TimeStep.SCALE.WEEKDAY: return moment(date).format('ddd D');
|
435
|
-
case TimeStep.SCALE.DAY: return moment(date).format('D');
|
436
|
-
case TimeStep.SCALE.MONTH: return moment(date).format('MMM');
|
437
|
-
case TimeStep.SCALE.YEAR: return moment(date).format('YYYY');
|
438
|
-
default: return '';
|
439
|
-
}
|
440
|
-
};
|
441
|
-
|
442
|
-
|
443
|
-
/**
|
444
|
-
* Returns formatted text for the major axis label, depending on the current
|
445
|
-
* date and the scale. For example when scale is MINUTE, the major scale is
|
446
|
-
* hours, and the hour will be formatted as "hh".
|
447
|
-
* @param {Date} [date] custom date. if not provided, current date is taken
|
448
|
-
*/
|
449
|
-
TimeStep.prototype.getLabelMajor = function(date) {
|
450
|
-
if (date == undefined) {
|
451
|
-
date = this.current;
|
452
|
-
}
|
453
|
-
|
454
|
-
//noinspection FallthroughInSwitchStatementJS
|
455
|
-
switch (this.scale) {
|
456
|
-
case TimeStep.SCALE.MILLISECOND:return moment(date).format('HH:mm:ss');
|
457
|
-
case TimeStep.SCALE.SECOND: return moment(date).format('D MMMM HH:mm');
|
458
|
-
case TimeStep.SCALE.MINUTE:
|
459
|
-
case TimeStep.SCALE.HOUR: return moment(date).format('ddd D MMMM');
|
460
|
-
case TimeStep.SCALE.WEEKDAY:
|
461
|
-
case TimeStep.SCALE.DAY: return moment(date).format('MMMM YYYY');
|
462
|
-
case TimeStep.SCALE.MONTH: return moment(date).format('YYYY');
|
463
|
-
case TimeStep.SCALE.YEAR: return '';
|
464
|
-
default: return '';
|
465
|
-
}
|
466
|
-
};
|