< prev index next >

modules/controls/src/test/java/javafx/scene/chart/LineChartTest.java

Print this page
rev 8907 : RT-46086: StackedAreaChart doesn't fade out removed series


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.scene.chart;
  27 
  28 /**
  29  *
  30  * @author paru
  31  */
  32 import org.junit.Test;
  33 import static org.junit.Assert.assertEquals;
  34 import javafx.collections.*;
  35 
  36 import com.sun.javafx.pgstub.StubToolkit;
  37 import com.sun.javafx.tk.Toolkit;
  38 
  39 import javafx.scene.Node;
  40 import javafx.scene.Scene;
  41 import javafx.scene.Group;
  42 import javafx.stage.Stage;
  43 import javafx.scene.shape.*;
  44 
  45 import org.junit.Ignore;
  46 
  47 
  48 public class LineChartTest extends XYChartTestBase {
  49 
  50     private Scene scene;
  51     private StubToolkit toolkit;
  52     private Stage stage;
  53     LineChart<Number,Number> lineChart;
  54     final XYChart.Series<Number, Number> series1 = new XYChart.Series<Number, Number>();
  55     
  56     @Override protected Chart createChart() {
  57         final NumberAxis xAxis = new NumberAxis();
  58         final NumberAxis yAxis = new NumberAxis();
  59         lineChart = new LineChart<Number,Number>(xAxis,yAxis);
  60         xAxis.setLabel("X Axis");
  61         yAxis.setLabel("Y Axis");
  62         lineChart.setTitle("HelloLineChart");
  63         // add starting data
  64         series1.getData().add(new XYChart.Data(10d, 10d));
  65         series1.getData().add(new XYChart.Data(25d, 20d));
  66         series1.getData().add(new XYChart.Data(30d, 15d));
  67         series1.getData().add(new XYChart.Data(50d, 15d));
  68         series1.getData().add(new XYChart.Data(80d, 10d));
  69         return lineChart;
  70     }
  71     
  72     private StringBuffer getSeriesLineFromPlot() {
  73         ObservableList<Node> childrenList = lineChart.getPlotChildren();
  74         StringBuffer sb = new StringBuffer();
  75         for (Node n : childrenList) {
  76             if (n instanceof Path && "chart-series-line".equals(n.getStyleClass().get(0))) {
  77                 Path line = (Path)n;
  78                 sb = computeSVGPath(line);
  79                 return sb;
  80             }
  81         }
  82         return sb;
  83     }
  84     
  85      @Test
  86     public void testSeriesRemoveWithCreateSymbolsFalse() {
  87         startApp();
  88         lineChart.getData().addAll(series1);
  89         pulse();










  90         lineChart.setCreateSymbols(false);
  91         System.out.println("Line Path = "+getSeriesLineFromPlot());
  92         if (!lineChart.getData().isEmpty()) {


  93             lineChart.getData().remove(0);
  94             pulse();
  95             StringBuffer sb = getSeriesLineFromPlot();
  96             assertEquals(sb.toString(), "");
  97         }






















  98     }
  99         
 100      @Test public void testCreateSymbols() {

 101          startApp();
 102          lineChart.setCreateSymbols(false);
 103          pulse();
 104          lineChart.getData().addAll(series1);
 105          pulse();
 106          assertEquals(0, countSymbols(lineChart, "chart-line-symbol"));
 107          
 108          lineChart.getData().clear();
 109          pulse();
 110          lineChart.setCreateSymbols(true);
 111          pulse();
 112          lineChart.getData().addAll(series1);
 113          assertEquals(5, countSymbols(lineChart, "chart-line-symbol"));
 114      }
 115      
 116     @Test
 117     public void testDataItemAdd() {
 118         startApp();
 119         lineChart.getData().addAll(series1);
 120         pulse();




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.scene.chart;
  27 
  28 import com.sun.javafx.scene.control.infrastructure.ControlTestUtils;
  29 import javafx.collections.ObservableList;









  30 import javafx.scene.Node;
  31 import javafx.scene.shape.Path;
  32 import static org.junit.Assert.assertEquals;



  33 import org.junit.Ignore;
  34 import org.junit.Test;
  35 
  36 public class LineChartTest extends XYChartTestBase {
  37 



  38     LineChart<Number,Number> lineChart;
  39     final XYChart.Series<Number, Number> series1 = new XYChart.Series<Number, Number>();
  40     
  41     @Override protected Chart createChart() {
  42         final NumberAxis xAxis = new NumberAxis();
  43         final NumberAxis yAxis = new NumberAxis();
  44         lineChart = new LineChart<Number,Number>(xAxis,yAxis);
  45         xAxis.setLabel("X Axis");
  46         yAxis.setLabel("Y Axis");
  47         lineChart.setTitle("HelloLineChart");
  48         // add starting data
  49         series1.getData().add(new XYChart.Data(10d, 10d));
  50         series1.getData().add(new XYChart.Data(25d, 20d));
  51         series1.getData().add(new XYChart.Data(30d, 15d));
  52         series1.getData().add(new XYChart.Data(50d, 15d));
  53         series1.getData().add(new XYChart.Data(80d, 10d));
  54         return lineChart;
  55     }
  56     
  57     private StringBuffer getSeriesLineFromPlot() {
  58         ObservableList<Node> childrenList = lineChart.getPlotChildren();
  59         StringBuffer sb = new StringBuffer();
  60         for (Node n : childrenList) {
  61             if (n instanceof Path && "chart-series-line".equals(n.getStyleClass().get(0))) {
  62                 Path line = (Path)n;
  63                 sb = computeSVGPath(line);
  64                 return sb;
  65             }
  66         }
  67         return sb;
  68     }
  69 
  70     @Test
  71     public void testSeriesRemove() {
  72         startApp();
  73         lineChart.getData().addAll(series1);
  74         pulse();
  75         // 5 symbols and 1 line node
  76         assertEquals(6, lineChart.getPlotChildren().size());
  77         lineChart.getData().remove(0);
  78         pulse();
  79         assertEquals(0, lineChart.getPlotChildren().size());
  80     }
  81 
  82     @Test
  83     public void testSeriesRemoveWithoutSymbols() {
  84         startApp();
  85         lineChart.setCreateSymbols(false);
  86         lineChart.getData().addAll(series1);
  87         pulse();
  88         // 1 line node
  89         assertEquals(1, lineChart.getPlotChildren().size());
  90         lineChart.getData().remove(0);
  91         pulse();
  92         assertEquals(0, lineChart.getPlotChildren().size());

  93     }
  94 
  95     @Test
  96     public void testSeriesRemoveWithoutSymbolsAnimated_rt_22124() {
  97         startApp();
  98         lineChart.setCreateSymbols(false);
  99         lineChart.getData().addAll(series1);
 100         pulse();
 101         // 1 line node
 102         assertEquals(1, lineChart.getPlotChildren().size());
 103 
 104         lineChart.setAnimated(true);
 105         Thread.UncaughtExceptionHandler exceptionHandler = ControlTestUtils.setHandler();
 106         try {
 107             lineChart.getData().remove(0);
 108         } finally {
 109             ControlTestUtils.resetHandler(exceptionHandler);
 110         }
 111         toolkit.setAnimationTime(450);
 112         assertEquals(1, lineChart.getPlotChildren().size());
 113         assertEquals(0.5, lineChart.getPlotChildren().get(0).getOpacity(), 0.0);
 114         toolkit.setAnimationTime(900);
 115         assertEquals(0, lineChart.getPlotChildren().size());
 116     }
 117 
 118     @Test
 119     public void testCreateSymbols() {
 120         startApp();
 121         lineChart.setCreateSymbols(false);
 122         pulse();
 123         lineChart.getData().addAll(series1);
 124         pulse();
 125         assertEquals(0, countSymbols(lineChart, "chart-line-symbol"));
 126 
 127         lineChart.getData().clear();
 128         pulse();
 129         lineChart.setCreateSymbols(true);
 130         pulse();
 131         lineChart.getData().addAll(series1);
 132         assertEquals(5, countSymbols(lineChart, "chart-line-symbol"));
 133     }
 134 
 135     @Test
 136     public void testDataItemAdd() {
 137         startApp();
 138         lineChart.getData().addAll(series1);
 139         pulse();


< prev index next >