if(points.isEmpty()) {
return;
}
CompressingXYDataset dataset = dataSeries.get(feed).getData();
double min;
double max;
if(plot.getAxisOrientationSetting() == AxisOrientationSetting.X_AXIS_AS_TIME) {
min = dataset.getMinX();
max = dataset.getMaxX();
} else {
min = dataset.getMinY();
max = dataset.getMaxY();
}
double datasetMinTime = Math.min(min, max);
double datasetMaxTime = Math.max(min, max);
if(dataset.getPointCount() == 0 || points.firstKey() >= datasetMaxTime) {
// TODO: Change this to use an aggregate add method
if(plot.getAxisOrientationSetting() == AxisOrientationSetting.X_AXIS_AS_TIME) {
for(Entry<Long, Double> point : points.entrySet()) {
dataset.add(point.getKey(), point.getValue());
}
} else {
for(Entry<Long, Double> point : points.entrySet()) {
dataset.add(point.getValue(), point.getKey());
}
}
if (plot.getMaxTime() >= datasetMaxTime) {
dataSeries.get(feed).setUpdateRegressionLine(true);
}
} else if(points.lastKey() <= datasetMinTime) {
// TODO: Make this efficient
double[] x = new double[points.size()];
double[] y = new double[x.length];
int i = 0;
for(Entry<Long, Double> p : points.entrySet()) {
x[i] = p.getKey();
y[i] = p.getValue();
i++;
}
if(plot.getAxisOrientationSetting() == AxisOrientationSetting.Y_AXIS_AS_TIME) {
double[] tmp = x;
x = y;
y = tmp;
}
dataset.prepend(x, 0, y, 0, x.length);
} else {
// Data appearing in the middle of the dataset.
// Assume that it's caused by the last second of data arriving twice,
// once from the initial historical request and once from the once-per-second update.
// It may also be values for predictive data we already loaded.
// In either case, the overlapping data should be identical to what we already have, so ignore it.
// Append the data that isn't redundant.
SortedMap<Long, Double> before = points.subMap(0L, (long) datasetMinTime);
SortedMap<Long, Double> after = points.subMap((long) datasetMaxTime, Long.MAX_VALUE);
SortedMap<Long, Double> overlap = points.subMap((long) datasetMinTime, (long) datasetMaxTime);
if(!overlap.isEmpty()) {
if(overlap.lastKey() - overlap.firstKey() > 10000) {
logger.warn("Cannot currently insert into the middle of a dataset: minX = " + datasetMinTime + ", maxX = " + datasetMaxTime
+ ", firstKey = " + points.firstKey() + ", lastKey = " + points.lastKey());
}
}
// TODO: Change this to use an aggregate add method
if(plot.getAxisOrientationSetting() == AxisOrientationSetting.X_AXIS_AS_TIME) {
if(!before.isEmpty()) {
double[] x = new double[before.size()];
double[] y = new double[x.length];
int i = 0;
for(Entry<Long, Double> point : before.entrySet()) {
x[i] = point.getKey();
y[i] = point.getValue();
i++;
}
dataset.prepend(x, 0, y, 0, x.length);
}
for(Entry<Long, Double> point : after.entrySet()) {
dataset.add(point.getKey(), point.getValue());
}
} else {
if(!before.isEmpty()) {
double[] x = new double[before.size()];
double[] y = new double[x.length];
int i = 0;
for(Entry<Long, Double> point : before.entrySet()) {
y[i] = point.getKey();
x[i] = point.getValue();
i++;
}
dataset.prepend(x, 0, y, 0, x.length);
}
for(Entry<Long, Double> point : after.entrySet()) {
dataset.add(point.getValue(), point.getKey());
}
}
}
dataSeries.get(feed).updateRegressionLine();
for(Entry<Long, Double> point : points.entrySet()) {