Class AbstractGraph<B>
- Type Parameters:
B
- the type of buffer backing the graph: typically this isdouble[]
but in some casesColor[]
,String[]
orMeshLambertMaterial[]
forPop2D
,PopGraph2D
orPopGraph3D
, respectively.
- All Implemented Interfaces:
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>
,ContextMenu.Listener
,ContextMenu.Provider
,Tooltip.Provider
- Direct Known Subclasses:
GenericPopGraph
,HistoGraph
,LineGraph
,ParaGraph
,S3Graph
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
The base interface for communicating with the controller of all graphs.static class
The style features for graphs.static interface
Graphs that show trajectories and support exporting their data should implement this interface.static class
Create custom Context2d that admits drawing dashed lines.static interface
Graphs that support shifting of their view should implement this interface.static interface
Graphs that support shifting should implement this interface.class
The zoom command for the context menu.static interface
Graphs that support zooming should implement this interface.static interface
Graphs that support zooming should implement this interface.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 Rectangle2D
The bounds of the displaying area.protected RingBuffer
<B> The buffer to store historical data, if applicable.private ContextMenu
The context menu to set the buffer size for graphs with historical data.private ContextMenuItem
The context menu item which triggers the buffer size context menu.protected Canvas
Handle to the canvas for drawing the graphics.protected String[]
The array of colors used for drawing the graph.protected ContextMenu
The reference to the (shared) context menu.protected AbstractGraph.Controller
The controller of this graph.protected static final int
The default buffer size.(package private) HandlerRegistration
The handler forDoubleClickEvent
s.protected Element
Handle to the object's underlying DOM element.protected AbstractGraph.MyContext2d
Handle to the graphical context for drawing on the canvas.protected boolean
Flag to indicate whether the graph displays a message.protected boolean
The flag to indicate whether the graph supports zoom.protected boolean
The flag to indicate whether the graph is live (visible, activated).protected boolean
The flag to indicate whether the left mouse button is pressed.protected Logger
Logger for keeping track of and reporting events and issues.protected String[]
The array of colors used for markers.protected ArrayList
<double[]> Markers for decorating the graph.private static final int
The maximum number of line segments to draw before returning control to the event loop.protected static final int
The minimum buffer size.static final int
The minimum time between updates in milliseconds.protected Module
The module backing the graph.(package private) HandlerRegistration
The handler forMouseDownEvent
s.(package private) HandlerRegistration
The handler forMouseMoveEvent
s.(package private) HandlerRegistration
The handler forMouseOutEvent
s.(package private) HandlerRegistration
The handler forMouseUpEvent
s.(package private) HandlerRegistration
The handler forMouseWheelEvent
s.protected int
Thex
-coordinate of the previous mouse or tap event.protected int
They
-coordinate of the previous mouse or tap event.protected static final double
Constant representing the numerical value ofprotected double
The distance between the pinching gesture.protected int
Thex
-coordinate of the center of the pinching gesture.protected int
They
-coordinate of the center of the pinching gesture.protected double
The scale of this graph.(package private) AbstractGraph.Shifter
The controller for shifting this graph.protected AbstractGraph.GraphStyle
The style of the graph.protected Tooltip
The reference to the (shared) tooltip.(package private) BasicTooltipProvider
The provider for tooltips.(package private) HandlerRegistration
The handler forTouchEndEvent
s.protected double
The time when the previous touch ended.(package private) HandlerRegistration
The handler forTouchMoveEvent
s.(package private) HandlerRegistration
The handler forTouchStartEvent
s.private static final double
Constant representing the numerical value ofprotected double
The field to store the time of the last update.protected Point2D
The coordinates of the lower left corner visible on the canvas.(package private) LayoutPanel
The wrapper element which displays the canvas.(package private) AbstractGraph.Zoomer
The controller for zooming this graph.protected double
The current zoom level.protected Timer
The timer to remove the CSS classes.evoludo-cursorZoomIn
or.evoludo-cursorZoomIn
, respectively, from the graph element after the inertia of zooming has worn off.(package private) ContextMenuItem
The context menu item to zoom in (enlarge) by a factor of2
.(package private) ContextMenuItem
The context menu item to zoom out (reduce) by a factor of1/2
.(package private) ContextMenuItem
The context menu item to reset the zoom level.Fields inherited from class UIObject
DEBUG_ID_PREFIX
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractGraph
(AbstractGraph.Controller controller, Module module) Create the base class for graphs. -
Method Summary
Modifier and TypeMethodDescriptionvoid
activate()
Perform necessary preparations to show the graph in the GUI.addContextMenuHandler
(ContextMenuHandler handler) void
autoscale
(boolean x, boolean y) Set auto-scaling for horizontal and vertical axes.protected boolean
Calculate bounds of drawing area.void
calcBounds
(int width, int height) Calculate bounds of drawing area.protected void
Clear the canvas.void
Clear the graph.void
Clear the history of the graph (if there is one).void
Clear the message.private void
closePath
(boolean fill) Helper method to close the path and draw (or fill) it.boolean
contains
(int x, int y) Checks if the (browser) coordinates(x, y)
are inside this graph.convertToScaledCoordinates
(int x, int y) Convert the (browser) coordinates(x, y)
to scaled coordinates in .convertToScaledCoordinates
(int x, int y, Point2D dest) Convert the (browser) coordinates(x, y)
to scaled coordinates in and store indest
.void
The graph is removed from the GUI.boolean
displayMessage
(String msg) Display messagemsg
on the graph (no HTML formatting).boolean
doUpdate()
Determine whether it is time to update the display.protected void
drawFrame
(int xLevels, int yLevels) Draw the frame of the graph including axis labels, ticks and tick marks, as applicable.protected void
drawFrame
(int xLevels, int yLevels, double gscale) Draw the frame of the graph including axis labels, ticks and tick marks, as applicable, after scaling the canvas bygscale
.abstract void
Export the graphical contextctx
.protected void
Fill the pathpath
.protected void
fillCircle
(double x, double y, double radius) Fill the circle with the center at(x,y)
and radiusradius
.protected void
fillRect
(double x, double y, double w, double h) Fill the rectangle with origin at(x,y)
, widthw
and heighth
.protected void
fillTextVertical
(String msg, double x, double y) Draw filled text vertically starting at point(x,y)
Return theRingBuffer<double[]>
containing historical data, if applicable.Get the module that backs the graph.getStyle()
Get the graph style.boolean
Check whether the graph entertains a buffer with historical data.boolean
Check if the graph displays a message.void
init()
Initialize the graph.void
onMouseDown
(MouseDownEvent event) void
onMouseMove
(MouseMoveEvent event) void
onMouseOut
(MouseOutEvent event) void
onMouseUp
(MouseUpEvent event) void
onMouseWheel
(MouseWheelEvent event) void
onResize()
void
onTouchEnd
(TouchEndEvent event) void
onTouchMove
(TouchMoveEvent event) void
onTouchStart
(TouchStartEvent event) void
paint()
Draw the graph.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)
.protected double[]
prependTime2Data
(double t, double[] data) Utility method to prepend time to data point.void
reset()
Reset the graph.protected void
Reset the transformation of the graphics context to the identity transform.protected void
setBufferCapacity
(int capacity) Sets the buffer capacity tocapacity
, if applicable.void
Assign a list of colors to the graph.protected void
Set the font tocssfont
in CSS format for drawing on the canvas.void
setMarkers
(ArrayList<double[]> markers) Assign a list of markers to the graph.void
setMarkers
(ArrayList<double[]> markers, String[] colors) Assign a list of markers with custom colors to the graph.protected void
setStrokeStyleAt
(int node) Set the stroke colour for node with indexnode
.void
setTooltipProvider
(BasicTooltipProvider tooltipProvider) Set the provider for tooltips.void
shift
(int dx, int dy) Shift the (zoomed) graph within the view port by(dx, dy)
.private void
Draw or fill (iffill == true
) the pathpath
.private void
sketchCircle
(double x, double y, double radius) Helper method to create a path for a circle with the center at(x,y)
and radiusradius
.protected void
Draw the pathpath
.protected void
strokeCircle
(double x, double y, double radius) Draw the circle with the center at(x,y)
and radiusradius
.protected void
strokeLine
(double sx, double sy, double ex, double ey) Draw a line from point(sx,sy)
to(ex,ey)
.protected void
strokeRect
(double x, double y, double w, double h) Draw the rectangle with origin at(x,y)
, widthw
and heighth
.private void
Update the canvas size and coordinate space dimensions.void
zoom()
Reset zoom.void
zoom
(double zoom) Adjust zoom level by the factorzoom
.protected void
zoom
(double zoom, double fx, double fy) Helper method to adjust zoom level with the zoom center at the scaled coordinates(fx, fy)
, specified as a fraction of the view port in horizontal and vertical directions, respectively.void
zoom
(double zoom, int x, int y) Adjust zoom level by the factorzoom
with the center at coordinates(x,y)
(in display coordinates as provided by event listeners).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 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 Tooltip.Provider
getTooltipAt
-
Field Details
-
doubleClickHandler
HandlerRegistration doubleClickHandlerThe handler forDoubleClickEvent
s. -
mouseOutHandler
HandlerRegistration mouseOutHandlerThe handler forMouseOutEvent
s. -
mouseDownHandler
HandlerRegistration mouseDownHandlerThe handler forMouseDownEvent
s. -
mouseUpHandler
HandlerRegistration mouseUpHandlerThe handler forMouseUpEvent
s. -
mouseMoveHandler
HandlerRegistration mouseMoveHandlerThe handler forMouseMoveEvent
s. -
mouseWheelHandler
HandlerRegistration mouseWheelHandlerThe handler forMouseWheelEvent
s. -
touchStartHandler
HandlerRegistration touchStartHandlerThe handler forTouchStartEvent
s. -
touchEndHandler
HandlerRegistration touchEndHandlerThe handler forTouchEndEvent
s. -
touchMoveHandler
HandlerRegistration touchMoveHandlerThe handler forTouchMoveEvent
s. -
zoomFactor
protected double zoomFactorThe current zoom level. -
viewCorner
The coordinates of the lower left corner visible on the canvas. -
controller
The controller of this graph. -
shifter
AbstractGraph.Shifter shifterThe controller for shifting this graph. -
zoomer
AbstractGraph.Zoomer zoomerThe controller for zooming this graph. -
contextMenu
The reference to the (shared) context menu. -
tooltip
The reference to the (shared) tooltip. -
tooltipProvider
BasicTooltipProvider tooltipProviderThe provider for tooltips. -
scale
protected double scaleThe scale of this graph. Used to translatewidth
andheight
into canvas coordinates. For example, on retina displays the scale is typically2
, i.e. two pixels per unit width or height.- See Also:
-
wrapper
LayoutPanel wrapperThe wrapper element which displays the canvas. Subclasses may use this to add further elements to the graph such as labels. -
logger
Logger for keeping track of and reporting events and issues. -
element
Handle to the object's underlying DOM element. -
canvas
Handle to the canvas for drawing the graphics. -
g
Handle to the graphical context for drawing on the canvas. -
colors
The array of colors used for drawing the graph. -
markers
Markers for decorating the graph. -
markerColors
The array of colors used for markers. -
module
The module backing the graph. -
isActive
protected boolean isActiveThe flag to indicate whether the graph is live (visible, activated). -
bounds
The bounds of the displaying area. This excludes any frames and/or axis labels. -
style
The style of the graph. Includes labels, fonts, etc. -
buffer
The buffer to store historical data, if applicable. -
MIN_BUFFER_SIZE
protected static final int MIN_BUFFER_SIZEThe minimum buffer size.- See Also:
-
DEFAULT_BUFFER_SIZE
protected static final int DEFAULT_BUFFER_SIZEThe default buffer size. Must be at leastMIN_BUFFER_SIZE
.- See Also:
-
MIN_MSEC_BETWEEN_UPDATES
public static final int MIN_MSEC_BETWEEN_UPDATESThe minimum time between updates in milliseconds.- See Also:
-
updatetime
protected double updatetimeThe field to store the time of the last update. -
bufferSizeMenu
The context menu to set the buffer size for graphs with historical data. -
bufferSizeTrigger
The context menu item which triggers the buffer size context menu. -
hasZoom
protected boolean hasZoomThe flag to indicate whether the graph supports zoom. The default is no support. -
zoomResetMenu
ContextMenuItem zoomResetMenuThe context menu item to reset the zoom level. -
zoomInMenu
ContextMenuItem zoomInMenuThe context menu item to zoom in (enlarge) by a factor of2
. -
zoomOutMenu
ContextMenuItem zoomOutMenuThe context menu item to zoom out (reduce) by a factor of1/2
. -
TWOPI
private static final double TWOPIConstant representing the numerical value of- See Also:
-
PIHALF
protected static final double PIHALFConstant representing the numerical value of- See Also:
-
MAX_SEGEMENTS
private static final int MAX_SEGEMENTSThe maximum number of line segments to draw before returning control to the event loop.- See Also:
-
hasMessage
protected boolean hasMessageFlag to indicate whether the graph displays a message. -
leftMouseButton
protected boolean leftMouseButtonThe flag to indicate whether the left mouse button is pressed. -
mouseX
protected int mouseXThex
-coordinate of the previous mouse or tap event. -
mouseY
protected int mouseYThey
-coordinate of the previous mouse or tap event. -
touchEndTime
protected double touchEndTimeThe time when the previous touch ended. -
pinchX
protected int pinchXThex
-coordinate of the center of the pinching gesture. -
pinchY
protected int pinchYThey
-coordinate of the center of the pinching gesture. -
pinchDist
protected double pinchDistThe distance between the pinching gesture. -
zoomInertiaTimer
The timer to remove the CSS classes.evoludo-cursorZoomIn
or.evoludo-cursorZoomIn
, respectively, from the graph element after the inertia of zooming has worn off.
-
-
Constructor Details
-
Method Details
-
setTooltipProvider
Set the provider for tooltips.- Parameters:
tooltipProvider
- the provider for tooltips
-
getBuffer
Return theRingBuffer<double[]>
containing historical data, if applicable.- Returns:
- the buffer with historical data or
null
-
doUpdate
public boolean doUpdate()Determine whether it is time to update the display.- Returns:
true
if time to update graph
-
activate
public void activate()Perform necessary preparations to show the graph in the GUI. Attaches mouse and touch handlers for graphs that implementAbstractGraph.Zooming
orAbstractGraph.Shifting
interfaces.- See Also:
-
deactivate
public void deactivate()The graph is removed from the GUI. Opportunity for some clean up. Removes all mouse and touch handlers from graph.- See Also:
-
onResize
public void onResize()- Specified by:
onResize
in interfaceRequiresResize
-
updateCanvas
private void updateCanvas()Update the canvas size and coordinate space dimensions. IMPORTANT: Setting the canvas size or the coordinate space dimensions clears the canvas (even with no actual changes)! -
reset
public void reset()Reset the graph. Clear canvas and messages. -
init
public void init()Initialize the graph. Do not clear graph. -
paint
public void paint()Draw the graph. -
getModule
Get the module that backs the graph.- Returns:
- the module
-
paint
public boolean paint(boolean force) Draw the graph. For re-drawing the graph, setforce
totrue
.- Parameters:
force
-true
to force re-drawing of graph- Returns:
true
if painting skipped
-
setMarkers
Assign a list of markers to the graph.- Parameters:
markers
- the list of markers
-
setMarkers
Assign a list of markers with custom colors to the graph.- Parameters:
markers
- the list of markerscolors
- the list of custom colors
-
setColors
Assign a list of colors to the graph.- Parameters:
colors
- the list of colors
-
hasHistory
public boolean hasHistory()Check whether the graph entertains a buffer with historical data.- Returns:
true
if the graph stores the data history
-
clearHistory
public void clearHistory()Clear the history of the graph (if there is one). -
prependTime2Data
protected double[] prependTime2Data(double t, double[] data) Utility method to prepend time to data point.- Parameters:
t
- the timedata
- the data- Returns:
- the new data array including time
-
populateContextMenuAt
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
- Parameters:
menu
- context menu entries are added herex
- horizontal coordinate (relative to listening widget)y
- horizontal coordinate (relative to listening widget)- See Also:
-
setBufferCapacity
protected void setBufferCapacity(int capacity) Sets the buffer capacity tocapacity
, if applicable.- Parameters:
capacity
- the new buffer capacity
-
contains
public boolean contains(int x, int y) Checks if the (browser) coordinates(x, y)
are inside this graph. This is useful for controllers that may manage several graphs.- Parameters:
x
- thex
-coordinate to checky
- they
-coordinate to check- Returns:
true
if(x, y)
is inside graph
-
convertToScaledCoordinates
Convert the (browser) coordinates(x, y)
to scaled coordinates in .- Parameters:
x
- thex
-coordinate to converty
- they
-coordinate to convert- Returns:
- the converted coordinates
-
convertToScaledCoordinates
Convert the (browser) coordinates(x, y)
to scaled coordinates in and store indest
.- Parameters:
x
- thex
-coordinate to converty
- they
-coordinate to convertdest
- the point to save the converted coordinates- Returns:
- the converted coordinates
-
export
Export the graphical contextctx
.- Parameters:
ctx
- the graphical context to export
-
calcBounds
protected boolean calcBounds()Calculate bounds of drawing area. If element has never been visible its size is not yet known.- Returns:
true
if bounds are successfully calculated.
-
calcBounds
public void calcBounds(int width, int height) Calculate bounds of drawing area.- Parameters:
width
- the width of the drawing areaheight
- the height of the drawing area
-
drawFrame
protected void drawFrame(int xLevels, int yLevels) Draw the frame of the graph including axis labels, ticks and tick marks, as applicable.Implementation Note:
The top, left corner of the canvas is assumed to be at(0, 0)
. Flips the direction of they
-axis.- Parameters:
xLevels
- the number of vertical levelsyLevels
- the number of horizontal levels- See Also:
-
drawFrame
protected void drawFrame(int xLevels, int yLevels, double gscale) Draw the frame of the graph including axis labels, ticks and tick marks, as applicable, after scaling the canvas bygscale
.Implementation Note:
After scaling the origin(0, 0)
is assumed to be in the bottom, left corner of the canvas.- Parameters:
xLevels
- the number of vertical levelsyLevels
- the number of horizontal levelsgscale
- the scaling applied to the coordinate transformation
-
setFont
Set the font tocssfont
in CSS format for drawing on the canvas.- Parameters:
cssfont
- the font for drawing
-
setStrokeStyleAt
protected void setStrokeStyleAt(int node) Set the stroke colour for node with indexnode
.- Parameters:
node
- the index of the node
-
stroke
Draw the pathpath
.- Parameters:
path
- the path to draw
-
fill
Fill the pathpath
.- Parameters:
path
- the path to fill
-
sketch
Draw or fill (iffill == true
) the pathpath
.Implementation notes:
- Drawing too many segments at once becomes very slow (why?).
- Periodically closing and stroking the path is orders of magnitudes faster!
- This simple change renders freezing of the GUI essentially a non issue.
- SVG seems to be a stickler about opening and closing paths or empty paths (see Canvas2SVG.js)
- Parameters:
path
- the path to draw (or fill)fill
-true
to fill path
-
closePath
private void closePath(boolean fill) Helper method to close the path and draw (or fill) it.- Parameters:
fill
-true
to fill path
-
strokeRect
protected void strokeRect(double x, double y, double w, double h) Draw the rectangle with origin at(x,y)
, widthw
and heighth
.- Parameters:
x
- thex
-coordinate of the originy
- they
-coordinate of the originw
- the width of the rectangleh
- the height of the rectangle
-
fillRect
protected void fillRect(double x, double y, double w, double h) Fill the rectangle with origin at(x,y)
, widthw
and heighth
.- Parameters:
x
- thex
-coordinate of the originy
- they
-coordinate of the originw
- the width of the rectangleh
- the height of the rectangle
-
strokeCircle
protected void strokeCircle(double x, double y, double radius) Draw the circle with the center at(x,y)
and radiusradius
.- Parameters:
x
- thex
-coordinate of the centery
- they
-coordinate of the centerradius
- the radius of the circle
-
fillCircle
protected void fillCircle(double x, double y, double radius) Fill the circle with the center at(x,y)
and radiusradius
.- Parameters:
x
- thex
-coordinate of the centery
- they
-coordinate of the centerradius
- the radius of the circle
-
sketchCircle
private void sketchCircle(double x, double y, double radius) Helper method to create a path for a circle with the center at(x,y)
and radiusradius
.- Parameters:
x
- thex
-coordinate of the centery
- they
-coordinate of the centerradius
- the radius of the circle
-
strokeLine
protected void strokeLine(double sx, double sy, double ex, double ey) Draw a line from point(sx,sy)
to(ex,ey)
.- Parameters:
sx
- thex
-coordinate of the start pointsy
- they
-coordinate of the start pointex
- thex
-coordinate of the end pointey
- they
-coordinate of the end point
-
fillTextVertical
Draw filled text vertically starting at point(x,y)
- Parameters:
msg
- the text to writex
- thex
-coordinate of the start pointy
- they
-coordinate of the start point
-
clearGraph
public void clearGraph()Clear the graph. -
clearCanvas
protected void clearCanvas() -
resetTransforms
protected void resetTransforms()Reset the transformation of the graphics context to the identity transform. -
displayMessage
Display messagemsg
on the graph (no HTML formatting).Implementation note:
The message is centered and scaled such that it fills approximately two thirds of the width of the graph.- Parameters:
msg
- the message to display- Returns:
true
if message displayed
-
clearMessage
public void clearMessage()Clear the message. -
hasMessage
public boolean hasMessage()Check if the graph displays a message.- Returns:
true
if message displayed
-
zoom
public void zoom()Reset zoom. Default implementation for graphs that implementZooming
.- See Also:
-
zoom
public void zoom(double zoom) Adjust zoom level by the factorzoom
. Default implementation for graphs that implementZooming
.- Parameters:
zoom
- the new zoom level- See Also:
-
zoom
public void zoom(double zoom, int x, int y) Adjust zoom level by the factorzoom
with the center at coordinates(x,y)
(in display coordinates as provided by event listeners). Default implementation for graphs that implementZooming
.- Parameters:
zoom
- the new zoom levelx
- thex
-coordinate of the zoom centery
- they
-coordinate of the zoom center- See Also:
-
zoom
protected void zoom(double zoom, double fx, double fy) Helper method to adjust zoom level with the zoom center at the scaled coordinates(fx, fy)
, specified as a fraction of the view port in horizontal and vertical directions, respectively.- Parameters:
zoom
- the new zoom levelfx
- the scaledx
-coordinate of the zoom centerfy
- the scaledy
-coordinate of the zoom center- See Also:
-
shift
public void shift(int dx, int dy) Shift the (zoomed) graph within the view port by(dx, dy)
. Default implementation for graphs that implementShifting
.- Parameters:
dx
- the horizontal shift of the graphdy
- the vertical shift of the graph- See Also:
-
onMouseOut
If mouse leaves graph while shifting the view stop shifting. Mouse events are no longer received and hence it is impossible to track releasing or pressing mouse buttons.
- Specified by:
onMouseOut
in interfaceMouseOutHandler
-
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.- Specified by:
onMouseDown
in interfaceMouseDownHandler
- See Also:
-
onMouseUp
Cancel all interactions with the graph and reset node and mouse information.
CSS Style Rules
- .evoludo-cursorMoveView
- removed from graph element.
- Specified by:
onMouseUp
in interfaceMouseUpHandler
- 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.
- Specified by:
onMouseMove
in interfaceMouseMoveHandler
- See Also:
-
onMouseWheel
Adjusts the zoom level of the graph, while preserving the location of the mouse on the graph. The zooming has inertia.
CSS Style Rules
- .evoludo-cursorZoomIn
- added to graph element when zooming in and removed when inertia stops.
- .evoludo-cursorZoomOut
- added to graph element when zooming out and removed when inertia stops.
- Specified by:
onMouseWheel
in interfaceMouseWheelHandler
- See Also:
-
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.
- Specified by:
onTouchStart
in interfaceTouchStartHandler
- See Also:
-
onTouchEnd
The number of touches on the graph changed.
- Specified by:
onTouchEnd
in interfaceTouchEndHandler
-
onTouchMove
The graph reacts to different kinds of touch moves:
- Move one finger
- Shift view
- Pinch two fingers
- Zoom view
- Specified by:
onTouchMove
in interfaceTouchMoveHandler
-
addContextMenuHandler
- Specified by:
addContextMenuHandler
in interfaceHasContextMenuHandlers
-
getStyle
Get the graph style.- Returns:
- the graph style
-
autoscale
public void autoscale(boolean x, boolean y) Set auto-scaling for horizontal and vertical axes.- Parameters:
x
-true
to automatically scale thex
-axisy
-true
to automatically scale they
-axis
-