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.

219 lines
6.6 KiB

  1. /**
  2. * Created by Alex on 2/10/14.
  3. */
  4. var graphMixinLoaders = {
  5. /**
  6. * Load a mixin into the graph 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. Graph.prototype[mixinFunction] = sourceVariable[mixinFunction];
  15. }
  16. }
  17. },
  18. /**
  19. * removes a mixin from the graph 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. Graph.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. },
  40. /**
  41. * This loads the node force solver based on the barnes hut or repulsion algorithm
  42. *
  43. * @private
  44. */
  45. _loadSelectedForceSolver : function() {
  46. // this overloads the this._calculateNodeForces
  47. if (this.constants.physics.barnesHut.enabled == true) {
  48. this._clearMixin(repulsionMixin);
  49. this.constants.physics.centralGravity = this.constants.physics.barnesHut.centralGravity;
  50. this.constants.physics.springLength = this.constants.physics.barnesHut.springLength;
  51. this.constants.physics.springConstant = this.constants.physics.barnesHut.springConstant;
  52. this.constants.physics.damping = this.constants.physics.barnesHut.damping;
  53. this.constants.physics.springGrowthPerMass = this.constants.physics.barnesHut.springGrowthPerMass;
  54. this._loadMixin(barnesHutMixin);
  55. }
  56. else {
  57. this._clearMixin(barnesHutMixin);
  58. this.barnesHutTree = undefined;
  59. this.constants.physics.centralGravity = this.constants.physics.repulsion.centralGravity;
  60. this.constants.physics.springLength = this.constants.physics.repulsion.springLength;
  61. this.constants.physics.springConstant = this.constants.physics.repulsion.springConstant;
  62. this.constants.physics.damping = this.constants.physics.repulsion.damping;
  63. this.constants.physics.springGrowthPerMass = this.constants.physics.repulsion.springGrowthPerMass;
  64. this._loadMixin(repulsionMixin);
  65. }
  66. },
  67. /**
  68. * Mixin the cluster system and initialize the parameters required.
  69. *
  70. * @private
  71. */
  72. _loadClusterSystem : function() {
  73. this.clusterSession = 0;
  74. this.hubThreshold = 5;
  75. this._loadMixin(ClusterMixin);
  76. },
  77. /**
  78. * Mixin the sector system and initialize the parameters required
  79. *
  80. * @private
  81. */
  82. _loadSectorSystem : function() {
  83. this.sectors = { },
  84. this.activeSector = ["default"];
  85. this.sectors["active"] = { },
  86. this.sectors["active"]["default"] = {"nodes":{},
  87. "edges":{},
  88. "nodeIndices":[],
  89. "formationScale": 1.0,
  90. "drawingNode": undefined };
  91. this.sectors["frozen"] = {},
  92. this.sectors["support"] = {"nodes":{},
  93. "edges":{},
  94. "nodeIndices":[],
  95. "formationScale": 1.0,
  96. "drawingNode": undefined };
  97. this.nodeIndices = this.sectors["active"]["default"]["nodeIndices"]; // the node indices list is used to speed up the computation of the repulsion fields
  98. this._loadMixin(SectorMixin);
  99. },
  100. /**
  101. * Mixin the selection system and initialize the parameters required
  102. *
  103. * @private
  104. */
  105. _loadSelectionSystem : function() {
  106. this.selectionObj = { };
  107. this._loadMixin(SelectionMixin);
  108. },
  109. /**
  110. * Mixin the navigationUI (User Interface) system and initialize the parameters required
  111. *
  112. * @private
  113. */
  114. _loadManipulationSystem : function() {
  115. // reset global variables -- these are used by the selection of nodes and edges.
  116. this.blockConnectingEdgeSelection = false;
  117. this.forceAppendSelection = false
  118. if (this.constants.dataManipulation.enabled == true) {
  119. // load the manipulator HTML elements. All styling done in css.
  120. if (this.manipulationDiv === undefined) {
  121. this.manipulationDiv = document.createElement('div');
  122. this.manipulationDiv.className = 'graph-manipulationDiv';
  123. this.manipulationDiv.id = 'graph-manipulationDiv';
  124. if (this.editMode == true) {
  125. this.manipulationDiv.style.display = "block";
  126. }
  127. else {
  128. this.manipulationDiv.style.display = "none";
  129. }
  130. this.containerElement.insertBefore(this.manipulationDiv, this.frame);
  131. }
  132. if (this.editModeDiv === undefined) {
  133. this.editModeDiv = document.createElement('div');
  134. this.editModeDiv.className = 'graph-manipulation-editMode';
  135. this.editModeDiv.id = 'graph-manipulation-editMode';
  136. if (this.editMode == true) {
  137. this.editModeDiv.style.display = "none";
  138. }
  139. else {
  140. this.editModeDiv.style.display = "block";
  141. }
  142. this.containerElement.insertBefore(this.editModeDiv, this.frame);
  143. }
  144. if (this.closeDiv === undefined) {
  145. this.closeDiv = document.createElement('div');
  146. this.closeDiv.className = 'graph-manipulation-closeDiv';
  147. this.closeDiv.id = 'graph-manipulation-closeDiv';
  148. this.closeDiv.style.display = this.manipulationDiv.style.display;
  149. this.containerElement.insertBefore(this.closeDiv, this.frame);
  150. }
  151. // load the manipulation functions
  152. this._loadMixin(manipulationMixin);
  153. // create the manipulator toolbar
  154. this._createManipulatorBar();
  155. }
  156. else {
  157. if (this.manipulationDiv !== undefined) {
  158. // removes all the bindings and overloads
  159. this._createManipulatorBar();
  160. // remove the manipulation divs
  161. this.containerElement.removeChild(this.manipulationDiv);
  162. this.containerElement.removeChild(this.editModeDiv);
  163. this.containerElement.removeChild(this.closeDiv);
  164. this.manipulationDiv = undefined;
  165. this.editModeDiv = undefined;
  166. this.closeDiv = undefined;
  167. // remove the mixin functions
  168. this._clearMixin(manipulationMixin);
  169. }
  170. }
  171. },
  172. /**
  173. * Mixin the navigation (User Interface) system and initialize the parameters required
  174. *
  175. * @private
  176. */
  177. _loadNavigationControls : function() {
  178. this._loadMixin(NavigationMixin);
  179. // the clean function removes the button divs, this is done to remove the bindings.
  180. this._cleanNavigation();
  181. if (this.constants.navigation.enabled == true) {
  182. this._loadNavigationElements();
  183. }
  184. }
  185. }