Class ParaGraph
- 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.HasTrajectory,AbstractGraph.Shifter,AbstractGraph.Shifting,AbstractGraph.Zoomer,AbstractGraph.Zooming,ContextMenu.Listener,ContextMenu.Provider,Tooltip.Provider
The graph is backed by a RingBuffer to store the trajectory. The
buffer is updated by calling addData(double, double[], boolean). It
is interactive and allows the user to zoom and shift the view. The user can
set the initial state by double-clicking on the graph. The graph can be
exported in PNG or SVG graphics formats or the trajectory data as CSV.
The graph provides fine grained configurations for mapping the data to the phase plane, for tooltips, for markers as well as for the style of the graph.
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassDefault mapping of data to the phase plane or phase plane projections.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 TypeFieldDescriptionprivate ContextMenuCheckBoxItemThe context menu item to autoscale the axes.private doubleThreshold for storing new data point in buffer.private ContextMenuItemThe context menu item to clear the canvas.(package private) booleanThe flag to indicate autoscaling of axes.(package private) double[]The starting point of the most recent trajectory.(package private) HasPhase2D.Data2PhaseThe map for converting data to phase plane coordinates.private static doubleThe minimum distance between two subsequent points in pixels.private booleanThe flag to indicate whether painting is already scheduled.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
ConstructorsConstructorDescriptionParaGraph(AbstractGraph.Controller controller, Module module) Create new parametric graph formodulerunning incontroller. -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate()Perform necessary preparations to show the graph in the GUI.voidaddData(double t, double[] data, boolean force) Add data to the graph.voidAutomatically adjust the range of both axes to fit the data in the buffer.voidcalcBounds(int width, int height) Calculate bounds of drawing area.private doubledistSq(double[] vec, double[] buf) Helper method to calculate the distance squared between two vectors.voidExport the graphical contextctx.voidexportTrajectory(StringBuilder export) Export the trajectory of the graph toexport.getMap()Get the map for converting data to phase plane coordinates.getTooltipAt(int x, int y) Get the tooltip information for the location with coordinates(x, y).private booleaninside(double x, double y) Check if point (in user coordinates but not yet scaled to axes) lies inside of phase plane.voidonDoubleClick(DoubleClickEvent event) voidonTouchStart(TouchStartEvent event) booleanpaint(boolean force) Draw the graph.private voidpaintPara(boolean withMarkers) Paint the trajectory in the phase plane.voidpopulateContextMenuAt(ContextMenu menu, int x, int y) Populate context menumenuin listening widget at (relative) position(x,y).private voidprocessInitXY(double x, double y) Helper method to convert screen coordinates into an initial configuration and set the controller's initial state.protected voidSchedule painting of the graph.voidSet the map for converting data to phase plane coordinates.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, hasMessage, init, onMouseDown, onMouseMove, onMouseOut, onMouseUp, onMouseWheel, onResize, onTouchEnd, onTouchMove, paint, prependTime2Data, reset, 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 MouseDownHandler
onMouseDownMethods inherited from interface MouseMoveHandler
onMouseMoveMethods inherited from interface MouseOutHandler
onMouseOutMethods inherited from interface MouseUpHandler
onMouseUpMethods inherited from interface MouseWheelHandler
onMouseWheelMethods inherited from interface TouchEndHandler
onTouchEndMethods inherited from interface TouchMoveHandler
onTouchMove
-
Field Details
-
init
double[] initThe starting point of the most recent trajectory. -
map
The map for converting data to phase plane coordinates. -
doAutoscale
boolean doAutoscaleThe flag to indicate autoscaling of axes. -
bufferThreshold
private double bufferThresholdThreshold for storing new data point in buffer. Roughly corresponds to the squared distance between two points that are at least a pixel apart. -
MIN_PIXELS
private static double MIN_PIXELSThe minimum distance between two subsequent points in pixels. -
paintScheduled
private boolean paintScheduledThe flag to indicate whether painting is already scheduled. Subsequent requests are ignored. -
clearMenu
The context menu item to clear the canvas. -
autoscaleMenu
The context menu item to autoscale the axes.
-
-
Constructor Details
-
ParaGraph
Create new parametric graph formodulerunning incontroller.- 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<double[]>- See Also:
-
setMap
Set the map for converting data to phase plane coordinates.- Parameters:
map- the conversion map
-
getMap
Get the map for converting data to phase plane coordinates.- Returns:
- the conversion map
-
addData
public void addData(double t, double[] data, boolean force) Add data to the graph. The timetis prepended to the data as the first element.- Parameters:
t- the time of the datadata- the data to addforce-trueto force adding the data- Implementation Notes:
- The data array is cloned and the time prepended before adding it to the buffer.
- In order to conserve memory the data is added only if the
distance between
the new data point and the last point in the buffer is larger
than threshold
bufferThreshold, unlessforce == true.
-
distSq
private double distSq(double[] vec, double[] buf) Helper method to calculate the distance squared between two vectors.- Parameters:
vec- the first vectorbuf- the second vector- Returns:
- the squared distance
-
paint
public boolean paint(boolean force) Description copied from class:AbstractGraphDraw the graph. For re-drawing the graph, setforcetotrue.- Overrides:
paintin classAbstractGraph<double[]>- Parameters:
force-trueto force re-drawing of graph- Returns:
trueif painting skipped
-
paintPara
private void paintPara(boolean withMarkers) Paint the trajectory in the phase plane. IfwithMarkersistruethe start and end points of the trajectory are marked with green and red circles, respectively.- Parameters:
withMarkers-trueto mark start and end points
-
calcBounds
public void calcBounds(int width, int height) Description copied from class:AbstractGraphCalculate bounds of drawing area.- Overrides:
calcBoundsin classAbstractGraph<double[]>- Parameters:
width- the width of the drawing areaheight- the height of the drawing area
-
autoscale
public void autoscale()Automatically adjust the range of both axes to fit the data in the buffer. -
schedulePaint
protected void schedulePaint()Schedule painting of the graph. If painting is already scheduled, subsequent requests are ignored.- See Also:
-
export
Description copied from class:AbstractGraphExport the graphical contextctx.- Specified by:
exportin classAbstractGraph<double[]>- Parameters:
ctx- the graphical context to export
-
onDoubleClick
- Specified by:
onDoubleClickin interfaceDoubleClickHandler
-
processInitXY
private void processInitXY(double x, double y) Helper method to convert screen coordinates into an initial configuration and set the controller's initial state.- Parameters:
x- thex-coordinate on screeny- they-coordinate on screen
-
onTouchStart
Description copied from class:AbstractGraphThe 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.
- Specified by:
onTouchStartin interfaceTouchStartHandler- Overrides:
onTouchStartin classAbstractGraph<double[]>- See Also:
-
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
-
inside
private boolean inside(double x, double y) Check if point (in user coordinates but not yet scaled to axes) lies inside of phase plane.- Parameters:
x-x-coordinate of pointy-y-coordinate of point- Returns:
trueif inside
-
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<double[]>- Parameters:
menu- context menu entries are added herex- horizontal coordinate (relative to listening widget)y- horizontal coordinate (relative to listening widget)- See Also:
-
exportTrajectory
Description copied from interface:AbstractGraph.HasTrajectoryExport the trajectory of the graph toexport.- Specified by:
exportTrajectoryin interfaceAbstractGraph.HasTrajectory- Parameters:
export- the string builder to export the trajectory
-