Package org.evoludo.graphics
Class GenericPopGraph<T,N extends Network>
Object
UIObject
Widget
Panel
SimplePanel
FocusPanel
AbstractGraph<T[]>
GenericPopGraph<T,N>
- Type Parameters:
T
- the type for storing the color dataN
- the type of the network representation, 2D or 3D
- All Implemented Interfaces:
DoubleClickHandler
,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>
,AbstractGraph.Zoomer
,AbstractGraph.Zooming
,Network.LayoutListener
,ContextMenu.Listener
,ContextMenu.Provider
,Tooltip.Provider
- Direct Known Subclasses:
PopGraph2D
,PopGraph3D
public abstract class GenericPopGraph<T,N extends Network>
extends AbstractGraph<T[]>
implements Network.LayoutListener, AbstractGraph.Zooming, DoubleClickHandler
The base class for population graphs. This class provides the basic
functionality for drawing population structures, e.g. lattices or networks.
The class is abstract and must be subclassed to provide the actual drawing
functionality, including:
- (dynamical) layouting of the population structure
- coloring of nodes according to their traits or fitness
- handling of mouse events
- Author:
- Christoph Hauert
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
The interface for communicating with graphs that show nodes, e.g.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 TypeFieldDescriptionprotected boolean
The mode of the animation of the network layouting process.private ContextMenuCheckBoxItem
The context menu item for animating the layouting process.private ContextMenuItem
The context menu item to clear the canvas.The map for translating discrete traits into colors.protected T[]
The array to store the data for drawing the population structure.private ContextMenuItem
The context menu item for updating the current node.private ContextMenu
The context menu for visually exploring (or debugging) the updating process.private ContextMenuItem
The context menu item for attaching the debug submenu.(package private) static final int
Return value iffindNodeAt(int, int)
couldn't find a node at the mouse position.(package private) static final int
Return value iffindNodeAt(int, int)
isn't implemented for the particular backing geometry.protected Geometry
The structure of the population.protected int
The index of the node that was hit by the mouse or a tap.(package private) boolean
The flag to indicate whether the graph has been invalidated and needs to be redrawn.private boolean
The flag to indicate whether the debug submenu is activated.protected Label
The label of the graph.(package private) static final int
Maximum number of edges in network for animated layout.(package private) static final int
Maximum number of nodes in network for animated layout.protected N
The network representation of the population structure ornull
if not applicable.(package private) boolean
The flag to indicate whether the graph needs to be drawn.private ContextMenuItem
The context menu item for rearranging networks through random shifts of node positions.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
Fields inherited from interface AbstractGraph.Zooming
ZOOM_INCR, ZOOM_MAX
-
Constructor Summary
ConstructorsConstructorDescriptionGenericPopGraph
(GenericPopGraph.PopGraphController controller, Module module) Create the base class for population graphs. -
Method Summary
Modifier and TypeMethodDescriptionvoid
activate()
Perform necessary preparations to show the graph in the GUI.protected abstract void
Draws structures with static layout of lattices.protected abstract void
Draws the network.abstract int
findNodeAt
(int x, int y) Find the index of the node at the location with coordinates(x, y)
.Get the map for translating trait values into colors.abstract String
getCSSColorAt
(int node) Get the color of the node at indexnode
as a CSS color string.T[]
getData()
Get the color data for all nodes as an array.Get the geometry backing the graph.Get the network representation of the graph represented by the geometry.getTooltipAt
(int x, int y) Get the tooltip information for the location with coordinates(x, y)
.(package private) boolean
Check whether the layout of the graph is animated.boolean
Check if the graph displays a message.(package private) boolean
Check whether the layout of the graph is static, i.e.void
Invalidate the network.void
Notification that the layouting process has completed.protected void
Draws structures with resulting from dynamic layouting of network.void
layoutUpdate
(double progress) Requests an incremental update of the current layout.void
onDoubleClick
(DoubleClickEvent event) void
onResize()
void
onTouchStart
(TouchStartEvent event) 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
setColorMap
(ColorMap<T> colorMap) Set the map for translating trait values into colors.void
setDebugEnabled
(boolean enabled) Set whether the debugging menu is enabled.void
setGeometry
(Geometry geometry) Set the geometry backing the graph.void
setGraphLabel
(String msg) Set the graph label to the stringmsg
(no HTML formatting).void
update
(boolean isNext) Update the graph.Methods inherited from class AbstractGraph
addContextMenuHandler, autoscale, calcBounds, calcBounds, clearCanvas, clearGraph, clearHistory, clearMessage, contains, convertToScaledCoordinates, convertToScaledCoordinates, deactivate, displayMessage, doUpdate, drawFrame, drawFrame, export, fill, fillCircle, fillRect, fillTextVertical, getBuffer, getModule, getStyle, hasHistory, init, onMouseDown, onMouseMove, onMouseOut, onMouseUp, onMouseWheel, onTouchEnd, onTouchMove, 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 AbstractGraph.Zoomer
zoom
Methods inherited from interface AbstractGraph.Zooming
zoom, zoom
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
Methods inherited from interface MouseWheelHandler
onMouseWheel
-
Field Details
-
geometry
The structure of the population. -
network
The network representation of the population structure ornull
if not applicable. -
data
The array to store the data for drawing the population structure. -
MAX_ANIMATE_LAYOUT_VERTICES_DEFAULT
static final int MAX_ANIMATE_LAYOUT_VERTICES_DEFAULTMaximum number of nodes in network for animated layout.- See Also:
-
MAX_ANIMATE_LAYOUT_LINKS_DEFAULT
static final int MAX_ANIMATE_LAYOUT_LINKS_DEFAULTMaximum number of edges in network for animated layout.- See Also:
-
animate
protected boolean animateThe mode of the animation of the network layouting process. -
noGraph
boolean noGraphThe flag to indicate whether the graph needs to be drawn.- See Also:
-
invalidated
boolean invalidatedThe flag to indicate whether the graph has been invalidated and needs to be redrawn. -
colorMap
The map for translating discrete traits into colors. -
label
The label of the graph. -
FINDNODEAT_OUT_OF_BOUNDS
static final int FINDNODEAT_OUT_OF_BOUNDSReturn value iffindNodeAt(int, int)
couldn't find a node at the mouse position.- See Also:
-
FINDNODEAT_UNIMPLEMENTED
static final int FINDNODEAT_UNIMPLEMENTEDReturn value iffindNodeAt(int, int)
isn't implemented for the particular backing geometry.- See Also:
-
hitNode
protected int hitNodeThe index of the node that was hit by the mouse or a tap. -
animateMenu
The context menu item for animating the layouting process. -
shakeMenu
The context menu item for rearranging networks through random shifts of node positions. -
clearMenu
The context menu item to clear the canvas. Only active for linear graphs to clear the history. -
debugNodeMenu
The context menu item for updating the current node. -
isDebugEnabled
private boolean isDebugEnabledThe flag to indicate whether the debug submenu is activated. For example, debugging does not make sense if the nodes refer to states of PDE calculations.
-
-
Constructor Details
-
GenericPopGraph
Create the base class for population graphs.- Parameters:
controller
- the controller of this graphmodule
- the module backing the graph
-
-
Method Details
-
activate
public void activate()Description copied from class:AbstractGraph
Perform necessary preparations to show the graph in the GUI. Attaches mouse and touch handlers for graphs that implementAbstractGraph.Zooming
orAbstractGraph.Shifting
interfaces.- Overrides:
activate
in classAbstractGraph<T[]>
- See Also:
-
onResize
public void onResize()- Specified by:
onResize
in interfaceRequiresResize
- Overrides:
onResize
in classAbstractGraph<T[]>
-
setGraphLabel
Set the graph label to the stringmsg
(no HTML formatting).- Parameters:
msg
- the text for the label of the graph
-
setGeometry
Set the geometry backing the graph.- Parameters:
geometry
- the structure of the population
-
getGeometry
Get the geometry backing the graph.- Returns:
- the structure of the population
-
setColorMap
Set the map for translating trait values into colors.- Parameters:
colorMap
- the trait-to-colour map
-
getColorMap
Get the map for translating trait values into colors.- Returns:
- the trait-to-colour map
-
getData
Get the color data for all nodes as an array.- Returns:
- the array of node colors
-
getNetwork
Get the network representation of the graph represented by the geometry.- Returns:
- the 2D network representation of this graph
-
hasMessage
public boolean hasMessage()Description copied from class:AbstractGraph
Check if the graph displays a message.- Overrides:
hasMessage
in classAbstractGraph<T[]>
- Returns:
true
if message displayed
-
reset
public void reset()Description copied from class:AbstractGraph
Reset the graph. Clear canvas and messages.- Overrides:
reset
in classAbstractGraph<T[]>
-
update
public void update(boolean isNext) Update the graph.- Parameters:
isNext
-true
if the state has changed
-
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<T[]>
- Parameters:
force
-true
to force re-drawing of graph- Returns:
true
if painting skipped
-
hasStaticLayout
boolean hasStaticLayout()Check whether the layout of the graph is static, i.e. a lattice or lattice hierarchy.- Returns:
true
if the layout is static
-
hasAnimatedLayout
boolean hasAnimatedLayout()Check whether the layout of the graph is animated.- Returns:
true
if the layout is animated
-
invalidate
public void invalidate()Invalidate the network. This forces networks to be regenerated. -
layoutUpdate
public void layoutUpdate(double progress) Description copied from interface:Network.LayoutListener
Requests an incremental update of the current layout.- Specified by:
layoutUpdate
in interfaceNetwork.LayoutListener
- Parameters:
progress
- the current progress- See Also:
-
layoutComplete
public void layoutComplete()Description copied from interface:Network.LayoutListener
Notification that the layouting process has completed. This get called if the desired accuracy has been achieved or if the maximum computational time for the layouting process has been reached.- Specified by:
layoutComplete
in interfaceNetwork.LayoutListener
- See Also:
-
drawLattice
protected abstract void drawLattice()Draws structures with static layout of lattices.- See Also:
-
layoutNetwork
protected void layoutNetwork()Draws structures with resulting from dynamic layouting of network.- See Also:
-
drawNetwork
protected abstract void drawNetwork()Draws the network. -
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
-
getCSSColorAt
Get the color of the node at indexnode
as a CSS color string.- Parameters:
node
- the index of the node- Returns:
- the color of the node
-
findNodeAt
public abstract int findNodeAt(int x, int y) Find the index of the node at the location with coordinates(x, y)
.- Parameters:
x
- thex
-coordinate of the locationy
- they
-coordinate of the location- Returns:
- the index of the node
-
onDoubleClick
- Specified by:
onDoubleClick
in interfaceDoubleClickHandler
-
onTouchStart
The graph reacts to different kinds of touches: short touches or taps (
<250
msec) and long touches (>250
msec). Long touches trigger different actions depending on the number of fingers:- Single finger
- Initiate shifting the view
- Two fingers
- Initiate pinching zoom.
The graph reacts to different kinds of touches:
- short touch with two fingers (
<250
msec) - display context menu.
- single long touch (
>250
msec) on a node - display the tooltip.
- long touch with two fingers (
>250
msec) - initiates pinching zoom.
- double tap on a node
- change the strategy of the node, if applicable.
- Specified by:
onTouchStart
in interfaceTouchStartHandler
- Overrides:
onTouchStart
in classAbstractGraph<T[]>
- See Also:
-
setDebugEnabled
public void setDebugEnabled(boolean enabled) Set whether the debugging menu is enabled.- Parameters:
enabled
-true
to enable debugging
-
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<T[]>
- Parameters:
menu
- context menu entries are added herex
- horizontal coordinate (relative to listening widget)y
- horizontal coordinate (relative to listening widget)- See Also:
-