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 TypeClassDescriptionclass
Marker 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.Zooming
Nested classes/interfaces inherited from class UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
Nested 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 int
The index of the current autoscale setting.private ContextMenuCheckBoxItem
The 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 boolean
The flag to indicate whether the autoscale y-axis menu is enabled.private boolean
The flag to indicate whether the data is normalized.static final int
The maximum number of bins for the histogram.(package private) String
The message to display if no histogram is available.static final int
The minimum width of a bin.(package private) int
The number of bins.private int
The index of the data row used for normalization.(package private) double
The number of samples in the histogram.(package private) int
The 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, zoomResetMenu
Fields inherited from class UIObject
DEBUG_ID_PREFIX
-
Constructor Summary
ConstructorsConstructorDescriptionHistoGraph
(AbstractGraph.Controller controller, Module module, int row) Create new histogram graph formodule
running incontroller
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addData
(double x) Add data pointx
to histogram.void
addData
(int bin) Add data point to histogram by increasing the count of the bin with indexbin
by one.void
addData
(int bin, double incr) Add data point to histogram by increasing the count of the bin with indexbin
byincr
.void
Add marker to histogram atx
with colorcolor
and descriptiondescr
.void
Add marker to histogram atx
with colorcolor
, descriptiondescr
, and linestylelinestyle
.double
bin2x
(int bin) Convert the bin index tox
-coordinate.void
Clear the histrogram data.void
Clear all markers from the histogram.void
Clear the message.boolean
displayMessage
(String msg) Display messagemsg
on the graph (no HTML formatting).private void
Double the range of the histogram by increasing the maximum value.private void
Double the range of the histogram by lowering the minimum value.protected void
Draw the marked bins.void
enableAutoscaleYMenu
(boolean enable) Enable or disable the autoscale y-axis menu.void
Export the graphical contextctx
.int
getBinAt
(int x, int y) Get the index of the bin at(x, y)
.double[][]
getData()
Get the data for the histogram.double
getData
(int idx) Get the data for the histogram in bin with indexidx
.int
Calculate 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 binbin
ornull
if no marker is set.double
Get the number of samples for this histogram.double
getSamples
(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)
.boolean
paint
(boolean force) Draw the graph.void
populateContextMenuAt
(ContextMenu menu, int x, int y) Populate context menumenu
in listening widget at (relative) position(x,y)
.void
reset()
Reset the graph.void
setData
(double[][] data) Set the data for the histogram.void
setNormalized
(boolean isNormalized) Set whether the data is normalized.void
setNormalized
(int normIdx) Set the index of the data row that is used for normalization.int
x2bin
(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, zoom
Methods 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, setTabIndex
Methods inherited from class SimplePanel
add, getContainerElement, getWidget, iterator, remove, setWidget, setWidget
Methods inherited from class Panel
add, adopt, clear, doAttachChildren, doDetachChildren, orphan, remove
Methods 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, unsinkEvents
Methods 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, toString
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface BasicTooltipProvider
getTooltipAt
Methods inherited from interface ContextMenu.Listener
getAbsoluteLeft, getAbsoluteTop
Methods inherited from interface HasHandlers
fireEvent
Methods inherited from interface HasTouchCancelHandlers
addTouchCancelHandler
Methods inherited from interface HasTouchEndHandlers
addTouchEndHandler
Methods inherited from interface HasTouchMoveHandlers
addTouchMoveHandler
Methods inherited from interface HasTouchStartHandlers
addTouchStartHandler
Methods 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-1
with 4 levels to0-0.5
with 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 multipleHistoGraph
s, 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 formodule
running 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 atx
with colorcolor
and descriptiondescr
.- Parameters:
x
- thex
-coordinate of the markercolor
- the color of the markerdescr
- the description of the marker
-
addMarker
Add marker to histogram atx
with 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 binbin
ornull
if 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. IfisNormalized
istrue
, the sum of the data in each bin is normalized to1.0
.
Note: This conflicts withsetNormalized(int)
.- Parameters:
isNormalized
-true
if the data is normalized,false
otherwise
-
setNormalized
public void setNormalized(int normIdx) Set the index of the data row that is used for normalization. If multipleHistoGraph
s 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 multipleHistoGraph
s, 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 multipleHistoGraph
s, 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 indexbin
by 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 indexbin
byincr
. 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 pointx
to histogram. The data point is added to the histogram for . If or the range is doubled to ) or ), 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:AbstractGraph
Reset the graph. Clear canvas and messages.- Overrides:
reset
in classAbstractGraph<double[]>
-
export
Description copied from class:AbstractGraph
Export the graphical contextctx
.- Specified by:
export
in classAbstractGraph<double[]>
- Parameters:
ctx
- the graphical context to export
-
displayMessage
Description copied from class:AbstractGraph
Display messagemsg
on 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:
displayMessage
in classAbstractGraph<double[]>
- Parameters:
msg
- the message to display- Returns:
true
if message displayed
-
clearMessage
public void clearMessage()Description copied from class:AbstractGraph
Clear the message.- Overrides:
clearMessage
in classAbstractGraph<double[]>
-
paint
public boolean paint(boolean force) Description copied from class:AbstractGraph
Draw the graph. For re-drawing the graph, setforce
totrue
.- Overrides:
paint
in classAbstractGraph<double[]>
- Parameters:
force
-true
to force re-drawing of graph- Returns:
true
if 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-1
if no bin is found.- Parameters:
x
- thex
-coordinatey
- they
-coordinate- Returns:
- the index of the bin
-
getTooltipAt
Description copied from interface:Tooltip.Provider
Get the tooltip information for the location with coordinates(x, y)
. The returned string may include HTML elements for formatting.- Specified by:
getTooltipAt
in 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:BasicTooltipProvider
Get 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:
getTooltipAt
in interfaceBasicTooltipProvider
- Parameters:
bar
- theindex
of the location- Returns:
- the tooltip
-
enableAutoscaleYMenu
public void enableAutoscaleYMenu(boolean enable) Enable or disable the autoscale y-axis menu.- Parameters:
enable
-true
to enable the autoscale menu
-
populateContextMenuAt
Description copied from class:AbstractGraph
Populate context menumenu
in listening widget at (relative) position(x,y)
.Adds buffer size menu and queries the controller to add further functionality.
- Specified by:
populateContextMenuAt
in interfaceContextMenu.Provider
- Overrides:
populateContextMenuAt
in 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:
-