/*===============================================================
Copyright (C) 2007 William J. Bosl

File name: 	Node.java

Written by: 	William J. Bosl

		Mailing address:
		Children's Hospital Informatics Program at 
	 	Harvard-MIT Division of Health Sciences and Technology
		Enders 150.5
		Children's Hospital Boston
		300 Longwood Avenue
		Boston, MA 02115

		email: william.bosl@childrens.harvard.edu

Modifications:
 * Clark Freifeld, 15 Mar 2006


This program is free software; you can redistribute it 
and/or modify it under the terms of the GNU General 
Public License as published by the Free Software 
Foundation; either version 2 of the License, or 
(at your option) any later version.

This program is distributed in the hope that it will 
be useful, but WITHOUT ANY WARRANTY; without even the 
implied warranty of MERCHANTABILITY or FITNESS FOR A 
PARTICULAR PURPOSE. See the GNU General Public License 
for more details.

You may access a copy of the GNU General Public License at: 
http://www.opensource.org/licenses/gpl-license.php; 
or, you may write to the Free Software Foundation, 
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

===============================================================*/

package bionet;

import javax.swing.JFrame;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.data.xy.XYDataset;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.plot.PlotOrientation;
 
public class PlotTimeSeries extends JFrame {
    
    /**
     * Plot the data in dataArray in an xy multiline graph
     * @param dataNames array of strings naming the datasets
     * @param dataArray the data
     * @param generation
     * @param score
     *
     */ 
    public void Plot(int ntseries, String[] dataNames, double[][] dataArray, int generation, double score) {
        XYSeriesCollection seriesColl = new XYSeriesCollection();
        for(int i = 1; i < dataNames.length; i++) {
            XYSeries series = new XYSeries(dataNames[i]);
            for(int j = 0; j < dataArray[0].length; j++) {
                series.add(dataArray[0][j], dataArray[i][j]);
            }
            seriesColl.addSeries(series);
        }
        XYDataset xyDataset = seriesColl;
        String title = " ";
        if(generation != 1) {
        	title = "Generation: " + generation + "\nScore = " + score;
        }
        String xLabel = "Time";
        String yLabel = dataNames[1];
        JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, xyDataset, PlotOrientation.VERTICAL, true, true, true);
  	    //createXYLineCharteChart(java.lang.String title, java.lang.String xAxisLabel, java.lang.String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)

        this.getContentPane().add(new ChartPanel(chart));
        this.setSize(800, 500);
        this.setVisible(true);
    }

    // test drive the JFreeChart stuff
    public static void main(String[] args) {
        DefaultPieDataset pieDataset = new DefaultPieDataset();
        pieDataset.setValue("JavaWorld", new Integer(175));
        pieDataset.setValue("Other", new Integer(25));
        // java.lang.String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls)
        JFreeChart chart = ChartFactory.createPieChart
                     ("Sample Pie Chart",   // Title
                      pieDataset,           // Dataset
                      true,                 // Show legend  
                      true,                 // tooltips
                      true                  // urls
                     );

        JFrame frame = new JFrame("Chart Example");
        frame.getContentPane().add(new ChartPanel(chart));

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800, 500);
        frame.setVisible(true);
     }
}
