Skip to content

Commit

Permalink
Update values table CSS style and number formatting
Browse files Browse the repository at this point in the history
Added `<style>` section to the *jelly* file with CSS style for data
values table, nice borders and light gray header background.

Added `formatNumber` method to format the numbers in the table for
improved readability and used it in the *jelly* file.
  • Loading branch information
radekdoulik committed May 15, 2018
1 parent 6059a3a commit 47b957b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/main/java/hudson/plugins/plot/PlotReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.NumberFormat;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -74,6 +75,23 @@ public List<Plot> getPlots() {
return plots;
}

// called from PlotReport/index.jelly
public String formatNumber(String number) {
String formatted;

try {
formatted = NumberFormat.getIntegerInstance().format(Integer.parseInt(number));
} catch (NumberFormatException e) {
try {
formatted = NumberFormat.getNumberInstance().format(Double.parseDouble(number));
} catch (NumberFormatException e2) {
return number;
}
}

return formatted;
}

// called from PlotReport/index.jelly
public void doGetPlot(StaplerRequest req, StaplerResponse rsp) {
String i = req.getParameter("index");
Expand Down
21 changes: 19 additions & 2 deletions src/main/resources/hudson/plugins/plot/PlotReport/index.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,39 @@

<d:taglib uri="chart">
<d:tag name="chart">
<style>
table.valuesTable {
text-align: right; border: 2px solid gray; border-collapse: collapse;
}
table.valuesTable tr {
border: 1px solid lightgray;
}
table.valuesTable th {
border: 1px solid gray;
background-color: #eee;
padding:.2em;
}
table.valuesTable td {
border: 1px solid lightgray;
padding:.2em;
}
</style>
<div id="${id}" style="margin-top: 2em">
<div align="right" style="width:750px">
<a href="#top"><img src="${rootURL}/images/24x24/up.gif"/>${%top}</a>
</div>
<j:if test="${it.getDisplayTableFlag(index)}">
<div>
<p>
<table border="1">
<table class="valuesTable">
<j:forEach var="tuple" items="${it.getTable(index)}" varStatus="loopStat3">
<tr>
<j:forEach var="col" items="${tuple}">
<j:if test="${loopStat3.index==0}">
<th> ${col} </th>
</j:if>
<j:if test="${loopStat3.index>0}">
<td> ${col} </td>
<td> ${it.formatNumber(col)} </td>
</j:if>
</j:forEach>
</tr>
Expand Down

0 comments on commit 47b957b

Please sign in to comment.