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
Abstract base class for visualizing a population as a graph. GenericPopGraph ties a population AbstractGeometry to an optional Network representation and provides common support for layouting, drawing, interaction and debugging for concrete graph views (2D/3D, lattice or general network).

Key responsibilities:

  • Manage the backing AbstractGeometry and its Network (if present). The network may be null for models without spatial structure (e.g. ODE/SDE).
  • Coordinate layouting: static lattice layouts are drawn directly via drawLattice(); drawNetwork() is used for dynamic/network layouts which calls back via Network.LayoutListener and this class drives the animation and final drawing via layoutNetwork() and drawNetwork().
  • Provide common interaction handling: tooltips, double-clicks, touch gestures (single/double tap, long press, pinch zoom), mouse cursor styling when hovering nodes, and context menu entries (shake, animate layout, clear history, debug submenu).
  • Maintain display state such as labelling, color mapping for node traits, invalidation/refresh logic and flags controlling animated layouting.

Design notes and behavior:

  • The class is generic in the node color/type T and the concrete Network implementation N. Subclasses are responsible for converting node data to CSS color strings and for hit-testing nodes at screen coordinates.
  • Subclasses must implement the rendering and hit-testing contract: drawLattice(), drawNetwork(), getCSSColorAt(int) and findNodeAt(int,int). These methods encapsulate geometry-specific drawing and input logic.
  • Layout updates are coordinated with the Network. For animated layouts the class may repeatedly request redraws during progress updates; for non-animated or very large networks animation can be disabled using the animate flag and size threshold constants.
  • layoutUpdate(double) and layoutComplete() are synchronized and used by the Network to report progress and completion. layoutNetwork() ensures that a layout exists before calling drawNetwork().
  • Touch handling distinguishes single tap, double tap, long press and multi-touch gestures to support node selection, tooltip display, pinching zoom and invoking node-specific actions.
  • Context menu population is centralized here. Implementations add graph-specific menu items but benefit from the common items provided (shake, animate, clear history and debug/update options). The debug submenu is gated by isDebugEnabled and the model type.
  • Invalidation resets the network (if present) and marks the view for redraw; update(boolean isNext) defers layout work using a scheduler to allow dependent views (3D rendering) to become ready.
  • TooltipProvider integration: if the view implements TooltipProvider.Index the class will use it to produce tooltips for nodes; otherwise a fallback basic provider may be used when available.

Important fields and conventions referenced by subclasses:

  • geometry - the population structure (may be null for non-spatial models).
  • network - the Network representation derived from the geometry (may be null).
  • data - array of node trait values used for coloring or other per-node state.
  • colorMap - maps node trait values (T) to display colors.
  • label - optional label displayed on the graph wrapper.
  • animate - flag enabling/disabling animated layout progress.
  • invalidated / noGraph / hasMessage - control redraw and message display behavior.
  • hitNode - index of last node hit by touch/mouse interactions.
  • Return codes for findNodeAt(int,int): FINDNODEAT_OUT_OF_BOUNDS and FINDNODEAT_UNIMPLEMENTED are used to signal special cases.

Extensibility:

Subclasses should concentrate on rendering and input mapping for a specific geometry (e.g. linear history plot, 2D lattice, 3D view). They should:
  1. Populate and maintain the data array and colorMap as needed.
  2. Implement getCSSColorAt(int) to return a valid CSS color string for a node.
  3. Implement drawLattice() for static lattice-based layouts and drawNetwork() for network-based rendering. drawNetwork() is invoked after network layout is finished (or repeatedly during animated layout).
  4. Implement findNodeAt(int,int) to map screen coordinates to node indices and honor the documented special return values.
Author:
Christoph Hauert
See Also:
  • Field Details

    • EVOLUDO_CURSOR_NODE

      public static final String EVOLUDO_CURSOR_NODE
      The CSS class name for changing the cursor when hovering over a node.
      See Also:
    • geometry

      protected AbstractGeometry 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

      protected GenericPopGraph(AbstractView<?> view, Module<?> module)
      Create the base class for population graphs.
      Parameters:
      view - the view of this graph
      module - the module backing the graph
  • Method Details

    • onLoad

      protected void onLoad()
      Overrides:
      onLoad in class AbstractGraph<T[]>
    • onUnload

      protected void onUnload()
      Overrides:
      onUnload in class AbstractGraph<T[]>
    • 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(AbstractGeometry geometry)
      Set the geometry backing the graph.
      Parameters:
      geometry - the structure of the population
    • getGeometry

      public AbstractGeometry 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 view 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:
    • addShakeMenu

      private void addShakeMenu(ContextMenu menu)
      Helper method to process the debug submenu logic for context menu.
      Parameters:
      menu - the context menu to which the shake menu is added
    • addAnimateMenu

      private void addAnimateMenu(ContextMenu menu)
      Helper method to process the debug submenu logic for context menu.
      Parameters:
      menu - the context menu to which the animate menu is added
    • addClearMenu

      private void addClearMenu(ContextMenu menu)
      Helper method to process the clear context menu.
      Parameters:
      menu - the context menu to which the clear menu is added
    • addDebugSubmenu

      private void addDebugSubmenu(ContextMenu menu, int x, int y)
      Helper method to process the debug submenu logic for context menu.
      Parameters:
      menu - the context menu to which the debug submenu is added
      x - the x-coordinate of the mouse when the context menu was invoked
      y - the y-coordinate of the mouse when the context menu was invoked