Package org.evoludo.graphics
Class LineGraph
Object
UIObject
Widget
Panel
SimplePanel
FocusPanel
AbstractGraph<double[]>
LineGraph
- 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>
,AbstractGraph.Shifter
,AbstractGraph.Shifting
,AbstractGraph.Zoomer
,AbstractGraph.Zooming
,BasicTooltipProvider
,ContextMenu.Listener
,ContextMenu.Provider
,Tooltip.Provider
public class LineGraph
extends AbstractGraph<double[]>
implements AbstractGraph.Shifting, AbstractGraph.Zooming, BasicTooltipProvider
Graph to visualize time series data. The graph can be shifted and zoomed.
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
The command to change the zoom level.Nested classes/interfaces inherited from class AbstractGraph
AbstractGraph.Controller, AbstractGraph.GraphStyle, AbstractGraph.HasTrajectory, AbstractGraph.MyContext2d, AbstractGraph.Shifter, AbstractGraph.Shifting, 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 TypeFieldDescriptionprivate ContextMenuItem
The context menu item to clear the graph.protected static final int
The default number of steps along thex
-axis.protected static final int
The minimum number of steps along thex
-axis.private boolean
The flag to indicate whether painting is already scheduled.(package private) Point2D
The center of the pinch gesture.(package private) double
The field to track the progress of the pinch gesture.protected double
The default number of (time) steps shown on this graph.(package private) int
The total shift in thex
-direction.(package private) int
The total shift in they
-direction.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
ConstructorsConstructorDescriptionLineGraph
(AbstractGraph.Controller controller, Module module) Create new line graph forcontroller
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addData
(double[] data) Add data to the graph.void
addData
(double t, double[] data) Add data to the graph.void
Export the graphical contextctx
.double
getSteps()
Get the number of steps along thex
-axis.getTooltipAt
(double x, double y) Get the tooltip at the scaled coordinates(x,y)
with the origin in the lower left corner of the graph.getTooltipAt
(int x, int y) Get the tooltip information for the location with coordinates(x, y)
.private double
interpolate
(double left, double right, double x) Interpolate linearly betweencurrent
andprev
atx
.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)
.void
reset()
Reset the graph.protected void
Schedule painting of the graph.void
setSteps
(double steps) Set the number of steps along thex
-axis.void
shift
(int dx, int dy) Shift the (zoomed) graph within the view port by(dx, dy)
.void
zoom()
Reset zoom.void
zoom
(double zoom, double x, double y) 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.Methods inherited from class AbstractGraph
activate, addContextMenuHandler, autoscale, calcBounds, 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, onTouchStart, paint, prependTime2Data, resetTransforms, setBufferCapacity, setColors, setFont, setMarkers, setMarkers, setStrokeStyleAt, setTooltipProvider, stroke, strokeCircle, strokeLine, strokeRect, 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.Zoomer
zoom
Methods inherited from interface AbstractGraph.Zooming
zoom
Methods inherited from interface BasicTooltipProvider
getTooltipAt
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 MouseDownHandler
onMouseDown
Methods inherited from interface MouseMoveHandler
onMouseMove
Methods inherited from interface MouseOutHandler
onMouseOut
Methods inherited from interface MouseUpHandler
onMouseUp
Methods inherited from interface MouseWheelHandler
onMouseWheel
Methods inherited from interface TouchEndHandler
onTouchEnd
Methods inherited from interface TouchMoveHandler
onTouchMove
Methods inherited from interface TouchStartHandler
onTouchStart
-
Field Details
-
steps
protected double stepsThe default number of (time) steps shown on this graph. -
paintScheduled
private boolean paintScheduledThe flag to indicate whether painting is already scheduled. Subsequent requests are ignored. -
pinchScale
double pinchScaleThe field to track the progress of the pinch gesture. -
pinch
Point2D pinchThe center of the pinch gesture. -
totDx
int totDxThe total shift in thex
-direction. -
totDy
int totDyThe total shift in they
-direction. -
MIN_STEPS
protected static final int MIN_STEPSThe minimum number of steps along thex
-axis.- See Also:
-
DEFAULT_STEPS
protected static final int DEFAULT_STEPSThe default number of steps along thex
-axis.- See Also:
-
clearMenu
The context menu item to clear the graph.
-
-
Constructor Details
-
LineGraph
Create new line graph forcontroller
. Theid
is used to distinguish different graphs of the same module to visualize different components of the data and represents the index of the data column.- Parameters:
controller
- the controller of this graphmodule
- the module backing the graph
-
-
Method Details
-
reset
public void reset()Description copied from class:AbstractGraph
Reset the graph. Clear canvas and messages.- Overrides:
reset
in classAbstractGraph<double[]>
-
addData
public void addData(double t, double[] data) Add data to the graph. The timet
is prepended to the data as the first element.- Parameters:
t
- the time of the datadata
- the data to add- Implementation Notes:
- The data array is cloned and the time prepended before adding it to the buffer.
-
addData
public void addData(double[] data) Add data to the graph.- Parameters:
data
- the data to add- Implementation Notes:
- The data array is directly added to the buffer. It is the caller's responsibility to ensure that the first entry represents time and the data remains unmodified.
-
paint
public boolean paint(boolean force) Description copied from class:AbstractGraph
Draw the graph. For re-drawing the graph, setforce
totrue
.- Overrides:
paint
in classAbstractGraph<double[]>
- Parameters:
force
-true
to force re-drawing of graph- Returns:
true
if painting skipped
-
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:AbstractGraph
Export the graphical contextctx
.- Specified by:
export
in classAbstractGraph<double[]>
- Parameters:
ctx
- the graphical context to export
-
shift
public void shift(int dx, int dy) Description copied from class:AbstractGraph
Shift the (zoomed) graph within the view port by(dx, dy)
. Default implementation for graphs that implementShifting
.- Specified by:
shift
in interfaceAbstractGraph.Shifter
- Overrides:
shift
in classAbstractGraph<double[]>
- Parameters:
dx
- the horizontal shift of the graphdy
- the vertical shift of the graph- See Also:
-
zoom
public void zoom()Description copied from class:AbstractGraph
Reset zoom. Default implementation for graphs that implementZooming
.- Specified by:
zoom
in interfaceAbstractGraph.Zooming
- Overrides:
zoom
in classAbstractGraph<double[]>
- See Also:
-
zoom
public void zoom(double zoom, double x, double y) Description copied from class:AbstractGraph
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.- Overrides:
zoom
in classAbstractGraph<double[]>
- Parameters:
zoom
- the new zoom levelx
- the scaledx
-coordinate of the zoom centery
- the scaledy
-coordinate of the zoom center- See Also:
-
getSteps
public double getSteps()Get the number of steps along thex
-axis.- Returns:
- the number of steps
-
setSteps
public void setSteps(double steps) Set the number of steps along thex
-axis.- Parameters:
steps
- the number of steps
-
getTooltipAt
Description copied from interface:Tooltip.Provider
Get the tooltip information for the location with coordinates(x, y)
. The returned string may include HTML elements for formatting.- Specified by:
getTooltipAt
in interfaceTooltip.Provider
- Parameters:
x
- thex
-coordinate for the tooltipy
- they
-coordinate for the tooltip- Returns:
- the (formatted) string with the tooltip info
-
getTooltipAt
Description copied from interface:BasicTooltipProvider
Get the tooltip at the scaled coordinates(x,y)
with the origin in the lower left corner of the graph.- Specified by:
getTooltipAt
in interfaceBasicTooltipProvider
- Parameters:
x
- thex
coordinatey
- they
coordinate- Returns:
- the tooltip
-
interpolate
private double interpolate(double left, double right, double x) Interpolate linearly betweencurrent
andprev
atx
.- Parameters:
left
- the left valueright
- the right valuex
- the location inbetween- Returns:
- the interpolated value
-
populateContextMenuAt
Description copied from class:AbstractGraph
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
- Overrides:
populateContextMenuAt
in 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:
-