vis-rails 0.0.6 → 1.0.0

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 (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,14 +1,13 @@
1
1
  /**
2
2
  * @constructor ItemRangeOverflow
3
3
  * @extends ItemRange
4
- * @param {ItemSet} parent
5
4
  * @param {Object} data Object containing parameters start, end
6
5
  * content, className.
7
6
  * @param {Object} [options] Options to set initial property values
8
7
  * @param {Object} [defaultOptions] default options
9
8
  * // TODO: describe available options
10
9
  */
11
- function ItemRangeOverflow (parent, data, options, defaultOptions) {
10
+ function ItemRangeOverflow (data, options, defaultOptions) {
12
11
  this.props = {
13
12
  content: {
14
13
  left: 0,
@@ -16,104 +15,42 @@ function ItemRangeOverflow (parent, data, options, defaultOptions) {
16
15
  }
17
16
  };
18
17
 
19
- // define a private property _width, which is the with of the range box
20
- // adhering to the ranges start and end date. The property width has a
21
- // getter which returns the max of border width and content width
22
- this._width = 0;
23
- Object.defineProperty(this, 'width', {
24
- get: function () {
25
- return (this.props.content && this._width < this.props.content.width) ?
26
- this.props.content.width :
27
- this._width;
28
- },
29
-
30
- set: function (width) {
31
- this._width = width;
32
- }
33
- });
34
-
35
- ItemRange.call(this, parent, data, options, defaultOptions);
18
+ ItemRange.call(this, data, options, defaultOptions);
36
19
  }
37
20
 
38
- ItemRangeOverflow.prototype = new ItemRange (null, null);
21
+ ItemRangeOverflow.prototype = new ItemRange (null);
22
+
23
+ ItemRangeOverflow.prototype.baseClassName = 'item rangeoverflow';
39
24
 
40
25
  /**
41
- * Repaint the item
42
- * @return {Boolean} changed
26
+ * Reposition the item horizontally
27
+ * @Override
43
28
  */
44
- ItemRangeOverflow.prototype.repaint = function repaint() {
45
- // TODO: make an efficient repaint
46
- var changed = false;
47
- var dom = this.dom;
48
-
49
- if (!dom) {
50
- this._create();
51
- dom = this.dom;
52
- changed = true;
29
+ ItemRangeOverflow.prototype.repositionX = function repositionX() {
30
+ var parentWidth = this.parent.width,
31
+ start = this.defaultOptions.toScreen(this.data.start),
32
+ end = this.defaultOptions.toScreen(this.data.end),
33
+ padding = 'padding' in this.options ? this.options.padding : this.defaultOptions.padding,
34
+ contentLeft;
35
+
36
+ // limit the width of the this, as browsers cannot draw very wide divs
37
+ if (start < -parentWidth) {
38
+ start = -parentWidth;
53
39
  }
54
-
55
- if (dom) {
56
- if (!this.parent) {
57
- throw new Error('Cannot repaint item: no parent attached');
58
- }
59
- var foreground = this.parent.getForeground();
60
- if (!foreground) {
61
- throw new Error('Cannot repaint time axis: ' +
62
- 'parent has no foreground container element');
63
- }
64
-
65
- if (!dom.box.parentNode) {
66
- foreground.appendChild(dom.box);
67
- changed = true;
68
- }
69
-
70
- // update content
71
- if (this.data.content != this.content) {
72
- this.content = this.data.content;
73
- if (this.content instanceof Element) {
74
- dom.content.innerHTML = '';
75
- dom.content.appendChild(this.content);
76
- }
77
- else if (this.data.content != undefined) {
78
- dom.content.innerHTML = this.content;
79
- }
80
- else {
81
- throw new Error('Property "content" missing in item ' + this.id);
82
- }
83
- changed = true;
84
- }
85
-
86
- this._repaintDeleteButton(dom.box);
87
- this._repaintDragLeft();
88
- this._repaintDragRight();
89
-
90
- // update class
91
- var className = (this.data.className? ' ' + this.data.className : '') +
92
- (this.selected ? ' selected' : '');
93
- if (this.className != className) {
94
- this.className = className;
95
- dom.box.className = 'item rangeoverflow' + className;
96
- changed = true;
97
- }
40
+ if (end > 2 * parentWidth) {
41
+ end = 2 * parentWidth;
98
42
  }
99
43
 
100
- return changed;
101
- };
44
+ // when range exceeds left of the window, position the contents at the left of the visible area
45
+ contentLeft = Math.max(-start, 0);
102
46
 
103
- /**
104
- * Reposition the item, recalculate its left, top, and width, using the current
105
- * range and size of the items itemset
106
- * @override
107
- */
108
- ItemRangeOverflow.prototype.reposition = function reposition() {
109
- var dom = this.dom,
110
- props = this.props;
47
+ this.left = start;
48
+ var boxWidth = Math.max(end - start, 1);
49
+ this.width = (this.props.content.width < boxWidth) ?
50
+ boxWidth :
51
+ start + contentLeft + this.props.content.width;
111
52
 
112
- if (dom) {
113
- dom.box.style.top = this.top + 'px';
114
- dom.box.style.left = this.left + 'px';
115
- dom.box.style.width = this._width + 'px';
116
-
117
- dom.content.style.left = props.content.left + 'px';
118
- }
53
+ this.dom.box.style.left = this.left + 'px';
54
+ this.dom.box.style.width = boxWidth + 'px';
55
+ this.dom.content.style.left = contentLeft + 'px';
119
56
  };
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Utility functions for ordering and stacking of items
3
+ */
4
+ var stack = {};
5
+
6
+ /**
7
+ * Order items by their start data
8
+ * @param {Item[]} items
9
+ */
10
+ stack.orderByStart = function orderByStart(items) {
11
+ items.sort(function (a, b) {
12
+ return a.data.start - b.data.start;
13
+ });
14
+ };
15
+
16
+ /**
17
+ * Order items by their end date. If they have no end date, their start date
18
+ * is used.
19
+ * @param {Item[]} items
20
+ */
21
+ stack.orderByEnd = function orderByEnd(items) {
22
+ items.sort(function (a, b) {
23
+ var aTime = ('end' in a.data) ? a.data.end : a.data.start,
24
+ bTime = ('end' in b.data) ? b.data.end : b.data.start;
25
+
26
+ return aTime - bTime;
27
+ });
28
+ };
29
+
30
+ /**
31
+ * Adjust vertical positions of the items such that they don't overlap each
32
+ * other.
33
+ * @param {Item[]} items
34
+ * All visible items
35
+ * @param {{item: number, axis: number}} margin
36
+ * Margins between items and between items and the axis.
37
+ * @param {boolean} [force=false]
38
+ * If true, all items will be repositioned. If false (default), only
39
+ * items having a top===null will be re-stacked
40
+ */
41
+ stack.stack = function _stack (items, margin, force) {
42
+ var i, iMax;
43
+
44
+ if (force) {
45
+ // reset top position of all items
46
+ for (i = 0, iMax = items.length; i < iMax; i++) {
47
+ items[i].top = null;
48
+ }
49
+ }
50
+
51
+ // calculate new, non-overlapping positions
52
+ for (i = 0, iMax = items.length; i < iMax; i++) {
53
+ var item = items[i];
54
+ if (item.top === null) {
55
+ // initialize top position
56
+ item.top = margin.axis;
57
+
58
+ do {
59
+ // TODO: optimize checking for overlap. when there is a gap without items,
60
+ // you only need to check for items from the next item on, not from zero
61
+ var collidingItem = null;
62
+ for (var j = 0, jj = items.length; j < jj; j++) {
63
+ var other = items[j];
64
+ if (other.top !== null && other !== item && stack.collision(item, other, margin.item)) {
65
+ collidingItem = other;
66
+ break;
67
+ }
68
+ }
69
+
70
+ if (collidingItem != null) {
71
+ // There is a collision. Reposition the items above the colliding element
72
+ item.top = collidingItem.top + collidingItem.height + margin.item;
73
+ }
74
+ } while (collidingItem);
75
+ }
76
+ }
77
+ };
78
+
79
+ /**
80
+ * Adjust vertical positions of the items without stacking them
81
+ * @param {Item[]} items
82
+ * All visible items
83
+ * @param {{item: number, axis: number}} margin
84
+ * Margins between items and between items and the axis.
85
+ */
86
+ stack.nostack = function nostack (items, margin) {
87
+ var i, iMax;
88
+
89
+ // reset top position of all items
90
+ for (i = 0, iMax = items.length; i < iMax; i++) {
91
+ items[i].top = margin.axis;
92
+ }
93
+ };
94
+
95
+ /**
96
+ * Test if the two provided items collide
97
+ * The items must have parameters left, width, top, and height.
98
+ * @param {Item} a The first item
99
+ * @param {Item} b The second item
100
+ * @param {Number} margin A minimum required margin.
101
+ * If margin is provided, the two items will be
102
+ * marked colliding when they overlap or
103
+ * when the margin between the two is smaller than
104
+ * the requested margin.
105
+ * @return {boolean} true if a and b collide, else false
106
+ */
107
+ stack.collision = function collision (a, b, margin) {
108
+ return ((a.left - margin) < (b.left + b.width) &&
109
+ (a.left + a.width + margin) > b.left &&
110
+ (a.top - margin) < (b.top + b.height) &&
111
+ (a.top + a.height + margin) > b.top);
112
+ };
@@ -97,6 +97,23 @@ util.extend = function (a, b) {
97
97
  return a;
98
98
  };
99
99
 
100
+ /**
101
+ * Test whether all elements in two arrays are equal.
102
+ * @param {Array} a
103
+ * @param {Array} b
104
+ * @return {boolean} Returns true if both arrays have the same length and same
105
+ * elements.
106
+ */
107
+ util.equalArray = function (a, b) {
108
+ if (a.length != b.length) return false;
109
+
110
+ for (var i = 1, len = a.length; i < len; i++) {
111
+ if (a[i] != b[i]) return false;
112
+ }
113
+
114
+ return true;
115
+ };
116
+
100
117
  /**
101
118
  * Convert an object to another type
102
119
  * @param {Boolean | Number | String | Date | Moment | Null | undefined} object
@@ -440,6 +457,22 @@ util.forEach = function forEach (object, callback) {
440
457
  }
441
458
  };
442
459
 
460
+ /**
461
+ * Convert an object into an array: all objects properties are put into the
462
+ * array. The resulting array is unordered.
463
+ * @param {Object} object
464
+ * @param {Array} array
465
+ */
466
+ util.toArray = function toArray(object) {
467
+ var array = [];
468
+
469
+ for (var prop in object) {
470
+ if (object.hasOwnProperty(prop)) array.push(object[prop]);
471
+ }
472
+
473
+ return array;
474
+ }
475
+
443
476
  /**
444
477
  * Update a property in an object
445
478
  * @param {Object} object
@@ -447,7 +480,7 @@ util.forEach = function forEach (object, callback) {
447
480
  * @param {*} value
448
481
  * @return {Boolean} changed
449
482
  */
450
- util.updateProperty = function updateProp (object, key, value) {
483
+ util.updateProperty = function updateProperty (object, key, value) {
451
484
  if (object[key] !== value) {
452
485
  object[key] = value;
453
486
  return true;
@@ -542,7 +575,7 @@ util.fakeGesture = function fakeGesture (element, event) {
542
575
  var eventType = null;
543
576
 
544
577
  // for hammer.js 1.0.5
545
- // var gesture = Hammer.event.collectEventData(this, eventType, event);
578
+ //var gesture = Hammer.event.collectEventData(this, eventType, event);
546
579
 
547
580
  // for hammer.js 1.0.6
548
581
  var touches = Hammer.event.getTouchList(event, eventType);
@@ -654,53 +687,104 @@ util.option.asElement = function (value, defaultValue) {
654
687
 
655
688
 
656
689
 
657
- util.GiveDec = function GiveDec(Hex)
658
- {
659
- if(Hex == "A")
690
+ util.GiveDec = function GiveDec(Hex) {
691
+ var Value;
692
+
693
+ if (Hex == "A")
660
694
  Value = 10;
661
- else
662
- if(Hex == "B")
695
+ else if (Hex == "B")
663
696
  Value = 11;
664
- else
665
- if(Hex == "C")
697
+ else if (Hex == "C")
666
698
  Value = 12;
667
- else
668
- if(Hex == "D")
699
+ else if (Hex == "D")
669
700
  Value = 13;
670
- else
671
- if(Hex == "E")
701
+ else if (Hex == "E")
672
702
  Value = 14;
673
- else
674
- if(Hex == "F")
703
+ else if (Hex == "F")
675
704
  Value = 15;
676
705
  else
677
- Value = eval(Hex)
706
+ Value = eval(Hex);
707
+
678
708
  return Value;
679
- }
709
+ };
710
+
711
+ util.GiveHex = function GiveHex(Dec) {
712
+ var Value;
680
713
 
681
- util.GiveHex = function GiveHex(Dec)
682
- {
683
714
  if(Dec == 10)
684
715
  Value = "A";
685
- else
686
- if(Dec == 11)
716
+ else if (Dec == 11)
687
717
  Value = "B";
688
- else
689
- if(Dec == 12)
718
+ else if (Dec == 12)
690
719
  Value = "C";
691
- else
692
- if(Dec == 13)
720
+ else if (Dec == 13)
693
721
  Value = "D";
694
- else
695
- if(Dec == 14)
722
+ else if (Dec == 14)
696
723
  Value = "E";
697
- else
698
- if(Dec == 15)
724
+ else if (Dec == 15)
699
725
  Value = "F";
700
726
  else
701
727
  Value = "" + Dec;
728
+
702
729
  return Value;
703
- }
730
+ };
731
+
732
+ /**
733
+ * Parse a color property into an object with border, background, and
734
+ * highlight colors
735
+ * @param {Object | String} color
736
+ * @return {Object} colorObject
737
+ */
738
+ util.parseColor = function(color) {
739
+ var c;
740
+ if (util.isString(color)) {
741
+ if (util.isValidHex(color)) {
742
+ var hsv = util.hexToHSV(color);
743
+ var lighterColorHSV = {h:hsv.h,s:hsv.s * 0.45,v:Math.min(1,hsv.v * 1.05)};
744
+ var darkerColorHSV = {h:hsv.h,s:Math.min(1,hsv.v * 1.25),v:hsv.v*0.6};
745
+ var darkerColorHex = util.HSVToHex(darkerColorHSV.h ,darkerColorHSV.h ,darkerColorHSV.v);
746
+ var lighterColorHex = util.HSVToHex(lighterColorHSV.h,lighterColorHSV.s,lighterColorHSV.v);
747
+
748
+ c = {
749
+ background: color,
750
+ border:darkerColorHex,
751
+ highlight: {
752
+ background:lighterColorHex,
753
+ border:darkerColorHex
754
+ }
755
+ };
756
+ }
757
+ else {
758
+ c = {
759
+ background:color,
760
+ border:color,
761
+ highlight: {
762
+ background:color,
763
+ border:color
764
+ }
765
+ };
766
+ }
767
+ }
768
+ else {
769
+ c = {};
770
+ c.background = color.background || 'white';
771
+ c.border = color.border || c.background;
772
+
773
+ if (util.isString(color.highlight)) {
774
+ c.highlight = {
775
+ border: color.highlight,
776
+ background: color.highlight
777
+ }
778
+ }
779
+ else {
780
+ c.highlight = {};
781
+ c.highlight.background = color.highlight && color.highlight.background || c.background;
782
+ c.highlight.border = color.highlight && color.highlight.border || c.border;
783
+ }
784
+ }
785
+
786
+ return c;
787
+ };
704
788
 
705
789
  /**
706
790
  * http://www.yellowpipe.com/yis/tools/hex-to-rgb/color-converter.php
@@ -796,17 +880,31 @@ util.HSVToRGB = function HSVToRGB(h, s, v) {
796
880
  return {r:Math.floor(r * 255), g:Math.floor(g * 255), b:Math.floor(b * 255) };
797
881
  };
798
882
 
799
- util.HSVToHex = function HSVToHex(h,s,v) {
800
- var rgb = util.HSVToRGB(h,s,v);
801
- return util.RGBToHex(rgb.r,rgb.g,rgb.b);
802
- }
883
+ util.HSVToHex = function HSVToHex(h, s, v) {
884
+ var rgb = util.HSVToRGB(h, s, v);
885
+ return util.RGBToHex(rgb.r, rgb.g, rgb.b);
886
+ };
803
887
 
804
888
  util.hexToHSV = function hexToHSV(hex) {
805
889
  var rgb = util.hexToRGB(hex);
806
- return util.RGBToHSV(rgb.r,rgb.g,rgb.b);
807
- }
890
+ return util.RGBToHSV(rgb.r, rgb.g, rgb.b);
891
+ };
808
892
 
809
893
  util.isValidHex = function isValidHex(hex) {
810
- var isOk = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(hex);
894
+ var isOk = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(hex);
811
895
  return isOk;
812
- }
896
+ };
897
+
898
+ util.copyObject = function copyObject(objectFrom, objectTo) {
899
+ for (var i in objectFrom) {
900
+ if (objectFrom.hasOwnProperty(i)) {
901
+ if (typeof objectFrom[i] == "object") {
902
+ objectTo[i] = {};
903
+ util.copyObject(objectFrom[i], objectTo[i]);
904
+ }
905
+ else {
906
+ objectTo[i] = objectFrom[i];
907
+ }
908
+ }
909
+ }
910
+ };