2architecture.tex 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. \section{Assumptions}\label{sec:assumptions}
  2. The following assumptions are made for the implementation of the node placement algorithm:
  3. \begin{itemize}
  4. \item There are no hyperedges.
  5. \item There are no port constraints.
  6. \item There are no labels.
  7. \item There are no cross-hierarchy edges.
  8. \item No edges over multiple layers (the previous phases should have added dummy nodes).
  9. \item Graphs are connected (maybe we will get rid of this assumption later, see chapter~\ref{ch:progress}).
  10. \end{itemize}
  11. \section{Overview}\label{sec:components}
  12. The \code{main} package contains an executable class \code{Main}.
  13. This classes main method reads a graph from a file using the \code{graph.io} package and then creates a MainView.
  14. The view then instantiates a \code{BKNodePlacement} algorithm and runs it.
  15. The \code{BKNodePlacement} repeatedly asks the \code{AnimationController} if a step should be done (this is further explained in section~\ref{sec:theActualAlgorithm}).
  16. It uses \code{LayeredGraphNode}s and \code{LayeredGraphEdge}s.
  17. Meanwhile the view displays the same \code{LayeredGraphNode}s and \code{LayeredGraphEdge}s on the screen.
  18. Figure~\ref{fig:components} contains a component diagram that illustrates these dependencies of the packages.
  19. \begin{figure}[htp]
  20. \centering
  21. \includegraphics[width=\linewidth,trim=0 11cm 0 0,clip]{img/components.pdf}
  22. \caption[Component diagram]{Component diagram visualizing the architecture of \appname. Each component resembles a java package.}
  23. \label{fig:components}
  24. \end{figure}
  25. \section{Input File Format}\label{sec:inputFileFormat}
  26. The input to \appname\ is a JSON file.
  27. An example is displayed in figure~\ref{fig:json-example}.
  28. The structure is as follows:
  29. \begin{itemize}
  30. \item The object in the JSON file is a node.
  31. \item A node has the attributes that are displayed in table~\ref{table:node-attributes}.
  32. \item An edge has the attributes that are displayed in table~\ref{table:edge-attributes}.
  33. \item Any additional attributes not listed here are ignored.
  34. For example they can be used as comment fields, to make the file more readable.
  35. \end{itemize}
  36. For parsing the JSON file the JSON-java library~\cite{leary_json-java:_2018} is used.
  37. The classes for reading and writing those JSON files are displayed in figure~\ref{fig:io}.
  38. The internal representation of graphs is further explained in the section~\ref{sec:graph}.
  39. \centering
  40. \begin{longtable}{|l|l|l|p{8.5cm}|}
  41. \hline
  42. Attribute & Type & Optional & Explanation \\\hline\hline
  43. name & string & yes & If not omitted, this must be unique for a given parent node. \\\hline
  44. width & integer & yes & The minimum width of the node.
  45. The node can be wider if it contains other nodes that need more space.
  46. If the whole layout is too large, it is resized, such that all nodes are proportionately shrunk: In that case the minimum width can be exceeded after the shrinking.
  47. Default 40.\\\hline
  48. height & integer & yes & The minimum height of the node.
  49. The node can be higher if it contains other nodes that need more space.
  50. If the whole layout is too large, it is resized, such that all nodes are proportionately shrunk: In that case the minimum height can be exceeded after the shrinking.
  51. Default 40.\\\hline
  52. dummy & boolean & yes & Iff this is explicitly set to true, then the node is a dummy node. \\\hline
  53. layers & < < node > > & yes & The layers of nodes inside this node (Hierarchy). \\\hline
  54. edges & < edge > & yes & The edges between nodes whose parent node is this node. Also see section~\ref{sec:assumptions}. \\\hline
  55. \caption[Node Attributes]{Node Attributes. < \emph{element type} > is a list.}
  56. \label{table:node-attributes}
  57. \end{longtable}
  58. \raggedright
  59. \begin{figure}[htp]
  60. \centering
  61. \includegraphics[width=\linewidth,trim=0 26cm 0 0,clip]{img/io.pdf}
  62. \caption[Class diagram of the \code{graph.io} package]{Class diagram of the \code{graph.io} package, containing utilities for reading and writing graphs.}
  63. \label{fig:io}
  64. \end{figure}
  65. \begin{table}[htp]
  66. \centering
  67. \begin{longtable}{|l|l|l|p{8.5cm}|}
  68. \hline
  69. Attribute & Type & Optional & Explanation \\\hline\hline
  70. source & string & no & The name of the source of this edge.
  71. Must be a node with the same parent node as the node specified by the \code{target} attribute. \\\hline
  72. target & string & no & The name of the target of this edge.
  73. Must be a node with the same parent node as the node specified by the \code{source} attribute. \\\hline
  74. \end{longtable}
  75. \caption{Edge Attributes}
  76. \label{table:edge-attributes}
  77. \end{table}
  78. %\begin{figure}[htp]
  79. % \centering
  80. % \includegraphics[width=0.9\textwidth]{img/json.png}
  81. % \caption[Input file format]{Input file format illustrated as a HERM diagram}
  82. % \label{fig:iff}
  83. %\end{figure}
  84. \begin{figure}
  85. \begin{lstinputlisting}[language=json,emph={}]{src/graph.json}
  86. \end{lstinputlisting}
  87. \caption[Example Input File]{Example Input file that is understood by \appname.}
  88. \label{fig:json-example}
  89. \end{figure}
  90. \section{Internal graph representation, \code{graph}}\label{sec:graph}
  91. One feature that is important to us, is to be able to work with hierarchical graphs (cf.\ chapter~\ref{ch:progress}).
  92. Therefore a node can contain other nodes and edges.
  93. So far this is similar to what we described in section~\ref{sec:inputFileFormat}.
  94. Additionally, there are multiple attributes that are used during the computation or as output variables.
  95. \begin{itemize}
  96. \item The \member{parent} of a node is the node that contains it in the hierarchy.
  97. \item \member{dummy} specifies whether this node is a dummy node.
  98. \item \member{name} is the name of the node.
  99. \item The attributes \member{shift}, \member{sink}, \member{root} and \member{align} correspond to the variables used by Brandes and Köpf~\cite{brandes_fast_2001}.
  100. They are summarized in table~\ref{table:bk-variables}.
  101. \item The attribute \member{xUndef} determines whether the x coordinate of the node has already been assigned a value.
  102. \item The attributes \member{x} and \member{y} are the coordinates of the node relative to its \member{parent}.
  103. \item The attributes \member{w} and \member{h} are the width and height of the node.
  104. \item The attributes \member{color} is the color in which the node is displayed.
  105. \item The attribute \member{selected} is used to highlight the node that is currently active in each layout.
  106. \end{itemize}
  107. The last six bullet points are available separately for each of the four extremal layouts.
  108. The last four bullet points are also separately available for the combined layout.
  109. Similarly, edges have the following attributes in addition to those given through the JSON format:
  110. \begin{itemize}
  111. \item \member{dummyEdge} specifies whether they are edges between two dummy nodes.
  112. \item \member{bindPoints} is a list of bend points for the edge, including the beginning and end point of the edge.
  113. \item \member{reversed} specifies if this edge was reversed earlier (not used by \appname).
  114. \item \member{graph} is the node that contains the edges (hierarchy).
  115. \item \member{conflicted} corresponds to the variable used by Brandes and Köpf~\cite{brandes_fast_2001} and indicates that this edge won't be drawn vertically.
  116. \end{itemize}
  117. The last bullet point is available separately for each of the four extremal layouts and for the combined layout.
  118. A class diagram of the package \code{graph} is displayed in figure~\ref{fig:graph}.
  119. \begin{figure}[htp]
  120. \centering
  121. \includegraphics[width=\linewidth,trim=0 10cm 0 0,clip]{img/graph.pdf}
  122. \caption{Class diagram of the \code{graph} package.}
  123. \label{fig:graph}
  124. \end{figure}
  125. \begin{table}[htp]
  126. \begin{longtable}{|l|p{10cm}|}
  127. \hline
  128. Attribute & Explanation \\\hline\hline
  129. \member{root} & The root node of the block of this node.
  130. Unique for all nodes in the same block. \\\hline
  131. \member{sink} & The topmost sink in the block graph that can be reached from the block that this node belongs to.
  132. Only used for nodes that are the root of a block.
  133. Unique for all nodes in the same class. \\\hline
  134. \member{shift} & The shift of the class that this node belongs to.
  135. Only used for nodes that are a sink of a class. \\\hline
  136. \member{align} & The next node in the same block as this node.
  137. The \member{align} of the last node in the block is the root node of the block again.\\\hline
  138. \end{longtable}
  139. \caption{Variables also used by Brandes and Köpf~\cite{brandes_fast_2001}}
  140. \label{table:bk-variables}
  141. \end{table}
  142. \section{The actual algorithm}\label{sec:theActualAlgorithm}
  143. This section expects the reader to be familiar with the node placement algorithm by Brandes and Köpf~\cite{brandes_fast_2001}.
  144. We recommend section 3.2.1 of Carstens~\cite{carstens_node_2012} for a detailed explanation.
  145. A stage of the algorithm, interface \code{AlgorithmStage}, is an interval during which each step of the algorithm is performed in a similar way.
  146. Each time such a step is performed it returns whether the stage is already finished or a breakpoint has been reached.
  147. For example, a forward step in the stage of calculating one extremal layout, \code{ExtremalLayoutCalc}, consists of either a step of calculating the blocks, \code{BlockCalc}, or a step of compacting the layout, \code{Compaction}.
  148. All the stages are displayed in class diagram~\ref{fig:animation_and_bk}.
  149. To be able to undo a step each stage needs to implement methods for both forward and backward steps.
  150. Note that the \code{AnimationController} is not a controller in the MVC sense that it processes user input, but in the sense that it \emph{controls} the execution of steps/stages.
  151. This works the following:
  152. \begin{enumerate}
  153. \item The \code{MainView} creates a node placement algorithm (only \code{BKNodePlacement} available).
  154. It sends an \code{AnimationController} as a parameter for the constructor.
  155. \item The algorithm concurrently asks the \code{AnimationController} if it should do a forward or backward step and if that is a \enquote{step into}, \enquote{step over} or \enquote{step out}.
  156. \item The \code{AnimationController} waits until it knows which action to take (for example if the user pressed Alt + Right arrow key).
  157. Alternatively, if the animation is not paused, it waits until a specific delay has passed.
  158. Then it returns to the algorithm which step to take next.
  159. \item The algorithm potentially calls one the step methods of other stages while executing one step.
  160. \end{enumerate}
  161. \begin{figure}[htp]
  162. \centering
  163. \includegraphics[width=\linewidth,trim=0 11cm 0 0,clip]{img/animation_and_bk.pdf}
  164. \caption{Class diagram of the packages \code{bk} and \code{animation}.}
  165. \label{fig:animation_and_bk}
  166. \end{figure}
  167. \section{View}\label{sec:view}
  168. This section only covers the software architecture regarding the views.
  169. For an explanation of what is actually displayed, see chapter~\ref{ch:ui}
  170. \begin{itemize}
  171. \item The main window displays a \code{lane} of the class \code{JLayeredPane} and a \code{menue} of the class \code{JPanel}.
  172. The main window itself is a \code{JFrame} from the Swing library.
  173. \item The \code{lane} display the current status of the graph.
  174. \item The \code{menue} display \code{NiceButton}s and pseudocode.
  175. \item \code{EdgeView} and \code{NodeView} are \code{JPanel}s, which means they can be drawn onto the \code{JFrame}.
  176. For this they have to know about which part of the graph and which layout they belong to (some attributes).
  177. \item A \code{NiceButton} is a \code{JButton} that has an image on it.
  178. \item For rendering the pseudocode we use a \code{PseudoCodeRenderer} that is a \code{DefaultTreeCellRenderer}.
  179. For example, it sets line numbers and highlights selected code lines.
  180. \item A \code{RenderHelper} that contains some additional utility functions for the views.
  181. \end{itemize}
  182. A class diagram of the packages \code{view} and \code{main} is displayed in figure~\ref{fig:view}.
  183. \begin{figure}[htp]
  184. \centering
  185. \includegraphics[width=\linewidth,trim=0 19cm 0 0,clip]{img/view.pdf}
  186. \caption{Class diagram of the packages \code{view} and \code{main}.}
  187. \label{fig:view}
  188. \end{figure}