Class GraphVisualizer

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, GraphConstants, LayoutCompleteEventListener

public class GraphVisualizer extends JPanel implements GraphConstants, LayoutCompleteEventListener
This class displays the graph we want to visualize. It should be sufficient to use only this class in weka.gui.graphvisulizer package to visualize a graph. The description of a graph should be provided as a string argument using readBIF or readDOT method in either XMLBIF03 or DOT format. Alternatively, an InputStream in XMLBIF03 can also be provided to another variation of readBIF. It would be necessary in case input is in DOT format to call the layoutGraph() method to display the graph correctly after the call to readDOT. It is also necessary to do so if readBIF is called and the graph description doesn't have x y positions for nodes.

The graph's data is held in two FastVectors, nodes are stored as objects of GraphNode class and edges as objects of GraphEdge class.

The graph is displayed by positioning and drawing each node according to its x y position and then drawing all the edges coming out of it give by its edges[][] array, the arrow heads are ofcourse marked in the opposite(ie original direction) or both directions if the edge is reversed or is in both directions. The graph is centered if it is smaller than it's display area. The edges are drawn from the bottom of the current node to the top of the node given by edges[][] array in GraphNode class, to avoid edges crossing over other nodes. This might need to be changed if another layout engine is added or the current Hierarchical engine is updated to avoid such crossings over nodes.

$Revision: 15104 $
Ashraf M. Kibriya (
See Also:
  • Constructor Details

    • GraphVisualizer

      public GraphVisualizer()
      Sets up the gui and initializes all the other previously uninitialized variables.
  • Method Details

    • layoutCompleted

      public void layoutCompleted(LayoutCompleteEvent le)
      This method is an implementation for LayoutCompleteEventListener class. It sets the size appropriate for m_gp GraphPanel and and revalidates it's container JScrollPane once a LayoutCompleteEvent is received from the LayoutEngine.
      Specified by:
      layoutCompleted in interface LayoutCompleteEventListener
    • layoutGraph

      public void layoutGraph()
      This method lays out the graph by calling the LayoutEngine's layoutGraph() method. This method should be called to display the graph nicely, unless the input XMLBIF03 already contains some layout information (ie the x,y positions of nodes.
    • readBIF

      public void readBIF(String instring) throws BIFFormatException
      BIF reader
      Reads a graph description in XMLBIF03 from a string
    • readBIF

      public void readBIF(InputStream instream) throws BIFFormatException
      BIF reader
      Reads a graph description in XMLBIF03 from an InputStrem
    • readDOT

      public void readDOT(Reader input)
      Dot reader
      Reads a graph description in DOT format from a string
    • main

      public static void main(String[] args)
      Main method to load a text file with the description of a graph from the command line