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.5 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. };
  46. /**
  47. * Mixin the cluster system and initialize the parameters required.
  48. *
  49. * @private
  50. */
  51. exports._loadClusterSystem = function () {
  52. this.clusterSession = 0;
  53. this.hubThreshold = 5;
  54. this._loadMixin(ClusterMixin);
  55. };
  56. /**
  57. * Mixin the sector system and initialize the parameters required
  58. *
  59. * @private
  60. */
  61. exports._loadSectorSystem = function () {
  62. this.sectors = {};
  63. this.activeSector = ["default"];
  64. this.sectors["active"] = {};
  65. this.sectors["active"]["default"] = {"nodes": {},
  66. "edges": {},
  67. "nodeIndices": [],
  68. "formationScale": 1.0,
  69. "drawingNode": undefined };
  70. this.sectors["frozen"] = {};
  71. this.sectors["support"] = {"nodes": {},
  72. "edges": {},
  73. "nodeIndices": [],
  74. "formationScale": 1.0,
  75. "drawingNode": undefined };
  76. this.nodeIndices = this.sectors["active"]["default"]["nodeIndices"]; // the node indices list is used to speed up the computation of the repulsion fields
  77. this._loadMixin(SectorsMixin);
  78. };
  79. /**
  80. * Mixin the selection system and initialize the parameters required
  81. *
  82. * @private
  83. */
  84. exports._loadSelectionSystem = function () {
  85. this.selectionObj = {nodes: {}, edges: {}};
  86. this._loadMixin(SelectionMixin);
  87. };
  88. /**
  89. * Mixin the navigationUI (User Interface) system and initialize the parameters required
  90. *
  91. * @private
  92. */
  93. exports._loadManipulationSystem = function () {
  94. // reset global variables -- these are used by the selection of nodes and edges.
  95. this.blockConnectingEdgeSelection = false;
  96. this.forceAppendSelection = false;
  97. if (this.constants.dataManipulation.enabled == true) {
  98. // load the manipulator HTML elements. All styling done in css.
  99. if (this.manipulationDiv === undefined) {
  100. this.manipulationDiv = document.createElement('div');
  101. this.manipulationDiv.className = 'network-manipulationDiv';
  102. this.manipulationDiv.id = 'network-manipulationDiv';
  103. if (this.editMode == true) {
  104. this.manipulationDiv.style.display = "block";
  105. }
  106. else {
  107. this.manipulationDiv.style.display = "none";
  108. }
  109. this.containerElement.insertBefore(this.manipulationDiv, this.frame);
  110. }
  111. if (this.editModeDiv === undefined) {
  112. this.editModeDiv = document.createElement('div');
  113. this.editModeDiv.className = 'network-manipulation-editMode';
  114. this.editModeDiv.id = 'network-manipulation-editMode';
  115. if (this.editMode == true) {
  116. this.editModeDiv.style.display = "none";
  117. }
  118. else {
  119. this.editModeDiv.style.display = "block";
  120. }
  121. this.containerElement.insertBefore(this.editModeDiv, this.frame);
  122. }
  123. if (this.closeDiv === undefined) {
  124. this.closeDiv = document.createElement('div');
  125. this.closeDiv.className = 'network-manipulation-closeDiv';
  126. this.closeDiv.id = 'network-manipulation-closeDiv';
  127. this.closeDiv.style.display = this.manipulationDiv.style.display;
  128. this.containerElement.insertBefore(this.closeDiv, this.frame);
  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.containerElement.removeChild(this.manipulationDiv);
  141. this.containerElement.removeChild(this.editModeDiv);
  142. this.containerElement.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. };