package evaluation;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import javax.imageio.ImageIO;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
public class Visualiser //extends JFrame
{
//private final DefaultCategoryDataset datasetT;
//private final DefaultCategoryDataset datasetR;
//private final DefaultCategoryDataset datasetU;
//PAT
private final DefaultCategoryDataset dataset;
private String comment;
private String title, x, y;
public Visualiser(String title, String x, String y){
comment = "Amount of unsatisfied clauses \n";
// datasetT = new DefaultCategoryDataset();
//datasetR = new DefaultCategoryDataset();
//datasetU = new DefaultCategoryDataset();
//Pat
dataset =new DefaultCategoryDataset();
this.title = title;
this.x = x;
this.y = y;
}
public void setValue(String algo, Double x, Double y){
//PAT
dataset.addValue(y,algo,x);
//if(algo.startsWith("SIMT"))
// datasetT.addValue(y, algo, x);
//else if(algo.startsWith("SIMR"))
// datasetR.addValue(y, algo, x);
//else if(algo.startsWith("SIMU"))
// datasetU.addValue(y, algo, x);
}
public void setComment(String algo, String comment){
this.comment+= algo + " - "+comment + "\n";
}
public void saveChart(String path){
//PAT
JFreeChart chart=ChartFactory.createLineChart(title,x,
y,dataset,PlotOrientation.VERTICAL,true,true,true);
/*
JFreeChart chartT = ChartFactory.createLineChart(title,x,
y,datasetT,PlotOrientation.VERTICAL,false,true,true);
JFreeChart chartR = ChartFactory.createLineChart(title,x,
y,datasetR,PlotOrientation.VERTICAL,false,true,true);
JFreeChart chartU = ChartFactory.createLineChart(title,x,
y,datasetU,PlotOrientation.VERTICAL,false,true,true);
BufferedImage biT = chartT.createBufferedImage(800, 500);
BufferedImage biR = chartR.createBufferedImage(800, 500);
BufferedImage biU = chartU.createBufferedImage(800, 500);
*/
//PAT
BufferedImage bi = chart.createBufferedImage(800, 500);
try{
// ImageIO.write(biT, "png", new File(path+"_T.png"));
//ImageIO.write(biR, "png", new File(path+"_R.png"));
//ImageIO.write(biU, "png", new File(path+"_U.png"));
//PAT
ImageIO.write(bi, "png", new File(path+".png"));
}catch(IOException ex){
ex.printStackTrace();
}
}
public void saveData(String path){
FileOutputStream out;
PrintStream p;
try {
out = new FileOutputStream(path+".txt");
p = new PrintStream( out );
/* for(Object r : datasetT.getRowKeys()){
for(Object c : datasetT.getColumnKeys()){
p.println(r + " = " + datasetT.getValue((Comparable)r,(Comparable)c));
}
p.println("--------------------------");
}
p.println("#########################");
for(Object r : datasetR.getRowKeys()){
for(Object c : datasetR.getColumnKeys()){
p.println(r + " = " + datasetR.getValue((Comparable)r,(Comparable)c));
}
p.println("--------------------------");
}
p.println("#########################");
for(Object r : datasetU.getRowKeys()){
for(Object c : datasetU.getColumnKeys()){
p.println(r + " = " + datasetU.getValue((Comparable)r,(Comparable)c));
}
p.println("--------------------------");
}
p.println("#########################");
*/
//PAT
for(Object r : dataset.getRowKeys()){
for(Object c : dataset.getColumnKeys()){
p.println(r + " = " + dataset.getValue((Comparable)r,(Comparable)c));
}
p.println("--------------------------");
}
p.println("#########################");
} catch (Exception e) {
System.err.println ("Error writing to file");
}
}
// public void showChart(){
// JPanel c = new JPanel();
// JTextArea commentArea = new JTextArea();
// commentArea.setText(comment);
// JFreeChart chart = ChartFactory.createLineChart(title,x,
// y,dataset,PlotOrientation.VERTICAL,true,true,true);
// c.add(new ChartPanel(chart));
// c.add(commentArea);
// setContentPane(c);
// setVisible(true);
// setLayout(new FlowLayout());
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//
// }
}