Package org.evoludo.graphics
Class HistoGraph
Object
UIObject
Widget
Panel
SimplePanel
FocusPanel
AbstractGraph<double[]>
HistoGraph
- All Implemented Interfaces:
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>,BasicTooltipProvider,ContextMenu.Listener,ContextMenu.Provider,Tooltip.Provider
Histogram graph for displaying data in bins. The data is stored in a 2D array
with the first index representing the data row and the second index the bin
index. The data can be normalized to the total number of samples or to a
specific data row. The graph can be used to display data for different types
of modules, such as degree distributions, strategies, fitness values, or
fixation probabilities.
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassMarker for highlighting a specific bin in the histogram.Nested classes/interfaces inherited from class AbstractGraph
AbstractGraph.Controller, AbstractGraph.GraphStyle, AbstractGraph.HasTrajectory, AbstractGraph.MyContext2d, AbstractGraph.Shifter, AbstractGraph.Shifting, AbstractGraph.ZoomCommand, AbstractGraph.Zoomer, AbstractGraph.ZoomingNested classes/interfaces inherited from class UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabledNested classes/interfaces inherited from interface HasWidgets
HasWidgets.ForIsWidget -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final double[][]The list of thresholds for automatically scaling the y-axis.private intThe index of the current autoscale setting.private ContextMenuCheckBoxItemThe context menu to select autoscaling of the y-axis.private ArrayList<HistoGraph.Marker> The list of markers for the histogram.(package private) double[][]The data array backing the histogram.private booleanThe flag to indicate whether the autoscale y-axis menu is enabled.private booleanThe flag to indicate whether the data is normalized.static final intThe maximum number of bins for the histogram.(package private) StringThe message to display if no histogram is available.static final intThe minimum width of a bin.(package private) intThe number of bins.private intThe index of the data row used for normalization.(package private) doubleThe number of samples in the histogram.(package private) intThe index of the data row.Fields inherited from class AbstractGraph
bounds, buffer, canvas, colors, contextMenu, controller, DEFAULT_BUFFER_SIZE, doubleClickHandler, element, g, hasMessage, hasZoom, isActive, leftMouseButton, logger, markerColors, markers, MIN_BUFFER_SIZE, MIN_MSEC_BETWEEN_UPDATES, module, mouseDownHandler, mouseMoveHandler, mouseOutHandler, mouseUpHandler, mouseWheelHandler, mouseX, mouseY, PIHALF, pinchDist, pinchX, pinchY, scale, shifter, style, tooltip, tooltipProvider, touchEndHandler, touchEndTime, touchMoveHandler, touchStartHandler, updatetime, viewCorner, wrapper, zoomer, zoomFactor, zoomInertiaTimer, zoomInMenu, zoomOutMenu, zoomResetMenuFields inherited from class UIObject
DEBUG_ID_PREFIX -
Constructor Summary
ConstructorsConstructorDescriptionHistoGraph(AbstractGraph.Controller controller, Module module, int row) Create new histogram graph formodulerunning incontroller. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddData(double x) Add data pointxto histogram.voidaddData(int bin) Add data point to histogram by increasing the count of the bin with indexbinby one.voidaddData(int bin, double incr) Add data point to histogram by increasing the count of the bin with indexbinbyincr.voidAdd marker to histogram atxwith colorcolorand descriptiondescr.voidAdd marker to histogram atxwith colorcolor, descriptiondescr, and linestylelinestyle.doublebin2x(int bin) Convert the bin index tox-coordinate.voidClear the histrogram data.voidClear all markers from the histogram.voidClear the message.booleandisplayMessage(String msg) Display messagemsgon the graph (no HTML formatting).private voidDouble the range of the histogram by increasing the maximum value.private voidDouble the range of the histogram by lowering the minimum value.protected voidDraw the marked bins.voidenableAutoscaleYMenu(boolean enable) Enable or disable the autoscale y-axis menu.voidExport the graphical contextctx.intgetBinAt(int x, int y) Get the index of the bin at(x, y).double[][]getData()Get the data for the histogram.doublegetData(int idx) Get the data for the histogram in bin with indexidx.intCalculate the maximum number of bins for the histogram with a width of at leastMIN_BIN_WIDTH.getNoteAt(int bin) Get the description of the marker at binbinornullif no marker is set.doubleGet the number of samples for this histogram.doublegetSamples(int idx) Get the total number of samples in bin with indexidx.getTooltipAt(int bar) Get the tooltip for the location with indexindex.getTooltipAt(int x, int y) Get the tooltip information for the location with coordinates(x, y).booleanpaint(boolean force) Draw the graph.voidpopulateContextMenuAt(ContextMenu menu, int x, int y) Populate context menumenuin listening widget at (relative) position(x,y).voidreset()Reset the graph.voidsetData(double[][] data) Set the data for the histogram.voidsetNormalized(boolean isNormalized) Set whether the data is normalized.voidsetNormalized(int normIdx) Set the index of the data row that is used for normalization.intx2bin(double x) Convertx-coordinate to bin index.Methods inherited from class AbstractGraph
activate, addContextMenuHandler, autoscale, calcBounds, calcBounds, clearCanvas, clearGraph, clearHistory, contains, convertToScaledCoordinates, convertToScaledCoordinates, deactivate, doUpdate, drawFrame, drawFrame, fill, fillCircle, fillRect, fillTextVertical, getBuffer, getModule, getStyle, hasHistory, hasMessage, init, onMouseDown, onMouseMove, onMouseOut, onMouseUp, onMouseWheel, onResize, onTouchEnd, onTouchMove, onTouchStart, paint, prependTime2Data, resetTransforms, setBufferCapacity, setColors, setFont, setMarkers, setMarkers, setStrokeStyleAt, setTooltipProvider, shift, stroke, strokeCircle, strokeLine, strokeRect, zoom, zoom, zoom, zoomMethods inherited from class FocusPanel
addBlurHandler, addClickHandler, addClickListener, addDoubleClickHandler, addDragEndHandler, addDragEnterHandler, addDragHandler, addDragLeaveHandler, addDragOverHandler, addDragStartHandler, addDropHandler, addFocusHandler, addFocusListener, addGestureChangeHandler, addGestureEndHandler, addGestureStartHandler, addKeyboardListener, addKeyDownHandler, addKeyPressHandler, addKeyUpHandler, addMouseDownHandler, addMouseListener, addMouseMoveHandler, addMouseOutHandler, addMouseOverHandler, addMouseUpHandler, addMouseWheelHandler, addMouseWheelListener, addTouchCancelHandler, addTouchEndHandler, addTouchMoveHandler, addTouchStartHandler, getTabIndex, removeClickListener, removeFocusListener, removeKeyboardListener, removeMouseListener, removeMouseWheelListener, setAccessKey, setFocus, setTabIndexMethods inherited from class SimplePanel
add, getContainerElement, getWidget, iterator, remove, setWidget, setWidgetMethods inherited from class Panel
add, adopt, clear, doAttachChildren, doDetachChildren, orphan, removeMethods inherited from class Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, onLoad, onUnload, 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, resolvePotentialElement, 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 BasicTooltipProvider
getTooltipAtMethods inherited from interface ContextMenu.Listener
getAbsoluteLeft, getAbsoluteTopMethods inherited from interface HasHandlers
fireEventMethods inherited from interface HasTouchCancelHandlers
addTouchCancelHandlerMethods inherited from interface HasTouchEndHandlers
addTouchEndHandlerMethods inherited from interface HasTouchMoveHandlers
addTouchMoveHandlerMethods inherited from interface HasTouchStartHandlers
addTouchStartHandlerMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
autoscale
private static final double[][] autoscaleThe list of thresholds for automatically scaling the y-axis. The first element of each row is the maximum value for the y-axis, the second element is the minimum value for the y-axis, and the third element is the number of levels for the y-axis.For example, the scale changes from
0-1with 4 levels to0-0.5with 5 levels if the maximum value drops below0.4. -
autoscaleidx
private int autoscaleidxThe index of the current autoscale setting. -
binmarkers
The list of markers for the histogram. -
data
double[][] dataThe data array backing the histogram. This may be shared by multipleHistoGraphs, each accessing a different row in the array. -
row
int rowThe index of the data row. -
message
String messageThe message to display if no histogram is available. -
isNormalized
private boolean isNormalizedThe flag to indicate whether the data is normalized. -
normIdx
private int normIdxThe index of the data row used for normalization. -
nSamples
double nSamplesThe number of samples in the histogram. -
nBins
int nBinsThe number of bins.- See Also:
- Implementation Notes:
- The number of bins needs to be even for doubling the range of the histogram.
-
MAX_BINS
public static final int MAX_BINSThe maximum number of bins for the histogram.- See Also:
-
MIN_BIN_WIDTH
public static final int MIN_BIN_WIDTHThe minimum width of a bin.- See Also:
-
autoscaleYMenu
The context menu to select autoscaling of the y-axis. -
enableAutoscaleYMenu
private boolean enableAutoscaleYMenuThe flag to indicate whether the autoscale y-axis menu is enabled.
-
-
Constructor Details
-
HistoGraph
Create new histogram graph formodulerunning incontroller. The row is used to identify data entries that apply to this histogram and represents the index of the data row.- Parameters:
controller- the controller of this graphmodule- the module backing the graphrow- the index of the data row
-
-
Method Details
-
addMarker
Add marker to histogram atxwith colorcolorand descriptiondescr.- Parameters:
x- thex-coordinate of the markercolor- the color of the markerdescr- the description of the marker
-
addMarker
Add marker to histogram atxwith colorcolor, descriptiondescr, and linestylelinestyle.- Parameters:
x- thex-coordinate of the markercolor- the color of the markerdescr- the description of the markerlinestyle- the linestyle of the marker
-
clearMarkers
public void clearMarkers()Clear all markers from the histogram. -
getNoteAt
Get the description of the marker at binbinornullif no marker is set.- Parameters:
bin- the index of the bin- Returns:
- the description of the marker
-
getMaxBins
public int getMaxBins()Calculate the maximum number of bins for the histogram with a width of at leastMIN_BIN_WIDTH.- Returns:
- the maximum number of bins
- See Also:
-
setNormalized
public void setNormalized(boolean isNormalized) Set whether the data is normalized. IfisNormalizedistrue, the sum of the data in each bin is normalized to1.0.
Note: This conflicts withsetNormalized(int).- Parameters:
isNormalized-trueif the data is normalized,falseotherwise
-
setNormalized
public void setNormalized(int normIdx) Set the index of the data row that is used for normalization. If multipleHistoGraphs share the same data, they all need to use the same row for normalization.
Note: This conflicts withsetNormalized(boolean).- Parameters:
normIdx- the index of the data row for normalization
-
getSamples
public double getSamples()Get the number of samples for this histogram.- Returns:
- the number of samples
-
getSamples
public double getSamples(int idx) Get the total number of samples in bin with indexidx. For data that is not normalized the number of samples is returned.- Parameters:
idx- the index of the bin- Returns:
- the number of samples
- See Also:
-
getData
public double[][] getData()Get the data for the histogram.
Note: The data may be shared by multipleHistoGraphs, each refering to a row in thedouble[][]array specified by the graphsrow.- Returns:
- the 2D data array for storing the histogram data
-
getData
public double getData(int idx) Get the data for the histogram in bin with indexidx. Whether this returns raw or normalized data depends on the setting of the graph.- Parameters:
idx- the index of the bin- Returns:
- the histogram data for the bin
idx - See Also:
-
setData
public void setData(double[][] data) Set the data for the histogram.
Note: The data may be shared by multipleHistoGraphs, each refering to a row in thedouble[][]array specified by the graphsrow.- Parameters:
data- the 2D data array for storing the histogram data
-
addData
public void addData(int bin) Add data point to histogram by increasing the count of the bin with indexbinby one. For normalized data the normalization is updated accordingly.- Parameters:
bin- the index of the bin in the histogram- See Also:
-
addData
public void addData(int bin, double incr) Add data point to histogram by increasing the count of the bin with indexbinbyincr. For normalized data the normalization is updated accordingly.- Parameters:
bin- the index of the bin in the histogramincr- the increment to add to the bin- See Also:
-
addData
public void addData(double x) Add data pointxto histogram. The data point is added to the histogram for \(x\in[x_\text{min},x_\text{max}]\). If \(x>x_\text{max}]\) or \(x<x_\text{min}]\) the range is doubled to \([x_\text{min}, x_\text{max} + (x_\text{max}-x_\text{min})]\)) or \([x_\text{min} - (x_\text{max}-x_\text{min}), x_\text{max}]\)), respectively. The number of bins remains unchanged.
Important: The number of bins needs to be even!- Parameters:
x- the new data point- See Also:
-
clearData
public void clearData()Clear the histrogram data. -
doubleMinRange
private void doubleMinRange()Double the range of the histogram by lowering the minimum value.- Implementation Notes:
- The number of bins needs to be even!
-
doubleMaxRange
private void doubleMaxRange()Double the range of the histogram by increasing the maximum value.- Implementation Notes:
- The number of bins needs to be even!
-
x2bin
public int x2bin(double x) Convertx-coordinate to bin index.- Parameters:
x- thex-coordinate- Returns:
- the index of the bin
-
bin2x
public double bin2x(int bin) Convert the bin index tox-coordinate.- Parameters:
bin- the index of the bin- Returns:
- the
x-coordinate
-
reset
public void reset()Description copied from class:AbstractGraphReset the graph. Clear canvas and messages.- Overrides:
resetin classAbstractGraph<double[]>
-
export
Description copied from class:AbstractGraphExport the graphical contextctx.- Specified by:
exportin classAbstractGraph<double[]>- Parameters:
ctx- the graphical context to export
-
displayMessage
Description copied from class:AbstractGraphDisplay messagemsgon the graph (no HTML formatting).Implementation note:
The message is centered and scaled such that it fills approximately two thirds of the width of the graph.- Overrides:
displayMessagein classAbstractGraph<double[]>- Parameters:
msg- the message to display- Returns:
trueif message displayed
-
clearMessage
public void clearMessage()Description copied from class:AbstractGraphClear the message.- Overrides:
clearMessagein classAbstractGraph<double[]>
-
paint
public boolean paint(boolean force) Description copied from class:AbstractGraphDraw the graph. For re-drawing the graph, setforcetotrue.- Overrides:
paintin classAbstractGraph<double[]>- Parameters:
force-trueto force re-drawing of graph- Returns:
trueif painting skipped
-
drawMarkers
protected void drawMarkers()Draw the marked bins. -
getBinAt
public int getBinAt(int x, int y) Get the index of the bin at(x, y). Returns-1if no bin is found.- Parameters:
x- thex-coordinatey- they-coordinate- Returns:
- the index of the bin
-
getTooltipAt
Description copied from interface:Tooltip.ProviderGet the tooltip information for the location with coordinates(x, y). The returned string may include HTML elements for formatting.- Specified by:
getTooltipAtin interfaceTooltip.Provider- Parameters:
x- thex-coordinate for the tooltipy- they-coordinate for the tooltip- Returns:
- the (formatted) string with the tooltip info
-
getTooltipAt
Description copied from interface:BasicTooltipProviderGet the tooltip for the location with indexindex. The index typically refers to an individual node but may equally refer to a location on a lattice for PDE models or trait distributions.- Specified by:
getTooltipAtin interfaceBasicTooltipProvider- Parameters:
bar- theindexof the location- Returns:
- the tooltip
-
enableAutoscaleYMenu
public void enableAutoscaleYMenu(boolean enable) Enable or disable the autoscale y-axis menu.- Parameters:
enable-trueto enable the autoscale menu
-
populateContextMenuAt
Description copied from class:AbstractGraphPopulate context menumenuin listening widget at (relative) position(x,y).Adds buffer size menu and queries the controller to add further functionality.
- Specified by:
populateContextMenuAtin interfaceContextMenu.Provider- Overrides:
populateContextMenuAtin classAbstractGraph<double[]>- Parameters:
menu- context menu entries are added herex- horizontal coordinate (relative to listening widget)y- horizontal coordinate (relative to listening widget)- See Also:
-