package com.pgorecki.pcr.appliedBiosystems;

import java.io.File;
import java.io.IOException;

import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.chart.renderer.category.StatisticalBarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.statistics.DefaultStatisticalCategoryDataset;

public class Plotter {
	
	public static DefaultStatisticalCategoryDataset getDatasetMeanΔΔcт(Experiment experiment) {
		DefaultStatisticalCategoryDataset dataset = new DefaultStatisticalCategoryDataset();
		for (Group group : experiment.getGroupList()) {
			if (group.isReference())
				continue;
			dataset.add(group.getMeanΔΔcт(), group.getSemΔΔcт(), group.getTargetName(), group.getName());
		}
		return dataset;
	}
	
	public static DefaultStatisticalCategoryDataset getDatasetRQ(Experiment experiment) {
		DefaultStatisticalCategoryDataset dataset = new DefaultStatisticalCategoryDataset();
		for (Group group : experiment.getGroupList()) {
			if (group.isReference())
				continue;
			dataset.add(group.getMeanRq(), group.getSemRq(), group.getTargetName(), group.getName());
		}
		return dataset;
	}
	
	public static void plot(Experiment experiment, String xAxis, String yAxis, String outFileName, CategoryDataset dataset) throws IOException {	
		CategoryAxis oxAxis = new CategoryAxis(xAxis);
		ValueAxis oyAxis = new NumberAxis(yAxis);
		CategoryItemRenderer renderer = new StatisticalBarRenderer();
		
		
		CategoryPlot plot = new CategoryPlot(dataset, oxAxis, oyAxis, renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);

        JFreeChart chart = new JFreeChart(experiment.getExperimentDefinition().getExperimentName(), JFreeChart.DEFAULT_TITLE_FONT, plot, true);        
        
        int width = 640;
        int height = 480; 
        File pieChart = new File("/home/piotr/workspace/" + outFileName + ".jpeg"); 
        ChartUtilities.saveChartAsJPEG(pieChart , chart , width , height);
	}

}

@@ -640,16 +640,111 @@
 ter %7B%0A%09%0A
+%09public final static int DEFAULT_WIDTH = 640;%0A%09public final static int DEFAULT_HEIGHT = 480;%0A%09%0A
 %09public 
@@ -820,32 +820,32 @@
 t experiment) %7B%0A
-
 %09%09DefaultStatist
@@ -1536,12 +1536,14 @@
 tic 
-void
+String
  plo
@@ -2129,85 +2129,22 @@
     
-int width = 640;%0A        int height = 480; %0A        File pieChart = new File(
+String path = 
 %22/ho
@@ -2187,16 +2187,55 @@
  %22.jpeg%22
+;%0A        File pieChart = new File(path
 ); %0A    
@@ -2292,23 +2292,76 @@
 t , 
-width , height)
+Plotter.DEFAULT_WIDTH , Plotter.DEFAULT_HEIGHT);%0A        return path
 ;%0A%09%7D

Add default dimension constants for the image. Plot method return path to the image.