Class Downsample
Largest-Triangle-Three-Buckets downsampling (Steinarsson, 2013): picks the points of a long series that keep its visual shape, so a million samples can be handed to a chart as a few thousand.
A LineSeries already draws only the highest and lowest point of every pixel column, so it
stays fast without this. Use it to cut memory and the cost of animating, hit testing and
tooltips on very large data:
double[] x = null;
double[] y = new double[100000];
for (int i = 0; i < y.length; i++) {
y[i] = Math.sin(i / 500.0);
}
LineSeries series = new LineSeries("Signal");
int[] keep = Downsample.lttb(x, y, 2000);
// pick(x, keep) is the kept indices when x is null, so the points keep their positions
series.setData(Downsample.pick(x, keep), Downsample.pick(y, keep));
-
Method Summary
-
Method Details
-
lttb
public static int[] lttb(double[] x, double[] y, int threshold) The indices of the points LTTB keeps, ascending; the first and last are always kept.
A NaN value is a gap. Gaps never take part in the triangle areas or bucket averages. A bucket that contains one keeps its first NaN index as a gap marker, so the gap survives downsampling rather than being bridged, and also keeps its best real point, so a sparse NaN does not cost the bucket its peak. The result therefore has
thresholdindices when the data has no gaps, and never more than2 * threshold - 2.Parameters
-
x: the x values, ascending; null means the index -
y: the y values -
threshold: how many points to keep, at least 3
Returns
the kept indices; every index when the series is already that short
-
-
pick
public static double[] pick(double[] values, int[] indices) The values at the given indices.
Parameters
-
values: the full array; null stands for an index based x, so the result is the kept indices themselves as doubles and the points keep their original x positions -
indices: whatlttbreturned
Returns
a new array of the picked values
-
-