Adapting to plot v2: Abstraction of graphs & new implementations: JZY3D, JavaFX, JFreeChart
This commit is contained in:
@@ -1,2 +1,4 @@
|
||||
# 3.1.0
|
||||
* Abstracted interfaces of plot package and implemented JZY3d, JFreeChart and JavaFX
|
||||
# 3.0.1
|
||||
* Update the fda.properties file and replace ch.psi.fda.aq.data.baseDirectory with ch.psi.fda.aq.data.dir.
|
||||
@@ -36,12 +36,6 @@
|
||||
<version>2.4.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.psi</groupId>
|
||||
<artifactId>plot</artifactId>
|
||||
<version>1.1.31</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.inject</groupId>
|
||||
<artifactId>guice</artifactId>
|
||||
@@ -97,6 +91,11 @@
|
||||
<version>4.8.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>plot</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package ch.psi.fda.ui.visualizer;
|
||||
|
||||
import ch.psi.plot.Plot;
|
||||
import ch.psi.plot.PlotSeries;
|
||||
|
||||
public interface SeriesDataFilter {
|
||||
/**
|
||||
@@ -27,4 +28,5 @@ public interface SeriesDataFilter {
|
||||
* @return
|
||||
*/
|
||||
public Plot getPlot();
|
||||
public PlotSeries getSeries();
|
||||
}
|
||||
|
||||
@@ -19,16 +19,6 @@
|
||||
|
||||
package ch.psi.fda.ui.visualizer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import ch.psi.fda.messages.DataMessage;
|
||||
import ch.psi.fda.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.messages.StreamDelimiterMessage;
|
||||
@@ -38,12 +28,20 @@ import ch.psi.fda.vdescriptor.XYSeries;
|
||||
import ch.psi.fda.vdescriptor.XYZSeries;
|
||||
import ch.psi.fda.vdescriptor.YSeries;
|
||||
import ch.psi.fda.vdescriptor.YZSeries;
|
||||
import ch.psi.plot.LinePlot;
|
||||
import ch.psi.plot.LinePlotBase;
|
||||
import ch.psi.plot.LinePlotSeries;
|
||||
import ch.psi.plot.MatrixPlot;
|
||||
import ch.psi.plot.MatrixPlotBase;
|
||||
import ch.psi.plot.MatrixPlotSeries;
|
||||
import ch.psi.plot.Plot;
|
||||
import ch.psi.plot.xy.LinePlot;
|
||||
import ch.psi.plot.xy.XYSeriesCollectionP;
|
||||
import ch.psi.plot.xy.XYSeriesP;
|
||||
import ch.psi.plot.xyz.MatrixPlot;
|
||||
import ch.psi.plot.xyz.MatrixPlotData;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
/**
|
||||
* Visualizer for visualizing data
|
||||
@@ -61,62 +59,83 @@ public class Visualizer {
|
||||
private List<SeriesDataFilter> filters;
|
||||
|
||||
private boolean first = true;
|
||||
|
||||
public Visualizer(VDescriptor vdescriptor){
|
||||
public Visualizer(VDescriptor vdescriptor){
|
||||
this(vdescriptor,null,null);
|
||||
}
|
||||
public Visualizer(VDescriptor vdescriptor, String linePlotImpl, String matrixPlotImpl){
|
||||
if (linePlotImpl==null){
|
||||
linePlotImpl="jfree";
|
||||
}
|
||||
if (matrixPlotImpl==null){
|
||||
matrixPlotImpl="jfree";
|
||||
}
|
||||
filters = new ArrayList<SeriesDataFilter>();
|
||||
|
||||
for(ch.psi.fda.vdescriptor.Plot vplot: vdescriptor.getPlots()){
|
||||
if(vplot instanceof ch.psi.fda.vdescriptor.LinePlot){
|
||||
ch.psi.fda.vdescriptor.LinePlot lp = (ch.psi.fda.vdescriptor.LinePlot) vplot;
|
||||
|
||||
// Create plot for visualization
|
||||
ch.psi.plot.xy.LinePlot plot = new ch.psi.plot.xy.LinePlot(lp.getTitle());
|
||||
|
||||
for(Series s: lp.getData()){
|
||||
if(s instanceof XYSeries){
|
||||
XYSeries sxy = (XYSeries)s;
|
||||
XYSeriesDataFilter filter = new XYSeriesDataFilter(sxy.getX(), sxy.getY(), plot);
|
||||
filter.setSeriesName(sxy.getY());
|
||||
filters.add(filter);
|
||||
}
|
||||
else if(s instanceof YSeries){
|
||||
YSeries sy = (YSeries)s;
|
||||
|
||||
XYSeriesArrayDataFilter filter = new XYSeriesArrayDataFilter(sy.getY(), plot);
|
||||
// filter.setMaxSeries(lp.getMaxSeries()*lp.getY().size()); // Workaround - keep for each array max series
|
||||
// filter.setOffset(lp.getOffset());
|
||||
// filter.setSize(lp.getSize());
|
||||
filter.setSeriesName(sy.getY());
|
||||
filters.add(filter);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if(vplot instanceof ch.psi.fda.vdescriptor.MatrixPlot){
|
||||
|
||||
// MatrixPlot does currently not support RegionPositioners because of the
|
||||
// plotting problems this would cause. If regions of the positioner have different
|
||||
// step sizes it is not easily possible (without (specialized) rasterization) to plot the data.
|
||||
|
||||
ch.psi.fda.vdescriptor.MatrixPlot lp = (ch.psi.fda.vdescriptor.MatrixPlot) vplot;
|
||||
MatrixPlotData data = new MatrixPlotData(lp.getMinX(), lp.getMaxX(), lp.getnX(), lp.getMinY(), lp.getMaxY(), lp.getnY());
|
||||
MatrixPlot plot = new MatrixPlot(lp.getTitle(), data);
|
||||
|
||||
for(Series s: lp.getData()){
|
||||
if(s instanceof XYZSeries){
|
||||
XYZSeries sxyz = (XYZSeries) s;
|
||||
filters.add(new XYZSeriesDataFilter(sxyz.getX(), sxyz.getY(), sxyz.getZ(), plot));
|
||||
|
||||
}
|
||||
else if(s instanceof YZSeries){
|
||||
YZSeries syz = (YZSeries) s;
|
||||
XYZSeriesArrayDataFilter filter = new XYZSeriesArrayDataFilter(syz.getY(), syz.getZ(), 0, 0, plot);
|
||||
filters.add(filter);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
try{
|
||||
for(ch.psi.fda.vdescriptor.Plot vplot: vdescriptor.getPlots()){
|
||||
if(vplot instanceof ch.psi.fda.vdescriptor.LinePlot){
|
||||
ch.psi.fda.vdescriptor.LinePlot lp = (ch.psi.fda.vdescriptor.LinePlot) vplot;
|
||||
|
||||
// Create plot for visualization
|
||||
LinePlot plot = LinePlotBase.newPlot(linePlotImpl);
|
||||
plot.setTitle(lp.getTitle());
|
||||
|
||||
for(Series s: lp.getData()){
|
||||
if(s instanceof XYSeries){
|
||||
XYSeries sxy = (XYSeries)s;
|
||||
XYSeriesDataFilter filter = new XYSeriesDataFilter(sxy.getX(), sxy.getY(), plot);
|
||||
filter.setSeriesName(sxy.getY());
|
||||
filters.add(filter);
|
||||
}
|
||||
else if(s instanceof YSeries){
|
||||
YSeries sy = (YSeries)s;
|
||||
|
||||
XYSeriesArrayDataFilter filter = new XYSeriesArrayDataFilter(sy.getY(), plot);
|
||||
// filter.setMaxSeries(lp.getMaxSeries()*lp.getY().size()); // Workaround - keep for each array max series
|
||||
// filter.setOffset(lp.getOffset());
|
||||
// filter.setSize(lp.getSize());
|
||||
filter.setSeriesName(sy.getY());
|
||||
filters.add(filter);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if(vplot instanceof ch.psi.fda.vdescriptor.MatrixPlot){
|
||||
|
||||
// MatrixPlot does currently not support RegionPositioners because of the
|
||||
// plotting problems this would cause. If regions of the positioner have different
|
||||
// step sizes it is not easily possible (without (specialized) rasterization) to plot the data.
|
||||
|
||||
ch.psi.fda.vdescriptor.MatrixPlot lp = (ch.psi.fda.vdescriptor.MatrixPlot) vplot;
|
||||
MatrixPlotSeries data = new MatrixPlotSeries("", lp.getMinX(), lp.getMaxX(), lp.getnX(), lp.getMinY(), lp.getMaxY(), lp.getnY());
|
||||
MatrixPlot plot = MatrixPlotBase.newPlot(matrixPlotImpl);
|
||||
plot.setTitle(lp.getTitle());
|
||||
plot.addSeries(data);
|
||||
|
||||
for(Series s: lp.getData()){
|
||||
if(s instanceof XYZSeries){
|
||||
XYZSeries sxyz = (XYZSeries) s;
|
||||
XYZSeriesDataFilter filter=new XYZSeriesDataFilter(sxyz.getX(), sxyz.getY(), sxyz.getZ(), plot);
|
||||
filter.setSeries(data);
|
||||
filters.add(filter);
|
||||
|
||||
}
|
||||
else if(s instanceof YZSeries){
|
||||
YZSeries syz = (YZSeries) s;
|
||||
XYZSeriesArrayDataFilter filter = new XYZSeriesArrayDataFilter(syz.getY(), syz.getZ(), 0, 0, plot);
|
||||
filter.setSeries(data);
|
||||
filters.add(filter);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Ignore if something goes wrong while adding a datapoint
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +154,7 @@ public class Visualizer {
|
||||
for (SeriesDataFilter f: filters) {
|
||||
Plot plot = f.getPlot();
|
||||
if(plot instanceof MatrixPlot){
|
||||
((MatrixPlotData) ((MatrixPlot)plot).getData()).clear();
|
||||
f.getSeries().clear();
|
||||
}
|
||||
}
|
||||
clearPlot = false;
|
||||
@@ -145,15 +164,15 @@ public class Visualizer {
|
||||
if(filter instanceof XYSeriesDataFilter){
|
||||
XYSeriesDataFilter xyfilter = (XYSeriesDataFilter) filter;
|
||||
|
||||
if(xyfilter.getActualSeries()==null || xyfilter.isNewseries()){
|
||||
if(xyfilter.getSeries()==null || xyfilter.isNewseries()){
|
||||
// First series that is filled by this filter!
|
||||
XYSeriesP s = new XYSeriesP(xyfilter.getSeriesName() + " " + ecount + "-" + xyfilter.getCount());
|
||||
((LinePlot)xyfilter.getPlot()).getData().addSeries(s);
|
||||
xyfilter.setActualSeries(s);
|
||||
LinePlotSeries s = new LinePlotSeries(xyfilter.getSeriesName() + " " + ecount + "-" + xyfilter.getCount());
|
||||
((LinePlot)xyfilter.getPlot()).addSeries(s);
|
||||
xyfilter.setSeries(s);
|
||||
xyfilter.setNewseries(false);
|
||||
}
|
||||
|
||||
XYSeriesP series = xyfilter.getActualSeries(); // TODO Does not work with multiple series filter per plot !!!!
|
||||
LinePlotSeries series = xyfilter.getSeries(); // TODO Does not work with multiple series filter per plot !!!!
|
||||
|
||||
// There might be other values than double in the data, therefore we have to check for it
|
||||
Object dX = message.getData(xyfilter.getIdX());
|
||||
@@ -168,7 +187,9 @@ public class Visualizer {
|
||||
}
|
||||
|
||||
// Add Data to the series
|
||||
series.add(dataX , dataY, updateAtStreamElement);
|
||||
/*
|
||||
series.add(dataX , dataY, updateAtStreamElement);*/
|
||||
series.appendData(dataX , dataY);
|
||||
}
|
||||
if(filter instanceof XYSeriesArrayDataFilter){
|
||||
final XYSeriesArrayDataFilter xyfilter = (XYSeriesArrayDataFilter) filter;
|
||||
@@ -179,31 +200,39 @@ public class Visualizer {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
XYSeriesP series = new XYSeriesP(xyfilter.getSeriesName() + "-" + xyfilter.getCount()); // Series name must be unique
|
||||
LinePlotSeries series = new LinePlotSeries(xyfilter.getSeriesName() + "-" + xyfilter.getCount()); // Series name must be unique
|
||||
xyfilter.incrementCount();
|
||||
|
||||
// ((LinePlot)xyfilter.getPlot()).getData().removeAllSeries(); // Remove all series from the data
|
||||
// If we can agree only to display one series at a time also a clear() on the actual series is better
|
||||
XYSeriesCollectionP sc = ((LinePlot)xyfilter.getPlot()).getData();
|
||||
sc.addSeries(series);
|
||||
((LinePlot)xyfilter.getPlot()).addSeries(series);
|
||||
xyfilter.setSeries(series);
|
||||
|
||||
// Remove outdated series
|
||||
if(sc.getSeriesCount()>xyfilter.getMaxSeries()){
|
||||
if(((LinePlot)xyfilter.getPlot()).getNumberOfSeries()>xyfilter.getMaxSeries()){
|
||||
// Remove oldest series
|
||||
sc.removeSeries(0);
|
||||
((LinePlot)xyfilter.getPlot()).removeSeries(((LinePlot)xyfilter.getPlot()).getSeries(0));
|
||||
}
|
||||
|
||||
double[] data = message.getData(xyfilter.getIdY());
|
||||
|
||||
|
||||
// Copy data starting from offset to size
|
||||
int size = data.length;
|
||||
int offset = xyfilter.getOffset();
|
||||
if(xyfilter.getSize()>0 && offset+xyfilter.getSize()<data.length){
|
||||
size = offset + xyfilter.getSize();
|
||||
}
|
||||
|
||||
((LinePlot)xyfilter.getPlot()).setUpdatesEnabled(false);
|
||||
for(int i=offset;i<size;i++){
|
||||
series.add(i,data[i], false); // Do not fire change event - this would degrade performance drastically
|
||||
//series.add(i,data[i], false); // Do not fire change event - this would degrade performance drastically
|
||||
series.appendData(i,data[i]);
|
||||
}
|
||||
series.fireSeriesChanged();
|
||||
((LinePlot)xyfilter.getPlot()).setUpdatesEnabled(updateAtStreamElement);
|
||||
// series.fireSeriesChanged();
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
@@ -211,7 +240,7 @@ public class Visualizer {
|
||||
else if(filter instanceof XYZSeriesDataFilter){
|
||||
XYZSeriesDataFilter xyzfilter = (XYZSeriesDataFilter) filter;
|
||||
try{
|
||||
((MatrixPlot)xyzfilter.getPlot()).getData().addData((Double) message.getData(xyzfilter.getIdX()),(Double) message.getData(xyzfilter.getIdY()), (Double) message.getData(xyzfilter.getIdZ()));
|
||||
xyzfilter.getSeries().appendData((Double) message.getData(xyzfilter.getIdX()),(Double) message.getData(xyzfilter.getIdY()), (Double) message.getData(xyzfilter.getIdZ()));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Ignore if something goes wrong while adding a datapoint
|
||||
@@ -227,12 +256,14 @@ public class Visualizer {
|
||||
// int size = xyzfilter.getSize();
|
||||
// for(int i=offset;i<offset+size; i++){
|
||||
for(int i=0;i<data.length; i++){
|
||||
((MatrixPlot)xyzfilter.getPlot()).getData().addData(i, y, data[i]);
|
||||
((MatrixPlot)xyzfilter).getSeries("").appendData(i, y, data[i]);
|
||||
}
|
||||
/*
|
||||
// Update data if update by point is enabled
|
||||
if(updateAtStreamElement){
|
||||
xyzfilter.getPlot().update();
|
||||
xyzfilter.getPlot().update(false);
|
||||
}
|
||||
*/
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Ignore if something goes wrong while adding a datapoint
|
||||
@@ -262,13 +293,7 @@ public class Visualizer {
|
||||
if(updateAtStreamDelimiter){
|
||||
for(SeriesDataFilter f: filters){
|
||||
Plot plot = f.getPlot();
|
||||
// for (Plot plot: plots) {
|
||||
if(plot instanceof MatrixPlot){
|
||||
((MatrixPlot)plot).update();
|
||||
}
|
||||
else if(plot instanceof LinePlot){
|
||||
((LinePlot) plot).update();
|
||||
}
|
||||
plot.update(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,13 +315,7 @@ public class Visualizer {
|
||||
// Update matrix plots
|
||||
for(SeriesDataFilter f: filters){
|
||||
Plot plot = f.getPlot();
|
||||
if(plot instanceof MatrixPlot){
|
||||
((MatrixPlot)plot).update();
|
||||
((MatrixPlot)plot).adaptColorMapScale(); // Update color scale at the end
|
||||
}
|
||||
else if(plot instanceof LinePlot){
|
||||
((LinePlot) plot).update();
|
||||
}
|
||||
plot.update(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package ch.psi.fda.ui.visualizer;
|
||||
|
||||
import ch.psi.plot.LinePlotSeries;
|
||||
import ch.psi.plot.Plot;
|
||||
|
||||
/**
|
||||
@@ -72,7 +73,18 @@ public class XYSeriesArrayDataFilter implements SeriesDataFilter {
|
||||
this.seriesName = seriesName;
|
||||
}
|
||||
|
||||
/**
|
||||
private LinePlotSeries series = null;
|
||||
|
||||
@Override
|
||||
public LinePlotSeries getSeries(){
|
||||
return series;
|
||||
}
|
||||
|
||||
public void setSeries(LinePlotSeries series){
|
||||
this.series=series;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the count
|
||||
*/
|
||||
public int getCount() {
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
|
||||
package ch.psi.fda.ui.visualizer;
|
||||
|
||||
import ch.psi.plot.Plot;
|
||||
import ch.psi.plot.xy.XYSeriesP;
|
||||
import ch.psi.plot.LinePlot;
|
||||
import ch.psi.plot.LinePlotSeries;
|
||||
import ch.psi.plot.PlotSeries;
|
||||
|
||||
/**
|
||||
* Metadata of a group of XYSeries.
|
||||
@@ -39,14 +40,20 @@ public class XYSeriesDataFilter implements SeriesDataFilter{
|
||||
private int count = 0;
|
||||
|
||||
// Plot the data of this filter goes to
|
||||
private final Plot plot;
|
||||
|
||||
// TODO WORKAROUND - XYZ filter must not have this property !!!!
|
||||
private XYSeriesP actualSeries = null;
|
||||
private final LinePlot plot;
|
||||
|
||||
private boolean newseries = false;
|
||||
|
||||
private LinePlotSeries series = null;
|
||||
@Override
|
||||
public LinePlotSeries getSeries(){
|
||||
return series;
|
||||
}
|
||||
public void setSeries(LinePlotSeries series){
|
||||
this.series=series;
|
||||
}
|
||||
|
||||
|
||||
public XYSeriesDataFilter(String idX, String idY, Plot plot){
|
||||
public XYSeriesDataFilter(String idX, String idY, LinePlot plot){
|
||||
this.idX = idX;
|
||||
this.idY = idY;
|
||||
this.plot = plot;
|
||||
@@ -70,15 +77,9 @@ public class XYSeriesDataFilter implements SeriesDataFilter{
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
public Plot getPlot() {
|
||||
public LinePlot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
public XYSeriesP getActualSeries() {
|
||||
return actualSeries;
|
||||
}
|
||||
public void setActualSeries(XYSeriesP actualSeries) {
|
||||
this.actualSeries = actualSeries;
|
||||
}
|
||||
public boolean isNewseries() {
|
||||
return newseries;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package ch.psi.fda.ui.visualizer;
|
||||
|
||||
import ch.psi.plot.MatrixPlotSeries;
|
||||
import ch.psi.plot.Plot;
|
||||
|
||||
public class XYZSeriesArrayDataFilter implements SeriesDataFilter {
|
||||
@@ -57,6 +58,16 @@ public class XYZSeriesArrayDataFilter implements SeriesDataFilter {
|
||||
public void setSeriesName(String seriesName) {
|
||||
this.seriesName = seriesName;
|
||||
}
|
||||
private MatrixPlotSeries series = null;
|
||||
|
||||
@Override
|
||||
public MatrixPlotSeries getSeries(){
|
||||
return series;
|
||||
}
|
||||
|
||||
public void setSeries(MatrixPlotSeries series){
|
||||
this.series=series;
|
||||
}
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package ch.psi.fda.ui.visualizer;
|
||||
|
||||
import ch.psi.plot.MatrixPlotSeries;
|
||||
import ch.psi.plot.Plot;
|
||||
|
||||
public class XYZSeriesDataFilter implements SeriesDataFilter {
|
||||
@@ -55,6 +56,16 @@ public class XYZSeriesDataFilter implements SeriesDataFilter {
|
||||
public void setSeriesName(String seriesName) {
|
||||
this.seriesName = seriesName;
|
||||
}
|
||||
|
||||
private MatrixPlotSeries series = null;
|
||||
|
||||
@Override
|
||||
public MatrixPlotSeries getSeries(){
|
||||
return series;
|
||||
}
|
||||
public void setSeries(MatrixPlotSeries series){
|
||||
this.series=series;
|
||||
}
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user