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.

195 lines
5.2 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. if (this.editMode == true) {
  103. this.manipulationDiv.style.display = "block";
  104. }
  105. else {
  106. this.manipulationDiv.style.display = "none";
  107. }
  108. this.frame.appendChild(this.manipulationDiv);
  109. }
  110. if (this.editModeDiv === undefined) {
  111. this.editModeDiv = document.createElement('div');
  112. this.editModeDiv.className = 'network-manipulation-editMode';
  113. if (this.editMode == true) {
  114. this.editModeDiv.style.display = "none";
  115. }
  116. else {
  117. this.editModeDiv.style.display = "block";
  118. }
  119. this.frame.appendChild(this.editModeDiv);
  120. }
  121. if (this.closeDiv === undefined) {
  122. this.closeDiv = document.createElement('div');
  123. this.closeDiv.className = 'network-manipulation-closeDiv';
  124. this.closeDiv.style.display = this.manipulationDiv.style.display;
  125. this.frame.appendChild(this.closeDiv);
  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.frame.removeChild(this.manipulationDiv);
  138. this.frame.removeChild(this.editModeDiv);
  139. this.frame.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. exports._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. exports._loadHierarchySystem = function () {
  167. this._loadMixin(HierarchicalLayoutMixin);
  168. };