Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * ParallelChart.java
3 *
4 * Copyright (c) 2002-2015 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.Axis;
29 import dr.app.gui.chart.DiscreteAxis;
30 import dr.app.gui.chart.JChart;
31 import dr.app.gui.chart.Plot;
32
33 /**
34 * A chart that has the primary dimension vertically and parallel plots horizonally (i.e.,
35 * for box plots, intervals and violins.
36 *
37 * @author Andrew Rambaut
38 */
39 public class JParallelChart extends JChart {
40
41 private final boolean horizontal;
42 private final DiscreteAxis parallelAxis;
43
44 public JParallelChart(Axis dimensionAxis) {
45 this(false, dimensionAxis);
46 }
47
48 public JParallelChart(boolean horizontal, Axis dimensionAxis) {
49 super(null,null);
50
51 this.horizontal = horizontal;
52
53 parallelAxis = new DiscreteAxis(true, true);
54 setXAxis(horizontal ? dimensionAxis : parallelAxis);
55 setYAxis(horizontal ? parallelAxis : dimensionAxis);
56 }
57
58 @Override
59 public void addPlot(Plot plot) {
60 super.addPlot(plot);
61
62 // set the range manually to the number of plots
63 parallelAxis.setRange(1.0, getPlotCount());
64 recalibrate();
65 repaint();
66 }
67
68 @Override
69 protected String getXAxisLabel(double value) {
70 if (horizontal) {
71 return super.getXAxisLabel(value);
72 } else {
73 return getPlotName(value);
74 }
75 }
76
77 @Override
78 protected String getYAxisLabel(double value) {
79 if (!horizontal) {
80 return super.getYAxisLabel(value);
81 } else {
82 return getPlotName(value);
83 }
84 }
85
86
87 private String getPlotName(double value) {
88 int index = (int)(value);
89 if (index >= 1 && index <= getPlotCount()) {
90 Plot plot = getPlot(index - 1);
91 return plot.getName();
92 } else {
93 return "";
94 }
95
96 }
97
98 }