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 interfaceThe 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.ZoomingNested classes/interfaces inherited from class UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabledNested classes/interfaces inherited from interface HasWidgets
HasWidgets.ForIsWidget -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanThe mode of the animation of the network layouting process.private ContextMenuCheckBoxItemThe context menu item for animating the layouting process.private ContextMenuItemThe 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 ContextMenuItemThe context menu item for updating the current node.private ContextMenuThe context menu for visually exploring (or debugging) the updating process.private ContextMenuItemThe context menu item for attaching the debug submenu.(package private) static final intReturn value iffindNodeAt(int, int)couldn't find a node at the mouse position.(package private) static final intReturn value iffindNodeAt(int, int)isn't implemented for the particular backing geometry.protected GeometryThe structure of the population.protected intThe index of the node that was hit by the mouse or a tap.(package private) booleanThe flag to indicate whether the graph has been invalidated and needs to be redrawn.private booleanThe flag to indicate whether the debug submenu is activated.protected LabelThe label of the graph.(package private) static final intMaximum number of edges in network for animated layout.(package private) static final intMaximum number of nodes in network for animated layout.protected NThe network representation of the population structure ornullif not applicable.(package private) booleanThe flag to indicate whether the graph needs to be drawn.private ContextMenuItemThe 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, zoomResetMenuFields inherited from class UIObject
DEBUG_ID_PREFIXFields 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 TypeMethodDescriptionvoidactivate()Perform necessary preparations to show the graph in the GUI.protected abstract voidDraws structures with static layout of lattices.protected abstract voidDraws the network.abstract intfindNodeAt(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 StringgetCSSColorAt(int node) Get the color of the node at indexnodeas 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) booleanCheck whether the layout of the graph is animated.booleanCheck if the graph displays a message.(package private) booleanCheck whether the layout of the graph is static, i.e.voidInvalidate the network.voidNotification that the layouting process has completed.protected voidDraws structures with resulting from dynamic layouting of network.voidlayoutUpdate(double progress) Requests an incremental update of the current layout.voidonDoubleClick(DoubleClickEvent event) voidonResize()voidonTouchStart(TouchStartEvent event) 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.voidsetColorMap(ColorMap<T> colorMap) Set the map for translating trait values into colors.voidsetDebugEnabled(boolean enabled) Set whether the debugging menu is enabled.voidsetGeometry(Geometry geometry) Set the geometry backing the graph.voidsetGraphLabel(String msg) Set the graph label to the stringmsg(no HTML formatting).voidupdate(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, 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 AbstractGraph.Zoomer
zoomMethods inherited from interface AbstractGraph.Zooming
zoom, zoomMethods 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, spliteratorMethods inherited from interface MouseWheelHandler
onMouseWheel
-
Field Details
-
geometry
The structure of the population. -
network
The network representation of the population structure ornullif 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:AbstractGraphPerform necessary preparations to show the graph in the GUI. Attaches mouse and touch handlers for graphs that implementAbstractGraph.ZoomingorAbstractGraph.Shiftinginterfaces.- Overrides:
activatein classAbstractGraph<T[]>- See Also:
-
onResize
public void onResize()- Specified by:
onResizein interfaceRequiresResize- Overrides:
onResizein 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:AbstractGraphCheck if the graph displays a message.- Overrides:
hasMessagein classAbstractGraph<T[]>- Returns:
trueif message displayed
-
reset
public void reset()Description copied from class:AbstractGraphReset the graph. Clear canvas and messages.- Overrides:
resetin classAbstractGraph<T[]>
-
update
public void update(boolean isNext) Update the graph.- Parameters:
isNext-trueif the state has changed
-
paint
public boolean paint(boolean force) Description copied from class:AbstractGraphDraw the graph. For re-drawing the graph, setforcetotrue.- Overrides:
paintin classAbstractGraph<T[]>- Parameters:
force-trueto force re-drawing of graph- Returns:
trueif painting skipped
-
hasStaticLayout
boolean hasStaticLayout()Check whether the layout of the graph is static, i.e. a lattice or lattice hierarchy.- Returns:
trueif the layout is static
-
hasAnimatedLayout
boolean hasAnimatedLayout()Check whether the layout of the graph is animated.- Returns:
trueif 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.LayoutListenerRequests an incremental update of the current layout.- Specified by:
layoutUpdatein interfaceNetwork.LayoutListener- Parameters:
progress- the current progress- See Also:
-
layoutComplete
public void layoutComplete()Description copied from interface:Network.LayoutListenerNotification 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:
layoutCompletein 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.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
-
getCSSColorAt
Get the color of the node at indexnodeas 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:
onDoubleClickin interfaceDoubleClickHandler
-
onTouchStart
The graph reacts to different kinds of touches: short touches or taps (
<250msec) and long touches (>250msec). 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 (
<250msec) - display context menu.
- single long touch (
>250msec) on a node - display the tooltip.
- long touch with two fingers (
>250msec) - initiates pinching zoom.
- double tap on a node
- change the strategy of the node, if applicable.
- Specified by:
onTouchStartin interfaceTouchStartHandler- Overrides:
onTouchStartin classAbstractGraph<T[]>- See Also:
-
setDebugEnabled
public void setDebugEnabled(boolean enabled) Set whether the debugging menu is enabled.- Parameters:
enabled-trueto enable debugging
-
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<T[]>- Parameters:
menu- context menu entries are added herex- horizontal coordinate (relative to listening widget)y- horizontal coordinate (relative to listening widget)- See Also:
-