Class Phase2D

All Implemented Interfaces:
HasAttachHandlers, HasHandlers, EventListener, HasVisibility, IsRenderable, IsWidget, ProvidesResize, RequiresResize, ChangeListener, LifecycleListener, RunListener, SampleListener

public class Phase2D extends AbstractView<ParaGraph>
Phase2D is a view that renders the model's mean trait trajectory in a two‑dimensional phase plane. It wraps a single ParaGraph instance to display a continuous trajectory over time and provides interactive controls to configure which traits appear on the horizontal (X) and vertical (Y) axes.

Responsibilities

  • Obtain the current model state (mean traits) and forward it to the ParaGraph for plotting as a time‑stamped trajectory point.
  • Manage a Data2Phase mapping object that transforms the model's state vector into X/Y coordinates (the map may be supplied by the module or created by the graph and propagated back to the module).
  • Configure graph appearance (axis labels, percent/density formatting, colors, markers) according to module and model settings (e.g., density vs. frequency).
  • Provide a context menu for selecting which trait(s) are summed into each axis, including support for multi‑trait axes, species headers for multispecies modules, and handling of "vacant" trait indices or reduced entries for density models.
  • Support export of visualizations and trajectory data (SVG, PNG and CSV trajectories).
  • Handle initialization and reset semantics for both continuous and discrete models (forwarding initial trait values to the underlying module where required).

Key behavioral notes

  • Only a single ParaGraph is allocated and used by this view; the protected graph field is a convenient reference to that single graph.
  • When reset(boolean) is called the view ensures the ParaGraph receives: markers from the module, the chosen Data2Phase map, axis labels and percent/density flags, and the configured trajectory color. A hard reset will clear the graph.
  • The Data2Phase map determines which trait indices contribute to each axis and whether axes are fixed. If the map does not provide axis labels, the view synthesizes labels from trait names (and species names when appropriate).
  • Trait labeling logic handles multispecies modules by prepending species names where useful, and by collapsing or omitting names in the common cases of single trait species or species with a trait + vacant index pair.
  • Context menu construction skips trait selection when axes are fixed. For configurable axes it computes the compact list of menu entries (accounting for density models that omit vacant indices), optionally inserts disabled species header items, and builds checkbox items representing each selectable trait. Selection state is synchronized back to the Data2Phase map.
  • Trait toggling is implemented by an inner TraitCommand which updates the map's trait lists (adding, replacing, or removing indices as appropriate), enforces at least one selected trait per axis, and updates the menu checked states.
  • update(boolean) only adds a new point to the ParaGraph when the model's update counter has changed; it forwards the current mean traits and repaints the graph.
  • setInitialState(double[]) forwards initial trait values to the module for discrete models; when successful it triggers model initialization through the engine.

Integration notes

  • The view interacts with an EvoLudoGWT engine to obtain the current Module and the associated model (for retrieving mean traits, update counts and settings).
  • The module may be multi‑species; the view queries the module for species modules, trait counts, trait names and vacant indices to construct menus and labels.
  • The ParaGraph and Data2Phase types are central collaborators: the graph is the visual component that draws trajectories and axes, while the map encapsulates projection and axis configuration logic.

Export support

The view advertises three export types: SVG, PNG and CSV of the trajectory data.

Usage

