Skip to content

Commit

Permalink
include a legend for weights #207
Browse files Browse the repository at this point in the history
  • Loading branch information
TatianaBurek committed Oct 20, 2020
1 parent 375a0d1 commit eef8743
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions java/edu/ucar/metviewer/scorecard/GraphicalOutputManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class GraphicalOutputManager {
+ ".title1 {width:100%; text-align:center; color:red; font-size:18px; padding-top: 10px;}"
+ ".title2 {width:100%; text-align:center; color:black; font-size:12px;padding-bottom: 10px;}"
+ ".legendTable {margin-top:15px;margin-bottom:10px;}"
+ ".weightsTable {margin-top:15px;}"
+ ".legendText {text-align:left;}";
public static final String CLASS = "class";
public static final String STYLE = "style";
Expand All @@ -89,6 +90,7 @@ class GraphicalOutputManager {
private final List<String> leftColumnsNames;
private final String symbolSize;
private WeightRequirements weightRequirements = null;
private final SortedMap<Double, String> weightToColor = new TreeMap<>(Collections.reverseOrder());


public GraphicalOutputManager(final Scorecard scorecard) {
Expand Down Expand Up @@ -197,13 +199,9 @@ private void initWeightRequirements(final String weightRequirementsFile) {
if (weightNode.getNodeType() == Node.ELEMENT_NODE &&
"Weight".equals(weightNode.getNodeName())) {
double weightValue = Double.parseDouble(weightNode.getAttributes().getNamedItem("weight").getNodeValue());
String color = null;
try {
color = String.valueOf(weightNode.getAttributes().getNamedItem("color").getNodeValue());
} catch (Exception e) {
}

List<WeightRequirements.Criteria> criteriaList = new ArrayList<>();
WeightRequirements.Weight weight = new WeightRequirements.Weight(weightValue, color, criteriaList);
WeightRequirements.Weight weight = new WeightRequirements.Weight(weightValue, criteriaList);
NodeList criteriaNodeList = weightNode.getChildNodes();
for (int i = 0; i < criteriaNodeList.getLength(); i++) {
Node criteriaNode = criteriaNodeList.item(i);
Expand All @@ -223,9 +221,15 @@ private void initWeightRequirements(final String weightRequirementsFile) {
}
}
weightList.add(weight);
} else if (weightNode.getNodeType() == Node.ELEMENT_NODE &&
"WeightToColor".equals(weightNode.getNodeName())) {
Double weightValue = Double.parseDouble(weightNode.getAttributes().getNamedItem("weight").getNodeValue());
String color = String.valueOf(weightNode.getAttributes().getNamedItem("color").getNodeValue());
weightToColor.put(weightValue, color);
}
}


} catch (ParserConfigurationException | IOException | SAXException e) {
logger.info("ERROR during reading weightRequirements XML file : " + e.getMessage());
logger.error(ERROR_MARKER, e.getMessage());
Expand Down Expand Up @@ -416,6 +420,9 @@ public void createGraphics() throws IOException, MissingFileException {

//add all html tags together
htmlBody.with(title1).with(title2).with(title3).with(htmlTable);
if (!weightToColor.isEmpty()){
htmlBody.with(createHtmlWeightLegend());
}
if (viewLegend) {
htmlBody.with(createHtmlLegend());
}
Expand All @@ -441,6 +448,25 @@ public void createGraphics() throws IOException, MissingFileException {
}
}

private ContainerTag createHtmlWeightLegend() {
ContainerTag legendTable = table().attr(CLASS, "weightsTable").attr("align", "center");
// create title
ContainerTag tr = tr();
ContainerTag td = td().attr("colspan", String.valueOf(weightToColor.size()))
.with(new UnescapedText("Weights"));
tr.with(td);
legendTable.with(tr);

tr = tr();
for (Map.Entry<Double, String> entry: weightToColor.entrySet()){
td = td().attr(STYLE, "border-color:" + entry.getValue() + ";" + "border-width:4px;")
.with(new UnescapedText(String.valueOf(entry.getKey())));
tr.with(td);
}
legendTable.with(tr);
return legendTable;
}

private ContainerTag createHtmlLegend() {
ContainerTag legendTable = table().attr(CLASS, "legendTable").attr("align", "center");
for (LegendRange range : rangeList) {
Expand Down Expand Up @@ -687,7 +713,7 @@ private ContainerTag createTableCell(BigDecimal valueForSymbol, BigDecimal value
title = String.valueOf(valueForSymbol);
if (weight != null) {
title = title + "(w" + weight.getWeight() + ")";
borderColor = weight.getColor();
borderColor = weightToColor.get(weight.getWeight());
}
break;
}
Expand All @@ -698,7 +724,7 @@ private ContainerTag createTableCell(BigDecimal valueForSymbol, BigDecimal value
String cellText = valueForNumber.toString();
if (weight != null) {
cellText = cellText + "(w" + weight.getWeight() + ")";
borderColor = weight.getColor();
borderColor = weightToColor.get(weight.getWeight());
}
valueContainer = div().with(new UnescapedText(cellText));
}
Expand All @@ -708,7 +734,7 @@ private ContainerTag createTableCell(BigDecimal valueForSymbol, BigDecimal value
title = String.valueOf(valueForSymbol);
if (weight != null) {
title = title + "(w" + weight.getWeight() + ")";
borderColor = weight.getColor();
borderColor = weightToColor.get(weight.getWeight());
}

}
Expand All @@ -719,7 +745,7 @@ private ContainerTag createTableCell(BigDecimal valueForSymbol, BigDecimal value
String cellText = valueForNumber.toString();
if (weight != null) {
cellText = cellText + "(w" + weight.getWeight() + ")";
borderColor = weight.getColor();
borderColor = weightToColor.get(weight.getWeight());
}
valueContainer = div().with(new UnescapedText(cellText));
}
Expand Down Expand Up @@ -753,7 +779,7 @@ private ContainerTag createTableCell(BigDecimal valueForSymbol, BigDecimal value
if (weight != null) {
String cellText = "w" + weight.getWeight();
valueContainer = div().with(new UnescapedText(cellText));
// result.with(valueContainer);
// result.with(valueContainer);
}

}
Expand Down

0 comments on commit eef8743

Please sign in to comment.