public class

FixedPointCountSampler

extends DataAdapterWrapper<Tx, Ty>
implements ZoomLevelUpdateable
java.lang.Object
   ↳ com.shinobicontrols.charts.DataAdapter<Tx, Ty>
     ↳ com.shinobicontrols.advancedcharting.core.DataAdapterWrapper<Tx, Ty>
       ↳ com.shinobicontrols.advancedcharting.sampling.FixedPointCountSampler<Tx, Ty>

Class Overview

The FixedPointCountSampler samples the data set of the DataAdapter it wraps based on a given zoom level, with the aim of always displaying the same number of data points regardless of how far the user has zoomed in or out. As this class implements the ZoomLevelUpdateable interface, it is usually used in conjunction with an AxisZoomLevelListener to automatically update the sampling of the data as the user zooms in and out of the chart. The sampling will increase as the chart is zoomed in (basing its calculations on the zoomLevel of one com.shinobicontrols.charts.Axis), so that the initial fully-zoomed-out view does not show the entire dataset.

This sampler assumes that the data is evenly distributed and uses the ratio of the data range that is visible to estimate how many points to display.

For example, say you have a 100 data points with X values from 1 to 100 and you want to display 10 points at any one time. If the visible range on the X-axis has a span of 50 it will sample one data point for every five.

The FixedPointCountSampler wraps, or decorates, another DataAdapter that provides the data points to be sampled. In many cases the wrapped DataAdapter will be a com.shinobicontrols.charts.SimpleDataAdapter or similar implementation but conceivably it could be another sampler. As the FixedPointCountSampler is itself a DataAdapter it can be given to a com.shinobicontrols.charts.Series via the setDataAdapter(DataAdapter) method.

Summary

[Expand]
Inherited Fields
From class com.shinobicontrols.advancedcharting.core.DataAdapterWrapper
Public Constructors
FixedPointCountSampler(DataAdapter<Tx, Ty> dataAdapter)
Constructs a new FixedPointCountSampler, wrapping the given DataAdapter and using a value of 10 as the default number of data points in the default range.
FixedPointCountSampler(DataAdapter<Tx, Ty> dataAdapter, int numberOfDataPointsInDefaultRange)
Constructs a new FixedPointCountSampler, wrapping the given DataAdapter and using the given numberOfDataPointsInDefaultRange value as a rough estimate of the number of data points in the default range were it not sampled.
Public Methods
List<Data<Tx, Ty>> getDataPointsForDisplay()
Implementations of this method should return a list of data points which are to be displayed on the chart.
int getMaximumNthPoint()
Returns the maximum point count that this sampler will sample at.
int getTargetPointCount()
Returns the number of points that this sampler will attempt to display on the chart.
void setMaximumNthPoint(int maximumNthPoint)
Sets the maximum point count that this sampler will sample at.
void setTargetPointCount(int targetPointCount)
Sets the number of points that this sampler will attempt to display on the chart.
void update(double zoomLevel)
Updates this ZoomLevelUpdateable based on the given zoomLevel value.
[Expand]
Inherited Methods
From class com.shinobicontrols.advancedcharting.core.DataAdapterWrapper
From class com.shinobicontrols.charts.DataAdapter
From class java.lang.Object
From interface com.shinobicontrols.advancedcharting.sampling.ZoomLevelUpdateable
From interface com.shinobicontrols.charts.DataAdapter.OnDataChangedListener
From interface java.lang.Iterable

Public Constructors

public FixedPointCountSampler (DataAdapter<Tx, Ty> dataAdapter)

Constructs a new FixedPointCountSampler, wrapping the given DataAdapter and using a value of 10 as the default number of data points in the default range.

Parameters
dataAdapter the source DataAdapter that provides the Data objects, must not be null otherwise an IllegalArgumentException will be thrown

public FixedPointCountSampler (DataAdapter<Tx, Ty> dataAdapter, int numberOfDataPointsInDefaultRange)

Constructs a new FixedPointCountSampler, wrapping the given DataAdapter and using the given numberOfDataPointsInDefaultRange value as a rough estimate of the number of data points in the default range were it not sampled. If no explicit default range has been set, this should likely be the same as the value returned from size() from the source DataAdapter, i.e. the total number of data points.

Parameters
dataAdapter the source DataAdapter that provides the Data objects, must not be null otherwise an IllegalArgumentException will be thrown
numberOfDataPointsInDefaultRange a rough estimate of the number of data points in the default range were it not sampled

Public Methods

public List<Data<Tx, Ty>> getDataPointsForDisplay ()

Implementations of this method should return a list of data points which are to be displayed on the chart. This method is called by the chart framework in response to notifyDataChanged(). It is not normally called by client code, though there is no harm in doing so.

Returns
  • a list of data points which are to be displayed on the chart

public int getMaximumNthPoint ()

Returns the maximum point count that this sampler will sample at.

For example, a value of 64 means this sampler will be able to vary the sampling between picking 1 out of every 64 points and 64 out of every 64 points.

A higher value means more points will be able to be sampled out, simplifying the initial data set.

We recommend using a power of 2, as this will ensure an even distribution of points being sampled from the data set. Additional sampled points will then be added between existing points as the chart is zoomed in (and removed as it is zoomed out).

By default this is 64.

Returns
  • the maximum point count that this sampler will sample at

public int getTargetPointCount ()

Returns the number of points that this sampler will attempt to display on the chart.

By default this is 16.

Returns
  • the number of points that this sampler will attempt to display on the chart

public void setMaximumNthPoint (int maximumNthPoint)

Sets the maximum point count that this sampler will sample at.

For example, a value of 64 means this sampler will be able to vary the sampling between picking 1 out of every 64 points and 64 out of every 64 points.

A higher value means more points will be able to be sampled out, simplifying the initial data set.

We recommend using a power of 2, as this will ensure an even distribution of points being sampled from the data set. Additional sampled points will then be added between existing points as the chart is zoomed in (and removed as it is zoomed out).

Parameters
maximumNthPoint the maximum point count for this sampler to sample at

public void setTargetPointCount (int targetPointCount)

Sets the number of points that this sampler will attempt to display on the chart. The given value must be greater than zero otherwise an IllegalArgumentException will be thrown.

Parameters
targetPointCount the number of points for this sampler to attempt to display on the chart

public void update (double zoomLevel)

Updates this ZoomLevelUpdateable based on the given zoomLevel value.

Parameters
zoomLevel the zoom level value to update this ZoomLevelUpdateable with