Class PopGraph2D

All Implemented Interfaces:
DoubleClickHandler, HasAllDragAndDropHandlers, HasAllFocusHandlers, HasAllGestureHandlers, HasAllKeyHandlers, HasAllMouseHandlers, HasAllTouchHandlers, HasBlurHandlers, HasClickHandlers, HasContextMenuHandlers, HasDoubleClickHandlers, HasDragEndHandlers, HasDragEnterHandlers, HasDragHandlers, HasDragLeaveHandlers, HasDragOverHandlers, HasDragStartHandlers, HasDropHandlers, HasFocusHandlers, HasGestureChangeHandlers, HasGestureEndHandlers, HasGestureStartHandlers, HasKeyDownHandlers, HasKeyPressHandlers, HasKeyUpHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseUpHandlers, HasMouseWheelHandlers, HasTouchCancelHandlers, HasTouchEndHandlers, HasTouchMoveHandlers, HasTouchStartHandlers, MouseDownHandler, MouseMoveHandler, MouseOutHandler, MouseUpHandler, MouseWheelHandler, TouchEndHandler, TouchMoveHandler, TouchStartHandler, HasAttachHandlers, EventHandler, HasHandlers, EventListener, AcceptsOneWidget, Focusable, HasFocus, HasOneWidget, HasVisibility, HasWidgets, HasWidgets.ForIsWidget, IsWidget, RequiresResize, SourcesClickEvents, SourcesFocusEvents, SourcesKeyboardEvents, SourcesMouseEvents, SourcesMouseWheelEvents, Iterable<Widget>, AbstractGraph.Shifter, AbstractGraph.Shifting, AbstractGraph.Zoomer, AbstractGraph.Zooming, Network.LayoutListener, ContextMenu.Listener, ContextMenu.Provider, Tooltip.Provider

public class PopGraph2D extends GenericPopGraph<String,Network2D> implements AbstractGraph.Shifting
The graphical representation of network structures in 2D. The graph is capable of displaying various types of lattices, networks, and hierarchical structures. The graph is also capable of displaying the history of a linear network.

The graph is interactive and allows the user to zoom and shift the view as well as customize the placement of nodes. The user can change the state of nodes by by double-clicking on them. The graph can be exported in PNG or SVG graphics formats.

