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,17 +1,12 @@
1
1
  /**
2
2
  * A horizontal time axis
3
- * @param {Component} parent
4
- * @param {Component[]} [depends] Components on which this components depends
5
- * (except for the parent)
6
3
  * @param {Object} [options] See TimeAxis.setOptions for the available
7
4
  * options.
8
5
  * @constructor TimeAxis
9
6
  * @extends Component
10
7
  */
11
- function TimeAxis (parent, depends, options) {
8
+ function TimeAxis (options) {
12
9
  this.id = util.randomUUID();
13
- this.parent = parent;
14
- this.depends = depends;
15
10
 
16
11
  this.dom = {
17
12
  majorLines: [],
@@ -42,8 +37,10 @@ function TimeAxis (parent, depends, options) {
42
37
  showMajorLabels: true
43
38
  };
44
39
 
45
- this.conversion = null;
46
40
  this.range = null;
41
+
42
+ // create the HTML DOM
43
+ this._create();
47
44
  }
48
45
 
49
46
  TimeAxis.prototype = new Component();
@@ -51,6 +48,13 @@ TimeAxis.prototype = new Component();
51
48
  // TODO: comment options
52
49
  TimeAxis.prototype.setOptions = Component.prototype.setOptions;
53
50
 
51
+ /**
52
+ * Create the HTML DOM for the TimeAxis
53
+ */
54
+ TimeAxis.prototype._create = function _create() {
55
+ this.frame = document.createElement('div');
56
+ };
57
+
54
58
  /**
55
59
  * Set a range (start and end)
56
60
  * @param {Range | Object} range A Range or an object containing start and end.
@@ -64,126 +68,70 @@ TimeAxis.prototype.setRange = function (range) {
64
68
  };
65
69
 
66
70
  /**
67
- * Convert a position on screen (pixels) to a datetime
68
- * @param {int} x Position on the screen in pixels
69
- * @return {Date} time The datetime the corresponds with given position x
70
- */
71
- TimeAxis.prototype.toTime = function(x) {
72
- var conversion = this.conversion;
73
- return new Date(x / conversion.scale + conversion.offset);
74
- };
75
-
76
- /**
77
- * Convert a datetime (Date object) into a position on the screen
78
- * @param {Date} time A date
79
- * @return {int} x The position on the screen in pixels which corresponds
80
- * with the given date.
81
- * @private
71
+ * Get the outer frame of the time axis
72
+ * @return {HTMLElement} frame
82
73
  */
83
- TimeAxis.prototype.toScreen = function(time) {
84
- var conversion = this.conversion;
85
- return (time.valueOf() - conversion.offset) * conversion.scale;
74
+ TimeAxis.prototype.getFrame = function getFrame() {
75
+ return this.frame;
86
76
  };
87
77
 
88
78
  /**
89
79
  * Repaint the component
90
- * @return {Boolean} changed
80
+ * @return {boolean} Returns true if the component is resized
91
81
  */
92
82
  TimeAxis.prototype.repaint = function () {
93
- var changed = 0,
94
- update = util.updateProperty,
95
- asSize = util.option.asSize,
83
+ var asSize = util.option.asSize,
96
84
  options = this.options,
97
- orientation = this.getOption('orientation'),
98
85
  props = this.props,
99
- step = this.step;
100
-
101
- var frame = this.frame;
102
- if (!frame) {
103
- frame = document.createElement('div');
104
- this.frame = frame;
105
- changed += 1;
106
- }
107
- frame.className = 'axis';
108
- // TODO: custom className?
109
-
110
- if (!frame.parentNode) {
111
- if (!this.parent) {
112
- throw new Error('Cannot repaint time axis: no parent attached');
113
- }
114
- var parentContainer = this.parent.getContainer();
115
- if (!parentContainer) {
116
- throw new Error('Cannot repaint time axis: parent has no container element');
117
- }
118
- parentContainer.appendChild(frame);
86
+ frame = this.frame;
119
87
 
120
- changed += 1;
121
- }
88
+ // update classname
89
+ frame.className = 'timeaxis'; // TODO: add className from options if defined
122
90
 
123
91
  var parent = frame.parentNode;
124
92
  if (parent) {
125
- var beforeChild = frame.nextSibling;
126
- parent.removeChild(frame); // take frame offline while updating (is almost twice as fast)
127
-
128
- var defaultTop = (orientation == 'bottom' && this.props.parentHeight && this.height) ?
129
- (this.props.parentHeight - this.height) + 'px' :
130
- '0px';
131
- changed += update(frame.style, 'top', asSize(options.top, defaultTop));
132
- changed += update(frame.style, 'left', asSize(options.left, '0px'));
133
- changed += update(frame.style, 'width', asSize(options.width, '100%'));
134
- changed += update(frame.style, 'height', asSize(options.height, this.height + 'px'));
135
-
136
- // get characters width and height
137
- this._repaintMeasureChars();
138
-
139
- if (this.step) {
140
- this._repaintStart();
141
-
142
- step.first();
143
- var xFirstMajorLabel = undefined;
144
- var max = 0;
145
- while (step.hasNext() && max < 1000) {
146
- max++;
147
- var cur = step.getCurrent(),
148
- x = this.toScreen(cur),
149
- isMajor = step.isMajor();
150
-
151
- // TODO: lines must have a width, such that we can create css backgrounds
152
-
153
- if (this.getOption('showMinorLabels')) {
154
- this._repaintMinorText(x, step.getLabelMinor());
155
- }
156
-
157
- if (isMajor && this.getOption('showMajorLabels')) {
158
- if (x > 0) {
159
- if (xFirstMajorLabel == undefined) {
160
- xFirstMajorLabel = x;
161
- }
162
- this._repaintMajorText(x, step.getLabelMajor());
163
- }
164
- this._repaintMajorLine(x);
165
- }
166
- else {
167
- this._repaintMinorLine(x);
168
- }
93
+ // calculate character width and height
94
+ this._calculateCharSize();
169
95
 
170
- step.next();
171
- }
96
+ // TODO: recalculate sizes only needed when parent is resized or options is changed
97
+ var orientation = this.getOption('orientation'),
98
+ showMinorLabels = this.getOption('showMinorLabels'),
99
+ showMajorLabels = this.getOption('showMajorLabels');
172
100
 
173
- // create a major label on the left when needed
174
- if (this.getOption('showMajorLabels')) {
175
- var leftTime = this.toTime(0),
176
- leftText = step.getLabelMajor(leftTime),
177
- widthText = leftText.length * (props.majorCharWidth || 10) + 10; // upper bound estimation
101
+ // determine the width and height of the elemens for the axis
102
+ var parentHeight = this.parent.height;
103
+ props.minorLabelHeight = showMinorLabels ? props.minorCharHeight : 0;
104
+ props.majorLabelHeight = showMajorLabels ? props.majorCharHeight : 0;
105
+ this.height = props.minorLabelHeight + props.majorLabelHeight;
106
+ this.width = frame.offsetWidth; // TODO: only update the width when the frame is resized?
178
107
 
179
- if (xFirstMajorLabel == undefined || widthText < xFirstMajorLabel) {
180
- this._repaintMajorText(0, leftText);
181
- }
182
- }
108
+ props.minorLineHeight = parentHeight + props.minorLabelHeight;
109
+ props.minorLineWidth = 1; // TODO: really calculate width
110
+ props.majorLineHeight = parentHeight + this.height;
111
+ props.majorLineWidth = 1; // TODO: really calculate width
183
112
 
184
- this._repaintEnd();
113
+ // take frame offline while updating (is almost twice as fast)
114
+ var beforeChild = frame.nextSibling;
115
+ parent.removeChild(frame);
116
+
117
+ // TODO: top/bottom positioning should be determined by options set in the Timeline, not here
118
+ if (orientation == 'top') {
119
+ frame.style.top = '0';
120
+ frame.style.left = '0';
121
+ frame.style.bottom = '';
122
+ frame.style.width = asSize(options.width, '100%');
123
+ frame.style.height = this.height + 'px';
124
+ }
125
+ else { // bottom
126
+ frame.style.top = '';
127
+ frame.style.bottom = '0';
128
+ frame.style.left = '0';
129
+ frame.style.width = asSize(options.width, '100%');
130
+ frame.style.height = this.height + 'px';
185
131
  }
186
132
 
133
+ this._repaintLabels();
134
+
187
135
  this._repaintLine();
188
136
 
189
137
  // put frame online again
@@ -195,34 +143,80 @@ TimeAxis.prototype.repaint = function () {
195
143
  }
196
144
  }
197
145
 
198
- return (changed > 0);
146
+ return this._isResized();
199
147
  };
200
148
 
201
149
  /**
202
- * Start a repaint. Move all DOM elements to a redundant list, where they
203
- * can be picked for re-use, or can be cleaned up in the end
150
+ * Repaint major and minor text labels and vertical grid lines
204
151
  * @private
205
152
  */
206
- TimeAxis.prototype._repaintStart = function () {
207
- var dom = this.dom,
208
- redundant = dom.redundant;
209
-
210
- redundant.majorLines = dom.majorLines;
211
- redundant.majorTexts = dom.majorTexts;
212
- redundant.minorLines = dom.minorLines;
213
- redundant.minorTexts = dom.minorTexts;
214
-
153
+ TimeAxis.prototype._repaintLabels = function () {
154
+ var orientation = this.getOption('orientation');
155
+
156
+ // calculate range and step (step such that we have space for 7 characters per label)
157
+ var start = util.convert(this.range.start, 'Number'),
158
+ end = util.convert(this.range.end, 'Number'),
159
+ minimumStep = this.options.toTime((this.props.minorCharWidth || 10) * 7).valueOf()
160
+ -this.options.toTime(0).valueOf();
161
+ var step = new TimeStep(new Date(start), new Date(end), minimumStep);
162
+ this.step = step;
163
+
164
+ // Move all DOM elements to a "redundant" list, where they
165
+ // can be picked for re-use, and clear the lists with lines and texts.
166
+ // At the end of the function _repaintLabels, left over elements will be cleaned up
167
+ var dom = this.dom;
168
+ dom.redundant.majorLines = dom.majorLines;
169
+ dom.redundant.majorTexts = dom.majorTexts;
170
+ dom.redundant.minorLines = dom.minorLines;
171
+ dom.redundant.minorTexts = dom.minorTexts;
215
172
  dom.majorLines = [];
216
173
  dom.majorTexts = [];
217
174
  dom.minorLines = [];
218
175
  dom.minorTexts = [];
219
- };
220
176
 
221
- /**
222
- * End a repaint. Cleanup leftover DOM elements in the redundant list
223
- * @private
224
- */
225
- TimeAxis.prototype._repaintEnd = function () {
177
+ step.first();
178
+ var xFirstMajorLabel = undefined;
179
+ var max = 0;
180
+ while (step.hasNext() && max < 1000) {
181
+ max++;
182
+ var cur = step.getCurrent(),
183
+ x = this.options.toScreen(cur),
184
+ isMajor = step.isMajor();
185
+
186
+ // TODO: lines must have a width, such that we can create css backgrounds
187
+
188
+ if (this.getOption('showMinorLabels')) {
189
+ this._repaintMinorText(x, step.getLabelMinor(), orientation);
190
+ }
191
+
192
+ if (isMajor && this.getOption('showMajorLabels')) {
193
+ if (x > 0) {
194
+ if (xFirstMajorLabel == undefined) {
195
+ xFirstMajorLabel = x;
196
+ }
197
+ this._repaintMajorText(x, step.getLabelMajor(), orientation);
198
+ }
199
+ this._repaintMajorLine(x, orientation);
200
+ }
201
+ else {
202
+ this._repaintMinorLine(x, orientation);
203
+ }
204
+
205
+ step.next();
206
+ }
207
+
208
+ // create a major label on the left when needed
209
+ if (this.getOption('showMajorLabels')) {
210
+ var leftTime = this.options.toTime(0),
211
+ leftText = step.getLabelMajor(leftTime),
212
+ widthText = leftText.length * (this.props.majorCharWidth || 10) + 10; // upper bound estimation
213
+
214
+ if (xFirstMajorLabel == undefined || widthText < xFirstMajorLabel) {
215
+ this._repaintMajorText(0, leftText, orientation);
216
+ }
217
+ }
218
+
219
+ // Cleanup leftover DOM elements from the redundant list
226
220
  util.forEach(this.dom.redundant, function (arr) {
227
221
  while (arr.length) {
228
222
  var elem = arr.pop();
@@ -233,14 +227,14 @@ TimeAxis.prototype._repaintEnd = function () {
233
227
  });
234
228
  };
235
229
 
236
-
237
230
  /**
238
231
  * Create a minor label for the axis at position x
239
232
  * @param {Number} x
240
233
  * @param {String} text
234
+ * @param {String} orientation "top" or "bottom" (default)
241
235
  * @private
242
236
  */
243
- TimeAxis.prototype._repaintMinorText = function (x, text) {
237
+ TimeAxis.prototype._repaintMinorText = function (x, text, orientation) {
244
238
  // reuse redundant label
245
239
  var label = this.dom.redundant.minorTexts.shift();
246
240
 
@@ -255,8 +249,16 @@ TimeAxis.prototype._repaintMinorText = function (x, text) {
255
249
  this.dom.minorTexts.push(label);
256
250
 
257
251
  label.childNodes[0].nodeValue = text;
252
+
253
+ if (orientation == 'top') {
254
+ label.style.top = this.props.majorLabelHeight + 'px';
255
+ label.style.bottom = '';
256
+ }
257
+ else {
258
+ label.style.top = '';
259
+ label.style.bottom = this.props.majorLabelHeight + 'px';
260
+ }
258
261
  label.style.left = x + 'px';
259
- label.style.top = this.props.minorLabelTop + 'px';
260
262
  //label.title = title; // TODO: this is a heavy operation
261
263
  };
262
264
 
@@ -264,9 +266,10 @@ TimeAxis.prototype._repaintMinorText = function (x, text) {
264
266
  * Create a Major label for the axis at position x
265
267
  * @param {Number} x
266
268
  * @param {String} text
269
+ * @param {String} orientation "top" or "bottom" (default)
267
270
  * @private
268
271
  */
269
- TimeAxis.prototype._repaintMajorText = function (x, text) {
272
+ TimeAxis.prototype._repaintMajorText = function (x, text, orientation) {
270
273
  // reuse redundant label
271
274
  var label = this.dom.redundant.majorTexts.shift();
272
275
 
@@ -281,17 +284,26 @@ TimeAxis.prototype._repaintMajorText = function (x, text) {
281
284
  this.dom.majorTexts.push(label);
282
285
 
283
286
  label.childNodes[0].nodeValue = text;
284
- label.style.top = this.props.majorLabelTop + 'px';
285
- label.style.left = x + 'px';
286
287
  //label.title = title; // TODO: this is a heavy operation
288
+
289
+ if (orientation == 'top') {
290
+ label.style.top = '0px';
291
+ label.style.bottom = '';
292
+ }
293
+ else {
294
+ label.style.top = '';
295
+ label.style.bottom = '0px';
296
+ }
297
+ label.style.left = x + 'px';
287
298
  };
288
299
 
289
300
  /**
290
301
  * Create a minor line for the axis at position x
291
302
  * @param {Number} x
303
+ * @param {String} orientation "top" or "bottom" (default)
292
304
  * @private
293
305
  */
294
- TimeAxis.prototype._repaintMinorLine = function (x) {
306
+ TimeAxis.prototype._repaintMinorLine = function (x, orientation) {
295
307
  // reuse redundant line
296
308
  var line = this.dom.redundant.minorLines.shift();
297
309
 
@@ -304,7 +316,14 @@ TimeAxis.prototype._repaintMinorLine = function (x) {
304
316
  this.dom.minorLines.push(line);
305
317
 
306
318
  var props = this.props;
307
- line.style.top = props.minorLineTop + 'px';
319
+ if (orientation == 'top') {
320
+ line.style.top = this.props.majorLabelHeight + 'px';
321
+ line.style.bottom = '';
322
+ }
323
+ else {
324
+ line.style.top = '';
325
+ line.style.bottom = this.props.majorLabelHeight + 'px';
326
+ }
308
327
  line.style.height = props.minorLineHeight + 'px';
309
328
  line.style.left = (x - props.minorLineWidth / 2) + 'px';
310
329
  };
@@ -312,9 +331,10 @@ TimeAxis.prototype._repaintMinorLine = function (x) {
312
331
  /**
313
332
  * Create a Major line for the axis at position x
314
333
  * @param {Number} x
334
+ * @param {String} orientation "top" or "bottom" (default)
315
335
  * @private
316
336
  */
317
- TimeAxis.prototype._repaintMajorLine = function (x) {
337
+ TimeAxis.prototype._repaintMajorLine = function (x, orientation) {
318
338
  // reuse redundant line
319
339
  var line = this.dom.redundant.majorLines.shift();
320
340
 
@@ -327,7 +347,14 @@ TimeAxis.prototype._repaintMajorLine = function (x) {
327
347
  this.dom.majorLines.push(line);
328
348
 
329
349
  var props = this.props;
330
- line.style.top = props.majorLineTop + 'px';
350
+ if (orientation == 'top') {
351
+ line.style.top = '0px';
352
+ line.style.bottom = '';
353
+ }
354
+ else {
355
+ line.style.top = '';
356
+ line.style.bottom = '0px';
357
+ }
331
358
  line.style.left = (x - props.majorLineWidth / 2) + 'px';
332
359
  line.style.height = props.majorLineHeight + 'px';
333
360
  };
@@ -340,7 +367,7 @@ TimeAxis.prototype._repaintMajorLine = function (x) {
340
367
  TimeAxis.prototype._repaintLine = function() {
341
368
  var line = this.dom.line,
342
369
  frame = this.frame,
343
- options = this.options;
370
+ orientation = this.getOption('orientation');
344
371
 
345
372
  // line before all axis elements
346
373
  if (this.getOption('showMinorLabels') || this.getOption('showMajorLabels')) {
@@ -357,167 +384,54 @@ TimeAxis.prototype._repaintLine = function() {
357
384
  this.dom.line = line;
358
385
  }
359
386
 
360
- line.style.top = this.props.lineTop + 'px';
387
+ if (orientation == 'top') {
388
+ line.style.top = this.height + 'px';
389
+ line.style.bottom = '';
390
+ }
391
+ else {
392
+ line.style.top = '';
393
+ line.style.bottom = this.height + 'px';
394
+ }
361
395
  }
362
396
  else {
363
- if (line && line.parentElement) {
364
- frame.removeChild(line.line);
397
+ if (line && line.parentNode) {
398
+ line.parentNode.removeChild(line);
365
399
  delete this.dom.line;
366
400
  }
367
401
  }
368
402
  };
369
403
 
370
404
  /**
371
- * Create characters used to determine the size of text on the axis
405
+ * Determine the size of text on the axis (both major and minor axis).
406
+ * The size is calculated only once and then cached in this.props.
372
407
  * @private
373
408
  */
374
- TimeAxis.prototype._repaintMeasureChars = function () {
375
- // calculate the width and height of a single character
376
- // this is used to calculate the step size, and also the positioning of the
377
- // axis
378
- var dom = this.dom,
379
- text;
380
-
381
- if (!dom.measureCharMinor) {
382
- text = document.createTextNode('0');
409
+ TimeAxis.prototype._calculateCharSize = function () {
410
+ // determine the char width and height on the minor axis
411
+ if (!('minorCharHeight' in this.props)) {
412
+ var textMinor = document.createTextNode('0');
383
413
  var measureCharMinor = document.createElement('DIV');
384
414
  measureCharMinor.className = 'text minor measure';
385
- measureCharMinor.appendChild(text);
415
+ measureCharMinor.appendChild(textMinor);
386
416
  this.frame.appendChild(measureCharMinor);
387
417
 
388
- dom.measureCharMinor = measureCharMinor;
418
+ this.props.minorCharHeight = measureCharMinor.clientHeight;
419
+ this.props.minorCharWidth = measureCharMinor.clientWidth;
420
+
421
+ this.frame.removeChild(measureCharMinor);
389
422
  }
390
423
 
391
- if (!dom.measureCharMajor) {
392
- text = document.createTextNode('0');
424
+ if (!('majorCharHeight' in this.props)) {
425
+ var textMajor = document.createTextNode('0');
393
426
  var measureCharMajor = document.createElement('DIV');
394
427
  measureCharMajor.className = 'text major measure';
395
- measureCharMajor.appendChild(text);
428
+ measureCharMajor.appendChild(textMajor);
396
429
  this.frame.appendChild(measureCharMajor);
397
430
 
398
- dom.measureCharMajor = measureCharMajor;
399
- }
400
- };
401
-
402
- /**
403
- * Reflow the component
404
- * @return {Boolean} resized
405
- */
406
- TimeAxis.prototype.reflow = function () {
407
- var changed = 0,
408
- update = util.updateProperty,
409
- frame = this.frame,
410
- range = this.range;
411
-
412
- if (!range) {
413
- throw new Error('Cannot repaint time axis: no range configured');
414
- }
415
-
416
- if (frame) {
417
- changed += update(this, 'top', frame.offsetTop);
418
- changed += update(this, 'left', frame.offsetLeft);
431
+ this.props.majorCharHeight = measureCharMajor.clientHeight;
432
+ this.props.majorCharWidth = measureCharMajor.clientWidth;
419
433
 
420
- // calculate size of a character
421
- var props = this.props,
422
- showMinorLabels = this.getOption('showMinorLabels'),
423
- showMajorLabels = this.getOption('showMajorLabels'),
424
- measureCharMinor = this.dom.measureCharMinor,
425
- measureCharMajor = this.dom.measureCharMajor;
426
- if (measureCharMinor) {
427
- props.minorCharHeight = measureCharMinor.clientHeight;
428
- props.minorCharWidth = measureCharMinor.clientWidth;
429
- }
430
- if (measureCharMajor) {
431
- props.majorCharHeight = measureCharMajor.clientHeight;
432
- props.majorCharWidth = measureCharMajor.clientWidth;
433
- }
434
-
435
- var parentHeight = frame.parentNode ? frame.parentNode.offsetHeight : 0;
436
- if (parentHeight != props.parentHeight) {
437
- props.parentHeight = parentHeight;
438
- changed += 1;
439
- }
440
- switch (this.getOption('orientation')) {
441
- case 'bottom':
442
- props.minorLabelHeight = showMinorLabels ? props.minorCharHeight : 0;
443
- props.majorLabelHeight = showMajorLabels ? props.majorCharHeight : 0;
444
-
445
- props.minorLabelTop = 0;
446
- props.majorLabelTop = props.minorLabelTop + props.minorLabelHeight;
447
-
448
- props.minorLineTop = -this.top;
449
- props.minorLineHeight = Math.max(this.top + props.majorLabelHeight, 0);
450
- props.minorLineWidth = 1; // TODO: really calculate width
451
-
452
- props.majorLineTop = -this.top;
453
- props.majorLineHeight = Math.max(this.top + props.minorLabelHeight + props.majorLabelHeight, 0);
454
- props.majorLineWidth = 1; // TODO: really calculate width
455
-
456
- props.lineTop = 0;
457
-
458
- break;
459
-
460
- case 'top':
461
- props.minorLabelHeight = showMinorLabels ? props.minorCharHeight : 0;
462
- props.majorLabelHeight = showMajorLabels ? props.majorCharHeight : 0;
463
-
464
- props.majorLabelTop = 0;
465
- props.minorLabelTop = props.majorLabelTop + props.majorLabelHeight;
466
-
467
- props.minorLineTop = props.minorLabelTop;
468
- props.minorLineHeight = Math.max(parentHeight - props.majorLabelHeight - this.top);
469
- props.minorLineWidth = 1; // TODO: really calculate width
470
-
471
- props.majorLineTop = 0;
472
- props.majorLineHeight = Math.max(parentHeight - this.top);
473
- props.majorLineWidth = 1; // TODO: really calculate width
474
-
475
- props.lineTop = props.majorLabelHeight + props.minorLabelHeight;
476
-
477
- break;
478
-
479
- default:
480
- throw new Error('Unkown orientation "' + this.getOption('orientation') + '"');
481
- }
482
-
483
- var height = props.minorLabelHeight + props.majorLabelHeight;
484
- changed += update(this, 'width', frame.offsetWidth);
485
- changed += update(this, 'height', height);
486
-
487
- // calculate range and step
488
- this._updateConversion();
489
-
490
- var start = util.convert(range.start, 'Number'),
491
- end = util.convert(range.end, 'Number'),
492
- minimumStep = this.toTime((props.minorCharWidth || 10) * 5).valueOf()
493
- -this.toTime(0).valueOf();
494
- this.step = new TimeStep(new Date(start), new Date(end), minimumStep);
495
- changed += update(props.range, 'start', start);
496
- changed += update(props.range, 'end', end);
497
- changed += update(props.range, 'minimumStep', minimumStep.valueOf());
498
- }
499
-
500
- return (changed > 0);
501
- };
502
-
503
- /**
504
- * Calculate the scale and offset to convert a position on screen to the
505
- * corresponding date and vice versa.
506
- * After the method _updateConversion is executed once, the methods toTime
507
- * and toScreen can be used.
508
- * @private
509
- */
510
- TimeAxis.prototype._updateConversion = function() {
511
- var range = this.range;
512
- if (!range) {
513
- throw new Error('No range configured');
514
- }
515
-
516
- if (range.conversion) {
517
- this.conversion = range.conversion(this.width);
518
- }
519
- else {
520
- this.conversion = Range.conversion(range.start, range.end, this.width);
434
+ this.frame.removeChild(measureCharMajor);
521
435
  }
522
436
  };
523
437