Debian Codegraph @

src/dr/app/gui/chart/JGridChart.java

raw symbols SCIP
1 /*
2 * JGridChart.java
3 *
4 * Copyright (c) 2002-2017 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.gui.chart;
27
28 import dr.app.gui.chart.*;
29
30 /**
31 * An NxK grid of individual plots
32 * @author Guy Baele
33 */
34 public class JGridChart extends JChart {
35
36 private final CustomAxis xVariableAxis;
37 private final CustomAxis yVariableAxis;
38
39 private int rowCount;
40 private int columnCount;
41
42 public JGridChart(double aspectRatio) {
43 super(null, null, aspectRatio);
44
45 xVariableAxis = new CustomAxis(1, 2);
46 yVariableAxis = new CustomAxis(1, 2);
47
48 //this sets the axes on the JGridChart
49 setXAxis(xVariableAxis);
50 setYAxis(yVariableAxis);
51
52 // set the row and column counts to the sqrt of the number of plots
53 rowCount = 0;
54 columnCount = 0;
55 }
56
57 public JGridChart(int rowCount, int columnCount, double aspectRatio) {
58 super(null, null, aspectRatio);
59
60 this.rowCount = rowCount;
61 this.columnCount = columnCount;
62
63 xVariableAxis = new CustomAxis(1, 2);
64 yVariableAxis = new CustomAxis(1, 2);
65
66 //this sets the axes on the JGridChart
67 setXAxis(xVariableAxis);
68 setYAxis(yVariableAxis);
69
70 }
71
72 public void setDimensions(int rowCount, int columnCount) {
73 this.rowCount = rowCount;
74 this.columnCount = columnCount;
75
76 xVariableAxis.setRange(1.0, columnCount);
77 yVariableAxis.setRange(1.0, rowCount);
78
79 recalibrate();
80 repaint();
81 }
82
83
84 @Override
85 public void addPlot(Plot plot) {
86
87 super.addPlot(plot);
88
89 int rowCount = this.rowCount;
90 int columnCount = this.columnCount;
91
92 if (rowCount < 1 || columnCount < 1) {
93 // set the range manually to the square root of the number of plots
94 int k = (int)Math.sqrt(getPlotCount());
95 rowCount = getPlotCount() / k;
96 columnCount = getPlotCount() % k;
97
98 if (plot.getXLocation() < 0 || plot.getYLocation() < 0) {
99 int x = 0;
100 int y = 0;
101 for (Plot p : getPlots()) {
102 p.setLocation(x, y);
103 x++;
104 if (x >= columnCount) {
105 x = 0;
106 y++;
107 }
108 }
109 }
110 }
111
112 xVariableAxis.setRange(1.0, columnCount);
113 yVariableAxis.setRange(1.0, rowCount);
114
115
116 recalibrate();
117 repaint();
118 }
119
120 @Override
121 protected String getXAxisLabel(double value) {
122 return getPlotName(value);
123 }
124
125 @Override
126 protected String getYAxisLabel(double value) {
127 return getPlotName(value);
128 }
129
130 private String getPlotName(double value) {
131 int index = (int)(value);
132 if (index >= 1 && index <= getPlotCount()) {
133 Plot plot = getPlot(index - 1);
134 return plot.getName();
135 } else {
136 return "";
137 }
138
139 }
140
141 }