Class MovingAverageRenderer
java.lang.Object
com.arbergashi.charts.render.BaseRenderer
com.arbergashi.charts.render.analysis.MovingAverageRenderer
- All Implemented Interfaces:
ChartRenderer
MovingAverageRenderer - Simple Moving Average (SMA) Overlay
Enterprise-grade moving average renderer with configurable window size, pixel decimation for large datasets, and dashed line styling.
Features:
- SMA Algorithm: Rolling window average calculation
- Configurable Window: Adjustable averaging period (default: 10)
- Pixel Decimation: Automatic downsampling for large datasets
- Dashed Style: Distinctive visual appearance with dash pattern
- Zero-Allocation: Path pooling and shape reuse
- Overlay Mode: Renders on top of existing data
Algorithm:
SMA[i] = (y[i] + y[i-1] + ... + y[i-window+1]) / window Rolling window implementation: sum = sum + y[i] - y[i-window] avg = sum / window
Performance Characteristics:
- Complexity: O(n) with rolling sum (not O(n*w)!)
- Small (
< 2k points):< 5ms - Large (2k-50k):
< 15mswith decimation - Memory: Zero allocations (path pooling)
Configuration:
chart.render.ma.window=10 // Averaging window size
chart.render.ma.maxPoints=8000 // Decimation threshold
chart.render.ma.width=1.6 // Line width (scaled)
chart.render.decimate.pixel=true // Enable pixel decimation
Visual Style:
- Dashed line (6px dash, 4px space)
- Semi-transparent (85% opacity)
- Rounded caps and joins
- Inherits series color
Use Cases:
- Trend identification in time-series data
- Noise reduction in scientific measurements
- Signal smoothing in financial charts
- Since:
- 2026-01-01
- Version:
- 2.0.0
- Author:
- Arber Gashi
-
Field Summary
Fields inherited from class BaseRenderer
PIXEL_BUF, PIXEL_BUF4 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddrawData(Graphics2D g2, ChartModel model, PlotContext context) Implementation-specific drawing logic.booleanIndicates whether this renderer should appear in the legend.Methods inherited from class BaseRenderer
drawHighlightPoint, drawI18nLabel, drawLabel, getArc, getCachedFont, getCachedGradient, getCachedStroke, getCachedStroke, getCachedStroke, getCubicCurve, getEllipse, getId, getLayerIndex, getLegendColor, getLine, getName, getPathCache, getPointAt, getRect, getRoundRectangle, getSeriesColor, getSeriesStroke, getTheme, getTooltipText, isMultiColor, pBuffer, pBuffer4, render, resolveTheme, seriesOrBase, setLayerIndex, setMultiColor, setTheme, setupQualityHints, themeAccent, themeAxisLabel, themeBackground, themeBearish, themeBullish, themeForeground, themeGrid, themeSeriesMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ChartRenderer
clearHover, createContext, getFocusValues, getPreferredYRange, renderEmptyState, supportsEmptyState
-
Constructor Details
-
MovingAverageRenderer
public MovingAverageRenderer()
-
-
Method Details
-
isLegendRequired
public boolean isLegendRequired()Description copied from class:BaseRendererIndicates whether this renderer should appear in the legend.- Specified by:
isLegendRequiredin interfaceChartRenderer- Overrides:
isLegendRequiredin classBaseRenderer- Returns:
- true if the renderer should appear in the legend
-
drawData
Description copied from class:BaseRendererImplementation-specific drawing logic. Must follow Zero-Allocation rules.- Specified by:
drawDatain classBaseRenderer
-