Skip to content

Commit

Permalink
Merge pull request #47 from radekdoulik/format-csv-tables
Browse files Browse the repository at this point in the history
Update values table CSS style and number formatting
  • Loading branch information
vgaidarji authored May 15, 2018
2 parents 6059a3a + 47b957b commit 83e0c19
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 83e0c19

Please sign in to comment.