package org.timepedia.chronoscope.client.plot;

import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.user.client.ui.RootPanel;

import org.timepedia.chronoscope.client.data.MockXYDataset;
import org.timepedia.chronoscope.client.XYDataset;
import org.timepedia.chronoscope.client.Chart;
import org.timepedia.chronoscope.client.XYPlot;
import org.timepedia.chronoscope.client.browser.ChartPanel;
import org.timepedia.chronoscope.client.browser.Chronoscope;

/**
 * Test case for XYPlot interface
 */
public class DefaultXYPlotTest extends GWTTestCase {

  public String getModuleName() {
    return "org.timepedia.chronoscope.Chronoscope";
  }

  /**
   * Test that issue #23 is fixed
   * http://code.google.com/p/gwt-chronoscope/issues/detail?id=23
   */
  public void testAutoAssignDatasetAxesSameAxis() {
    
    XYDataset ds[]=new XYDataset[2];
    ds[0]=new MockXYDataset();
    ds[1]=new MockXYDataset();
    ChartPanel cp= Chronoscope.createTimeseriesChart(ds, 600, 400);
    RootPanel.get().add(cp);
    XYPlot plot = cp.getChart().getPlot();
    
    assertSame(plot.getRangeAxis(0), plot.getRangeAxis(1));
    
  }
  
  /**
   * Test that issue #23 is fixed
   * http://code.google.com/p/gwt-chronoscope/issues/detail?id=23
   */
  public void testAutoAssignDatasetAxesDifferentAxis() {
    
    XYDataset ds[]=new XYDataset[2];
    ds[0]=new MockXYDataset();
    MockXYDataset mds = new MockXYDataset();
    mds.setAxisId("different");
    ds[1]= mds;
    
    ChartPanel cp= Chronoscope.createTimeseriesChart(ds, 600, 400);
    RootPanel.get().add(cp);
    XYPlot plot = cp.getChart().getPlot();
    
    assertNotSame(plot.getRangeAxis(0), plot.getRangeAxis(1));
    
  }
}


@@ -289,20 +289,21 @@
 .client.
-Char
+XYPlo
 t;%0Aimpor
@@ -329,38 +329,109 @@
 onoscope.client.
-XYPlot
+canvas.ViewReadyCallback;%0Aimport org.timepedia.chronoscope.client.canvas.View
 ;%0Aimport org.tim
@@ -1069,33 +1069,107 @@
     
-RootPanel.get().add(cp);%0A
+cp.setReadyListener(new ViewReadyCallback() %7B%0A        public void onViewReady(View view) %7B%0A        
     
@@ -1174,34 +1174,36 @@
   XYPlot plot = 
-cp
+view
 .getChart().getP
@@ -1205,33 +1205,36 @@
 .getPlot();%0A    
-%0A
+    
     assertSame(p
@@ -1277,24 +1277,119 @@
 is(1));%0A    
+        finishTest();%0A        %7D%0A    %7D);%0A    delayTestFinish(2000);%0A    RootPanel.get().add(cp);
 %0A  %7D%0A  %0A  /*
@@ -1800,33 +1800,107 @@
     
-RootPanel.get().add(cp);%0A
+cp.setReadyListener(new ViewReadyCallback() %7B%0A        public void onViewReady(View view) %7B%0A        
     
@@ -1913,18 +1913,20 @@
  plot = 
-cp
+view
 .getChar
@@ -1940,25 +1940,28 @@
 Plot();%0A    
-%0A
+    
     assertNo
@@ -2015,16 +2015,111 @@
 ));%0A    
+        finishTest();%0A        %7D%0A    %7D);%0A    delayTestFinish(2000);%0A    RootPanel.get().add(cp);
 %0A  %7D%0A%7D%0A%0A

Test class updated to support Windows, which uses Flash, so test case involving chart attachment must be asynchronous