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.

197 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.clusteredNodes = {};
  56. this._loadMixin(ClusterMixin);
  57. };
  58. /**
  59. * Mixin the sector system and initialize the parameters required
  60. *
  61. * @private
  62. */
  63. exports._loadSectorSystem = function () {
  64. this.body.sectors = {};
  65. this.activeSector = ["default"];
  66. this.body.sectors["active"] = {};
  67. this.body.sectors["active"]["default"] = {"nodes": {},
  68. "edges": {},
  69. "nodeIndices": [],
  70. "formationScale": 1.0,
  71. "drawingNode": undefined };
  72. this.body.sectors["frozen"] = {};
  73. this.body.sectors["support"] = {"nodes": {},
  74. "edges": {},
  75. "nodeIndices": [],
  76. "formationScale": 1.0,
  77. "drawingNode": undefined };
  78. this.body.nodeIndices = this.body.sectors["active"]["default"]["nodeIndices"]; // the node indices list is used to speed up the computation of the repulsion fields
  79. this._loadMixin(SectorsMixin);
  80. };
  81. /**
  82. * Mixin the selection system and initialize the parameters required
  83. *
  84. * @private
  85. */
  86. exports._loadSelectionSystem = function () {
  87. this.selectionObj = {nodes: {}, edges: {}};
  88. this._loadMixin(SelectionMixin);
  89. };
  90. /**
  91. * Mixin the navigationUI (User Interface) system and initialize the parameters required
  92. *
  93. * @private
  94. */
  95. exports._loadManipulationSystem = function () {
  96. // reset global variables -- these are used by the selection of nodes and edges.
  97. this.blockConnectingEdgeSelection = false;
  98. this.forceAppendSelection = false;
  99. if (this.constants.dataManipulation.enabled == true) {
  100. // load the manipulator HTML elements. All styling done in css.
  101. if (this.manipulationDiv === undefined) {
  102. this.manipulationDiv = document.createElement('div');
  103. this.manipulationDiv.className = 'network-manipulationDiv';
  104. if (this.editMode == true) {
  105. this.manipulationDiv.style.display = "block";
  106. }
  107. else {
  108. this.manipulationDiv.style.display = "none";
  109. }
  110. this.frame.appendChild(this.manipulationDiv);
  111. }
  112. if (this.editModeDiv === undefined) {
  113. this.editModeDiv = document.createElement('div');
  114. this.editModeDiv.className = '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.frame.appendChild(this.editModeDiv);
  122. }
  123. if (this.closeDiv === undefined) {
  124. this.closeDiv = document.createElement('div');
  125. this.closeDiv.className = 'network-manipulation-closeDiv';
  126. this.closeDiv.style.display = this.manipulationDiv.style.display;
  127. this.frame.appendChild(this.closeDiv);
  128. }
  129. // load the manipulation functions
  130. this._loadMixin(ManipulationMixin);
  131. // create the manipulator toolbar
  132. this._createManipulatorBar();
  133. }
  134. else {
  135. if (this.manipulationDiv !== undefined) {
  136. // removes all the bindings and overloads
  137. this._createManipulatorBar();
  138. // remove the manipulation divs
  139. this.frame.removeChild(this.manipulationDiv);
  140. this.frame.removeChild(this.editModeDiv);
  141. this.frame.removeChild(this.closeDiv);
  142. this.manipulationDiv = undefined;
  143. this.editModeDiv = undefined;
  144. this.closeDiv = undefined;
  145. // remove the mixin functions
  146. this._clearMixin(ManipulationMixin);
  147. }
  148. }
  149. };
  150. /**
  151. * Mixin the navigation (User Interface) system and initialize the parameters required
  152. *
  153. * @private
  154. */
  155. exports._loadNavigationControls = function () {
  156. this._loadMixin(NavigationMixin);
  157. // the clean function removes the button divs, this is done to remove the bindings.
  158. this._cleanNavigation();
  159. if (this.constants.navigation.enabled == true) {
  160. this._loadNavigationElements();
  161. }
  162. };
  163. /**
  164. * Mixin the hierarchical layout system.
  165. *
  166. * @private
  167. */
  168. exports._loadHierarchySystem = function () {
  169. this._loadMixin(HierarchicalLayoutMixin);
  170. };