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.

158 lines
4.2 KiB

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