/*
 *  Draco Econometrics
 *  Copyright (C) 2006-2008 Approximatrix, LLC
 *  http://www.approximatrix.com
 *  
 *  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 3 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 should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.approximatrix.draco.plot.ui;

import java.util.ArrayList;

import com.approximatrix.charting.*;
import com.approximatrix.charting.model.*;
import com.approximatrix.charting.render.*;

/*
 * Created on Jan 26, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author armstrongj
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class DataPlot extends GenericPlotInterface {
	
	// Charting variables
	MultiScatterDataModel data = null;
	
	
	public DataPlot(ArrayList incoming_data, 
	        		String[] incoming_series_labels) {

		// construct the chart immediately
		data = new MultiScatterDataModel();
		for(int i=0;i<Math.min(incoming_data.size(),incoming_series_labels.length);i++) {
			data.addData((double[][])incoming_data.get(i),incoming_series_labels[i]);
		}
		initialize();
	}

	public DataPlot(ArrayList incoming_data, 
			        String incoming_x_label, 
					String[] incoming_series_labels) {
		
		this(incoming_data,incoming_series_labels);
		panel.getCoordSystem().setXAxisUnit(incoming_x_label);
	}
	
	public DataPlot(ArrayList incoming_data, 
			String incoming_x_label, 
			String[] incoming_series_labels,
			String title) {

		this(incoming_data,incoming_x_label,incoming_series_labels);
		panel.setTitle(new Title(title));

	}
	
	public DataPlot(MultiScatterDataModel model,
			        String title) {
		
		data = model;
		
		initialize();
		panel.setTitle(new Title(title));
	}
	
	private void initialize() {
		panel = new ExtPrintableChartPanel(data, "Plot", DefaultChart.LINEAR_X_LINEAR_Y);
		
		// Create the chart renderer
		MultiScatterChartRenderer renderer = new MultiScatterChartRenderer(panel.getCoordSystem(), data);
		
		// Disable point buffering - BufferedChartRenderer will suffice
		renderer.setAllowBuffer(false);
		
		// Add the renderer to the panel
		panel.addChartRenderer(renderer, 1);
	}
	
	//public void chartDataChanged(ChartDataModelEvent evt) {
	//	// The DataModel changed -> update display
	//	panel.revalidate();
	//	repaint();
	//}    
	
	//public void actionPerformed(ActionEvent evt) {
		// The Timer generated an event -> update DataModel with random data
		//data.insertValue(0, new Double(Math.random() * 10.0 + 20.0), new Double(time));
		//data.insertValue(1, new Double(Math.random() * 7.0 + 10.0), new Double(time));
		//time++;
	//}
	
	
 
 }
