Class GenericPopGraph<T,N extends Network>

Type Parameters:
T - the type for storing the color data
N - the type of the network representation, 2D or 3D
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.Zoomer, AbstractGraph.Zooming, Network.LayoutListener, ContextMenu.Listener, ContextMenu.Provider, Tooltip.Provider
Direct Known Subclasses:
PopGraph2D, PopGraph3D

public abstract class GenericPopGraph<T,N extends Network> extends AbstractGraph<T[]> implements Network.LayoutListener, AbstractGraph.Zooming, DoubleClickHandler
The base class for population graphs. This class provides the basic functionality for drawing population structures, e.g. lattices or networks. The class is abstract and must be subclassed to provide the actual drawing functionality, including:
  • (dynamical) layouting of the population structure
  • coloring of nodes according to their traits or fitness
  • handling of mouse events
The class is designed to be used in conjunction with a controller that provides additional functionality, e.g. the ability to change the strategy of a node or to display additional information.
Author:
Christoph Hauert
See Also:
  • Field Details

    • geometry

      protected Geometry geometry
      The structure of the population.
    • network

      protected N extends Network network
      The network representation of the population structure or null if not applicable.
    • data

      protected T[] data
      The array to store the data for drawing the population structure.
    • MAX_ANIMATE_LAYOUT_VERTICES_DEFAULT

      static final int MAX_ANIMATE_LAYOUT_VERTICES_DEFAULT
      Maximum number of nodes in network for animated layout.
      See Also:
    • animate

      protected boolean animate
      The mode of the animation of the network layouting process.
    • noGraph

      boolean noGraph
      The flag to indicate whether the graph needs to be drawn.
      See Also:
    • invalidated

      boolean invalidated
      The flag to indicate whether the graph has been invalidated and needs to be redrawn.
    • colorMap

      protected ColorMap<T> colorMap
      The map for translating discrete traits into colors.
    • label

      protected Label label
      The label of the graph.
    • FINDNODEAT_OUT_OF_BOUNDS

      static final int FINDNODEAT_OUT_OF_BOUNDS
      Return value if findNodeAt(int, int) couldn't find a node at the mouse position.
      See Also:
    • FINDNODEAT_UNIMPLEMENTED

      static final int FINDNODEAT_UNIMPLEMENTED
      Return value if findNodeAt(int, int) isn't implemented for the particular backing geometry.
      See Also:
    • hitNode

      protected int hitNode
      The index of the node that was hit by the mouse or a tap.
    • animateMenu

      private ContextMenuCheckBoxItem animateMenu
      The context menu item for animating the layouting process.
    • shakeMenu

      private ContextMenuItem shakeMenu
      The context menu item for rearranging networks through random shifts of node positions.
    • clearMenu

      private ContextMenuItem clearMenu
      The context menu item to clear the canvas. Only active for linear graphs to clear the history.
    • debugSubmenu

      private ContextMenu debugSubmenu
      The context menu for visually exploring (or debugging) the updating process.
    • debugNodeMenu

      private ContextMenuItem debugNodeMenu
      The context menu item for updating the current node.
    • debugSubmenuTrigger

      private ContextMenuItem debugSubmenuTrigger
      The context menu item for attaching the debug submenu.
    • isDebugEnabled

      private boolean isDebugEnabled
      The flag to indicate whether the debug submenu is activated. For example, debugging does not make sense if the nodes refer to states of PDE calculations.
  • Constructor Details

    • GenericPopGraph

      public GenericPopGraph(GenericPopGraph.PopGraphController controller, Module module)
      Create the base class for population graphs.
      Parameters:
      controller - the controller of this graph
      module - the module backing the graph
  • Method Details

    • 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 AbstractGraph<T[]>
      See Also:
    • onResize

      public void onResize()
      Specified by:
      onResize in interface RequiresResize
      Overrides:
      onResize in class AbstractGraph<T[]>
    • setGraphLabel

      public void setGraphLabel(String msg)
      Set the graph label to the string msg (no HTML formatting).
      Parameters:
      msg - the text for the label of the graph
    • setGeometry

      public void setGeometry(Geometry geometry)
      Set the geometry backing the graph.
      Parameters:
      geometry - the structure of the population
    • getGeometry

      public Geometry getGeometry()
      Get the geometry backing the graph.
      Returns:
      the structure of the population
    • setColorMap

      public void setColorMap(ColorMap<T> colorMap)
      Set the map for translating trait values into colors.
      Parameters:
      colorMap - the trait-to-colour map
    • getColorMap

      public ColorMap<T> getColorMap()
      Get the map for translating trait values into colors.
      Returns:
      the trait-to-colour map
    • getData

      public T[] getData()
      Get the color data for all nodes as an array.
      Returns:
      the array of node colors
    • getNetwork

      public N getNetwork()
      Get the network representation of the graph represented by the geometry.
      Returns:
      the 2D network representation of this graph
    • hasMessage

      public boolean hasMessage()
      Description copied from class: AbstractGraph
      Check if the graph displays a message.
      Overrides:
      hasMessage in class AbstractGraph<T[]>
      Returns:
      true if message displayed
    • reset

      public void reset()
      Description copied from class: AbstractGraph
      Reset the graph. Clear canvas and messages.
      Overrides:
      reset in class AbstractGraph<T[]>
    • update

      public void update(boolean isNext)
      Update the graph.
      Parameters:
      isNext - true if the state has changed
    • paint

      public boolean paint(boolean force)
      Description copied from class: AbstractGraph
      Draw the graph. For re-drawing the graph, set force to true.
      Overrides:
      paint in class AbstractGraph<T[]>
      Parameters:
      force - true to force re-drawing of graph
      Returns:
      true if painting skipped
    • hasStaticLayout

      boolean hasStaticLayout()
      Check whether the layout of the graph is static, i.e. a lattice or lattice hierarchy.
      Returns:
      true if the layout is static
    • hasAnimatedLayout

      boolean hasAnimatedLayout()
      Check whether the layout of the graph is animated.
      Returns:
      true if the layout is animated
    • invalidate

      public void invalidate()
      Invalidate the network. This forces networks to be regenerated.
    • layoutUpdate

      public void layoutUpdate(double progress)
      Description copied from interface: Network.LayoutListener
      Requests an incremental update of the current layout.
      Specified by:
      layoutUpdate in interface Network.LayoutListener
      Parameters:
      progress - the current progress
      See Also:
    • layoutComplete

      public void layoutComplete()
      Description copied from interface: Network.LayoutListener
      Notification that the layouting process has completed. This get called if the desired accuracy has been achieved or if the maximum computational time for the layouting process has been reached.
      Specified by:
      layoutComplete in interface Network.LayoutListener
      See Also:
    • drawLattice

      protected abstract void drawLattice()
      Draws structures with static layout of lattices.
      See Also:
    • layoutNetwork

      protected void layoutNetwork()
      Draws structures with resulting from dynamic layouting of network.
      See Also:
    • drawNetwork

      protected abstract void drawNetwork()
      Draws the network.
    • getTooltipAt

      public String getTooltipAt(int x, int y)
      Description copied from interface: Tooltip.Provider
      Get the tooltip information for the location with coordinates (x, y). The returned string may include HTML elements for formatting.
      Specified by:
      getTooltipAt in interface Tooltip.Provider
      Parameters:
      x - the x-coordinate for the tooltip
      y - the y-coordinate for the tooltip
      Returns:
      the (formatted) string with the tooltip info
    • getCSSColorAt

      public abstract String getCSSColorAt(int node)
      Get the color of the node at index node as a CSS color string.
      Parameters:
      node - the index of the node
      Returns:
      the color of the node
    • findNodeAt

      public abstract int findNodeAt(int x, int y)
      Find the index of the node at the location with coordinates (x, y).
      Parameters:
      x - the x-coordinate of the location
      y - the y-coordinate of the location
      Returns:
      the index of the node
    • onDoubleClick

      public void onDoubleClick(DoubleClickEvent event)
      Specified by:
      onDoubleClick in interface DoubleClickHandler
    • onTouchStart

      public void onTouchStart(TouchStartEvent event)

      The graph reacts to different kinds of touches: short touches or taps (&lt;250 msec) and long touches (&gt;250 msec). Long touches trigger different actions depending on the number of fingers:

      Single finger
      Initiate shifting the view
      Two fingers
      Initiate pinching zoom.

      The graph reacts to different kinds of touches:

      short touch with two fingers (&lt;250 msec)
      display context menu.
      single long touch (&gt;250 msec) on a node
      display the tooltip.
      long touch with two fingers (&gt;250 msec)
      initiates pinching zoom.
      double tap on a node
      change the strategy of the node, if applicable.
      Specified by:
      onTouchStart in interface TouchStartHandler
      Overrides:
      onTouchStart in class AbstractGraph<T[]>
      See Also:
    • setDebugEnabled

      public void setDebugEnabled(boolean enabled)
      Set whether the debugging menu is enabled.
      Parameters:
      enabled - true to enable debugging
    • populateContextMenuAt

      public void populateContextMenuAt(ContextMenu menu, int x, int y)
      Description copied from class: AbstractGraph
      Populate context menu menu in listening widget at (relative) position (x,y).

      Adds buffer size menu and queries the controller to add further functionality.

      Specified by:
      populateContextMenuAt in interface ContextMenu.Provider
      Overrides:
      populateContextMenuAt in class AbstractGraph<T[]>
      Parameters:
      menu - context menu entries are added here
      x - horizontal coordinate (relative to listening widget)
      y - horizontal coordinate (relative to listening widget)
      See Also: