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.

198 lines
5.3 KiB

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