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.PopGraphController
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 int
The height of a node for lattices.protected int
Convenience variable.protected int
The diameter of nodes for networks.protected int
The width of a node for lattices.protected int
Convenience variable.(package private) static final int
Convenience variable.protected boolean
The flag to indicate whetherGenericPopGraph.hitNode
is being dragged.(package private) int
Convenience variable.(package private) int[]
Convenience variable.(package private) boolean
Convenience variable.static final int
The maximum size of a linear graph.(package private) static final int
The minimum height of a node in pixels.(package private) static final int
The minimum diameter of a node in pixels.(package private) static final int
The minimum width of a node in pixels.protected int
The 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, noGraph
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
ConstructorsConstructorDescriptionPopGraph2D
(GenericPopGraph.PopGraphController controller, Module module) Create a graph for graphically visualizing the structure of a network (or population). -
Method Summary
Modifier and TypeMethodDescriptionvoid
activate()
Perform necessary preparations to show the graph in the GUI.void
calcBounds
(int width, int height) Calculate bounds of drawing area.protected void
Draws structures with static layout of lattices.protected void
Draws the network.void
Export the graphical contextctx
.int
findNodeAt
(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 indexnode
as a CSS color string.void
onMouseDown
(MouseDownEvent event) void
onMouseMove
(MouseMoveEvent event) void
onMouseUp
(MouseUpEvent event) .evoludo-cursorGrabNode removed from graph element. .evoludo-cursorMoveNode removed from graph element.void
onTouchEnd
(TouchEndEvent event) void
onTouchMove
(TouchMoveEvent event) move one finger on node shift node.boolean
paint
(boolean force) Draw the graph.private boolean
Helper method to get the canvas ready for drawing the graph.void
setGeometry
(Geometry geometry) Set the geometry backing the graph.void
shiftNodeBy
(int nodeidx, int dx, int dy) Shift a single node with indexnodeidx
by(dx, dy)
.void
update
(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, setGraphLabel
Methods 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, 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.Shifter
shift
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 MouseOutHandler
onMouseOut
Methods inherited from interface MouseWheelHandler
onMouseWheel
Methods 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.hitNode
is 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:GenericPopGraph
Set the geometry backing the graph.- Overrides:
setGeometry
in classGenericPopGraph<String,
Network2D> - Parameters:
geometry
- the structure of the population
-
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 classGenericPopGraph<String,
Network2D> - See Also:
-
update
public void update(boolean isNext) Update the graph.- Overrides:
update
in classGenericPopGraph<String,
Network2D> - Parameters:
isNext
-true
if the state has changed
-
paint
public boolean paint(boolean force) Draw the graph. For re-drawing the graph, setforce
totrue
.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:
paint
in classGenericPopGraph<String,
Network2D> - Parameters:
force
-true
to force re-drawing of graph- Returns:
true
if painting skipped- See Also:
-
drawLattice
protected void drawLattice()Description copied from class:GenericPopGraph
Draws structures with static layout of lattices.- Specified by:
drawLattice
in classGenericPopGraph<String,
Network2D> - See Also:
-
drawNetwork
protected void drawNetwork()Description copied from class:GenericPopGraph
Draws the network.- Specified by:
drawNetwork
in classGenericPopGraph<String,
Network2D>
-
prepCanvas
private boolean prepCanvas()Helper method to get the canvas ready for drawing the graph.- Returns:
true
if the canvas is ready for drawing
-
calcBounds
public void calcBounds(int width, int height) Description copied from class:AbstractGraph
Calculate bounds of drawing area.- Overrides:
calcBounds
in classAbstractGraph<String[]>
- Parameters:
width
- the width of the drawing areaheight
- the height of the drawing area
-
getCSSColorAt
Get the color of the node at indexnode
as a CSS color string.- Specified by:
getCSSColorAt
in 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:
findNodeAt
in 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
MouseMoveEvent
s.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
MouseMoveEvent
s.CSS Style Rules
- .evoludo-cursorGrabNode
- added to graph element.
- Specified by:
onMouseDown
in interfaceMouseDownHandler
- Overrides:
onMouseDown
in 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:
onMouseUp
in interfaceMouseUpHandler
- Overrides:
onMouseUp
in 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
MouseDownEvent
and 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:
onMouseMove
in interfaceMouseMoveHandler
- Overrides:
onMouseMove
in classAbstractGraph<String[]>
- See Also:
-
onTouchEnd
The number of touches on the graph changed.
The number of touches on the graph changed.
- Specified by:
onTouchEnd
in interfaceTouchEndHandler
- Overrides:
onTouchEnd
in 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:
onTouchMove
in interfaceTouchMoveHandler
- Overrides:
onTouchMove
in classAbstractGraph<String[]>
-
shiftNodeBy
public void shiftNodeBy(int nodeidx, int dx, int dy) Shift a single node with indexnodeidx
by(dx, dy)
. Positivedx
shift the node to the right and positivedy
shift 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:AbstractGraph
Export the graphical contextctx
.- Specified by:
export
in classAbstractGraph<String[]>
- Parameters:
ctx
- the graphical context to export
-