Place the view into the application's UI container; call reset(hard) after model or module changes to synchronize graph settings, and rely on the engine's pacemaker to drive periodic update calls to append trajectory points.
Author:
Christoph Hauert
See Also:
  • Field Details

    • graph

      protected ParaGraph graph
      The graph that displays the trajectory in a 2D phase plane.
      Implementation Notes:
      ParaGraph graph is a short-cut to graphs.get(0) as long as only a single graph is acceptable.
    • state

      protected double[] state
      The current state of the model.
    • map

      protected HasPhase2D.Data2Phase map
      The map that transforms the current state of the model to a point on the 2D phase plane.
    • traitXItems

      private ContextMenuCheckBoxItem[] traitXItems
      The context menu for selecting traits to display on the horizontal axis.
    • traitYItems

      private ContextMenuCheckBoxItem[] traitYItems
      The context menu for selecting traits to display on the vertical axis.
    • traitXMenu

      private ContextMenu traitXMenu
      The context menu trigger for selecting traits to display on the horizontal axis.
    • traitYMenu

      private ContextMenu traitYMenu
      The context menu trigger for selecting traits to display on the vertical axis.
  • Constructor Details

    • Phase2D

      public Phase2D(EvoLudoGWT engine)
      Construct a new view to display the time series data of the current EvoLudo model as a trajectory in a 2D phase plane.
      Parameters:
      engine - the pacemaker for running the model
  • Method Details

    • getName

      public String getName()
      Description copied from class: AbstractView
      Get the name of this view. This is used to dynamically build the view selector.
      Specified by:
      getName in class AbstractView<ParaGraph>
      Returns:
      the name of this view
    • allocateGraphs

      protected boolean allocateGraphs()
      Description copied from class: AbstractView
      Allocate all graphs managed by this view. This is called when loading the view. Once all views are attached to the browser DOM a call to the graph's calcBounds(int, int) is triggered through setBounds(int, int) to properly calculate the layout.
      Specified by:
      allocateGraphs in class AbstractView<ParaGraph>
      Returns:
      true if graphs were (re)allocated
      See Also:
    • unload

      public void unload()
      Description copied from class: AbstractView
      Unload the view. This is called when changing the module or model that implement this view. This is independent of the activation of the view.
      Overrides:
      unload in class AbstractView<ParaGraph>
    • reset

      public void reset(boolean hard)
      Description copied from class: AbstractView
      Called when a module has been reset. All graphs are reset and updated if needed, unless hard is true.
      Overrides:
      reset in class AbstractView<ParaGraph>
      Parameters:
      hard - the flag to indicate whether to do a hard reset
    • modelDidInit

      public void modelDidInit()
      Description copied from interface: RunListener
      Called after the EvoLudo model got re-initialized.
      Specified by:
      modelDidInit in interface RunListener
      Overrides:
      modelDidInit in class AbstractView<ParaGraph>
    • update

      public void update(boolean force)
      Description copied from class: AbstractView
      Called when the view needs updating. This gets called when the selected view changed or new data is available from the model. Views may ignore updating requests unless force is true.
      Specified by:
      update in class AbstractView<ParaGraph>
      Parameters:
      force - true to force the update
    • getXAxisLabel

      private String getXAxisLabel()
      Get the label of the horizontal axis.
      Returns:
      the label of the x-axis
    • getYAxisLabel

      private String getYAxisLabel()
      Get the label of the vertical axis.
      Returns:
      the label of the y-axis
    • getTraitName

      private String getTraitName(int idx)
      Get the name of the trait with index idx. In multi-species modules the species name is prepended and the index refers to traits of all species.
      Parameters:
      idx - the index of the trait
      Returns:
      the name of the trait
    • setInitialState

      public boolean setInitialState(double[] init)
      Description copied from class: AbstractView
      Notifies the controller that the user requested setting a new initial configuration init (optional implementation).
      Overrides:
      setInitialState in class AbstractView<ParaGraph>
      Parameters:
      init - the new initial configuration
      Returns:
      true if the request was honoured
    • populateContextMenu

      public void populateContextMenu(ContextMenu menu)
      Description copied from class: AbstractView
      Opportunity for the controller to add functionality to the context menu (optional implementation).
      Overrides:
      populateContextMenu in class AbstractView<ParaGraph>
      Parameters:
      menu - the context menu
    • buildTraitMenus

      private void buildTraitMenus(ContextMenu parent, List<? extends Module<?>> species, boolean isMultispecies)
      Build or update trait selection sub-menus for the X and Y axes.
      Parameters:
      parent - the parent context menu
      species - the list of species modules
      isMultispecies - whether multiple species are present
    • computeTotalTraits

      private int computeTotalTraits(List<? extends Module<?>> species, boolean isDensity)
      Compute total number of trait entries that will appear in the trait menus.
      Parameters:
      species - the list of species modules
      isDensity - whether the model is a density model
      Returns:
      the total number of trait entries
    • populateTraitItems

      private void populateTraitItems(List<? extends Module<?>> species, boolean isMultispecies)
      Populate the trait menu items and optional species headers.
      Parameters:
      species - the list of species modules
      isMultispecies - whether multiple species are present
    • addDisabledSpeciesName

      private void addDisabledSpeciesName(Module<?> mod, ContextMenu menu)
      Add a disabled menu entry used as species header.
      Parameters:
      mod - the species module
      menu - the context menu to populate
    • exportTypes

      protected AbstractView.ExportType[] exportTypes()
      Description copied from class: AbstractView
      Return the list of export types that are acceptable for _all_ graphs in this view.
      Overrides:
      exportTypes in class AbstractView<ParaGraph>
      Returns:
      the list of viable export types