Skip to content

Commit 9216f92

Browse files
Added a check for negative integrated data points that represent values below the detection limit. Fixed city name and site name queries. Fixed long heat map X-axis labels that were not always being rotated. Added a border to the heat map legend. Added a feature that automatically makes the heat map background light grey if the legend goes nearly all the way to white. Added a new Cube Helix colour gradient (https://people.phy.cam.ac.uk/dag9/CUBEHELIX/) for the heat maps. Fixed empty brackets appearing in the report/heat map titles when there are no units.
1 parent e5730cd commit 9216f92

File tree

8 files changed

+85
-11
lines changed

8 files changed

+85
-11
lines changed
Loading
Loading

src/main/java/com/dbf/naps/data/analysis/DataQueryRunner.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ protected String getReportTitle(String units) {
186186
break;
187187
}
188188

189-
if(!getConfig().getAggregateFunction().equals(AggregateFunction.NONE) && !getConfig().getAggregateFunction().equals(AggregateFunction.COUNT)) {
189+
if(units != null && !units.isEmpty()
190+
&& !getConfig().getAggregateFunction().equals(AggregateFunction.NONE)
191+
&& !getConfig().getAggregateFunction().equals(AggregateFunction.COUNT)) {
190192
title.append(" (");
191193
title.append(units);
192194
title.append(")");

src/main/java/com/dbf/naps/data/analysis/heatmap/HeatMapGradient.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,59 @@ public class HeatMapGradient {
6363
Color.decode("#000000"), //Black
6464
};
6565

66+
private static final Color[] CUBEHELIX_GRADIENT = new Color[] {
67+
Color.decode("#000000"),
68+
Color.decode("#090309"),
69+
Color.decode("#100614"),
70+
Color.decode("#160a1f"),
71+
Color.decode("#190f2b"),
72+
Color.decode("#1a1536"),
73+
Color.decode("#1a1c3f"),
74+
Color.decode("#182448"),
75+
Color.decode("#152d4e"),
76+
Color.decode("#123752"),
77+
Color.decode("#104153"),
78+
Color.decode("#0e4b53"),
79+
Color.decode("#0d544f"),
80+
Color.decode("#0e5d4b"),
81+
Color.decode("#126644"),
82+
Color.decode("#176d3d"),
83+
Color.decode("#207336"),
84+
Color.decode("#2a782f"),
85+
Color.decode("#387b29"),
86+
Color.decode("#477d25"),
87+
Color.decode("#577d23"),
88+
Color.decode("#697d24"),
89+
Color.decode("#7b7c28"),
90+
Color.decode("#8d7a2f"),
91+
Color.decode("#9e7938"),
92+
Color.decode("#ae7745"),
93+
Color.decode("#bd7654"),
94+
Color.decode("#c87564"),
95+
Color.decode("#d27677"),
96+
Color.decode("#d9788a"),
97+
Color.decode("#dd7b9d"),
98+
Color.decode("#de80af"),
99+
Color.decode("#de86c1"),
100+
Color.decode("#db8dd1"),
101+
Color.decode("#d795de"),
102+
Color.decode("#d29fe9"),
103+
Color.decode("#cca9f1"),
104+
Color.decode("#c7b3f7"),
105+
Color.decode("#c3bdfa"),
106+
Color.decode("#c0c8fb"),
107+
Color.decode("#bed1fa"),
108+
Color.decode("#bfdaf8"),
109+
Color.decode("#c2e2f6"),
110+
Color.decode("#c7e9f3"),
111+
Color.decode("#cdeff1"),
112+
Color.decode("#d6f3f0"),
113+
Color.decode("#e0f7f0"),
114+
Color.decode("#eafaf3"),
115+
Color.decode("#f5fdf8"),
116+
Color.decode("#ffffff")
117+
};
118+
66119

67120
private static final List<Color[]> GRADIENTS = new ArrayList<Color[]>();
68121

@@ -73,6 +126,7 @@ public class HeatMapGradient {
73126
GRADIENTS.add(COLOUR_BLIND_GRADIENT);
74127
GRADIENTS.add(BLACK_RED_ORANGE_GRADIENT);
75128
GRADIENTS.add(WHITE_HOT_GRADIENT);
129+
GRADIENTS.add(CUBEHELIX_GRADIENT);
76130
GRADIENTS.add(GREY_GRADIENT);
77131
}
78132

src/main/java/com/dbf/naps/data/analysis/heatmap/HeatMapRunner.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private static void renderHeatMap(File dataFile, List<DataQueryRecord> records,
112112
final int halfCellHeight = cellHeight / 2;
113113

114114
//Only rotate the x-axis labels when they are too big
115-
final boolean rotateXLabels = (xAxisLabelHeight - labelPadding) > cellWidth;
115+
final boolean rotateXLabels = (xAxisLabelHeight ) > (cellWidth- labelPadding);
116116
if(!rotateXLabels) {
117117
xAxisLabelHeight = xAxisLabelMaxSize.getValue();
118118
}
@@ -182,8 +182,13 @@ private static void renderHeatMap(File dataFile, List<DataQueryRecord> records,
182182

183183
//Start the actual drawing onto the canvas
184184
try {
185-
//Make the background all white
186-
g2d.setColor(Color.WHITE);
185+
//Make the background all white, except if the colour scale goes to white
186+
Color maxColour = HeatMapGradient.getColour(1.0, colourGradient);
187+
if(maxColour.getBlue() > 240 && maxColour.getGreen() > 240 && maxColour.getRed() > 240) {
188+
g2d.setColor(new Color(210, 210, 210));
189+
} else {
190+
g2d.setColor(Color.WHITE);
191+
}
187192
g2d.fillRect(0, 0, imageWidth, imageHeight);
188193

189194
//Render the text smoothly
@@ -230,6 +235,10 @@ private static void renderHeatMap(File dataFile, List<DataQueryRecord> records,
230235
g2d.fillRect(legendStartPosX, legendStartPosY + (i * cellHeight), cellWidth, cellHeight);
231236
}
232237

238+
//Render the legend border on top of the boxes
239+
g2d.setColor(Color.BLACK);
240+
g2d.drawRect(legendStartPosX, legendStartPosY, cellWidth-1, (cellHeight*legendBoxes) -1);
241+
233242
//Will will need to determine the width of each title individually using fontMetrics
234243
g2d.setFont(smallTitleFont);
235244
g2d.setColor(Color.BLACK); //Reset back to black! The last colour was from the legend

src/main/java/com/dbf/naps/data/db/mappers/DataMapper.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public interface DataMapper {
2929
+ " d.year &gt;= #{startYear} and d.year &lt;= #{endYear}"
3030
+ "<if test=\"valueUpperBound != null\">and d.data &lt;= #{valueUpperBound}</if>"
3131
+ "<if test=\"valueLowerBound != null\">and d.data &gt;= #{valueLowerBound}</if>"
32-
+ "<if test=\"siteName != null &amp;&amp; !siteName.isEmpty()\">and s.station_name LIKE '%#{siteName}%'</if>"
33-
+ "<if test=\"cityName != null &amp;&amp; !cityName.isEmpty()\">and s.city_name LIKE '%#{cityName}%'</if>"
32+
+ "<if test=\"siteName != null &amp;&amp; !siteName.isEmpty()\">and s.station_name LIKE '%' || #{siteName} || '%'</if>"
33+
+ "<if test=\"cityName != null &amp;&amp; !cityName.isEmpty()\">and s.city_name LIKE '%' || #{cityName} || '%'</if>"
3434
+ "<if test=\"provTerr != null &amp;&amp; !provTerr.isEmpty()\">and s.prov_terr in <foreach collection='provTerr' item='prov' index='index' open='(' separator = ',' close=')'>#{prov}</foreach></if>"
3535
+ "<if test=\"siteType != null &amp;&amp; !siteType.isEmpty()\">and s.site_type in <foreach collection='siteType' item='sType' index='index' open='(' separator = ',' close=')'>#{sType}</foreach></if>"
3636
+ "<if test=\"urbanization != null &amp;&amp; !urbanization.isEmpty()\">and s.urbanization in <foreach collection='urbanization' item='urb' index='index' open='(' separator = ',' close=')'>#{urb}</foreach></if>"
@@ -71,8 +71,8 @@ public List<DataRecordGroup> getExportDataGroups(
7171
+ " where 1=1"
7272
+ "<if test=\"valueUpperBound != null\">and d.data &lt;= #{valueUpperBound}</if>"
7373
+ "<if test=\"valueLowerBound != null\">and d.data &gt;= #{valueLowerBound}</if>"
74-
+ "<if test=\"siteName != null &amp;&amp; !siteName.isEmpty()\">and s.station_name LIKE '%#{siteName}%'</if>"
75-
+ "<if test=\"cityName != null &amp;&amp; !cityName.isEmpty()\">and s.city_name LIKE '%#{cityName}%'</if>"
74+
+ "<if test=\"siteName != null &amp;&amp; !siteName.isEmpty()\">and s.station_name LIKE '%' || #{siteName} || '%'</if>"
75+
+ "<if test=\"cityName != null &amp;&amp; !cityName.isEmpty()\">and s.city_name LIKE '%' || #{cityName} || '%'</if>"
7676
+ "<if test=\"provTerr != null &amp;&amp; !provTerr.isEmpty()\">and s.prov_terr in <foreach collection='provTerr' item='prov' index='index' open='(' separator = ',' close=')'>#{prov}</foreach></if>"
7777
+ "<if test=\"siteType != null &amp;&amp; !siteType.isEmpty()\">and s.site_type in <foreach collection='siteType' item='sType' index='index' open='(' separator = ',' close=')'>#{sType}</foreach></if>"
7878
+ "<if test=\"urbanization != null &amp;&amp; !urbanization.isEmpty()\">and s.urbanization in <foreach collection='urbanization' item='urb' index='index' open='(' separator = ',' close=')'>#{urb}</foreach></if>"
@@ -131,8 +131,8 @@ public List<String> getDistinctUnits(
131131
+ " where 1=1"
132132
+ "<if test=\"valueUpperBound != null\">and d.data &lt;= #{valueUpperBound}</if>"
133133
+ "<if test=\"valueLowerBound != null\">and d.data &gt;= #{valueLowerBound}</if>"
134-
+ "<if test=\"siteName != null &amp;&amp; !siteName.isEmpty()\">and s.station_name LIKE '%#{siteName}%'</if>"
135-
+ "<if test=\"cityName != null &amp;&amp; !cityName.isEmpty()\">and s.city_name LIKE '%#{cityName}%'</if>"
134+
+ "<if test=\"siteName != null &amp;&amp; !siteName.isEmpty()\">and s.station_name LIKE '%' || #{siteName} || '%'</if>"
135+
+ "<if test=\"cityName != null &amp;&amp; !cityName.isEmpty()\">and s.city_name LIKE '%' || #{cityName} || '%'</if>"
136136
+ "<if test=\"provTerr != null &amp;&amp; !provTerr.isEmpty()\">and s.prov_terr in <foreach collection='provTerr' item='prov' index='index' open='(' separator = ',' close=')'>#{prov}</foreach></if>"
137137
+ "<if test=\"siteType != null &amp;&amp; !siteType.isEmpty()\">and s.site_type in <foreach collection='siteType' item='sType' index='index' open='(' separator = ',' close=')'>#{sType}</foreach></if>"
138138
+ "<if test=\"urbanization != null &amp;&amp; !urbanization.isEmpty()\">and s.urbanization in <foreach collection='urbanization' item='urb' index='index' open='(' separator = ',' close=')'>#{urb}</foreach></if>"

src/main/java/com/dbf/naps/data/globals/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ public class Constants {
2121
public static final int DATASET_YEAR_END = Year.now().getValue();
2222

2323
public static final BigDecimal bigDecimal1000 = new BigDecimal(1000);
24+
public static final BigDecimal bigDecimal0 = new BigDecimal(0);
2425

2526
}

src/main/java/com/dbf/naps/data/utilities/DataCleaner.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.slf4j.Logger;
1111
import org.slf4j.LoggerFactory;
1212

13+
import com.dbf.naps.data.globals.Constants;
14+
1315
public class DataCleaner {
1416

1517
private static final Logger log = LoggerFactory.getLogger(DataCleaner.class);
@@ -52,13 +54,19 @@ public static BigDecimal parseLongitude(String longitudeRaw) {
5254
}
5355

5456
public static BigDecimal extractDecimalData(String rawValue, boolean ignoreError) {
55-
//Data points are allowed to be null
57+
//These all represent missing data points
58+
//Data points are allowed to be null.
59+
//Negative data points are different. They generally represent "below the detection limit"
5660
if (rawValue == null || rawValue.equals("") || rawValue.equals("-") || rawValue.startsWith("-99")) return null;
5761

5862
try {
5963
BigDecimal decimalVal = new BigDecimal(rawValue);
6064
//Make sure the scale is less than the error of a double
6165
decimalVal = decimalVal.setScale(10, RoundingMode.HALF_UP);
66+
if (decimalVal.compareTo(Constants.bigDecimal0) < 0) {
67+
//Negative values are to be treated as below the detection limit and thus zero
68+
decimalVal = Constants.bigDecimal0;
69+
}
6270
return decimalVal;
6371
} catch (NumberFormatException e){
6472
if(!ignoreError) throw new IllegalArgumentException("Invalid decimal data point: " + rawValue, e);

0 commit comments

Comments
 (0)