Debian Codegraph @

src/dr/app/gui/tree/NodeHeightBoxPlot.java

raw symbols SCIP
1 /*
2 * NodeHeightBoxPlot.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.tree;
27
28 import dr.evolution.tree.Tree;
29 import dr.evolution.tree.NodeRef;
30
31 import java.awt.*;
32 import java.awt.geom.Rectangle2D;
33 import java.awt.geom.Line2D;
34
35 /**
36 * Created by IntelliJ IDEA.
37 * User: alexei
38 * Date: Dec 3, 2004
39 * Time: 10:09:18 AM
40 * To change this template use File | Settings | File Templates.
41 */
42 public class NodeHeightBoxPlot implements NodeDecorator {
43
44 public NodeHeightBoxPlot() {
45
46 this(new BasicStroke(1.0f), new BasicStroke(0.5f), true);
47 }
48
49 public NodeHeightBoxPlot(Stroke lineStroke, Stroke whiskerStroke, boolean fill) {
50 this.lineStroke = lineStroke;
51 this.whiskerStroke = whiskerStroke;
52 this.fill = fill;
53 }
54
55 public boolean isDecoratable(Tree tree, NodeRef node) {
56 return false; //To change body of implemented methods use File | Settings | File Templates.
57 }
58
59 public void decorateNode(Tree tree, NodeRef node, Graphics2D g2, CoordinateTransform transform) {
60
61 // look for node height statistics
62 Double mean = (Double)tree.getNodeAttribute(node, "nodeHeight.mean");
63 if (mean != null) {
64 Double hpdUpper = (Double)tree.getNodeAttribute(node, "nodeHeight.hpdUpper");
65 Double hpdLower = (Double)tree.getNodeAttribute(node, "nodeHeight.hpdLower");
66 Double min = (Double)tree.getNodeAttribute(node, "nodeHeight.min");
67 Double max = (Double)tree.getNodeAttribute(node, "nodeHeight.max");
68
69 // plot height statistics as box plot
70 double meanX = transform.xCoordinate(mean.doubleValue());
71 double minX = transform.xCoordinate(min.doubleValue());
72 double maxX = transform.xCoordinate(max.doubleValue());
73 double upperX = transform.xCoordinate(hpdUpper.doubleValue());
74 double lowerX = transform.xCoordinate(hpdLower.doubleValue());
75 //System.out.println(upperX + " " + lowerX);
76
77 double y = transform.yCoordinate(tree, node);
78
79 g2.setStroke(lineStroke);
80 if (fill) {
81 g2.setColor(Color.white);
82 g2.fill(new Rectangle2D.Double(upperX, y-5,lowerX-upperX,10));
83 }
84 g2.setColor(Color.gray);
85 g2.draw(new Rectangle2D.Double(upperX, y-5,lowerX-upperX,10));
86 g2.draw(new Line2D.Double(meanX, y-5,meanX,y+5));
87
88 g2.setStroke(whiskerStroke);
89 g2.draw(new Line2D.Double(lowerX, y,minX,y));
90 g2.draw(new Line2D.Double(maxX, y,upperX,y));
91 }
92
93 }
94
95 Stroke lineStroke = new BasicStroke(1.0f);
96 Stroke whiskerStroke = new BasicStroke(0.5f);
97 boolean fill = true;
98 }