Class 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
  • Field Details

    • steps

      protected double steps
      The default number of (time) steps shown on this graph.
    • paintScheduled

      private boolean paintScheduled
      The flag to indicate whether painting is already scheduled. Subsequent requests are ignored.
    • pinchScale

      double pinchScale
      The field to track the progress of the pinch gesture.
    • pinch

      Point2D pinch
      The center of the pinch gesture.
    • totDx

      int totDx
      The total shift in the x-direction.
    • totDy

      int totDy
      The total shift in the y-direction.
    • MIN_STEPS

      protected static final int MIN_STEPS
      The minimum number of steps along the x-axis.
      See Also:
    • DEFAULT_STEPS

      protected static final int DEFAULT_STEPS
      The default number of steps along the x-axis.
      See Also:
    • clearMenu

      private ContextMenuItem clearMenu
      The context menu item to clear the graph.
  • Constructor Details

    • LineGraph

      public LineGraph(AbstractGraph.Controller controller, Module module)
      Create new line graph for controller. The id 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 graph
      module - 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 class AbstractGraph<double[]>
    • addData

      public void addData(double t, double[] data)
      Add data to the graph. The time t is prepended to the data as the first element.
      Parameters:
      t - the time of the data
      data - 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, set force to true.
      Overrides:
      paint in class AbstractGraph<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

      public void export(AbstractGraph.MyContext2d ctx)
      Description copied from class: AbstractGraph
      Export the graphical context ctx.
      Specified by:
      export in class AbstractGraph<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 implement Shifting.
      Specified by:
      shift in interface AbstractGraph.Shifter
      Overrides:
      shift in class AbstractGraph<double[]>
      Parameters:
      dx - the horizontal shift of the graph
      dy - the vertical shift of the graph
      See Also:
    • zoom

      public void zoom()
      Description copied from class: AbstractGraph
      Reset zoom. Default implementation for graphs that implement Zooming.
      Specified by:
      zoom in interface AbstractGraph.Zooming
      Overrides:
      zoom in class AbstractGraph<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 class AbstractGraph<double[]>
      Parameters:
      zoom - the new zoom level
      x - the scaled x-coordinate of the zoom center
      y - the scaled y-coordinate of the zoom center
      See Also:
    • getSteps

      public double getSteps()
      Get the number of steps along the x-axis.
      Returns:
      the number of steps
    • setSteps

      public void setSteps(double steps)
      Set the number of steps along the x-axis.
      Parameters:
      steps - the number of steps
    • getTooltipAt

      public String getTooltipAt(int x, int y)
      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 interface Tooltip.Provider
      Parameters:
      x - the x-coordinate for the tooltip
      y - the y-coordinate for the tooltip
      Returns:
      the (formatted) string with the tooltip info
    • getTooltipAt

      public String getTooltipAt(double x, double y)
      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 interface BasicTooltipProvider
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      the tooltip
    • interpolate

      private double interpolate(double left, double right, double x)
      Interpolate linearly between current and prev at x.
      Parameters:
      left - the left value
      right - the right value
      x - the location inbetween
      Returns:
      the interpolated value
    • populateContextMenuAt

      public void populateContextMenuAt(ContextMenu menu, int x, int y)
      Description copied from class: AbstractGraph
      Populate context menu menu in listening widget at (relative) position (x,y).

      Adds buffer size menu and queries the controller to add further functionality.

      Specified by:
      populateContextMenuAt in interface ContextMenu.Provider
      Overrides:
      populateContextMenuAt in class AbstractGraph<double[]>
      Parameters:
      menu - context menu entries are added here
      x - horizontal coordinate (relative to listening widget)
      y - horizontal coordinate (relative to listening widget)
      See Also: