Class Distribution

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

public class Distribution extends AbstractView<PopGraph2D> implements TooltipProvider.Index
View component that renders the distribution of continuous traits for one or more species in the EvoLudo simulation. This view produces either a 1D histogram (for a single trait) with temporal history represented as stacked rows, or a 2D density plot (phase plane) for pairs of traits. The view is intended to be used with continuous models only and expects the simulation model to provide trait ranges and histogram data. For more than two traits the context menu allows to select the traits shown along the horizontal and vertical axes.

Responsibilities

  • Create and manage one PopGraph2D per species module returned by the engine.
  • Allocate and maintain a shared bin storage array sized to the current geometry (nBins for 1D, nBins * nBins for 2D).
  • Configure graph appearance (axis labels, ranges, ticks, color map) based on the underlying Continuous module trait metadata.
  • Request 1D/2D trait histogram data from the CModel implementation and translate those values into the graph data using the graph's color map.
  • Provide tooltips for histogram bins and a contextual menu to select which traits to display on the X/Y axes (the latter only for multi-trait modules).

Behavioral notes

  • The number of bins per axis is configurable from the context menu (100/200/500), with DEFAULT_BINS (100) as the initial value. For single-trait modules a LINEAR geometry of size nBins is used (with history rows), for multi-trait modules a square lattice with nBins * nBins bins is used.
  • The shared bins array is reallocated when the geometry size changes.
  • When initializing or resetting, the view updates axis ranges from the Continuous module's reported trait min/max; changes to those ranges trigger a hard reset of the corresponding PopGraph2D.
  • The view currently only supports Data.TRAIT type; calls with other Data types throw UnsupportedOperationException.
  • The tooltip content formats trait interval(s), frequency, and (for 1D histograms) the associated time slice.
  • Trait selection via the context menu is available when the module exposes three or more traits; submenus allow choosing the trait displayed on each axis. Selecting an axis trait triggers a hard reset to rebuild geometries and redraw.
  • Export formats supported by this view are SVG and PNG.

Collaborators

  • EvoLudoGWT engine — provides modules, configuration, and model time/updates.
  • PopGraph2D — per-species graph widget used to render histogram/heatmap data.
  • CModel — queried for 1D/2D trait histogram data.
  • Continuous — module type that exposes trait names and min/max ranges.
  • AbstractGeometry — describes graph layout (LINEAR or SQUARE) and required storage size.

Notes

Histogram data are copied into the shared bins buffer and immediately applied to the graph's data arrays. This avoids repeated allocations but means that graphs cannot retain history independently.
Author:
Christoph Hauert
  • Field Details

    • DEFAULT_BINS

      protected static final int DEFAULT_BINS
      Default number of bins per trait axis for histograms.
      See Also:
    • BIN_OPTIONS

      private static final int[] BIN_OPTIONS
      Available bin counts per axis.
    • INVALID_FREQUENCY

      private static final double INVALID_FREQUENCY
      Sentinel for unavailable frequency values.
      See Also:
    • nBins

      private int nBins
      Active number of bins per axis.
    • bins

      double[] bins
      The storage to accommodate the trait histograms.
    • legendMax

      private double[] legendMax
      Per-module maxima for the histogram color legend.
    • traitXIdx

      int traitXIdx
      The index of the trait to be shown along the x-axis.
    • traitYIdx

      int traitYIdx
      The index of the trait to be shown along the y-axis.
  • Constructor Details

    • Distribution

      public Distribution(EvoLudoGWT engine, Data type)
      Construct a new view to display the distribution of continuous traits of the current EvoLudo model.
      Parameters:
      engine - the pacemaker for running the model
      type - the type of data to display
  • 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<PopGraph2D>
      Returns:
      the name of this view
    • getBufferMenuCapacities

      public int[] getBufferMenuCapacities()
      Description copied from class: AbstractView
      Return capacities offered in the synchronized buffer-size menu.
      Overrides:
      getBufferMenuCapacities in class AbstractView<PopGraph2D>
      Returns:
      capacities in entries
    • 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<PopGraph2D>
      Returns:
      true if graphs were (re)allocated
      See Also:
    • reset

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

      private void resetTrait(PopGraph2D graph, boolean hard)
      Reset the given graph for displaying trait distributions.
      Parameters:
      graph - the graph to reset
      hard - the flag to indicate whether to force 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<PopGraph2D>
    • updateData

      protected void updateData(boolean force)
      Description copied from class: AbstractView
      Update view-specific data even when GUI rendering is throttled.
      Overrides:
      updateData in class AbstractView<PopGraph2D>
      Parameters:
      force - whether the update was explicitly forced
    • 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<PopGraph2D>
      Parameters:
      force - true to force the update
    • afterResize

      protected void afterResize()
      Description copied from class: AbstractView
      Hook for resize work that needs to happen after the graphs are resized but before the view is repainted.
      Overrides:
      afterResize in class AbstractView<PopGraph2D>
    • createGeometry

      private AbstractGeometry createGeometry(int nTraits)
      Create a geometry for the given number of traits. Utility method to generate a linear geometry (with history) for a single trait and a 2D square lattice for multiple traits.
      Parameters:
      nTraits - the number of traits
      Returns:
      the geometry
    • getTooltipAt

      public String getTooltipAt(AbstractGraph<?> graph, int node)
      Description copied from interface: TooltipProvider.Index
      Get the tooltip for the location with index index.
      Specified by:
      getTooltipAt in interface TooltipProvider.Index
      Parameters:
      graph - the graph requesting the tooltip
      node - the index of the location
      Returns:
      the tooltip for the node
      See Also:
    • 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<PopGraph2D>
      Parameters:
      menu - the context menu
    • getLegendMax

      public double getLegendMax(int moduleId)
      Get the maximum histogram frequency for the legend of the module with index moduleId.
      Parameters:
      moduleId - the module identifier
      Returns:
      the current histogram maximum or 0.0
    • addBinsMenu

      private void addBinsMenu(ContextMenu menu)
      Add binning controls to the context menu.
      Parameters:
      menu - the context menu to populate
    • applyBinsPerAxis

      private void applyBinsPerAxis(int newBins)
      Apply a new number of bins per axis and preserve existing rendered data.
      Parameters:
      newBins - the new number of bins per axis
    • 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<PopGraph2D>
      Returns:
      the list of viable export types