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 TypeClassDescriptionclassThe 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.ZoomingNested classes/interfaces inherited from class UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabledNested classes/interfaces inherited from interface HasWidgets
HasWidgets.ForIsWidget -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ContextMenuItemThe context menu item to clear the graph.protected static final intThe default number of steps along thex-axis.protected static final intThe minimum number of steps along thex-axis.private booleanThe flag to indicate whether painting is already scheduled.(package private) Point2DThe center of the pinch gesture.(package private) doubleThe field to track the progress of the pinch gesture.protected doubleThe default number of (time) steps shown on this graph.(package private) intThe total shift in thex-direction.(package private) intThe 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, zoomResetMenuFields inherited from class UIObject
DEBUG_ID_PREFIXFields 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 TypeMethodDescriptionvoidaddData(double[] data) Add data to the graph.voidaddData(double t, double[] data) Add data to the graph.voidExport the graphical contextctx.doublegetSteps()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 doubleinterpolate(double left, double right, double x) Interpolate linearly betweencurrentandprevatx.booleanpaint(boolean force) Draw the graph.voidpopulateContextMenuAt(ContextMenu menu, int x, int y) Populate context menumenuin listening widget at (relative) position(x,y).voidreset()Reset the graph.protected voidSchedule painting of the graph.voidsetSteps(double steps) Set the number of steps along thex-axis.voidshift(int dx, int dy) Shift the (zoomed) graph within the view port by(dx, dy).voidzoom()Reset zoom.voidzoom(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, 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.Zoomer
zoomMethods inherited from interface AbstractGraph.Zooming
zoomMethods inherited from interface BasicTooltipProvider
getTooltipAtMethods 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
onTouchMoveMethods 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. Theidis 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:AbstractGraphReset the graph. Clear canvas and messages.- Overrides:
resetin classAbstractGraph<double[]>
-
addData
public void addData(double t, double[] data) 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 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: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
-
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
-
shift
public void shift(int dx, int dy) Description copied from class:AbstractGraphShift the (zoomed) graph within the view port by(dx, dy). Default implementation for graphs that implementShifting.- Specified by:
shiftin interfaceAbstractGraph.Shifter- Overrides:
shiftin 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:AbstractGraphReset zoom. Default implementation for graphs that implementZooming.- Specified by:
zoomin interfaceAbstractGraph.Zooming- Overrides:
zoomin classAbstractGraph<double[]>- See Also:
-
zoom
public void zoom(double zoom, double x, double y) Description copied from class:AbstractGraphHelper 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:
zoomin 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.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
-
getTooltipAt
Description copied from interface:BasicTooltipProviderGet the tooltip at the scaled coordinates(x,y)with the origin in the lower left corner of the graph.- Specified by:
getTooltipAtin interfaceBasicTooltipProvider- Parameters:
x- thexcoordinatey- theycoordinate- Returns:
- the tooltip
-
interpolate
private double interpolate(double left, double right, double x) Interpolate linearly betweencurrentandprevatx.- Parameters:
left- the left valueright- the right valuex- the location inbetween- Returns:
- the interpolated value
-
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:
-