mxGraphHierarchyEdge.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /**
  2. * Copyright (c) 2006-2015, JGraph Ltd
  3. * Copyright (c) 2006-2015, Gaudenz Alder
  4. */
  5. /**
  6. * Class: mxGraphHierarchyEdge
  7. *
  8. * An abstraction of a hierarchical edge for the hierarchy layout
  9. *
  10. * Constructor: mxGraphHierarchyEdge
  11. *
  12. * Constructs a hierarchy edge
  13. *
  14. * Arguments:
  15. *
  16. * edges - a list of real graph edges this abstraction represents
  17. */
  18. function mxGraphHierarchyEdge(edges)
  19. {
  20. mxGraphAbstractHierarchyCell.apply(this, arguments);
  21. this.edges = edges;
  22. this.ids = [];
  23. for (var i = 0; i < edges.length; i++)
  24. {
  25. this.ids.push(mxObjectIdentity.get(edges[i]));
  26. }
  27. };
  28. /**
  29. * Extends mxGraphAbstractHierarchyCell.
  30. */
  31. mxGraphHierarchyEdge.prototype = new mxGraphAbstractHierarchyCell();
  32. mxGraphHierarchyEdge.prototype.constructor = mxGraphHierarchyEdge;
  33. /**
  34. * Variable: edges
  35. *
  36. * The graph edge(s) this object represents. Parallel edges are all grouped
  37. * together within one hierarchy edge.
  38. */
  39. mxGraphHierarchyEdge.prototype.edges = null;
  40. /**
  41. * Variable: ids
  42. *
  43. * The object identities of the wrapped cells
  44. */
  45. mxGraphHierarchyEdge.prototype.ids = null;
  46. /**
  47. * Variable: source
  48. *
  49. * The node this edge is sourced at
  50. */
  51. mxGraphHierarchyEdge.prototype.source = null;
  52. /**
  53. * Variable: target
  54. *
  55. * The node this edge targets
  56. */
  57. mxGraphHierarchyEdge.prototype.target = null;
  58. /**
  59. * Variable: isReversed
  60. *
  61. * Whether or not the direction of this edge has been reversed
  62. * internally to create a DAG for the hierarchical layout
  63. */
  64. mxGraphHierarchyEdge.prototype.isReversed = false;
  65. /**
  66. * Function: invert
  67. *
  68. * Inverts the direction of this internal edge(s)
  69. */
  70. mxGraphHierarchyEdge.prototype.invert = function(layer)
  71. {
  72. var temp = this.source;
  73. this.source = this.target;
  74. this.target = temp;
  75. this.isReversed = !this.isReversed;
  76. };
  77. /**
  78. * Function: getNextLayerConnectedCells
  79. *
  80. * Returns the cells this cell connects to on the next layer up
  81. */
  82. mxGraphHierarchyEdge.prototype.getNextLayerConnectedCells = function(layer)
  83. {
  84. if (this.nextLayerConnectedCells == null)
  85. {
  86. this.nextLayerConnectedCells = [];
  87. for (var i = 0; i < this.temp.length; i++)
  88. {
  89. this.nextLayerConnectedCells[i] = [];
  90. if (i == this.temp.length - 1)
  91. {
  92. this.nextLayerConnectedCells[i].push(this.source);
  93. }
  94. else
  95. {
  96. this.nextLayerConnectedCells[i].push(this);
  97. }
  98. }
  99. }
  100. return this.nextLayerConnectedCells[layer - this.minRank - 1];
  101. };
  102. /**
  103. * Function: getPreviousLayerConnectedCells
  104. *
  105. * Returns the cells this cell connects to on the next layer down
  106. */
  107. mxGraphHierarchyEdge.prototype.getPreviousLayerConnectedCells = function(layer)
  108. {
  109. if (this.previousLayerConnectedCells == null)
  110. {
  111. this.previousLayerConnectedCells = [];
  112. for (var i = 0; i < this.temp.length; i++)
  113. {
  114. this.previousLayerConnectedCells[i] = [];
  115. if (i == 0)
  116. {
  117. this.previousLayerConnectedCells[i].push(this.target);
  118. }
  119. else
  120. {
  121. this.previousLayerConnectedCells[i].push(this);
  122. }
  123. }
  124. }
  125. return this.previousLayerConnectedCells[layer - this.minRank - 1];
  126. };
  127. /**
  128. * Function: isEdge
  129. *
  130. * Returns true.
  131. */
  132. mxGraphHierarchyEdge.prototype.isEdge = function()
  133. {
  134. return true;
  135. };
  136. /**
  137. * Function: getGeneralPurposeVariable
  138. *
  139. * Gets the value of temp for the specified layer
  140. */
  141. mxGraphHierarchyEdge.prototype.getGeneralPurposeVariable = function(layer)
  142. {
  143. return this.temp[layer - this.minRank - 1];
  144. };
  145. /**
  146. * Function: setGeneralPurposeVariable
  147. *
  148. * Set the value of temp for the specified layer
  149. */
  150. mxGraphHierarchyEdge.prototype.setGeneralPurposeVariable = function(layer, value)
  151. {
  152. this.temp[layer - this.minRank - 1] = value;
  153. };
  154. /**
  155. * Function: getCoreCell
  156. *
  157. * Gets the first core edge associated with this wrapper
  158. */
  159. mxGraphHierarchyEdge.prototype.getCoreCell = function()
  160. {
  161. if (this.edges != null && this.edges.length > 0)
  162. {
  163. return this.edges[0];
  164. }
  165. return null;
  166. };