package jeranvier.ui.chart;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JFrame;

import jeranvier.math.timeseries.Timeseries;
import jeranvier.math.timeseries.TimeseriesCollection;

public class ChartFrame<X extends Number, Y extends Number> extends JFrame{
	private static final long serialVersionUID = -0L;
	
	public ChartFrame(PrettyChart<X, Y> prettyChart){
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.getContentPane().setBackground(Color.WHITE);
		this.setPreferredSize(new Dimension(800, 500));
		KeyboardController keyboardController = new KeyboardController(prettyChart.getChart());
		this.addKeyListener(keyboardController);
		this.getContentPane().add(prettyChart);
	}
	
	public static void main(String args[]){
		int NUMBER_OF_POINTS = 6000; //per timeseries
		TimeseriesCollection.Builder tscb = new TimeseriesCollection.Builder();
		Timeseries.Builder tsb = new Timeseries.Builder();
		for(double i = -NUMBER_OF_POINTS/2; i <NUMBER_OF_POINTS/2; i++){
			double v = Math.exp(-i*i/(2*300*300))/(300*Math.sqrt(2*Math.PI));
			tsb.put((long) i, v);
		}
		tscb.putTimeseries("a", tsb.build());
		
		tsb = new Timeseries.Builder();
		for(double i = -NUMBER_OF_POINTS/2; i <NUMBER_OF_POINTS/2; i++){
			double v = Math.exp(-i*i/(2*200*200))/(200*Math.sqrt(2*Math.PI));
			tsb.put((long) i, v);
		}
		tscb.putTimeseries("b", tsb.build());
		
		tsb = new Timeseries.Builder();
		for(double i = -NUMBER_OF_POINTS/2; i <NUMBER_OF_POINTS/2; i++){
			double v = Math.cos(i/300)/1000;
			tsb.put((long) i, v);
		}
		tscb.putTimeseries("c", tsb.build());
		
		tsb = new Timeseries.Builder();
		for(double i = -NUMBER_OF_POINTS/20; i <NUMBER_OF_POINTS/20; i++){
			double v = 0.0;
			tsb.put((long) i*10, v);
		}
		Timeseries marker = tsb.build();
		

		Chart<Long, Double> chart = new TimeChart(tscb.build());
		chart.addMarker("marker1", marker);
		chart.addMarker("marker2", marker);
		chart.addMarker("marker3", marker);
		chart.addMarker("marker4", marker);
		chart.addMarker("marker5", marker);
		chart.addMarker("marker6", marker);
		chart.addMarker("marker7", marker);
		chart.addMarker("marker8", marker);
		chart.addMarker("marker9", marker);
		PrettyChart<Long, Double> prettyChart = new PrettyChart<Long, Double>(chart);
		ChartFrame<Long, Double> cf = new ChartFrame<>(prettyChart);
		cf.setLocation(200, 200);
		cf.pack();
		cf.revalidate();
		cf.setVisible(true);
	}

	public void display() {
		setLocation(200, 200);
		pack();
		revalidate();
		repaint();
		setVisible(true);		
	}

}

@@ -1122,17 +1122,24 @@
 series(%22
-a
+normal 1
 %22, tsb.b
@@ -1371,17 +1371,24 @@
 series(%22
-b
+normal 2
 %22, tsb.b
@@ -1588,16 +1588,21 @@
 eries(%22c
+os(x)
 %22, tsb.b
@@ -1734,10 +1734,28 @@
 v = 
+Math.tanh(i/300)/10
 0
-.
 0;%0A%09
@@ -1776,11 +1776,8 @@
 g) i
-*10
 , v)
@@ -1903,319 +1903,12 @@
 er(%22
-marker1%22, marker);%0A%09%09chart.addMarker(%22marker2%22, marker);%0A%09%09chart.addMarker(%22marker3%22, marker);%0A%09%09chart.addMarker(%22marker4%22, marker);%0A%09%09chart.addMarker(%22marker5%22, marker);%0A%09%09chart.addMarker(%22marker6%22, marker);%0A%09%09chart.addMarker(%22marker7%22, marker);%0A%09%09chart.addMarker(%22marker8%22, marker);%0A%09%09chart.addMarker(%22marker9
+tanh
 %22, m

update the example for the chart system