vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
5.5 KiB

  1. /**
  2. * Created by Alex on 2/10/14.
  3. */
  4. var networkMixinLoaders = {
  5. /**
  6. * Load a mixin into the network object
  7. *
  8. * @param {Object} sourceVariable | this object has to contain functions.
  9. * @private
  10. */
  11. _loadMixin: function (sourceVariable) {
  12. for (var mixinFunction in sourceVariable) {
  13. if (sourceVariable.hasOwnProperty(mixinFunction)) {
  14. Network.prototype[mixinFunction] = sourceVariable[mixinFunction];
  15. }
  16. }
  17. },
  18. /**
  19. * removes a mixin from the network object.
  20. *
  21. * @param {Object} sourceVariable | this object has to contain functions.
  22. * @private
  23. */
  24. _clearMixin: function (sourceVariable) {
  25. for (var mixinFunction in sourceVariable) {
  26. if (sourceVariable.hasOwnProperty(mixinFunction)) {
  27. Network.prototype[mixinFunction] = undefined;
  28. }
  29. }
  30. },
  31. /**
  32. * Mixin the physics system and initialize the parameters required.
  33. *
  34. * @private
  35. */
  36. _loadPhysicsSystem: function () {
  37. this._loadMixin(physicsMixin);
  38. this._loadSelectedForceSolver();
  39. if (this.constants.configurePhysics == true) {
  40. this._loadPhysicsConfiguration();
  41. }
  42. },
  43. /**
  44. * Mixin the cluster system and initialize the parameters required.
  45. *
  46. * @private
  47. */
  48. _loadClusterSystem: function () {
  49. this.clusterSession = 0;
  50. this.hubThreshold = 5;
  51. this._loadMixin(ClusterMixin);
  52. },
  53. /**
  54. * Mixin the sector system and initialize the parameters required
  55. *
  56. * @private
  57. */
  58. _loadSectorSystem: function () {
  59. this.sectors = {};
  60. this.activeSector = ["default"];
  61. this.sectors["active"] = {};
  62. this.sectors["active"]["default"] = {"nodes": {},
  63. "edges": {},
  64. "nodeIndices": [],
  65. "formationScale": 1.0,
  66. "drawingNode": undefined };
  67. this.sectors["frozen"] = {};
  68. this.sectors["support"] = {"nodes": {},
  69. "edges": {},
  70. "nodeIndices": [],
  71. "formationScale": 1.0,
  72. "drawingNode": undefined };
  73. this.nodeIndices = this.sectors["active"]["default"]["nodeIndices"]; // the node indices list is used to speed up the computation of the repulsion fields
  74. this._loadMixin(SectorMixin);
  75. },
  76. /**
  77. * Mixin the selection system and initialize the parameters required
  78. *
  79. * @private
  80. */
  81. _loadSelectionSystem: function () {
  82. this.selectionObj = {nodes: {}, edges: {}};
  83. this._loadMixin(SelectionMixin);
  84. },
  85. /**
  86. * Mixin the navigationUI (User Interface) system and initialize the parameters required
  87. *
  88. * @private
  89. */
  90. _loadManipulationSystem: function () {
  91. // reset global variables -- these are used by the selection of nodes and edges.
  92. this.blockConnectingEdgeSelection = false;
  93. this.forceAppendSelection = false;
  94. if (this.constants.dataManipulation.enabled == true) {
  95. // load the manipulator HTML elements. All styling done in css.
  96. if (this.manipulationDiv === undefined) {
  97. this.manipulationDiv = document.createElement('div');
  98. this.manipulationDiv.className = 'network-manipulationDiv';
  99. this.manipulationDiv.id = 'network-manipulationDiv';
  100. if (this.editMode == true) {
  101. this.manipulationDiv.style.display = "block";
  102. }
  103. else {
  104. this.manipulationDiv.style.display = "none";
  105. }
  106. this.containerElement.insertBefore(this.manipulationDiv, this.frame);
  107. }
  108. if (this.editModeDiv === undefined) {
  109. this.editModeDiv = document.createElement('div');
  110. this.editModeDiv.className = 'network-manipulation-editMode';
  111. this.editModeDiv.id = 'network-manipulation-editMode';
  112. if (this.editMode == true) {
  113. this.editModeDiv.style.display = "none";
  114. }
  115. else {
  116. this.editModeDiv.style.display = "block";
  117. }
  118. this.containerElement.insertBefore(this.editModeDiv, this.frame);
  119. }
  120. if (this.closeDiv === undefined) {
  121. this.closeDiv = document.createElement('div');
  122. this.closeDiv.className = 'network-manipulation-closeDiv';
  123. this.closeDiv.id = 'network-manipulation-closeDiv';
  124. this.closeDiv.style.display = this.manipulationDiv.style.display;
  125. this.containerElement.insertBefore(this.closeDiv, this.frame);
  126. }
  127. // load the manipulation functions
  128. this._loadMixin(manipulationMixin);
  129. // create the manipulator toolbar
  130. this._createManipulatorBar();
  131. }
  132. else {
  133. if (this.manipulationDiv !== undefined) {
  134. // removes all the bindings and overloads
  135. this._createManipulatorBar();
  136. // remove the manipulation divs
  137. this.containerElement.removeChild(this.manipulationDiv);
  138. this.containerElement.removeChild(this.editModeDiv);
  139. this.containerElement.removeChild(this.closeDiv);
  140. this.manipulationDiv = undefined;
  141. this.editModeDiv = undefined;
  142. this.closeDiv = undefined;
  143. // remove the mixin functions
  144. this._clearMixin(manipulationMixin);
  145. }
  146. }
  147. },
  148. /**
  149. * Mixin the navigation (User Interface) system and initialize the parameters required
  150. *
  151. * @private
  152. */
  153. _loadNavigationControls: function () {
  154. this._loadMixin(NavigationMixin);
  155. // the clean function removes the button divs, this is done to remove the bindings.
  156. this._cleanNavigation();
  157. if (this.constants.navigation.enabled == true) {
  158. this._loadNavigationElements();
  159. }
  160. },
  161. /**
  162. * Mixin the hierarchical layout system.
  163. *
  164. * @private
  165. */
  166. _loadHierarchySystem: function () {
  167. this._loadMixin(HierarchicalLayoutMixin);
  168. }
  169. };