Class Histogram
- All Implemented Interfaces:
HasAttachHandlers, HasHandlers, EventListener, HasVisibility, IsRenderable, IsWidget, ProvidesResize, RequiresResize, ChangeListener, LifecycleListener, RunListener, SampleListener
Histogram view for displaying binned distributions of model quantities.
This class implements a graphical view that manages one or more
HistoGraph
instances to display histograms for different types of data produced by the
simulation model. The view supports a variety of Data types:
TRAIT- histograms of continuous trait distributions (uses CModel APIs)FITNESS- histograms of fitness/payoff values (continuous or discrete)DEGREE- degree distributions of interaction and competition graphsSTATISTICS_FIXATION_PROBABILITY- per-node fixation probability samplesSTATISTICS_FIXATION_TIME- fixation time samples and absorption timesSTATISTICS_STATIONARY- stationary distributions / visit-count histograms
Responsibilities
- Allocate and layout the required number of
HistoGraphpanels for each module and data type, taking into account multi-species modules and module-specific settings (traits, vacant indices, population size, etc.). - Configure default and data-specific
GraphStylesettings (axis labels, normalization, color, autoscaling, custom y-levels). - Manage histogram buffers and binning parameters (bin size, scale factors, max bins) and ensure data arrays are allocated with proper dimensions.
- Periodically update histogram contents by querying the underlying model (e.g., fetching trait/fitness/degree histogram data, mean traits for stationary statistics, fixation sample callbacks).
- Handle special cases such as PDE/DE/ODE/SDE models and well-mixed populations (display messages instead of histograms where appropriate).
- Support context menu actions and export types appropriate for the
chosen
Datatype (SVG/PNG and CSV for statistics).
Lifecycle
- The view is constructed with an
EvoLudoGWTengine and aDatatype indicating which histogram to display. load()registers listeners for statistical sample events when displaying fixation statistics.allocateGraphs()is responsible for creating HistoGraph instances based on the currently configured modules; it avoids unnecessary rebuilds by comparing required and existing graph counts.reset(boolean)recomputes graph-specific configuration (axis ranges, markers, normalization flags) and may force a full repaint when axis limits change. It delegates type-specific reset logic to helper methods (resetTrait, resetFitness, resetDegree, resetFixationProbability, resetFixationTime, resetStationary).update(boolean)pulls fresh histogram data from the model and triggers painting of all graphs. For performance, updates are skipped when the view is inactive for dynamic data.modelSample(boolean)receives fixation-sample callbacks and increments the appropriate histogram bins; it also handles per-sample bookkeeping to avoid double-counting.modelSettings()andmodelDidInit()are used to reapply module-specific settings and to initialize HistoGraph objects after model initialization.
Implementation details
- scale2bins and binSize are used to map model values (counts, densities, or node indices) to histogram bins. Their values depend on the Data type and the population/graph size.
- For stationary and fixation statistics the view chooses a sensible bin
count that honors
HistoGraph.MAX_BINSand per-graph max bin limits. - For degree distributions, the view computes a displayable maximum degree
with maxDegree(int) (rounding up to human-friendly magnitudes) and
limits the resulting bin count to
HistoGraph.MAX_BINS. - Directed graphs create separate histograms for in-degree, out-degree, and total degree. When interaction and competition geometries differ, histograms are created for both structures.
- For PDE/DE model types that are regular or lattice-like the view may display a short explanatory message instead of a histogram.
- The class caches whether degree distributions have been processed and re-computes them only when geometries are dynamic or when not yet processed.
- Frequent status calculations and graph paints are throttled to avoid
excessive CPU usage (see
MIN_MSEC_BETWEEN_UPDATESand timestamp checks).
Fixation statistics
- For
STATISTICS_FIXATION_PROBABILITYthe view accumulates counts per node (possibly binned) and reports normalized probabilities in the y-axis. - For
STATISTICS_FIXATION_TIMEthe view supports two modes:- a per-node fixation time histogram (node index on x-axis and average/weighted time in y), or
- a distribution of fixation times aggregated across nodes (binned times on x-axis).
- A special absorption histogram collects fixation times irrespective of initial node (displayed as an extra graph when applicable).
- The view produces human-readable status strings that summarize average fixation probability and fixation time statistics for display in the UI.
Export and context menu
- Depending on the Data type, export formats include SVG and PNG for all histograms, and CSV (tabular statistical data) for statistical views.
- The context menu includes a Clear action for
STATISTICS_STATIONARYto reset accumulated stationary counts.
- Author:
- Christoph Hauert
- See Also:
-
Nested Class Summary
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 TypeFieldDescription(package private) intThe size of the bins in pixels.private ContextMenuItemThe clear context menu.protected booleanThe flag to indicate whether the properties of the gemetric structure have been processed.protected booleanFlag to indicate whether the model entertains multiple species, i.e.(package private) doubleThe scaling factor to map the data onto bins.protected StringThe status of the view.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
ConstructorsConstructorDescriptionHistogram(EvoLudoGWT engine, Data type) Construct a new view to display the histogram of various quantities. -
Method Summary
Modifier and TypeMethodDescriptionprivate intaddDegreeGraphs(List<? extends Module<?>> species, int nGraphs) Add degree graphs for the given module.private intaddFitnessGraphs(List<? extends Module<?>> species, int nGraphs) Add fitness graphs for the given module.private intaddFixationProbabilityGraphs(List<? extends Module<?>> species, int nGraphs) Add fixation probability graphs for the given module.private intaddFixationTimeGraphs(List<? extends Module<?>> species, int nGraphs) Add fixation time graphs for the given module.private intaddStationaryGraphs(List<? extends Module<?>> species, int nGraphs) Add stationary distribution graphs for the given module.private intaddTraitGraphs(List<? extends Module<?>> species) Add trait histogram for the given module.protected booleanAllocate all graphs managed by this view.private voidapplyDefaultStyle(GraphStyle style) Apply default style settings to the given graph style.private voidapplyDegreeStyle(HistoGraph graph, int n, int nGraphs, int xdeco) Apply style settings for degree histograms.private booleanapplyFitnessStyle(HistoGraph graph, int n, int xdeco) Apply style settings for fitness histograms.private voidapplyFixationProbabilityStyle(HistoGraph graph, int n, int xdeco) Apply style settings for fixation probability histograms.private voidapplyFixationTimeStyle(HistoGraph graph, int n, int xdeco, boolean isDistribution) Apply style settings for fixation time histograms.private voidapplyStationaryStyle(HistoGraph graph, int n, int xdeco) Apply style settings for stationary distribution histograms.private booleanapplyTraitStyle(HistoGraph graph, int n) Apply style settings for trait histograms.private intCount how many graphs are required based on currentDatatype and module settings.private intcreateGraphs(int nGraphs) Create and configure graphs for all species; returns the number of x-label rows that should be considered when computing layout.private booleandoFixtimeDistr(Module<?> module) Helper method to check whether to show the fixation time distribution or the fixation times for each node.private double[][]ensureDegreeData(HistoGraph graph, AbstractGeometry inter, AbstractGeometry comp, double[][] data) Ensure the provided data buffer is sized appropriately for the given interaction/competition geometries, update the histogram data and set axis limits on the graph; returns the (possibly new) data buffer.protected voidExport the statistics data.protected AbstractView.ExportType[]Return the list of export types that are acceptable for _all_ graphs in this view.private StringformatDistributionMean(double[] dist, GraphStyle style) Format mean ± sdev for a distribution stored in data (assumed normalized counts).private StringformatWeightedMean(double[] dat, double[] sam) Compute weighted mean ± sdev from node-wise times (dat) and sample counts (sam).private intgetDegreeBins(AbstractGeometry inter, AbstractGeometry comp) Determine the number of bins required for the degree distributions of the interaction and competition geometries.private intgetDegreeGraphs(AbstractGeometry inter, AbstractGeometry comp) Determine the number of histograms required for the degree distributions of the interaction and competition geometries.private voidgetDegreeHistogramData(double[][] data, AbstractGeometry geometry, int idx, double ibinwidth) Generate the degree histogram data for the given geometry.private voidgetDegreeHistogramData(double[][] data, AbstractGeometry inter, AbstractGeometry comp) Generate the degree histogram data for the given interaction and competition geometries.private String[]getDegreeLabels(int nTraits, boolean interUndirected) Get the labels for the degree distributions of the interaction and competition geometries.private StringBuild status string for fixation probabilities.private StringBuild status string for fixation times.getMode()Get the mode required by this view.getName()Get the name of this view.getStatus(boolean force) Get the status of this view.private booleanhandleDEGraph(HistoGraph graph, ModelType mt, Module<?> module) Handle messaging for DE/PDE models; returns true if a message was set on the graph and further processing should be skipped.booleanload()Load the view.private static intmaxDegree(int max) Calculate the maximum degree for displaying the degree distribution.voidCalled after the EvoLudo model got re-initialized.voidmodelSample(boolean success) Called whenever the EvoLudo model finished generating a statistics sample.voidCalled when the settings of the EvoLudo model changed but no reset was necessary.voidOpportunity for the controller to add functionality to the context menu (optional implementation).voidreset(boolean hard) Called when a module has been reset.private voidReset degree graphs.private booleanReset fitness graphs.private voidReset fixation probability graphs.private voidReset fixation time graphs.private voidReset stationary distribution graphs.private booleanReset trait graphs.voidupdate(boolean force) Called when the view needs updating.private voidUpdate degree histograms, delegating to getDegreeHistogramData where needed.private voidUpdate fitness histograms.private voidUpdate stationary statistics histograms.private voidUpdate trait histograms (continuous models).Methods inherited from class AbstractView
activate, deactivate, destroyGraphs, export, export, exportDataHeader, exportMeanData, exportPNG, exportSVG, exportTrajData, getGraphAt, getLogger, getModel, getStatus, getType, hasLayout, isActive, isRunning, layoutComplete, modelChanged, modelDidReset, modelStopped, modelUnloaded, moduleRestored, moduleUnloaded, mouseHitNode, mouseHitNode, onKeyDown, onKeyUp, onResize, onUnload, parse, populateContextMenuAt, scheduleUpdate, setBounds, setInitialState, setOptions, shift, unload, 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
-
Field Details
-
scale2bins
double scale2binsThe scaling factor to map the data onto bins. -
binSize
int binSizeThe size of the bins in pixels. -
isMultispecies
protected boolean isMultispeciesFlag to indicate whether the model entertains multiple species, i.e.nSpecies>1. Convenience field. Reduces calls toModule. -
degreeProcessed
protected boolean degreeProcessedThe flag to indicate whether the properties of the gemetric structure have been processed. -
status
The status of the view. -
clearMenu
The clear context menu.
-
-
Constructor Details
-
Histogram
Construct a new view to display the histogram of various quantities.- Parameters:
engine- the pacemaker for running the modeltype- the type of data to display
-
-
Method Details
-
load
public boolean load()Description copied from class:AbstractViewLoad the view. This is called for modules and models that implement this view. This is called early on when initializing the view and is independent of the activation of the view.- Overrides:
loadin classAbstractView<HistoGraph>- Returns:
trueif view had not been loaded- See Also:
-
getMode
Description copied from class:AbstractViewGet the mode required by this view.- Overrides:
getModein classAbstractView<HistoGraph>- Returns:
- the mode required by this view
-
getName
Description copied from class:AbstractViewGet the name of this view. This is used to dynamically build the view selector.- Specified by:
getNamein classAbstractView<HistoGraph>- 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<HistoGraph>- Returns:
trueif graphs were (re)allocated- See Also:
-
countGraphs
private int countGraphs()Count how many graphs are required based on currentDatatype and module settings.- Returns:
- number of histogram panels required
-
createGraphs
private int createGraphs(int nGraphs) Create and configure graphs for all species; returns the number of x-label rows that should be considered when computing layout.- Parameters:
nGraphs- total number of graphs to create across species- Returns:
- the number of x-label rows created
-
addTraitGraphs
-
addFitnessGraphs
-
addDegreeGraphs
-
addFixationProbabilityGraphs
-
addFixationTimeGraphs
-
addStationaryGraphs
-
applyDefaultStyle
Apply default style settings to the given graph style.- Parameters:
style- the graph style to modify
-
applyTraitStyle
Apply style settings for trait histograms.- Parameters:
graph- the graph to stylen- the index of the graph- Returns:
trueif hard reset is required
-
applyFitnessStyle
Apply style settings for fitness histograms. The x-axis decorations are determined by thexdecoparameter:0no decorations,1tick labels only,2x-label and tick labels.- Parameters:
graph- the graph to stylen- the index of the graphxdeco- specify x-axis decorations- Returns:
trueif hard reset is required
-
applyDegreeStyle
Apply style settings for degree histograms.- Parameters:
graph- the graph to stylen- the index of the graphnGraphs- the total number of graphsxdeco- decoration level: 0 none, 1 show tick labels, 2 show labels
-
applyFixationProbabilityStyle
Apply style settings for fixation probability histograms.- Parameters:
graph- the graph to stylen- the index of the graphxdeco- decoration level: 0 none, 1 show tick labels, 2 show labels
-
applyFixationTimeStyle
Apply style settings for fixation time histograms.- Parameters:
graph- the graph to stylen- the index of the graphxdeco- decoration level: 0 none, 1 show tick labels, 2 show labelsisDistribution-truewhen plotting fixation-time distributions
-
applyStationaryStyle
Apply style settings for stationary distribution histograms.- Parameters:
graph- the graph to stylen- the index of the graphxdeco- decoration level: 0 none, 1 show tick labels, 2 show labels
-
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<HistoGraph>- Parameters:
hard- the flag to indicate whether to do a hard reset
-
resetTraitGraphs
private boolean resetTraitGraphs()Reset trait graphs.- Returns:
trueif hard reset is required
-
resetFitnessGraphs
private boolean resetFitnessGraphs()Reset fitness graphs.- Returns:
trueif hard reset is required
-
resetDegreeGraphs
private void resetDegreeGraphs()Reset degree graphs. -
resetFixationProbabilityGraphs
private void resetFixationProbabilityGraphs()Reset fixation probability graphs. -
resetFixationTimeGraphs
private void resetFixationTimeGraphs()Reset fixation time graphs. Depending on the population size either the fixation times are show for each node or as a distribution. -
resetStationaryGraphs
private void resetStationaryGraphs()Reset stationary distribution graphs. -
modelSettings
public void modelSettings()Description copied from interface:RunListenerCalled when the settings of the EvoLudo model changed but no reset was necessary. -
modelDidInit
public void modelDidInit()Description copied from interface:RunListenerCalled after the EvoLudo model got re-initialized.- Specified by:
modelDidInitin interfaceRunListener- Overrides:
modelDidInitin classAbstractView<HistoGraph>
-
modelSample
public void modelSample(boolean success) Description copied from interface:SampleListenerCalled whenever the EvoLudo model finished generating a statistics sample.- Parameters:
success- indicates whether the sampling was successful.
-
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<HistoGraph>- Parameters:
force-trueto force the update
-
updateTrait
private void updateTrait()Update trait histograms (continuous models). -
updateFitness
private void updateFitness()Update fitness histograms. -
updateDegree
private void updateDegree()Update degree histograms, delegating to getDegreeHistogramData where needed. -
handleDEGraph
Handle messaging for DE/PDE models; returns true if a message was set on the graph and further processing should be skipped.- Parameters:
graph- target histogrammt- current model typemodule- module owning the histogram- Returns:
trueif the graph now displays a message
-
ensureDegreeData
private double[][] ensureDegreeData(HistoGraph graph, AbstractGeometry inter, AbstractGeometry comp, double[][] data) Ensure the provided data buffer is sized appropriately for the given interaction/competition geometries, update the histogram data and set axis limits on the graph; returns the (possibly new) data buffer.- Parameters:
graph- target histograminter- interaction geometrycomp- competition geometrydata- current data buffer- Returns:
- data buffer ready to be reused by the histogram
-
updateStationary
private void updateStationary()Update stationary statistics histograms. -
doFixtimeDistr
Helper method to check whether to show the fixation time distribution or the fixation times for each node.- Parameters:
module- the module of the graph- Returns:
trueto show the fixation time distribution
-
getStatus
Description copied from class:AbstractViewGet the status of this view. Views that aggregate data may want to provide custom status information. HTML formatting is acceptable. Some status updates may be expensive to compute and views may decide to ignore thegetStatusrequest, except ifforceistrue.- Overrides:
getStatusin classAbstractView<HistoGraph>- Parameters:
force- whether to force an update of the status- Returns:
- the status of this view
-
getFixationProbabilityStatus
Build status string for fixation probabilities.- Returns:
- formatted status text
-
getFixationTimeStatus
Build status string for fixation times.- Returns:
- formatted status text
-
formatDistributionMean
Format mean ± sdev for a distribution stored in data (assumed normalized counts).- Parameters:
dist- the distribution datastyle- the graph style for scaling- Returns:
- the formatted string
-
formatWeightedMean
Compute weighted mean ± sdev from node-wise times (dat) and sample counts (sam).- Parameters:
dat- the data arraysam- the sample counts- Returns:
- the formatted string
-
maxDegree
private static int maxDegree(int max) Calculate the maximum degree for displaying the degree distribution. This roundsmaxup to10, 20, 50, 100, 200, 500, 1000etc.- Parameters:
max- the maximum degree of the graph- Returns:
- the maximum degree to display
-
getDegreeHistogramData
Generate the degree histogram data for the given interaction and competition geometries.- Parameters:
data- the data array for storing the histogramsinter- the interaction graphcomp- the competition graph
-
getDegreeHistogramData
private void getDegreeHistogramData(double[][] data, AbstractGeometry geometry, int idx, double ibinwidth) Generate the degree histogram data for the given geometry.- Parameters:
data- the data array for storing the histogramsgeometry- the interaction graphidx- the index for placing the histogram dataibinwidth- the scaling factor to map degrees to bins
-
getDegreeGraphs
Determine the number of histograms required for the degree distributions of the interaction and competition geometries.- Parameters:
inter- the interaction geometrycomp- the competition geometry- Returns:
- the number of histograms required
-
getDegreeBins
Determine the number of bins required for the degree distributions of the interaction and competition geometries.- Parameters:
inter- the interaction geometrycomp- the competition geometry- Returns:
- the number of histograms required
-
getDegreeLabels
Get the labels for the degree distributions of the interaction and competition geometries.- Parameters:
nTraits- the number of traitsinterUndirected-trueif the interaction graph is undirected- Returns:
- the labels for the degree distributions
-
populateContextMenu
Description copied from class:AbstractViewOpportunity for the controller to add functionality to the context menu (optional implementation).- Overrides:
populateContextMenuin classAbstractView<HistoGraph>- Parameters:
menu- the context menu
-
exportTypes
Description copied from class:AbstractViewReturn the list of export types that are acceptable for _all_ graphs in this view.- Overrides:
exportTypesin classAbstractView<HistoGraph>- Returns:
- the list of viable export types
-
exportStatData
protected void exportStatData()Description copied from class:AbstractViewExport the statistics data.Important: Must be overridden by subclasses that return
AbstractView.ExportType.CSV_STATamong their export data types.- Overrides:
exportStatDatain classAbstractView<HistoGraph>- See Also:
-