1 | public class XYBarChartTests extends TestCase {↵ | | 1 | public class XYLineChartTests extends TestCase {↵
|
|
2 | /** A chart. */↵ | | 2 | /** A chart. */↵
|
3 | private JFreeChart chart;↵ | | 3 | private JFreeChart chart;↵
|
|
4 | /**↵ | | 4 | /**↵
|
5 | * Returns the tests as a test suite.↵ | | 5 | * Returns the tests as a test suite.↵
|
6 | *↵ | | 6 | *↵
|
7 | * @return The test suite.↵ | | 7 | * @return The test suite.↵
|
8 | */↵ | | 8 | */↵
|
9 | public static Test suite() {↵ | | 9 | public static Test suite() {↵
|
10 | return new TestSuite(XYBarChartTests.class);↵ | | 10 | return new TestSuite(XYLineChartTests.class);↵
|
11 | }↵ | | 11 | }↵
|
|
12 | /**↵ | | 12 | /**↵
|
13 | * Constructs a new set of tests.↵ | | 13 | * Constructs a new set of tests.↵
|
14 | *↵ | | 14 | *↵
|
15 | * @param name the name of the tests.↵ | | 15 | * @param name the name of the tests.↵
|
16 | */↵ | | 16 | */↵
|
17 | public XYBarChartTests(String name) {↵ | | 17 | public XYLineChartTests(String name) {↵
|
18 | super(name);↵ | | 18 | super(name);↵
|
19 | }↵ | | 19 | }↵
|
|
20 | /**↵ | | 20 | /**↵
|
21 | * Common test setup.↵ | | 21 | * Common test setup.↵
|
22 | */↵ | | 22 | */↵
|
23 | protected void setUp() {↵ | | 23 | protected void setUp() {↵
|
24 | this.chart = createChart();↵ | | 24 | this.chart = createChart();↵
|
25 | }↵ | | 25 | }↵
|
|
26 | /**↵ | | 26 | /**↵
|
27 | * Draws the chart with a null info object to make sure that no exceptions ↵ | | 27 | * Draws the chart with a null info object to make sure that no exceptions ↵
|
28 | * are thrown (a problem that was occurring at one point).↵ | | 28 | * are thrown (a problem that was occurring at one point).↵
|
29 | */↵ | | 29 | */↵
|
30 | public void testDrawWithNullInfo() {↵ | | 30 | public void testDrawWithNullInfo() {↵
|
|
31 | boolean success = false;↵ | | 31 | boolean success = false;↵
|
32 | try {↵ | | 32 | try {↵
|
33 | BufferedImage image = new BufferedImage(200 , 100, ↵ | | 33 | BufferedImage image = new BufferedImage(200 , 100, ↵
|
34 | BufferedImage.TYPE_INT_RGB);↵ | | 34 | BufferedImage.TYPE_INT_RGB);↵
|
35 | Graphics2D g2 = image.createGraphics();↵ | | 35 | Graphics2D g2 = image.createGraphics();↵
|
36 | this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, ↵ | | 36 | this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, ↵
|
37 | null);↵ | | 37 | null);↵
|
38 | g2.dispose();↵ | | 38 | g2.dispose();↵
|
39 | success = true;↵ | | 39 | success = true;↵
|
40 | }↵ | | 40 | }↵
|
41 | catch (Exception e) {↵ | | 41 | catch (Exception e) {↵
|
42 | success = false;↵ | | 42 | success = false;↵
|
43 | e.printStackTrace();↵ | | 43 | e.printStackTrace();↵
|
44 | }↵ | | 44 | }↵
|
45 | assertTrue(success);↵ | | 45 | assertTrue(success);↵
|
|
46 | }↵ | | 46 | }↵
|
|
47 | /**↵ | | 47 | /**↵
|
48 | * Replaces the dataset and checks that it has changed as expected.↵ | | 48 | * Replaces the dataset and checks that it has changed as expected.↵
|
49 | */↵ | | 49 | */↵
|
50 | public void testReplaceDataset() {↵ | | 50 | public void testReplaceDataset() {↵
|
|
51 | // create a dataset...↵ | | 51 | // create a dataset...↵
|
52 | XYSeries series1 = new XYSeries("Series 1");↵ | | 52 | XYSeries series1 = new XYSeries("Series 1");↵
|
53 | series1.add(10.0, 10.0);↵ | | 53 | series1.add(10.0, 10.0);↵
|
54 | series1.add(20.0, 20.0);↵ | | 54 | series1.add(20.0, 20.0);↵
|
55 | series1.add(30.0, 30.0);↵ | | 55 | series1.add(30.0, 30.0);↵
|
56 | XYDataset dataset = new XYSeriesCollection(series1);↵ | | 56 | XYDataset dataset = new XYSeriesCollection(series1);↵
|
|
57 | LocalListener l = new LocalListener();↵ | | 57 | LocalListener l = new LocalListener();↵
|
58 | this.chart.addChangeListener(l);↵ | | 58 | this.chart.addChangeListener(l);↵
|
59 | ↵ | | |
|
60 | XYPlot plot = (XYPlot) this.chart.getPlot();↵ | | 59 | XYPlot plot = (XYPlot) this.chart.getPlot();↵
|
61 | plot.setDataset(dataset);↵ | | 60 | plot.setDataset(dataset);↵
|
62 | assertEquals(true, l.flag);↵ | | 61 | assertEquals(true, l.flag);↵
|
63 | ValueAxis axis = plot.getRangeAxis();↵ | | 62 | ValueAxis axis = plot.getRangeAxis();↵
|
64 | Range range = axis.getRange();↵ | | 63 | Range range = axis.getRange();↵
|
65 | assertTrue("Expecting the lower bound of the range to be around 10: "↵ | | 64 | assertTrue("Expecting the lower bound of the range to be around 10: "↵
|
66 | + range.getLowerBound(), range.getLowerBound() <= 10);↵ | | 65 | + range.getLowerBound(), range.getLowerBound() <= 10);↵
|
67 | assertTrue("Expecting the upper bound of the range to be around 30: "↵ | | 66 | assertTrue("Expecting the upper bound of the range to be around 30: "↵
|
68 | + range.getUpperBound(), range.getUpperBound() >= 30);↵ | | 67 | + range.getUpperBound(), range.getUpperBound() >= 30);↵
|
|
69 | }↵ | | 68 | }↵
|
|
70 | /**↵ | | 69 | /**↵
|
71 | * Check that setting a tool tip generator for a series does override the↵ | | 70 | * Check that setting a tool tip generator for a series does override the↵
|
72 | * default generator.↵ | | 71 | * default generator.↵
|
73 | */↵ | | 72 | */↵
|
74 | public void testSetSeriesToolTipGenerator() {↵ | | 73 | public void testSetSeriesToolTipGenerator() {↵
|
75 | XYPlot plot = (XYPlot) this.chart.getPlot();↵ | | 74 | XYPlot plot = (XYPlot) this.chart.getPlot();↵
|
76 | XYItemRenderer renderer = plot.getRenderer();↵ | | 75 | XYItemRenderer renderer = plot.getRenderer();↵
|
77 | StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator();↵ | | 76 | StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator();↵
|
78 | renderer.setSeriesToolTipGenerator(0, tt);↵ | | 77 | renderer.setSeriesToolTipGenerator(0, tt);↵
|
79 | XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0);↵ | | 78 | XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0);↵
|
80 | assertTrue(tt2 == tt);↵ | | 79 | assertTrue(tt2 == tt);↵
|
81 | }↵ | | 80 | }↵
|
82 | ↵ | | 81 | ↵
|
83 | /**↵ | | 82 | /**↵
|
84 | * Create a horizontal bar chart with sample data in the range -3 to +3.↵ | | 83 | * Create a horizontal bar chart with sample data in the range -3 to +3.↵
|
85 | *↵ | | 84 | *↵
|
86 | * @return The chart.↵ | | 85 | * @return The chart.↵
|
87 | */↵ | | 86 | */↵
|
88 | private static JFreeChart createChart() {↵ | | 87 | private static JFreeChart createChart() {↵
|
|
89 | // create a dataset...↵ | | 88 | // create a dataset...↵
|
90 | XYSeries series1 = new XYSeries("Series 1");↵ | | 89 | XYSeries series1 = new XYSeries("Series 1");↵
|
91 | series1.add(1.0, 1.0);↵ | | 90 | series1.add(1.0, 1.0);↵
|
92 | series1.add(2.0, 2.0);↵ | | 91 | series1.add(2.0, 2.0);↵
|
93 | series1.add(3.0, 3.0);↵ | | 92 | series1.add(3.0, 3.0);↵
|
94 | IntervalXYDataset dataset = new XYBarDataset(new XYSeriesCollection(↵ | | 93 | XYDataset dataset = new XY↵
|
95 | series1), 1.0);↵ | | 94 | SeriesCollection(series1);↵
|
96 | ↵ | | |
|
97 | // create the chart...↵ | | 95 | // create the chart...↵
|
98 | return ChartFactory.createXYBarChart(↵ | | 96 | return ChartFactory.createXYLineChart(↵
|
99 | "XY Bar Chart", // chart title↵ | | 97 | "XY Line Chart", // chart title↵
|
100 | "Domain", false,↵ | | 98 | "Domain",↵
|
101 | "Range",↵ | | 99 | "Range",↵
|
102 | dataset, // data↵ | | 100 | dataset, // data↵
|
103 | PlotOrientation.VERTICAL,↵ | | 101 | PlotOrientation.VERTICAL,↵
|
104 | true, // include legend↵ | | 102 | true, // include legend↵
|
105 | true, // tooltips↵ | | 103 | true, // tooltips↵
|
106 | true // urls↵ | | 104 | true // urls↵
|
107 | );↵ | | 105 | );↵
|
|
108 | }↵ | | 106 | }↵
|
|
109 | /**↵ | | 107 | /**↵
|
110 | * A chart change listener.↵ | | 108 | * A chart change listener.↵
|
111 | *↵ | | 109 | *↵
|
112 | */↵ | | 110 | */↵
|
113 | static class LocalListener implements ChartChangeListener {↵ | | 111 | static class LocalListener implements ChartChangeListener {↵
|
|
114 | /** A flag. */↵ | | 112 | /** A flag. */↵
|
115 | private boolean flag = false;↵ | | 113 | private boolean flag = false;↵
|
|
116 | /**↵ | | 114 | /**↵
|
117 | * Event handler.↵ | | 115 | * Event handler.↵
|
118 | *↵ | | 116 | *↵
|
119 | * @param event the event.↵ | | 117 | * @param event the event.↵
|
120 | */↵ | | 118 | */↵
|
121 | public void chartChanged(ChartChangeEvent event) {↵ | | 119 | public void chartChanged(ChartChangeEvent event) {↵
|
122 | this.flag = true | | 120 | this.flag = true
|