Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
StandardHCToolTipGenerator |
|
| 3.0;3 |
1 | /* ======================================================================= | |
2 | * A visualisation library extension for JFreeChart. Please see JFreeChart | |
3 | * for further information. | |
4 | * ======================================================================= | |
5 | * Copyright (C) 2006 University of Helsinki, Department of Computer Science | |
6 | * | |
7 | * This library is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU Lesser General Public | |
9 | * License as published by the Free Software Foundation; either | |
10 | * version 2.1 of the License, or (at your option) any later version. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
18 | * License along with this library; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | * ----------------------------- | |
21 | * Contact: ohtu@cs.helsinki.fi | |
22 | * ----------------------------- | |
23 | * | |
24 | */ | |
25 | ||
26 | package org.jfree.chart.labels; | |
27 | ||
28 | import org.jfree.chart.plot.HCTreeNodeInfo; | |
29 | import org.jfree.data.hc.HeatMap; | |
30 | import org.jfree.data.hc.DataRange; | |
31 | ||
32 | /** | |
33 | * A standard tool tip generator to be used with a {@link HCPlot}. | |
34 | * @author viski project | |
35 | */ | |
36 | public class StandardHCToolTipGenerator implements HCToolTipGenerator { | |
37 | ||
38 | ||
39 | /** | |
40 | * Creates a new tool tip generator. | |
41 | */ | |
42 | 5 | public StandardHCToolTipGenerator() { |
43 | ; | |
44 | 5 | } |
45 | ||
46 | /** | |
47 | * Generates a tooltip text string for a particular clustering tree node. | |
48 | * | |
49 | * @param node HCTreeNodeInfo for the node used. | |
50 | * | |
51 | * @return The tooltip text. | |
52 | */ | |
53 | public String generateToolTip(HCTreeNodeInfo node) { | |
54 | 66 | return node.toString(); |
55 | } | |
56 | ||
57 | /** | |
58 | * Generates a tooltip text string for a particular heatmap block. | |
59 | * | |
60 | * @param heatmap the HeatMap. | |
61 | * @param columnRange the columns displayed in the block. | |
62 | * @param rowRange the rows displayed in the block. | |
63 | * | |
64 | * @return The tooltip text. | |
65 | */ | |
66 | public String generateToolTip( | |
67 | HeatMap heatmap, | |
68 | DataRange rowRange, | |
69 | DataRange columnRange | |
70 | ) { | |
71 | int minRow; | |
72 | int maxRow; | |
73 | int minColumn; | |
74 | int maxColumn; | |
75 | int rowCounter; | |
76 | int columnCounter; | |
77 | int blockCount; | |
78 | double averageValue; | |
79 | ||
80 | try { | |
81 | 65 | minRow = rowRange.getLeftBound(); |
82 | 63 | maxRow = rowRange.getRightBound(); |
83 | 63 | minColumn = columnRange.getLeftBound(); |
84 | 62 | maxColumn = columnRange.getRightBound(); |
85 | 3 | } catch (Exception e) { |
86 | 3 | return "This block contains no data."; |
87 | 62 | } |
88 | ||
89 | 62 | if ((minRow == maxRow) && (minColumn == maxColumn)) { |
90 | ||
91 | 46 | return "(" + minRow + "," + minColumn + ") = " |
92 | + heatmap.get(minRow,minColumn); | |
93 | } | |
94 | ||
95 | for ( | |
96 | 16 | averageValue = 0, blockCount = 0, rowCounter = minRow; |
97 | 50 | rowCounter <= maxRow; |
98 | 34 | rowCounter++ |
99 | ) { | |
100 | for ( | |
101 | 35 | columnCounter = minColumn; |
102 | 195 | columnCounter <= maxColumn; |
103 | 160 | columnCounter++, blockCount++ |
104 | ) { | |
105 | 161 | averageValue += heatmap.get(rowCounter,columnCounter); |
106 | } | |
107 | } | |
108 | 15 | averageValue = averageValue/blockCount; |
109 | ||
110 | 15 | return "(" + minRow + "," + minColumn + ") .. " |
111 | + "(" + maxRow + "," + maxColumn + ") = " | |
112 | + averageValue + " (contains " + blockCount + " blocks)"; | |
113 | ||
114 | } | |
115 | ||
116 | } | |
117 |