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.HasLogScaleY, 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, AbstractGraph.HasLogScaleY, BasicTooltipProvider
LineGraph visualizes time series data as one or more line plots inside a
resizable, pannable and zoomable canvas. It extends
AbstractGraph<double[]>
and implements interactions for shifting and zooming (Shifting, Zooming),
optional logarithmic y-axis scaling (HasLogScaleY) and provides tooltips
(BasicTooltipProvider).
Concepts and data layout:
- Each element stored in the internal RingBuffer is a double[] whose first element is the time stamp and subsequent elements are the values to plot for each line (index 1..n). Some modules use a specific layout (e.g. mean, mean-sdev, mean+sdev).
- The graph maintains an x-range [xMin, xMax] and a y-range [yMin, yMax] via the Style object. The x-range is expressed in the same time units as the first element of the data arrays. The buffer capacity and style.xIncr determine the maximum historical range available for panning (the absolute bounds are [absMin, absMax] where absMax is hard-coded to 0.0 and absMin = absMax - capacity*xIncr).
- The graph can operate with autoscaling for the y-axis (style.autoscaleY) or with fixed y-limits. When autoscale is enabled, added data updates yMin/yMax to at least cover observed values; ranges are expanded but never shrunk automatically.
- Logarithmic y-scaling is supported (style.logScaleY), but it requires strictly positive values; if negative or zero values are present the graph disables log-scaling and issues a warning. When autoscaling and log-scaling interact, small positive minima are adjusted to a fraction of the maximum to avoid log(0).
Main behaviors and responsibilities:
- Construction: create a LineGraph with a Mean view and a Module that supplies trait names, colors and data semantics.
- Parsing: parse(String args) accepts a comma-separated argument string
(no spaces around commas) and recognizes options:
log,xmin <value>,xmax <value>,ymin <value>,ymax <value>. ymin/ymax disable autoscale when specified. - Data ingestion: addData(double t, double[] data) prepends time and delegates to addData(double[]). addData(double[]) appends the data array into the RingBuffer (the caller must ensure the first element is time and the array is not modified afterwards). addData updates the autoscaled y-range and may disable log-scaling if non-positive values are encountered.
- Resetting/initialization: reset() prepares the buffer, initializes autoscaled y-range and recomputes the number of steps along x relative to the current view. Buffer size is at least DEFAULT_BUFFER_SIZE or the view width, and steps are clamped between 1 and buffer capacity.
- Painting: paint(boolean force) renders the lines, optional markers and axes frame. The method clips drawing to the plotting area, supports linear or log y-scaling, and draws colored lines and markers using the module-provided color scheme. Painting is scheduled on the UI thread using schedulePaint() to coalesce multiple requests.
- Interaction:
- shift(dx, dy) pans the x-range in multiples of style.xIncr. Small mouse/touch deltas that do not exceed a single increment are accumulated until sufficient movement occurs. Shifting respects the absolute data bounds determined by the buffer capacity.
- zoom() resets the view to a default zoom focused on the latest data (xMax = 0.0 and xMin = xMax - max(1, DEFAULT_STEPS*xIncr)).
- zoom(double zoom, double x, double y) zooms around the right-hand end (xMax is treated as the reference) and enforces a minimum number of steps (MIN_STEPS). Zooming also snaps bounds to integer multiples of style.xIncr and clamps to the available history.
- Tooltips: getTooltipAt(int x,int y) converts pixel coordinates to normalized plotting coordinates and delegates to getTooltipAt(double x, double y). The tooltip builder searches the buffer to interpolate the time and values at the requested x position and returns an HTML table with the x-value, y-value and per-trait values (or mean ± sdev when applicable). Tooltips are suppressed while the left mouse button is held and when the point lies outside bounds.
- Context menu: populateContextMenuAt adds a "Clear" action that clears the graph history and triggers an immediate repaint.
Fields of interest (summary):
- steps: number of steps shown along the x-axis (clamped to [1, buffer.capacity]).
- buffer: RingBuffer<double[]> storing historical data arrays (time + values).
- style: visual and interaction configuration (xMin/xMax/yMin/yMax, xIncr, autoscaleY, logScaleY, markerSize, lineWidth, etc.).
- paintScheduled: coalesces deferred paint requests.
- pinchScale / pinch: state used for touch pinch gestures (scale and center).
Important implementation notes and caveats:
- The buffer stores references to the provided double[] objects for performance — callers must not modify arrays after passing them to addData(double[]).
- Log-scaling requires strictly positive y-values. If negative or zero values exist the graph will disable log-scale and emit a warning.
- Painting occurs on the UI thread and is scheduled via GWT Scheduler; callers should avoid heavy synchronous work on the UI thread during paint() to keep the UI responsive.
- Precision: x- and y-axis snapping to style.xIncr is used to keep numeric bounds aligned with the data grid; floating point rounding may occur when snapping or computing steps.
This class is intended for use within the EvoLudo UI framework and relies on the surrounding infrastructure (Style, RingBuffer, Module, Mean view, drawing context MyContext2d and Scheduler). It focuses on correctness of visualization, responsive UI updates via scheduled paints and robust handling of autoscaling and log-scaling edge cases.
Usage example (conceptual):
LineGraph g = new LineGraph(meanView, module);
g.parse("ymin 0.0,ymax 1.0"); // configure
g.addData(t, new double[]{t, v1, v2, ...});
g.zoom(2.0, sx, sy); // zoom in
// tooltips and context menu are integrated into the hosting UI
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractGraph
AbstractGraph.HasLogScaleY, 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 booleanFlag indicating that the next sample must be appended to anchor a new run after a restart or a change in time direction.protected static final intThe default number of steps along thex-axis.protected static final intThe minimum number of steps along thex-axis.private booleanFlag indicating that the next sample starts a new time series because the model was re-initialized.(package private) intThe number of lines to plot.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.(package private) doubleThe default number of (time) steps shown on this graph.private static final doubleThe time value used to separate distinct time series in the history buffer.(package private) intThe total shift in thex-direction.(package private) intThe total shift in they-direction.private static final doublePadding applied when fitting the y-axis to visible data.Fields inherited from class AbstractGraph
bounds, buffer, canvas, colors, contextMenu, CSS_CURSOR_MOVE_VIEW, CURSOR_GRAB_NODE_CLASS, CURSOR_MOVE_NODE_CLASS, CURSOR_ZOOM_IN_CLASS, CURSOR_ZOOM_OUT_CLASS, DEFAULT_BUFFER_SIZE, doubleClickHandler, element, g, hasMessage, hasZoom, leftMouseButton, logger, markerColors, markers, message, MIN_BUFFER_SIZE, MIN_CURVATURE_STEP_SQ, MIN_NORM_DELTA, MIN_NORM_DIST_SQ, module, mouseDownHandler, mouseMoveHandler, mouseOutHandler, mouseUpHandler, mouseWheelHandler, mouseX, mouseY, msgFontSize, msgLabel, msgLineHeight, PIHALF, pinchDist, pinchX, pinchY, scale, shifter, style, tooltip, tooltipProvider, touchEndHandler, touchEndTime, touchMoveHandler, touchStartHandler, TURN_COS_THRESHOLD, view, viewCorner, wrapper, yAxisLabelTickSkip, zoomer, zoomFactor, zoomInertiaTimerFields inherited from class UIObject
DEBUG_ID_PREFIXFields inherited from interface AbstractGraph.Zooming
ZOOM_INCR, ZOOM_MAXFields inherited from interface BasicTooltipProvider
SPAN_COLOR, TABLE_CELL_BULLET, TABLE_CELL_NEXT, TABLE_CELL_NEXT_COLOR, TABLE_END, TABLE_ROW_END, TABLE_ROW_START, TABLE_ROW_START_COLOR, TABLE_ROW_START_RIGHT, TABLE_SEPARATOR, TABLE_STYLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddData(double[] data) Add data to the graph.voidaddData(double t, double[] data) Add data to the graph.private voidappendData(double[] data) Append a sample to the history and update autoscaling metadata.private voidappendSeparator(int length) Append an in-buffer separator that marks the beginning of a new time series.private voidappendTipContinuous(StringBuilder tip, double[] inter, Color[] colors) Append mean ± sdev row for Continuous modules.private voidappendTipHeader(StringBuilder tip, double mouset, double yval) Build and append the static header rows (label, x and y rows) to the tooltip.private voidappendTipInterpolation(StringBuilder tip, double mouset) Append interpolated values (either Continuous mean±sdev or trait values) to the tooltip builder using the precomputed interpolation result.private voidappendTipTraits(StringBuilder tip, double[] inter, Color[] colors) Append individual trait rows for non-Continuous modules.voidcalcBounds(int width, int height) Calculate bounds of drawing area.private voidClamp the y-axis range for logarithmic scaling.private intcompareData(double[] o1, double[] o2) Compare two data arrays based on their minimum value (ignoring first entry, time).private double[]computeYScale(double h) Compute y-axis scale info: [ymin, yScale, yInset]private voiddrawLatestMarkers(double width, double[] yinfo, int nLines) Draw markers for the newest sample (extracted helper).private voiddrawLines(double width, double[] yinfo, int nLines) Draw the line plots.private voiddrawMarkers(double width, double[] yinfo, int nLines) Draw horizontal marker lines (if any) using the same y transform.private voiddrawSegmentClipped(double start, double end, double[] prev, double[] current, int nLines, double[] yinfo, double width) Draw a historical segment between 'start' and 'end', handling clipping against the visible window (-w ..voidExport the graphical contextctx.private double[]findInterpolationForMouse(double mouset) Scan the buffer and determine the two surrounding samples and the interpolation factor for the supplied mouse time.intGet the number of lines plotted in this graph.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 doublehistoryStepWidth(double[] current, double[] prev) Return whether a step between buffered samples should contribute to the displayed history.voidinit()Initialize the graph.protected booleaninside(int x, int y) Check if the event coordinates are inside the interactive plot area.private doubleinterpolate(double left, double right, double x) Interpolate linearly betweencurrentandprevatx.protected booleankeepSample(RingBuffer<double[]> buffer, double[] current, double[] last) Decide whether to retain a candidate sample by applying a display-agnostic heuristic: normalized mean squared distance and local curvature.private doublemapY(double y, double[] yinfo) Map a normalized y-value into the inset plotting area.private voidnoLogY()Helper method to disable log scale ony-axis and issue warning.protected voidonLoad()booleanpaint(boolean force) Draw the graph.booleanParse the arguments for the graph.private voidParse command line options for the graph.voidpopulateContextMenuAt(ContextMenu menu, int x, int y) Populate context menumenuin listening widget at (relative) position(x,y).voidpopulateLocalAxesMenu(ContextMenu axesMenu) Opportunity for graph subclasses to contribute graph-local entries to the shared axes submenu assembled by the owning view.protected voidpopulateZoomMenu(ContextMenu menu) Populate the zoom submenu with standard zoom actions.voidreset()Reset the graph.protected voidSchedule painting of the graph.voidAssign a list of colors to the graph.(package private) voidsetLogY(boolean logY) Set they-axis to logarithmic scale iflogYistrueand ifyMin ≥ 0.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).private inttimeStepDirection(double newerTime, double olderTime) Get the direction of a time step.private voidupdateAutoscale(double[] data) Update autoscaledy-range from a newly appended sample.private booleanupdateTimeOnly(double[] current, double[] last) Return whether the latest buffered sample should only update its time entry.private booleanUpdate the x-axis range to show all buffered data (latest segment only).private voidUpdate the x-axis tick label offset to the most recent finite time value.private booleanupdateYRangeFromBuffer(boolean visibleOnly, boolean addMargin) Update the y-axis range based on buffered data.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, addClearMenu, addContextMenuHandler, addLogScaleMenu, addZoomMenu, adjustBoundsForLegend, autoscale, calcBounds, clearCanvas, clearGraph, clearHistory, clearMessage, contains, convertToScaledCoordinates, convertToScaledCoordinates, deactivate, displayMessage, displayMessage, drawFrame, drawFrame, fill, fillCircle, fillCircle, fillCircle, fillRect, fillTextVertical, getBuffer, getMaxViewCornerX, getMaxViewCornerY, getModule, getStyle, getYAxisLabelTickSkip, hasHistory, hasMessage, hasSignificantTurn, maxDelta, normDelta, normDeltaSq, onMessageCleared, onMessageDisplayed, onMouseDown, onMouseMove, onMouseOut, onMouseUp, onMouseWheel, onResize, onTouchEnd, onTouchMove, onTouchStart, onUnload, paint, prependTime2Data, resetTransforms, setFont, setMarkers, setMarkers, setStrokeStyleAt, setTooltipProvider, stroke, strokeCircle, strokeCircle, strokeCircle, strokeLine, 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, 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
double stepsThe default number of (time) steps shown on this graph. -
nLines
int nLinesThe number of lines to plot. -
ZOOM_FIT_MARGIN
private static final double ZOOM_FIT_MARGINPadding applied when fitting the y-axis to visible data.- See Also:
-
newTimeseries
private boolean newTimeseriesFlag indicating that the next sample starts a new time series because the model was re-initialized. -
TIME_SERIES_BREAK
private static final double TIME_SERIES_BREAKThe time value used to separate distinct time series in the history buffer.- See Also:
-
appendNextSample
private boolean appendNextSampleFlag indicating that the next sample must be appended to anchor a new run after a restart or a change in time direction. -
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:
-
-
Constructor Details
-
LineGraph
Create new line graph forview. 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:
view- the view of this graphmodule- the module backing the graph
-
-
Method Details
-
onLoad
protected void onLoad()- Overrides:
onLoadin classAbstractGraph<double[]>
-
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
-
parse
Description copied from class:AbstractGraphParse the arguments for the graph. Default implementation does nothing.- Overrides:
parsein classAbstractGraph<double[]>- Parameters:
args- the arguments for the graph- Returns:
trueif parsing was successful
-
parseArgs
Parse command line options for the graph. The following options are recognized:log: enable logarithmic scaling on the y-axisxmin <value>: set the minimum x-axis valuexmax <value>: set the maximum x-axis valueymin <value>: set the minimum y-axis valueymax <value>: set the maximum y-axis value
- Parameters:
args- the command line arguments (comma separated, no spaces)
-
setColors
Description copied from class:AbstractGraphAssign a list of colors to the graph.- Overrides:
setColorsin classAbstractGraph<double[]>- Parameters:
colors- the list of colors
-
getNLines
public int getNLines()Get the number of lines plotted in this graph.- Returns:
- the number of lines
-
reset
public void reset()Description copied from class:AbstractGraphReset the graph. Clear canvas and messages.- Overrides:
resetin classAbstractGraph<double[]>
-
init
public void init()Description copied from class:AbstractGraphInitialize the graph. Do not clear graph.- Overrides:
initin 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:
- If the change relative to the latest buffered sample is negligible, only the latest sample's time entry is updated unless the new sample is needed to anchor the beginning of a flat segment. Model initialization inserts a separator and starts a new buffered time series. Changes in the direction of time are always appended, and the following sample is retained once to anchor the new direction. Otherwise 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.
-
appendData
private void appendData(double[] data) Append a sample to the history and update autoscaling metadata.- Parameters:
data- the sample to append
-
appendSeparator
private void appendSeparator(int length) Append an in-buffer separator that marks the beginning of a new time series.- Parameters:
length- the length of the separator sample
-
updateAutoscale
private void updateAutoscale(double[] data) Update autoscaledy-range from a newly appended sample.- Parameters:
data- the latest buffered sample (time prepended)
-
updateTimeOnly
private boolean updateTimeOnly(double[] current, double[] last) Return whether the latest buffered sample should only update its time entry.- Parameters:
current- candidate samplelast- latest buffered sample- Returns:
trueif only time should be updated
-
timeStepDirection
private int timeStepDirection(double newerTime, double olderTime) Get the direction of a time step.- Parameters:
newerTime- the newer time valueolderTime- the older time value- Returns:
+1for forward time,-1for backward time, or0if no finite direction can be inferred
-
historyStepWidth
private double historyStepWidth(double[] current, double[] prev) Return whether a step between buffered samples should contribute to the displayed history.- Parameters:
current- the current newer sampleprev- the adjacent older sample- Returns:
- the displayed width of this history step, or
0.0if the step should be hidden
-
keepSample
Description copied from class:AbstractGraphDecide whether to retain a candidate sample by applying a display-agnostic heuristic: normalized mean squared distance and local curvature.- Overrides:
keepSamplein classAbstractGraph<double[]>- Parameters:
buffer- ring buffer holding retained samples (latest first)current- candidate sample including prepended timelast- most recently retained sample including prepended time- Returns:
trueif sample should be kept
-
setLogY
void setLogY(boolean logY) Description copied from class:AbstractGraphSet they-axis to logarithmic scale iflogYistrueand ifyMin ≥ 0. IfyMin == 0it is increased to0.01 * yMax. IfyMin < 0logarithmic scale requests are ignored.- Overrides:
setLogYin classAbstractGraph<double[]>- Parameters:
logY-trueto set logarithmic scale ony-axis
-
noLogY
private void noLogY()Helper method to disable log scale ony-axis and issue warning. -
compareData
private int compareData(double[] o1, double[] o2) Compare two data arrays based on their minimum value (ignoring first entry, time). Returns a negative integer, zero, or a positive integer if the minimum of the first argument is less than, equal to, or greater than the second, respectively.- Parameters:
o1- the first data arrayo2- the second data array- Returns:
- a negative integer, zero, or a positive integer
-
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
-
computeYScale
private double[] computeYScale(double h) Compute y-axis scale info: [ymin, yScale, yInset]- Parameters:
h- the height of the plotting area- Returns:
- an array containing [ymin, yScale, yInset]
-
mapY
private double mapY(double y, double[] yinfo) Map a normalized y-value into the inset plotting area.- Parameters:
y- the y-value relative to the lower graph boundyinfo- the y-axis transform info- Returns:
- the mapped y-coordinate inside the plotting area
-
drawLines
private void drawLines(double width, double[] yinfo, int nLines) Draw the line plots.- Parameters:
width- the width of the plotting areayinfo- the y-axis transform infonLines- the number of lines to draw
-
drawLatestMarkers
private void drawLatestMarkers(double width, double[] yinfo, int nLines) Draw markers for the newest sample (extracted helper).- Parameters:
width- the width of the plotting areayinfo- the y-axis transform infonLines- the number of lines to draw
-
drawSegmentClipped
private void drawSegmentClipped(double start, double end, double[] prev, double[] current, int nLines, double[] yinfo, double width) Draw a historical segment between 'start' and 'end', handling clipping against the visible window (-w .. 0) and log/linear y transforms.- Parameters:
start- starting x-coordinate of the segmentend- ending x-coordinate of the segmentprev- the previous data arraycurrent- the current data arraynLines- the number of lines to drawyinfo- the y-axis transform infowidth- the width of the plotting area
-
drawMarkers
private void drawMarkers(double width, double[] yinfo, int nLines) Draw horizontal marker lines (if any) using the same y transform.- Parameters:
width- the width of the plotting areayinfo- the y-axis transform infonLines- the number of lines to draw
-
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
-
inside
protected boolean inside(int x, int y) Description copied from class:AbstractGraphCheck if the event coordinates are inside the interactive plot area. Default implementation accepts all coordinates.- Overrides:
insidein classAbstractGraph<double[]>- Parameters:
x- thex-coordinate relative to the graph elementy- they-coordinate relative to the graph element- Returns:
trueif inside the interactive plot area
-
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
-
appendTipHeader
Build and append the static header rows (label, x and y rows) to the tooltip.- Parameters:
tip- builder receiving the markupmouset- x-axis value under the cursoryval- y-axis value under the cursor
-
findInterpolationForMouse
private double[] findInterpolationForMouse(double mouset) Scan the buffer and determine the two surrounding samples and the interpolation factor for the supplied mouse time.- Parameters:
mouset- the mouse time- Returns:
- the interpolated data array (time + values) or null if not found
-
appendTipInterpolation
Append interpolated values (either Continuous mean±sdev or trait values) to the tooltip builder using the precomputed interpolation result.- Parameters:
tip- the tooltip buildermouset- the mouse time
-
appendTipContinuous
Append mean ± sdev row for Continuous modules.- Parameters:
tip- the tooltip builderinter- the interpolated data arraycolors- the colors for each trait
-
appendTipTraits
Append individual trait rows for non-Continuous modules.- Parameters:
tip- the tooltip builderinter- the interpolated data arraycolors- the colors for each trait
-
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 view 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:
-
populateLocalAxesMenu
Description copied from class:AbstractGraphOpportunity for graph subclasses to contribute graph-local entries to the shared axes submenu assembled by the owning view.- Overrides:
populateLocalAxesMenuin classAbstractGraph<double[]>- Parameters:
axesMenu- the axes submenu to populate
-
populateZoomMenu
Description copied from class:AbstractGraphPopulate the zoom submenu with standard zoom actions.- Overrides:
populateZoomMenuin classAbstractGraph<double[]>- Parameters:
menu- the zoom submenu to populate
-
updateYRangeFromBuffer
private boolean updateYRangeFromBuffer(boolean visibleOnly, boolean addMargin) Update the y-axis range based on buffered data.- Parameters:
visibleOnly- whether to limit to the visible x-rangeaddMargin- whether to add a small top/bottom margin- Returns:
trueif the range was updated
-
updateXRangeFromBuffer
private boolean updateXRangeFromBuffer()Update the x-axis range to show all buffered data (latest segment only).- Returns:
trueif the range was updated
-
updateXTickOffset
private void updateXTickOffset()Update the x-axis tick label offset to the most recent finite time value. -
clampLogRange
private void clampLogRange()Clamp the y-axis range for logarithmic scaling.
-