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.

171 lines
4.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. 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 selection system and initialize the parameters required
  60. *
  61. * @private
  62. */
  63. exports._loadSelectionSystem = function () {
  64. this.selectionObj = {nodes: {}, edges: {}};
  65. this._loadMixin(SelectionMixin);
  66. };
  67. /**
  68. * Mixin the navigationUI (User Interface) system and initialize the parameters required
  69. *
  70. * @private
  71. */
  72. exports._loadManipulationSystem = function () {
  73. // reset global variables -- these are used by the selection of nodes and edges.
  74. this.blockConnectingEdgeSelection = false;
  75. this.forceAppendSelection = false;
  76. if (this.constants.dataManipulation.enabled == true) {
  77. // load the manipulator HTML elements. All styling done in css.
  78. if (this.manipulationDiv === undefined) {
  79. this.manipulationDiv = document.createElement('div');
  80. this.manipulationDiv.className = 'network-manipulationDiv';
  81. if (this.editMode == true) {
  82. this.manipulationDiv.style.display = "block";
  83. }
  84. else {
  85. this.manipulationDiv.style.display = "none";
  86. }
  87. this.frame.appendChild(this.manipulationDiv);
  88. }
  89. if (this.editModeDiv === undefined) {
  90. this.editModeDiv = document.createElement('div');
  91. this.editModeDiv.className = 'network-manipulation-editMode';
  92. if (this.editMode == true) {
  93. this.editModeDiv.style.display = "none";
  94. }
  95. else {
  96. this.editModeDiv.style.display = "block";
  97. }
  98. this.frame.appendChild(this.editModeDiv);
  99. }
  100. if (this.closeDiv === undefined) {
  101. this.closeDiv = document.createElement('div');
  102. this.closeDiv.className = 'network-manipulation-closeDiv';
  103. this.closeDiv.style.display = this.manipulationDiv.style.display;
  104. this.frame.appendChild(this.closeDiv);
  105. }
  106. // load the manipulation functions
  107. this._loadMixin(ManipulationMixin);
  108. // create the manipulator toolbar
  109. this._createManipulatorBar();
  110. }
  111. else {
  112. if (this.manipulationDiv !== undefined) {
  113. // removes all the bindings and overloads
  114. this._createManipulatorBar();
  115. // remove the manipulation divs
  116. this.frame.removeChild(this.manipulationDiv);
  117. this.frame.removeChild(this.editModeDiv);
  118. this.frame.removeChild(this.closeDiv);
  119. this.manipulationDiv = undefined;
  120. this.editModeDiv = undefined;
  121. this.closeDiv = undefined;
  122. // remove the mixin functions
  123. this._clearMixin(ManipulationMixin);
  124. }
  125. }
  126. };
  127. /**
  128. * Mixin the navigation (User Interface) system and initialize the parameters required
  129. *
  130. * @private
  131. */
  132. exports._loadNavigationControls = function () {
  133. this._loadMixin(NavigationMixin);
  134. // the clean function removes the button divs, this is done to remove the bindings.
  135. this._cleanNavigation();
  136. if (this.constants.navigation.enabled == true) {
  137. this._loadNavigationElements();
  138. }
  139. };
  140. /**
  141. * Mixin the hierarchical layout system.
  142. *
  143. * @private
  144. */
  145. exports._loadHierarchySystem = function () {
  146. this._loadMixin(HierarchicalLayoutMixin);
  147. };