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 import com.sun.javafx.scene.control.infrastructure.ControlTestUtils;
30 import java.io.IOException;
31 import java.io.OutputStream;
32 import java.io.PrintStream;
33 import org.junit.Test;
34 import static org.junit.Assert.assertEquals;
35 import javafx.collections.*;
36
37
38 import javafx.scene.Node;
39 import javafx.scene.Group;
40 import javafx.scene.shape.*;
41 import static org.junit.Assert.assertTrue;
42
43 import org.junit.Ignore;
44
45
46 public class AreaChartTest extends XYChartTestBase {
47 AreaChart<Number,Number> ac;
48 final XYChart.Series<Number, Number> series1 = new XYChart.Series<Number, Number>();
49 boolean useCategoryAxis = false;
50 final String[] countries = {"USA", "Italy", "France", "China", "India"};
51 protected Chart createChart() {
52 final NumberAxis yAxis = new NumberAxis();
53 ObservableList<XYChart.Data> data = FXCollections.observableArrayList();
54 Axis xAxis;
55 if (useCategoryAxis) {
56 xAxis = new CategoryAxis();
57 ((CategoryAxis)xAxis).setCategories(FXCollections.observableArrayList(countries));
58 // add starting data
59 series1.getData().add(new XYChart.Data(countries[0], 10d));
60 series1.getData().add(new XYChart.Data(countries[1], 20d));
61 series1.getData().add(new XYChart.Data(countries[2], 15d));
62 series1.getData().add(new XYChart.Data(countries[3], 15d));
63 series1.getData().add(new XYChart.Data(countries[4], 10d));
64 } else {
84 StringBuffer sb = new StringBuffer();
85 for (Node n : childrenList) {
86 if (n instanceof Group) {
87 for (Node gn : ((Group)n).getChildren()) {
88 if (gn instanceof Path && "chart-series-area-line".equals(gn.getStyleClass().get(0))) {
89 Path line = (Path)gn;
90 sb = computeSVGPath(line);
91 return sb;
92 }
93 }
94 }
95 }
96 return sb;
97 }
98
99 @Test
100 public void testSeriesRemove() {
101 startApp();
102 ac.getData().addAll(series1);
103 pulse();
104 if (!ac.getData().isEmpty()) {
105 ac.getData().remove(0);
106 pulse();
107 StringBuffer sb = getSeriesLineFromPlot();
108 assertEquals(sb.toString(), "");
109 }
110 }
111
112 @Test @Ignore
113 public void testDataItemRemove() {
114 startApp();
115 ac.getData().addAll(series1);
116 pulse();
117 if (!ac.getData().isEmpty()) {
118 series1.getData().remove(0);
119 pulse();
120 StringBuffer sb = getSeriesLineFromPlot();
121 assertEquals(sb.toString(), "L247.0 171.0 L412.0 171.0 L658.0 284.0 ");
122 }
123 }
124
125 @Test
126 public void testAreaChartWithCategoryAxis() {
127 useCategoryAxis = true;
128 startApp();
129 useCategoryAxis = false;
|
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.FXCollections;
30 import javafx.collections.ObservableList;
31 import javafx.scene.Group;
32 import javafx.scene.Node;
33 import javafx.scene.shape.Path;
34 import static org.junit.Assert.assertEquals;
35 import org.junit.Ignore;
36 import org.junit.Test;
37
38 public class AreaChartTest extends XYChartTestBase {
39 AreaChart<Number,Number> ac;
40 final XYChart.Series<Number, Number> series1 = new XYChart.Series<Number, Number>();
41 boolean useCategoryAxis = false;
42 final String[] countries = {"USA", "Italy", "France", "China", "India"};
43 protected Chart createChart() {
44 final NumberAxis yAxis = new NumberAxis();
45 ObservableList<XYChart.Data> data = FXCollections.observableArrayList();
46 Axis xAxis;
47 if (useCategoryAxis) {
48 xAxis = new CategoryAxis();
49 ((CategoryAxis)xAxis).setCategories(FXCollections.observableArrayList(countries));
50 // add starting data
51 series1.getData().add(new XYChart.Data(countries[0], 10d));
52 series1.getData().add(new XYChart.Data(countries[1], 20d));
53 series1.getData().add(new XYChart.Data(countries[2], 15d));
54 series1.getData().add(new XYChart.Data(countries[3], 15d));
55 series1.getData().add(new XYChart.Data(countries[4], 10d));
56 } else {
76 StringBuffer sb = new StringBuffer();
77 for (Node n : childrenList) {
78 if (n instanceof Group) {
79 for (Node gn : ((Group)n).getChildren()) {
80 if (gn instanceof Path && "chart-series-area-line".equals(gn.getStyleClass().get(0))) {
81 Path line = (Path)gn;
82 sb = computeSVGPath(line);
83 return sb;
84 }
85 }
86 }
87 }
88 return sb;
89 }
90
91 @Test
92 public void testSeriesRemove() {
93 startApp();
94 ac.getData().addAll(series1);
95 pulse();
96 // 5 symbols and 1 area group
97 assertEquals(6, ac.getPlotChildren().size());
98 ac.getData().remove(0);
99 pulse();
100 assertEquals(0, ac.getPlotChildren().size());
101 }
102
103 @Test
104 public void testSeriesRemoveWithoutSymbols() {
105 startApp();
106 ac.setCreateSymbols(false);
107 ac.getData().addAll(series1);
108 pulse();
109 // 1 area group
110 assertEquals(1, ac.getPlotChildren().size());
111 ac.getData().remove(0);
112 pulse();
113 assertEquals(0, ac.getPlotChildren().size());
114 }
115
116 @Test
117 public void testSeriesRemoveWithoutSymbolsAnimated_rt_22124() {
118 startApp();
119 ac.setCreateSymbols(false);
120 ac.getData().addAll(series1);
121 pulse();
122 // 1 area group
123 assertEquals(1, ac.getPlotChildren().size());
124
125 ac.setAnimated(true);
126 Thread.UncaughtExceptionHandler exceptionHandler = ControlTestUtils.setHandler();
127 try {
128 ac.getData().remove(0);
129 } finally {
130 ControlTestUtils.resetHandler(exceptionHandler);
131 }
132 toolkit.setAnimationTime(200);
133 assertEquals(1, ac.getPlotChildren().size());
134 assertEquals(0.5, ac.getPlotChildren().get(0).getOpacity(), 0.0);
135 toolkit.setAnimationTime(400);
136 assertEquals(0, ac.getPlotChildren().size());
137 }
138
139 @Test @Ignore
140 public void testDataItemRemove() {
141 startApp();
142 ac.getData().addAll(series1);
143 pulse();
144 if (!ac.getData().isEmpty()) {
145 series1.getData().remove(0);
146 pulse();
147 StringBuffer sb = getSeriesLineFromPlot();
148 assertEquals(sb.toString(), "L247.0 171.0 L412.0 171.0 L658.0 284.0 ");
149 }
150 }
151
152 @Test
153 public void testAreaChartWithCategoryAxis() {
154 useCategoryAxis = true;
155 startApp();
156 useCategoryAxis = false;
|