Added item count to LinePlotSeries
This commit is contained in:
@@ -87,6 +87,15 @@ public class LinePlotSeries extends PlotSeries<LinePlot> {
|
||||
return getPlot().getSeriesData(this)[0].length;
|
||||
}
|
||||
|
||||
private int maxItemCount=-1;
|
||||
public int getMaxItemCount() {
|
||||
return maxItemCount;
|
||||
}
|
||||
public void setMaxItemCount(int value) {
|
||||
maxItemCount=value;
|
||||
}
|
||||
|
||||
|
||||
//Tools
|
||||
public double getAverage() {
|
||||
double average = 0.0;
|
||||
|
||||
@@ -76,7 +76,7 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
|
||||
try {
|
||||
doUpdate();
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(PlotBase.class.getName()).log(Level.SEVERE, null, ex);
|
||||
//Logger.getLogger(PlotBase.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -282,7 +282,7 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
|
||||
try {
|
||||
updateSeries(series);
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(LinePlotBase.class.getName()).log(Level.SEVERE, null, ex);
|
||||
//Logger.getLogger(LinePlotBase.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -131,6 +131,13 @@ public class LinePlot extends ch.psi.plot.LinePlotBase {
|
||||
return (XYChart.Series) (series.getToken());
|
||||
}
|
||||
|
||||
LinePlotSeries getLinePlotSeries(XYChart.Series s) {
|
||||
for (LinePlotSeries series:this.getAllSeries())
|
||||
if (series.getToken()==s)
|
||||
return series;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doUpdate() {
|
||||
if (mTimerFX != null) {
|
||||
@@ -305,7 +312,9 @@ public class LinePlot extends ch.psi.plot.LinePlotBase {
|
||||
// return;
|
||||
synchronized (seriesList) {
|
||||
for (Iterator<Series> it = seriesList.keySet().iterator(); it.hasNext();) {
|
||||
XYChart.Series series = it.next();
|
||||
XYChart.Series series = it.next();
|
||||
LinePlotSeries lps = getLinePlotSeries(series);
|
||||
int maxItemCount = (lps==null) ? -1 : lps.getMaxItemCount();
|
||||
if (isPlottingSeries(series)) {
|
||||
ConcurrentLinkedQueue<Data<Number, Number>> queue = seriesList.get(series);
|
||||
//int count=0;
|
||||
@@ -320,6 +329,10 @@ public class LinePlot extends ch.psi.plot.LinePlotBase {
|
||||
}
|
||||
}
|
||||
series.getData().addAll(queue);
|
||||
if ((maxItemCount>0)&&(series.getData().size()>maxItemCount)){
|
||||
series.getData().remove(0, series.getData().size()-maxItemCount);
|
||||
}
|
||||
|
||||
queue.clear();
|
||||
|
||||
}
|
||||
|
||||
@@ -89,8 +89,10 @@ public class LinePlot extends LinePlotBase {
|
||||
@Override
|
||||
protected Object onAddedSeries(LinePlotSeries series) {
|
||||
final XYSeries s = new XYSeries(series.getName());
|
||||
if (series.getMaxItemCount()>0){
|
||||
s.setMaximumItemCount(series.getMaxItemCount());
|
||||
}
|
||||
data.addSeries(s);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -129,6 +129,9 @@ public class LinePlot extends LinePlotBase {
|
||||
plot.addData(view, x, y);
|
||||
else
|
||||
view.add(x, y);
|
||||
if (series.getMaxItemCount()>0){
|
||||
view.garbagePointLimit(series.getMaxItemCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +140,9 @@ public class LinePlot extends LinePlotBase {
|
||||
JLDataView view = getDataView(series);
|
||||
if (view != null) {
|
||||
view.setData(x, y);
|
||||
if (series.getMaxItemCount()>0){
|
||||
view.garbagePointLimit(series.getMaxItemCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user