Class Phase2D
- All Implemented Interfaces:
HasAttachHandlers, HasHandlers, EventListener, HasVisibility, IsRenderable, IsWidget, ProvidesResize, RequiresResize, ChangeListener, LifecycleListener, RunListener, SampleListener
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
ParaGraphfor 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
graphfield is a convenient reference to that single graph. - When
reset(boolean)is called the view ensures the ParaGraph receives: markers from the module, the chosenData2Phasemap, axis labels and percent/density flags, and the configured trajectory color. A hard reset will clear the graph. - The
Data2Phasemap 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
Data2Phasemap. - Trait toggling is implemented by an inner
TraitCommandwhich 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
EvoLudoGWTengine 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; callreset(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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassCommand to toggle the inclusion of a trait on the phase plane axes.Nested classes/interfaces inherited from class AbstractView
AbstractView.ExportCommand, AbstractView.ExportTypeNested classes/interfaces inherited from class UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabledNested classes/interfaces inherited from interface ChangeListener
ChangeListener.PendingAction -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ParaGraphThe graph that displays the trajectory in a 2D phase plane.protected HasPhase2D.Data2PhaseThe map that transforms the current state of the model to a point on the 2D phase plane.protected double[]The current state of the model.private ContextMenuCheckBoxItem[]The context menu for selecting traits to display on the horizontal axis.private ContextMenuThe context menu trigger for selecting traits to display on the horizontal axis.private ContextMenuCheckBoxItem[]The context menu for selecting traits to display on the vertical axis.private ContextMenuThe context menu trigger for selecting traits to display on the vertical axis.Fields inherited from class AbstractView
engine, exportSubmenu, exportSubmenuTrigger, gCols, graphs, gRows, isActive, isLoaded, logger, MIN_MSEC_BETWEEN_UPDATES, model, options, restoreMenu, timestamp, type, updatetime, wrapperFields inherited from class UIObject
DEBUG_ID_PREFIX -
Constructor Summary
ConstructorsConstructorDescriptionPhase2D(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. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddDisabledSpeciesName(Module<?> mod, ContextMenu menu) Add a disabled menu entry used as species header.protected booleanAllocate all graphs managed by this view.private voidbuildTraitMenus(ContextMenu parent, List<? extends Module<?>> species, boolean isMultispecies) Build or update trait selection sub-menus for the X and Y axes.private intcomputeTotalTraits(List<? extends Module<?>> species, boolean isDensity) Compute total number of trait entries that will appear in the trait menus.protected AbstractView.ExportType[]Return the list of export types that are acceptable for _all_ graphs in this view.getName()Get the name of this view.private StringgetTraitName(int idx) Get the name of the trait with indexidx.private StringGet the label of the horizontal axis.private StringGet the label of the vertical axis.voidCalled after the EvoLudo model got re-initialized.voidOpportunity for the controller to add functionality to the context menu (optional implementation).private voidpopulateTraitItems(List<? extends Module<?>> species, boolean isMultispecies) Populate the trait menu items and optional species headers.voidreset(boolean hard) Called when a module has been reset.booleansetInitialState(double[] init) Notifies the controller that the user requested setting a new initial configurationinit(optional implementation).voidunload()Unload the view.voidupdate(boolean force) Called when the view needs updating.Methods inherited from class AbstractView
activate, deactivate, destroyGraphs, export, export, exportDataHeader, exportMeanData, exportPNG, exportStatData, exportSVG, exportTrajData, getGraphAt, getLogger, getMode, getModel, getStatus, getStatus, getType, hasLayout, isActive, isRunning, layoutComplete, load, modelChanged, modelDidReset, modelStopped, modelUnloaded, moduleRestored, moduleUnloaded, mouseHitNode, mouseHitNode, onKeyDown, onKeyUp, onResize, onUnload, parse, populateContextMenuAt, scheduleUpdate, setBounds, setOptions, shift, update, zoomMethods inherited from class Composite
claimElement, getWidget, initializeClaimedElement, initWidget, isAttached, onAttach, onBrowserEvent, onDetach, render, render, resolvePotentialElement, setWidgetMethods inherited from class Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isOrWasAttached, onLoad, removeFromParent, setLayoutData, sinkEvents, unsinkEventsMethods inherited from class UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface LifecycleListener
modelLoaded, moduleLoadedMethods inherited from interface RunListener
modelRelaxed, modelRunning, modelSettingsMethods inherited from interface SampleListener
modelSample
-
Field Details
-
graph
The graph that displays the trajectory in a 2D phase plane.- Implementation Notes:
ParaGraph graphis a short-cut tographs.get(0)as long as only a single graph is acceptable.
-
state
protected double[] stateThe current state of the model. -
map
The map that transforms the current state of the model to a point on the 2D phase plane. -
traitXItems
The context menu for selecting traits to display on the horizontal axis. -
traitYItems
The context menu for selecting traits to display on the vertical axis. -
traitXMenu
The context menu trigger for selecting traits to display on the horizontal axis. -
traitYMenu
The context menu trigger for selecting traits to display on the vertical axis.
-
-
Constructor Details
-
Phase2D
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
Description copied from class:AbstractViewGet the name of this view. This is used to dynamically build the view selector.- Specified by:
getNamein classAbstractView<ParaGraph>- Returns:
- the name of this view
-
allocateGraphs
protected boolean allocateGraphs()Description copied from class:AbstractViewAllocate 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'scalcBounds(int, int)is triggered throughsetBounds(int, int)to properly calculate the layout.- Specified by:
allocateGraphsin classAbstractView<ParaGraph>- Returns:
trueif graphs were (re)allocated- See Also:
-
unload
public void unload()Description copied from class:AbstractViewUnload 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:
unloadin classAbstractView<ParaGraph>
-
reset
public void reset(boolean hard) Description copied from class:AbstractViewCalled when a module has been reset. All graphs are reset and updated if needed, unlesshardistrue.- Overrides:
resetin classAbstractView<ParaGraph>- Parameters:
hard- the flag to indicate whether to do a hard reset
-
modelDidInit
public void modelDidInit()Description copied from interface:RunListenerCalled after the EvoLudo model got re-initialized.- Specified by:
modelDidInitin interfaceRunListener- Overrides:
modelDidInitin classAbstractView<ParaGraph>
-
update
public void update(boolean force) Description copied from class:AbstractViewCalled 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 unlessforceistrue.- Specified by:
updatein classAbstractView<ParaGraph>- Parameters:
force-trueto force the update
-
getXAxisLabel
Get the label of the horizontal axis.- Returns:
- the label of the
x-axis
-
getYAxisLabel
-
getTraitName
Get the name of the trait with indexidx. 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:AbstractViewNotifies the controller that the user requested setting a new initial configurationinit(optional implementation).- Overrides:
setInitialStatein classAbstractView<ParaGraph>- Parameters:
init- the new initial configuration- Returns:
trueif the request was honoured
-
populateContextMenu
Description copied from class:AbstractViewOpportunity for the controller to add functionality to the context menu (optional implementation).- Overrides:
populateContextMenuin classAbstractView<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 menuspecies- the list of species modulesisMultispecies- whether multiple species are present
-
computeTotalTraits
Compute total number of trait entries that will appear in the trait menus.- Parameters:
species- the list of species modulesisDensity- whether the model is a density model- Returns:
- the total number of trait entries
-
populateTraitItems
-
addDisabledSpeciesName
Add a disabled menu entry used as species header.- Parameters:
mod- the species modulemenu- the context menu to populate
-
exportTypes
Description copied from class:AbstractViewReturn the list of export types that are acceptable for _all_ graphs in this view.- Overrides:
exportTypesin classAbstractView<ParaGraph>- Returns:
- the list of viable export types
-