1 /* 2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 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 test.javafx.scene.chart; 27 28 import javafx.collections.FXCollections; 29 import javafx.collections.ObservableList; 30 import javafx.scene.Group; 31 import javafx.scene.Node; 32 import javafx.scene.chart.AreaChart; 33 import javafx.scene.chart.Axis; 34 import javafx.scene.chart.CategoryAxis; 35 import javafx.scene.chart.Chart; 36 import javafx.scene.chart.NumberAxis; 37 import javafx.scene.chart.XYChart; 38 import javafx.scene.chart.XYChartShim; 39 import javafx.scene.shape.Path; 40 import static org.junit.Assert.assertEquals; 41 import org.junit.Ignore; 42 import org.junit.Test; 43 44 public class AreaChartTest extends XYChartTestBase { 45 AreaChart<Number,Number> ac; 46 final XYChart.Series<Number, Number> series1 = new XYChart.Series<Number, Number>(); 47 boolean useCategoryAxis = false; 48 final String[] countries = {"USA", "Italy", "France", "China", "India"}; 49 protected Chart createChart() { 50 final NumberAxis yAxis = new NumberAxis(); 51 ObservableList<XYChart.Data> data = FXCollections.observableArrayList(); 52 Axis xAxis; 53 if (useCategoryAxis) { 54 xAxis = new CategoryAxis(); 55 ((CategoryAxis)xAxis).setCategories(FXCollections.observableArrayList(countries)); 56 // add starting data 57 series1.getData().add(new XYChart.Data(countries[0], 10d)); 58 series1.getData().add(new XYChart.Data(countries[1], 20d)); 59 series1.getData().add(new XYChart.Data(countries[2], 15d)); 60 series1.getData().add(new XYChart.Data(countries[3], 15d)); 61 series1.getData().add(new XYChart.Data(countries[4], 10d)); 62 } else { 63 xAxis = new NumberAxis(); 64 ac = new AreaChart<Number,Number>(xAxis,yAxis); 65 // add starting data 66 series1.getData().add(new XYChart.Data(10d, 10d)); 67 series1.getData().add(new XYChart.Data(25d, 20d)); 68 series1.getData().add(new XYChart.Data(30d, 15d)); 69 series1.getData().add(new XYChart.Data(50d, 15d)); 70 series1.getData().add(new XYChart.Data(80d, 10d)); 71 } 72 73 xAxis.setLabel("X Axis"); 74 yAxis.setLabel("Y Axis"); 75 ac.setTitle("HelloAreaChart"); 76 77 return ac; 78 } 79 80 private StringBuffer getSeriesLineFromPlot() { 81 ObservableList<Node> childrenList = XYChartShim.getPlotChildren(ac); 82 StringBuffer sb = new StringBuffer(); 83 for (Node n : childrenList) { 84 if (n instanceof Group) { 85 for (Node gn : ((Group)n).getChildren()) { 86 if (gn instanceof Path && "chart-series-area-line".equals(gn.getStyleClass().get(0))) { 87 Path line = (Path)gn; 88 sb = computeSVGPath(line); 89 return sb; 90 } 91 } 92 } 93 } 94 return sb; 95 } 96 97 @Test @Ignore 98 public void testDataItemRemove() { 99 startApp(); 100 ac.getData().addAll(series1); 101 pulse(); 102 if (!ac.getData().isEmpty()) { 103 series1.getData().remove(0); 104 pulse(); 105 StringBuffer sb = getSeriesLineFromPlot(); 106 assertEquals(sb.toString(), "L247.0 171.0 L412.0 171.0 L658.0 284.0 "); 107 } 108 } 109 110 @Test 111 public void testAreaChartWithCategoryAxis() { 112 useCategoryAxis = true; 113 startApp(); 114 useCategoryAxis = false; 115 } 116 117 @Test public void testCreateSymbols() { 118 startApp(); 119 ac.getData().clear(); 120 ac.setCreateSymbols(false); 121 pulse(); 122 ac.getData().addAll(series1); 123 pulse(); 124 assertEquals(0, countSymbols(ac, "chart-area-symbol")); 125 126 ac.getData().clear(); 127 ac.setCreateSymbols(true); 128 pulse(); 129 ac.getData().addAll(series1); 130 pulse(); 131 assertEquals(5, countSymbols(ac, "chart-area-symbol")); 132 } 133 }