ref 17249: Save produced charts as report

https://support.d4science.org/issues/17249

Added PDF support for Speedometer
This commit is contained in:
Giancarlo Panichi 2020-05-25 19:44:14 +02:00
parent 8ca0cbeb69
commit 9177c518d1
4 changed files with 179 additions and 49 deletions

View File

@ -464,7 +464,7 @@ public class BoxPlotAnnualPanelResult {
var kpiName = $doc.getElementById(kpiId); var kpiName = $doc.getElementById(kpiId);
yPos += 2; yPos += 2;
pdoc.setFontSize(16); pdoc.setFontSize(14);
pdoc.setFontType("bold"); pdoc.setFontType("bold");
pdoc.text(kpiName.textContent, xPos, yPos, 'left'); pdoc.text(kpiName.textContent, xPos, yPos, 'left');
yPos += 6; yPos += 6;
@ -497,7 +497,7 @@ public class BoxPlotAnnualPanelResult {
console.log('Title current table: ' console.log('Title current table: '
+ titleCurrentTable.textContent); + titleCurrentTable.textContent);
yPos += 2; yPos += 2;
pdoc.setFontSize(12); pdoc.setFontSize(10);
pdoc.setFontType("bold"); pdoc.setFontType("bold");
pdoc.text(titleCurrentTable.textContent, xPos, yPos, pdoc.text(titleCurrentTable.textContent, xPos, yPos,
'left'); 'left');
@ -531,7 +531,7 @@ public class BoxPlotAnnualPanelResult {
console.log('Title current image: ' console.log('Title current image: '
+ titleCurrentImage.textContent); + titleCurrentImage.textContent);
yPos += 2; yPos += 2;
pdoc.setFontSize(12); pdoc.setFontSize(10);
pdoc.setFontType("bold"); pdoc.setFontType("bold");
pdoc.text(titleCurrentImage.textContent, xPos, pdoc.text(titleCurrentImage.textContent, xPos,
yPos, 'left'); yPos, 'left');

View File

@ -46,13 +46,13 @@ public class SpeedometerAnnualPanelResult {
private Map<Integer, FlexTable> boxPlotOrderBy = new HashMap<Integer, FlexTable>(); private Map<Integer, FlexTable> boxPlotOrderBy = new HashMap<Integer, FlexTable>();
private PerformFishAnnualAnalyticsViewController viewAnnualController; private PerformFishAnnualAnalyticsViewController viewAnnualController;
private int requestId = 0;
private int outputIteration = 0; private int outputIteration = 0;
private int outputNumber = 0; private int outputNumber = 1;
private int requestId;
public SpeedometerAnnualPanelResult(int reqId, PerformFishAnnualAnalyticsViewController viewAnnualController, public SpeedometerAnnualPanelResult(int reqId, PerformFishAnnualAnalyticsViewController viewAnnualController,
PerformFishResponse thePerformFishResponse, PerformFishResponse thePerformFishResponse, final DataMinerAlgorithms algorithm, String focusID,
final DataMinerAlgorithms algorithm, String focusID, List<KPI> inputKPI, final List<KPI> outputKPI) { List<KPI> inputKPI, final List<KPI> outputKPI) {
GWT.log("RequestID: " + reqId); GWT.log("RequestID: " + reqId);
requestId = reqId; requestId = reqId;
this.viewAnnualController = viewAnnualController; this.viewAnnualController = viewAnnualController;
@ -91,6 +91,7 @@ public class SpeedometerAnnualPanelResult {
oIteration++; oIteration++;
String title = "KPI: " + kpi.getName(); String title = "KPI: " + kpi.getName();
HTML toBigTitle = new HTML(title); HTML toBigTitle = new HTML(title);
toBigTitle.getElement().setId("KPI_SpeedometerAnnual_" + requestId + "_" + oIteration);
toBigTitle.getElement().addClassName("to-big-title"); toBigTitle.getElement().addClassName("to-big-title");
submitRequestPanel.addWidget(toBigTitle); submitRequestPanel.addWidget(toBigTitle);
HorizontalPanel hp = new HorizontalPanel(); HorizontalPanel hp = new HorizontalPanel();
@ -121,7 +122,8 @@ public class SpeedometerAnnualPanelResult {
* @param tabTitle * @param tabTitle
*/ */
private void callDataMinerServiceForChart(final DataMinerInputParameters dmInputParameters, private void callDataMinerServiceForChart(final DataMinerInputParameters dmInputParameters,
final SubmitRequestPanel requestPanel, final ComplexPanel panelContainer, final Tab tab, final int oIteration) { final SubmitRequestPanel requestPanel, final ComplexPanel panelContainer, final Tab tab,
final int oIteration) {
GWT.log("Building DM request with input parameters: " + dmInputParameters); GWT.log("Building DM request with input parameters: " + dmInputParameters);
@ -222,7 +224,6 @@ public class SpeedometerAnnualPanelResult {
}); });
} }
/** /**
* Append DM input table. * Append DM input table.
* *
@ -246,10 +247,15 @@ public class SpeedometerAnnualPanelResult {
return dataInputsFormatter; return dataInputsFormatter;
} }
private String getOutputId(int oIteration, String title) {
String outputId = "OutputId_" + requestId + "_" + oIteration + "_" + 1;
return outputId;
}
private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse, private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
final DataMinerAlgorithms chartType, List<KPI> inputKPIs, List<KPI> outputKPIs, final String focusID, final DataMinerAlgorithms chartType, List<KPI> inputKPIs, List<KPI> outputKPIs, final String focusID,
final Panel container, boolean displayError, int oIteration) { final Panel container, boolean displayError, final int oIteration) {
String title = displayError ? "No results " : ""; String title = displayError ? "No results " : "";
@ -264,11 +270,7 @@ public class SpeedometerAnnualPanelResult {
final String toTitle = title; final String toTitle = title;
int oNumber = 0;
for (OutputFile outputFile : dmResponse.getListOutput()) { for (OutputFile outputFile : dmResponse.getListOutput()) {
oNumber++;
final String outputId = "OutputId_" + requestId+"_"+oIteration + "_" + oNumber;
final FileContentType fileContentType = outputFile.getDataType(); final FileContentType fileContentType = outputFile.getDataType();
switch (outputFile.getDataType()) { switch (outputFile.getDataType()) {
@ -294,6 +296,7 @@ public class SpeedometerAnnualPanelResult {
title += "Selected Farm: " + focusID + "<br>"; title += "Selected Farm: " + focusID + "<br>";
title += "Normalized with respect to all farm data in the VRE"; title += "Normalized with respect to all farm data in the VRE";
String outputId = getOutputId(oIteration, title);
ShowResult showResult = new ShowResult(outputId, title, fileContentType); ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showImage(base64Content); showResult.showImage(base64Content);
container.add(showResult); container.add(showResult);
@ -321,6 +324,7 @@ public class SpeedometerAnnualPanelResult {
String title = toTitle; String title = toTitle;
String outputId = getOutputId(oIteration, title);
ShowResult showResult = new ShowResult(outputId, title, fileContentType); ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showCSVFile(result, cssTableStyle); showResult.showCSVFile(result, cssTableStyle);
container.add(showResult); container.add(showResult);
@ -335,8 +339,6 @@ public class SpeedometerAnnualPanelResult {
} }
outputNumber=oNumber;
} }
private void displayingOrderedBoxPlot(final DataMinerResponse dmResponse, String title, final Panel container, private void displayingOrderedBoxPlot(final DataMinerResponse dmResponse, String title, final Panel container,
@ -431,6 +433,20 @@ public class SpeedometerAnnualPanelResult {
for (var i = 1; i <= outputIteration; i++) { for (var i = 1; i <= outputIteration; i++) {
var kpiId = 'KPI_SpeedometerAnnual_' + requestId + '_' + i;
console.log('kpiId: ' + kpiId);
var kpiName = $doc.getElementById(kpiId);
yPos += 2;
pdoc.setFontSize(14);
pdoc.setFontType("bold");
pdoc.text(kpiName.textContent, xPos, yPos, 'left');
yPos += 6;
pdoc.setFontSize(10);
pdoc.setFontType("normal");
for (var j = 1; j <= outputNumber; j++) { for (var j = 1; j <= outputNumber; j++) {
var outputId = 'OutputId_' + requestId + '_' + i + '_' + j; var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;
@ -451,6 +467,19 @@ public class SpeedometerAnnualPanelResult {
// foo could get resolved and it's defined // foo could get resolved and it's defined
var childrenTable = resultOutputNumber.children; var childrenTable = resultOutputNumber.children;
var titleCurrentTable = childrenTable[0].rows[0].cells[0];
console.log('Title current table: '
+ titleCurrentTable.textContent);
yPos += 2;
pdoc.setFontSize(10);
pdoc.setFontType("bold");
pdoc.text(titleCurrentTable.textContent, xPos, yPos,
'left');
yPos += 6;
pdoc.setFontSize(10);
pdoc.setFontType("normal");
var secondDiv = childrenTable[0].rows[1].cells[0]; var secondDiv = childrenTable[0].rows[1].cells[0];
var secondTable = secondDiv.children[0].children[0]; var secondTable = secondDiv.children[0].children[0];
@ -471,6 +500,20 @@ public class SpeedometerAnnualPanelResult {
if (resultType == 'image') { if (resultType == 'image') {
console.log('Result Type image: ' + i); console.log('Result Type image: ' + i);
var childrenTable = resultOutputNumber.children; var childrenTable = resultOutputNumber.children;
var titleCurrentImage = childrenTable[0].rows[0].cells[0];
console.log('Title current image: '
+ titleCurrentImage.textContent);
yPos += 2;
pdoc.setFontSize(10);
pdoc.setFontType("bold");
pdoc.text(titleCurrentImage.textContent, xPos,
yPos, 'left');
yPos += 6;
pdoc.setFontSize(10);
pdoc.setFontType("normal");
var secondDiv = childrenTable[0].rows[1].cells[0]; var secondDiv = childrenTable[0].rows[1].cells[0];
var imageElement = secondDiv.getElementsByTagName( var imageElement = secondDiv.getElementsByTagName(
'img').item(0); 'img').item(0);
@ -489,7 +532,29 @@ public class SpeedometerAnnualPanelResult {
} }
} }
if (i == outputNumber) {
} else {
if (pdfHeightInMM - yPos < pdfHeightInMM / 4) {
//var numberOfPages=pdoc.internal.getNumberOfPages();
//console.log('NumberOfPages: '+numberOfPages);
var currentPage = pdoc.internal.getCurrentPageInfo().pageNumber;
console.log('CurrentPage: ' + currentPage);
var footner = 'Page ' + currentPage;
pdoc.text(footner, pageCenter, pdfHeightInMM - 7, 'center');
pdoc.addPage();
yPos = tMargin; // Restart position
} }
}
}
var currentPage = pdoc.internal.getCurrentPageInfo().pageNumber;
console.log('CurrentPage: ' + currentPage);
var footner = 'Page ' + currentPage;
pdoc.text(footner, pageCenter, pdfHeightInMM - 7, 'center');
console.log('Done'); console.log('Done');

View File

@ -411,7 +411,7 @@ public class BoxPlotPanelResult {
var kpiName = $doc.getElementById(kpiId); var kpiName = $doc.getElementById(kpiId);
yPos += 2; yPos += 2;
pdoc.setFontSize(16); pdoc.setFontSize(14);
pdoc.setFontType("bold"); pdoc.setFontType("bold");
pdoc.text(kpiName.textContent, xPos, yPos, 'left'); pdoc.text(kpiName.textContent, xPos, yPos, 'left');
yPos += 6; yPos += 6;
@ -444,7 +444,7 @@ public class BoxPlotPanelResult {
console.log('Title current table: ' console.log('Title current table: '
+ titleCurrentTable.textContent); + titleCurrentTable.textContent);
yPos += 2; yPos += 2;
pdoc.setFontSize(12); pdoc.setFontSize(10);
pdoc.setFontType("bold"); pdoc.setFontType("bold");
pdoc.text(titleCurrentTable.textContent, xPos, yPos, pdoc.text(titleCurrentTable.textContent, xPos, yPos,
'left'); 'left');
@ -478,7 +478,7 @@ public class BoxPlotPanelResult {
console.log('Title current image: ' console.log('Title current image: '
+ titleCurrentImage.textContent); + titleCurrentImage.textContent);
yPos += 2; yPos += 2;
pdoc.setFontSize(12); pdoc.setFontSize(10);
pdoc.setFontType("bold"); pdoc.setFontType("bold");
pdoc.text(titleCurrentImage.textContent, xPos, pdoc.text(titleCurrentImage.textContent, xPos,
yPos, 'left'); yPos, 'left');

View File

@ -42,7 +42,7 @@ public class SpeedometerPanelResult {
private PerformFishAnalyticsViewController viewController; private PerformFishAnalyticsViewController viewController;
private int requestId; private int requestId;
private int outputIteration = 0; private int outputIteration = 0;
private int outputNumber = 0; private int outputNumber = 1;
public SpeedometerPanelResult(int reqId, PerformFishAnalyticsViewController viewController, public SpeedometerPanelResult(int reqId, PerformFishAnalyticsViewController viewController,
final DataMinerAlgorithms algorithm, String focusID, List<KPI> inputKPI, final List<KPI> outputKPI) { final DataMinerAlgorithms algorithm, String focusID, List<KPI> inputKPI, final List<KPI> outputKPI) {
@ -83,6 +83,7 @@ public class SpeedometerPanelResult {
oIteration++; oIteration++;
String title = "KPI: " + kpi.getName(); String title = "KPI: " + kpi.getName();
HTML toBigTitle = new HTML(title); HTML toBigTitle = new HTML(title);
toBigTitle.getElement().setId("KPI_Speedometer_" + requestId + "_" + oIteration);
toBigTitle.getElement().addClassName("to-big-title"); toBigTitle.getElement().addClassName("to-big-title");
submitRequestPanel.addWidget(toBigTitle); submitRequestPanel.addWidget(toBigTitle);
HorizontalPanel hp = new HorizontalPanel(); HorizontalPanel hp = new HorizontalPanel();
@ -193,9 +194,15 @@ public class SpeedometerPanelResult {
}); });
} }
private String getOutputId(int oIteration, String title) {
String outputId = "OutputId_" + requestId + "_" + oIteration + "_" + 1;
return outputId;
}
private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse, private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
final DataMinerAlgorithms chartType, List<KPI> inputKPIs, List<KPI> outputKPIs, final String focusID, final DataMinerAlgorithms chartType, List<KPI> inputKPIs, List<KPI> outputKPIs, final String focusID,
final Panel container, boolean displayError, int oIteration) { final Panel container, boolean displayError, final int oIteration) {
String title = displayError ? "No results " : ""; String title = displayError ? "No results " : "";
@ -210,11 +217,7 @@ public class SpeedometerPanelResult {
final String toTitle = title; final String toTitle = title;
int oNumber = 0;
for (OutputFile outputFile : dmResponse.getListOutput()) { for (OutputFile outputFile : dmResponse.getListOutput()) {
oNumber++;
final String outputId = "OutputId_" + requestId+"_"+oIteration + "_" + oNumber;
final FileContentType fileContentType = outputFile.getDataType(); final FileContentType fileContentType = outputFile.getDataType();
switch (outputFile.getDataType()) { switch (outputFile.getDataType()) {
@ -239,6 +242,7 @@ public class SpeedometerPanelResult {
title += "Selected Batch ID: " + focusID + "<br>"; title += "Selected Batch ID: " + focusID + "<br>";
title += "Normalized with respect to all batches in the VRE"; title += "Normalized with respect to all batches in the VRE";
String outputId = getOutputId(oIteration, title);
ShowResult showResult = new ShowResult(outputId, title, fileContentType); ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showImage(base64Content); showResult.showImage(base64Content);
container.add(showResult); container.add(showResult);
@ -266,6 +270,7 @@ public class SpeedometerPanelResult {
String title = toTitle; String title = toTitle;
String outputId = getOutputId(oIteration, title);
ShowResult showResult = new ShowResult(outputId, title, fileContentType); ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showCSVFile(result, cssTableStyle); showResult.showCSVFile(result, cssTableStyle);
container.add(showResult); container.add(showResult);
@ -279,12 +284,8 @@ public class SpeedometerPanelResult {
} }
outputNumber=oNumber;
} }
/** /**
* Remove the spinner if all DM responses are returned. * Remove the spinner if all DM responses are returned.
* *
@ -355,6 +356,20 @@ public class SpeedometerPanelResult {
for (var i = 1; i <= outputIteration; i++) { for (var i = 1; i <= outputIteration; i++) {
var kpiId = 'KPI_Speedometer_' + requestId + '_' + i;
console.log('kpiId: ' + kpiId);
var kpiName = $doc.getElementById(kpiId);
yPos += 2;
pdoc.setFontSize(14);
pdoc.setFontType("bold");
pdoc.text(kpiName.textContent, xPos, yPos, 'left');
yPos += 6;
pdoc.setFontSize(10);
pdoc.setFontType("normal");
for (var j = 1; j <= outputNumber; j++) { for (var j = 1; j <= outputNumber; j++) {
var outputId = 'OutputId_' + requestId + '_' + i + '_' + j; var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;
@ -375,6 +390,19 @@ public class SpeedometerPanelResult {
// foo could get resolved and it's defined // foo could get resolved and it's defined
var childrenTable = resultOutputNumber.children; var childrenTable = resultOutputNumber.children;
var titleCurrentTable = childrenTable[0].rows[0].cells[0];
console.log('Title current table: '
+ titleCurrentTable.textContent);
yPos += 2;
pdoc.setFontSize(10);
pdoc.setFontType("bold");
pdoc.text(titleCurrentTable.textContent, xPos, yPos,
'left');
yPos += 6;
pdoc.setFontSize(10);
pdoc.setFontType("normal");
var secondDiv = childrenTable[0].rows[1].cells[0]; var secondDiv = childrenTable[0].rows[1].cells[0];
var secondTable = secondDiv.children[0].children[0]; var secondTable = secondDiv.children[0].children[0];
@ -395,6 +423,20 @@ public class SpeedometerPanelResult {
if (resultType == 'image') { if (resultType == 'image') {
console.log('Result Type image: ' + i); console.log('Result Type image: ' + i);
var childrenTable = resultOutputNumber.children; var childrenTable = resultOutputNumber.children;
var titleCurrentImage = childrenTable[0].rows[0].cells[0];
console.log('Title current image: '
+ titleCurrentImage.textContent);
yPos += 2;
pdoc.setFontSize(10);
pdoc.setFontType("bold");
pdoc.text(titleCurrentImage.textContent, xPos,
yPos, 'left');
yPos += 6;
pdoc.setFontSize(10);
pdoc.setFontType("normal");
var secondDiv = childrenTable[0].rows[1].cells[0]; var secondDiv = childrenTable[0].rows[1].cells[0];
var imageElement = secondDiv.getElementsByTagName( var imageElement = secondDiv.getElementsByTagName(
'img').item(0); 'img').item(0);
@ -413,11 +455,34 @@ public class SpeedometerPanelResult {
} }
} }
if (i == outputNumber) {
} else {
if (pdfHeightInMM - yPos < pdfHeightInMM / 4) {
//var numberOfPages=pdoc.internal.getNumberOfPages();
//console.log('NumberOfPages: '+numberOfPages);
var currentPage = pdoc.internal.getCurrentPageInfo().pageNumber;
console.log('CurrentPage: ' + currentPage);
var footner = 'Page ' + currentPage;
pdoc.text(footner, pageCenter, pdfHeightInMM - 7, 'center');
pdoc.addPage();
yPos = tMargin; // Restart position
} }
}
}
var currentPage = pdoc.internal.getCurrentPageInfo().pageNumber;
console.log('CurrentPage: ' + currentPage);
var footner = 'Page ' + currentPage;
pdoc.text(footner, pageCenter, pdfHeightInMM - 7, 'center');
console.log('Done'); console.log('Done');
pdoc.save(filename); pdoc.save(filename);
}-*/; }-*/;
} }