Class PopGraph2D
- 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.Shifter,AbstractGraph.Shifting,AbstractGraph.Zoomer,AbstractGraph.Zooming,Network.LayoutListener,ContextMenu.Listener,ContextMenu.Provider,Tooltip.Provider
The graph is interactive and allows the user to zoom and shift the view as well as customize the placement of nodes. The user can change the state of nodes by by double-clicking on them. The graph can be exported in PNG or SVG graphics formats.
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested classes/interfaces inherited from class GenericPopGraph
GenericPopGraph.PopGraphControllerNested 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 intThe height of a node for lattices.protected intConvenience variable.protected intThe diameter of nodes for networks.protected intThe width of a node for lattices.protected intConvenience variable.(package private) static final intConvenience variable.protected booleanThe flag to indicate whetherGenericPopGraph.hitNodeis being dragged.(package private) intConvenience variable.(package private) int[]Convenience variable.(package private) booleanConvenience variable.static final intThe maximum size of a linear graph.(package private) static final intThe minimum height of a node in pixels.(package private) static final intThe minimum diameter of a node in pixels.(package private) static final intThe minimum width of a node in pixels.protected intThe size of the graph for lattices.Fields inherited from class GenericPopGraph
animate, colorMap, data, FINDNODEAT_OUT_OF_BOUNDS, FINDNODEAT_UNIMPLEMENTED, geometry, hitNode, invalidated, label, MAX_ANIMATE_LAYOUT_LINKS_DEFAULT, MAX_ANIMATE_LAYOUT_VERTICES_DEFAULT, network, noGraphFields 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
ConstructorsConstructorDescriptionPopGraph2D(GenericPopGraph.PopGraphController controller, Module module) Create a graph for graphically visualizing the structure of a network (or population). -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate()Perform necessary preparations to show the graph in the GUI.voidcalcBounds(int width, int height) Calculate bounds of drawing area.protected voidDraws structures with static layout of lattices.protected voidDraws the network.voidExport the graphical contextctx.intfindNodeAt(int x, int y) Find the index of the node at the location with coordinates(x, y).getCSSColorAt(int node) Get the color of the node at indexnodeas a CSS color string.voidonMouseDown(MouseDownEvent event) voidonMouseMove(MouseMoveEvent event) voidonMouseUp(MouseUpEvent event) .evoludo-cursorGrabNode removed from graph element. .evoludo-cursorMoveNode removed from graph element.voidonTouchEnd(TouchEndEvent event) voidonTouchMove(TouchMoveEvent event) move one finger on node shift node.booleanpaint(boolean force) Draw the graph.private booleanHelper method to get the canvas ready for drawing the graph.voidsetGeometry(Geometry geometry) Set the geometry backing the graph.voidshiftNodeBy(int nodeidx, int dx, int dy) Shift a single node with indexnodeidxby(dx, dy).voidupdate(boolean isNext) Update the graph.Methods inherited from class GenericPopGraph
getColorMap, getData, getGeometry, getNetwork, getTooltipAt, hasAnimatedLayout, hasMessage, hasStaticLayout, invalidate, layoutComplete, layoutNetwork, layoutUpdate, onDoubleClick, onResize, onTouchStart, populateContextMenuAt, reset, setColorMap, setDebugEnabled, setGraphLabelMethods inherited from class AbstractGraph
addContextMenuHandler, autoscale, calcBounds, clearCanvas, clearGraph, clearHistory, clearMessage, contains, convertToScaledCoordinates, convertToScaledCoordinates, deactivate, displayMessage, doUpdate, drawFrame, drawFrame, fill, fillCircle, fillRect, fillTextVertical, getBuffer, getModule, getStyle, hasHistory, init, onMouseOut, onMouseWheel, 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.Shifter
shiftMethods 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 MouseOutHandler
onMouseOutMethods inherited from interface MouseWheelHandler
onMouseWheelMethods inherited from interface TouchStartHandler
onTouchStart
-
Field Details
-
MAX_LINEAR_SIZE
public static final int MAX_LINEAR_SIZEThe maximum size of a linear graph. This affects memory allocation to retain the history of the graph.- See Also:
-
side
protected int sideThe size of the graph for lattices. -
dw
protected int dwThe width of a node for lattices. -
dw2
protected int dw2Convenience variable. One half of the width of a node for lattices,dw/2. -
dh
protected int dhThe height of a node for lattices. -
dh3
protected int dh3Convenience variable. One third of the height of a node for lattices,dh/3. -
dR
protected int dRThe diameter of nodes for networks. -
MIN_DW
static final int MIN_DWThe minimum width of a node in pixels.- See Also:
-
MIN_DH
static final int MIN_DHThe minimum height of a node in pixels.- See Also:
-
MIN_DR
static final int MIN_DRThe minimum diameter of a node in pixels.- See Also:
-
isHierarchy
boolean isHierarchyConvenience variable. The flag indicating whether the backing geometry is a hierarchical structure. -
hLevels
int hLevelsConvenience variable. The number of hierarchical levels. -
hPeriods
int[] hPeriodsConvenience variable. The number of units in each hierarchical level. -
HIERARCHY_GAP
static final int HIERARCHY_GAPConvenience variable. The gap between subsequent units in hierarchical structures.- See Also:
-
hitDragged
protected boolean hitDraggedThe flag to indicate whetherGenericPopGraph.hitNodeis being dragged.
-
-
Constructor Details
-
PopGraph2D
Create a graph for graphically visualizing the structure of a network (or population). Allocates the canvas and the label and retrieves the shared tooltip and context menu.CSS Style Rules
- .evoludo-PopGraph2D
- the graph element.
- .evoludo-Label2D
- the label element.
- Parameters:
controller- the controller of this graphmodule- the module backing the graph
-
-
Method Details
-
setGeometry
Description copied from class:GenericPopGraphSet the geometry backing the graph.- Overrides:
setGeometryin classGenericPopGraph<String,Network2D> - Parameters:
geometry- the structure of the population
-
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 classGenericPopGraph<String,Network2D> - See Also:
-
update
public void update(boolean isNext) Update the graph.- Overrides:
updatein classGenericPopGraph<String,Network2D> - Parameters:
isNext-trueif the state has changed
-
paint
public boolean paint(boolean force) Draw the graph. For re-drawing the graph, setforcetotrue.Depending on the backing geometry this either
- shows a message, if no graphical representation is available, e.g. for 3D cubic lattices, or if there are too many nodes so that each node becomes to small to display on screen.
- shows lattice geometries.
- initiates the generic layouting process for arbitrary network structures.
- Overrides:
paintin classGenericPopGraph<String,Network2D> - Parameters:
force-trueto force re-drawing of graph- Returns:
trueif painting skipped- See Also:
-
drawLattice
protected void drawLattice()Description copied from class:GenericPopGraphDraws structures with static layout of lattices.- Specified by:
drawLatticein classGenericPopGraph<String,Network2D> - See Also:
-
drawNetwork
protected void drawNetwork()Description copied from class:GenericPopGraphDraws the network.- Specified by:
drawNetworkin classGenericPopGraph<String,Network2D>
-
prepCanvas
private boolean prepCanvas()Helper method to get the canvas ready for drawing the graph.- Returns:
trueif the canvas is ready for drawing
-
calcBounds
public void calcBounds(int width, int height) Description copied from class:AbstractGraphCalculate bounds of drawing area.- Overrides:
calcBoundsin classAbstractGraph<String[]>- Parameters:
width- the width of the drawing areaheight- the height of the drawing area
-
getCSSColorAt
Get the color of the node at indexnodeas a CSS color string.- Specified by:
getCSSColorAtin classGenericPopGraph<String,Network2D> - Parameters:
node- the index of the node- Returns:
- the color of the node
-
findNodeAt
public int findNodeAt(int x, int y) Find the index of the node at the location with coordinates(x, y).- Specified by:
findNodeAtin classGenericPopGraph<String,Network2D> - Parameters:
x- thex-coordinate of the locationy- they-coordinate of the location- Returns:
- the index of the node
-
onMouseDown
If a node has been hit by a left-click, remember the node's index and the current mouse coordinates. This information might be used by subsequent
MouseMoveEvents.If a node has been hit by a left-click, remember the node's index and the current mouse coordinates. This information might be used by subsequent
MouseMoveEvents.CSS Style Rules
- .evoludo-cursorGrabNode
- added to graph element.
- Specified by:
onMouseDownin interfaceMouseDownHandler- Overrides:
onMouseDownin classAbstractGraph<String[]>- See Also:
-
onMouseUp
Cancel all interactions with the graph and reset node and mouse information.
CSS Style Rules
- .evoludo-cursorMoveView
- removed from graph element.
- .evoludo-cursorGrabNode
- removed from graph element.
- .evoludo-cursorMoveNode
- removed from graph element.
- Specified by:
onMouseUpin interfaceMouseUpHandler- Overrides:
onMouseUpin classAbstractGraph<String[]>- See Also:
-
onMouseMove
If the left mouse-key is pressed the graph is shifted within its viewport. Note this requires that the zoom level of the graph exceeds
1.CSS Style Rules
- .evoludo-cursorMoveView
- added to graph element when shifting the view.
If a node has been hit by a
MouseDownEventand is being dragged, the position of the node is shifted. This allows to customize the display of the graph.CSS Style Rules
- .evoludo-cursorMoveNode
- added to graph element when dragging a node.
- Specified by:
onMouseMovein interfaceMouseMoveHandler- Overrides:
onMouseMovein classAbstractGraph<String[]>- See Also:
-
onTouchEnd
The number of touches on the graph changed.
The number of touches on the graph changed.
- Specified by:
onTouchEndin interfaceTouchEndHandler- Overrides:
onTouchEndin classAbstractGraph<String[]>
-
onTouchMove
The graph reacts to different kinds of touch moves:
- Move one finger
- Shift view
- Pinch two fingers
- Zoom view
- move one finger on node
- shift node.
- Specified by:
onTouchMovein interfaceTouchMoveHandler- Overrides:
onTouchMovein classAbstractGraph<String[]>
-
shiftNodeBy
public void shiftNodeBy(int nodeidx, int dx, int dy) Shift a single node with indexnodeidxby(dx, dy). Positivedxshift the node to the right and positivedyshift upwards.- Parameters:
nodeidx- the index of the nodedx- the horizontal shift of the nodedy- the vertical shift of the node
-
export
Description copied from class:AbstractGraphExport the graphical contextctx.- Specified by:
exportin classAbstractGraph<String[]>- Parameters:
ctx- the graphical context to export
-