Author:
Christoph Hauert
  • Field Details

    • MAX_LINEAR_SIZE

      public static final int MAX_LINEAR_SIZE
      The maximum size of a linear graph. This affects memory allocation to retain the history of the graph.
      See Also:
    • side

      protected int side
      The size of the graph for lattices.
    • dw

      protected int dw
      The width of a node for lattices.
    • dw2

      protected int dw2
      Convenience variable. One half of the width of a node for lattices, dw/2.
    • dh

      protected int dh
      The height of a node for lattices.
    • dh3

      protected int dh3
      Convenience variable. One third of the height of a node for lattices, dh/3.
    • dR

      protected int dR
      The diameter of nodes for networks.
    • MIN_DW

      static final int MIN_DW
      The minimum width of a node in pixels.
      See Also:
    • MIN_DH

      static final int MIN_DH
      The minimum height of a node in pixels.
      See Also:
    • MIN_DR

      static final int MIN_DR
      The minimum diameter of a node in pixels.
      See Also:
    • isHierarchy

      boolean isHierarchy
      Convenience variable. The flag indicating whether the backing geometry is a hierarchical structure.
    • hLevels

      int hLevels
      Convenience variable. The number of hierarchical levels.
    • hPeriods

      int[] hPeriods
      Convenience variable. The number of units in each hierarchical level.
    • HIERARCHY_GAP

      static final int HIERARCHY_GAP
      Convenience variable. The gap between subsequent units in hierarchical structures.
      See Also:
    • hitDragged

      protected boolean hitDragged
      The flag to indicate whether GenericPopGraph.hitNode is being dragged.
  • Constructor Details

    • PopGraph2D

      public PopGraph2D(GenericPopGraph.PopGraphController controller, Module module)
      Create a graph for graphically visualizing the structure of a network (or population). Allocates the canvas and the label and retrieves the shared tooltip and context menu.

      CSS Style Rules

      .evoludo-PopGraph2D
      the graph element.
      .evoludo-Label2D
      the label element.
      Parameters:
      controller - the controller of this graph
      module - the module backing the graph
  • Method Details

    • setGeometry

      public void setGeometry(Geometry geometry)
      Description copied from class: GenericPopGraph
      Set the geometry backing the graph.
      Overrides:
      setGeometry in class GenericPopGraph<String,Network2D>
      Parameters:
      geometry - the structure of the population
    • activate

      public void activate()
      Description copied from class: AbstractGraph
      Perform necessary preparations to show the graph in the GUI. Attaches mouse and touch handlers for graphs that implement AbstractGraph.Zooming or AbstractGraph.Shifting interfaces.
      Overrides:
      activate in class GenericPopGraph<String,Network2D>
      See Also:
    • update

      public void update(boolean isNext)
      Update the graph.
      Overrides:
      update in class GenericPopGraph<String,Network2D>
      Parameters:
      isNext - true if the state has changed
    • paint

      public boolean paint(boolean force)
      Draw the graph. For re-drawing the graph, set force to true.

      Depending on the backing geometry this either

      1. shows a message, if no graphical representation is available, e.g. for 3D cubic lattices, or if there are too many nodes so that each node becomes to small to display on screen.
      2. shows lattice geometries.
      3. initiates the generic layouting process for arbitrary network structures.
      Overrides:
      paint in class GenericPopGraph<String,Network2D>
      Parameters:
      force - true to force re-drawing of graph
      Returns:
      true if painting skipped
      See Also:
    • drawLattice

      protected void drawLattice()
      Description copied from class: GenericPopGraph
      Draws structures with static layout of lattices.
      Specified by:
      drawLattice in class GenericPopGraph<String,Network2D>
      See Also:
    • drawNetwork

      protected void drawNetwork()
      Description copied from class: GenericPopGraph
      Draws the network.
      Specified by:
      drawNetwork in class GenericPopGraph<String,Network2D>
    • prepCanvas

      private boolean prepCanvas()
      Helper method to get the canvas ready for drawing the graph.
      Returns:
      true if the canvas is ready for drawing
    • calcBounds

      public void calcBounds(int width, int height)
      Description copied from class: AbstractGraph
      Calculate bounds of drawing area.
      Overrides:
      calcBounds in class AbstractGraph<String[]>
      Parameters:
      width - the width of the drawing area
      height - the height of the drawing area
    • getCSSColorAt

      public String getCSSColorAt(int node)
      Get the color of the node at index node as a CSS color string.
      Specified by:
      getCSSColorAt in class GenericPopGraph<String,Network2D>
      Parameters:
      node - the index of the node
      Returns:
      the color of the node
    • findNodeAt

      public int findNodeAt(int x, int y)
      Find the index of the node at the location with coordinates (x, y).
      Specified by:
      findNodeAt in class GenericPopGraph<String,Network2D>
      Parameters:
      x - the x-coordinate of the location
      y - the y-coordinate of the location
      Returns:
      the index of the node
    • onMouseDown

      public void onMouseDown(MouseDownEvent event)

      If a node has been hit by a left-click, remember the node's index and the current mouse coordinates. This information might be used by subsequent MouseMoveEvents.

      If a node has been hit by a left-click, remember the node's index and the current mouse coordinates. This information might be used by subsequent MouseMoveEvents.

      CSS Style Rules

      .evoludo-cursorGrabNode
      added to graph element.
      Specified by:
      onMouseDown in interface MouseDownHandler
      Overrides:
      onMouseDown in class AbstractGraph<String[]>
      See Also:
    • onMouseUp

      public void onMouseUp(MouseUpEvent event)

      Cancel all interactions with the graph and reset node and mouse information.

      CSS Style Rules

      .evoludo-cursorMoveView
      removed from graph element.
      .evoludo-cursorGrabNode
      removed from graph element.
      .evoludo-cursorMoveNode
      removed from graph element.
      Specified by:
      onMouseUp in interface MouseUpHandler
      Overrides:
      onMouseUp in class AbstractGraph<String[]>
      See Also:
    • onMouseMove

      public void onMouseMove(MouseMoveEvent event)

      If the left mouse-key is pressed the graph is shifted within its viewport. Note this requires that the zoom level of the graph exceeds 1.

      CSS Style Rules

      .evoludo-cursorMoveView
      added to graph element when shifting the view.

      If a node has been hit by a MouseDownEvent and is being dragged, the position of the node is shifted. This allows to customize the display of the graph.

      CSS Style Rules

      .evoludo-cursorMoveNode
      added to graph element when dragging a node.
      Specified by:
      onMouseMove in interface MouseMoveHandler
      Overrides:
      onMouseMove in class AbstractGraph<String[]>
      See Also:
    • onTouchEnd

      public void onTouchEnd(TouchEndEvent event)

      The number of touches on the graph changed.

      The number of touches on the graph changed.

      Specified by:
      onTouchEnd in interface TouchEndHandler
      Overrides:
      onTouchEnd in class AbstractGraph<String[]>
    • onTouchMove

      public void onTouchMove(TouchMoveEvent event)

      The graph reacts to different kinds of touch moves:

      Move one finger
      Shift view
      Pinch two fingers
      Zoom view
      move one finger on node
      shift node.
      Specified by:
      onTouchMove in interface TouchMoveHandler
      Overrides:
      onTouchMove in class AbstractGraph<String[]>
    • shiftNodeBy

      public void shiftNodeBy(int nodeidx, int dx, int dy)
      Shift a single node with index nodeidx by (dx, dy). Positive dx shift the node to the right and positive dy shift upwards.
      Parameters:
      nodeidx - the index of the node
      dx - the horizontal shift of the node
      dy - the vertical shift of the node
    • export

      public void export(AbstractGraph.MyContext2d ctx)
      Description copied from class: AbstractGraph
      Export the graphical context ctx.
      Specified by:
      export in class AbstractGraph<String[]>
      Parameters:
      ctx - the graphical context to export