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
Abstract base class for visualizing a population as a graph. GenericPopGraph
ties a population AbstractGeometry to an optional Network representation and
provides common support for layouting, drawing, interaction and debugging for
concrete graph views (2D/3D, lattice or general network).
Key responsibilities:
- Manage the backing AbstractGeometry and its Network (if present). The network may be null for models without spatial structure (e.g. ODE/SDE).
- Coordinate layouting: static lattice layouts are drawn directly via
drawLattice();drawNetwork()is used for dynamic/network layouts which calls back viaNetwork.LayoutListenerand this class drives the animation and final drawing vialayoutNetwork()anddrawNetwork(). - Provide common interaction handling: tooltips, double-clicks, touch gestures (single/double tap, long press, pinch zoom), mouse cursor styling when hovering nodes, and context menu entries (shake, animate layout, clear history, debug submenu).
- Maintain display state such as labelling, color mapping for node traits, invalidation/refresh logic and flags controlling animated layouting.
Design notes and behavior:
- The class is generic in the node color/type T and the concrete Network implementation N. Subclasses are responsible for converting node data to CSS color strings and for hit-testing nodes at screen coordinates.
- Subclasses must implement the rendering and hit-testing contract:
drawLattice(),drawNetwork(),getCSSColorAt(int)andfindNodeAt(int,int). These methods encapsulate geometry-specific drawing and input logic. - Layout updates are coordinated with the Network. For animated layouts the class may repeatedly request redraws during progress updates; for non-animated or very large networks animation can be disabled using the animate flag and size threshold constants.
layoutUpdate(double)andlayoutComplete()are synchronized and used by the Network to report progress and completion.layoutNetwork()ensures that a layout exists before callingdrawNetwork().- Touch handling distinguishes single tap, double tap, long press and multi-touch gestures to support node selection, tooltip display, pinching zoom and invoking node-specific actions.
- Context menu population is centralized here. Implementations add graph-specific menu items but benefit from the common items provided (shake, animate, clear history and debug/update options). The debug submenu is gated by isDebugEnabled and the model type.
- Invalidation resets the network (if present) and marks the view for
redraw;
update(boolean isNext)defers layout work using a scheduler to allow dependent views (3D rendering) to become ready. - TooltipProvider integration: if the view implements TooltipProvider.Index the class will use it to produce tooltips for nodes; otherwise a fallback basic provider may be used when available.
Important fields and conventions referenced by subclasses:
geometry- the population structure (may be null for non-spatial models).network- the Network representation derived from the geometry (may be null).data- array of node trait values used for coloring or other per-node state.colorMap- maps node trait values (T) to display colors.label- optional label displayed on the graph wrapper.animate- flag enabling/disabling animated layout progress.invalidated/noGraph/hasMessage- control redraw and message display behavior.hitNode- index of last node hit by touch/mouse interactions.- Return codes for
findNodeAt(int,int):FINDNODEAT_OUT_OF_BOUNDSandFINDNODEAT_UNIMPLEMENTEDare used to signal special cases.
Extensibility:
Subclasses should concentrate on rendering and input mapping for a specific geometry (e.g. linear history plot, 2D lattice, 3D view). They should:- Populate and maintain the
dataarray andcolorMapas needed. - Implement
getCSSColorAt(int)to return a valid CSS color string for a node. - Implement
drawLattice()for static lattice-based layouts anddrawNetwork()for network-based rendering.drawNetwork()is invoked after network layout is finished (or repeatedly during animated layout). - Implement
findNodeAt(int,int)to map screen coordinates to node indices and honor the documented special return values.
- Author:
- Christoph Hauert
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractGraph
AbstractGraph.HasLogScaleY, 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.static final StringThe CSS class name for changing the cursor when hovering over a node.(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 AbstractGeometryThe 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, CSS_CURSOR_MOVE_VIEW, CURSOR_GRAB_NODE_CLASS, CURSOR_MOVE_NODE_CLASS, CURSOR_ZOOM_IN_CLASS, CURSOR_ZOOM_OUT_CLASS, DEFAULT_BUFFER_SIZE, doubleClickHandler, element, g, hasMessage, hasZoom, leftMouseButton, logger, logYMenu, 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, view, 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
ConstructorsModifierConstructorDescriptionprotectedGenericPopGraph(AbstractView<?> view, Module<?> module) Create the base class for population graphs. -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate()Perform necessary preparations to show the graph in the GUI.private voidaddAnimateMenu(ContextMenu menu) Helper method to process the debug submenu logic for context menu.private voidaddClearMenu(ContextMenu menu) Helper method to process the clear context menu.private voidaddDebugSubmenu(ContextMenu menu, int x, int y) Helper method to process the debug submenu logic for context menu.private voidaddShakeMenu(ContextMenu menu) Helper method to process the debug submenu logic for context menu.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) protected voidonLoad()voidonResize()voidonTouchStart(TouchStartEvent event) protected voidonUnload()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(AbstractGeometry 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, fillCircle, fillCircle, fillRect, fillTextVertical, getBuffer, getModule, getStyle, hasHistory, init, onMouseDown, onMouseMove, onMouseOut, onMouseUp, onMouseWheel, onTouchEnd, onTouchMove, paint, parse, prependTime2Data, resetTransforms, setBufferCapacity, setColors, setFont, setLogY, setMarkers, setMarkers, setStrokeStyleAt, setTooltipProvider, shift, stroke, strokeCircle, strokeCircle, strokeCircle, strokeLine, 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, 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
-
EVOLUDO_CURSOR_NODE
The CSS class name for changing the cursor when hovering over a node.- See Also:
-
geometry
The structure of the population. -
network
-
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
-
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:
view- the view of this graphmodule- the module backing the graph
-
-
Method Details
-
onLoad
protected void onLoad()- Overrides:
onLoadin classAbstractGraph<T[]>
-
onUnload
protected void onUnload()- Overrides:
onUnloadin classAbstractGraph<T[]>
-
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
-
getColorMap
-
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 view 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:
-
addShakeMenu
Helper method to process the debug submenu logic for context menu.- Parameters:
menu- the context menu to which the shake menu is added
-
addAnimateMenu
Helper method to process the debug submenu logic for context menu.- Parameters:
menu- the context menu to which the animate menu is added
-
addClearMenu
Helper method to process the clear context menu.- Parameters:
menu- the context menu to which the clear menu is added
-