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);
yPos += 2;
pdoc.setFontSize(16);
pdoc.setFontSize(14);
pdoc.setFontType("bold");
pdoc.text(kpiName.textContent, xPos, yPos, 'left');
yPos += 6;
@ -497,7 +497,7 @@ public class BoxPlotAnnualPanelResult {
console.log('Title current table: '
+ titleCurrentTable.textContent);
yPos += 2;
pdoc.setFontSize(12);
pdoc.setFontSize(10);
pdoc.setFontType("bold");
pdoc.text(titleCurrentTable.textContent, xPos, yPos,
'left');
@ -531,7 +531,7 @@ public class BoxPlotAnnualPanelResult {
console.log('Title current image: '
+ titleCurrentImage.textContent);
yPos += 2;
pdoc.setFontSize(12);
pdoc.setFontSize(10);
pdoc.setFontType("bold");
pdoc.text(titleCurrentImage.textContent, xPos,
yPos, 'left');

View File

@ -46,15 +46,15 @@ public class SpeedometerAnnualPanelResult {
private Map<Integer, FlexTable> boxPlotOrderBy = new HashMap<Integer, FlexTable>();
private PerformFishAnnualAnalyticsViewController viewAnnualController;
private int requestId = 0;
private int outputIteration = 0;
private int outputNumber = 0;
private int requestId;
private int outputNumber = 1;
public SpeedometerAnnualPanelResult(int reqId, PerformFishAnnualAnalyticsViewController viewAnnualController,
PerformFishResponse thePerformFishResponse,
final DataMinerAlgorithms algorithm, String focusID, List<KPI> inputKPI, final List<KPI> outputKPI) {
GWT.log("RequestID: "+reqId);
requestId=reqId;
PerformFishResponse thePerformFishResponse, final DataMinerAlgorithms algorithm, String focusID,
List<KPI> inputKPI, final List<KPI> outputKPI) {
GWT.log("RequestID: " + reqId);
requestId = reqId;
this.viewAnnualController = viewAnnualController;
TextResource algDescr = PerformFishResources.INSTANCE.farm_SPEEDOMETER();
@ -91,6 +91,7 @@ public class SpeedometerAnnualPanelResult {
oIteration++;
String title = "KPI: " + kpi.getName();
HTML toBigTitle = new HTML(title);
toBigTitle.getElement().setId("KPI_SpeedometerAnnual_" + requestId + "_" + oIteration);
toBigTitle.getElement().addClassName("to-big-title");
submitRequestPanel.addWidget(toBigTitle);
HorizontalPanel hp = new HorizontalPanel();
@ -117,11 +118,12 @@ public class SpeedometerAnnualPanelResult {
* the panel
* @param tab
* the tab
* @param tabDescr
* @param tabTitle
* @param tabDescr
* @param tabTitle
*/
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);
@ -207,7 +209,7 @@ public class SpeedometerAnnualPanelResult {
GWT.log("I'm displaying: " + dmResponse);
displayOutputFilesAsStaticEntities(dmResponse, dmInputParameters.getChartType(),
dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
dmInputParameters.getFocusID(), panelContainer, false,oIteration);
dmInputParameters.getFocusID(), panelContainer, false, oIteration);
}
@Override
@ -216,13 +218,12 @@ public class SpeedometerAnnualPanelResult {
checkTabSpinner(requestPanel, tab);
displayOutputFilesAsStaticEntities(null, dmInputParameters.getChartType(),
dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
dmInputParameters.getFocusID(), panelContainer, true,oIteration);
dmInputParameters.getFocusID(), panelContainer, true, oIteration);
}
});
}
/**
* Append DM input table.
*
@ -246,10 +247,15 @@ public class SpeedometerAnnualPanelResult {
return dataInputsFormatter;
}
private String getOutputId(int oIteration, String title) {
String outputId = "OutputId_" + requestId + "_" + oIteration + "_" + 1;
return outputId;
}
private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
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 " : "";
@ -264,13 +270,9 @@ public class SpeedometerAnnualPanelResult {
final String toTitle = title;
int oNumber = 0;
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()) {
case IMAGE:
PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile,
@ -293,11 +295,12 @@ public class SpeedometerAnnualPanelResult {
title = chartType.getTitle() + "<br>";
title += "Selected Farm: " + focusID + "<br>";
title += "Normalized with respect to all farm data in the VRE";
String outputId = getOutputId(oIteration, title);
ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showImage(base64Content);
container.add(showResult);
}
});
break;
@ -321,6 +324,7 @@ public class SpeedometerAnnualPanelResult {
String title = toTitle;
String outputId = getOutputId(oIteration, title);
ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showCSVFile(result, cssTableStyle);
container.add(showResult);
@ -334,8 +338,6 @@ public class SpeedometerAnnualPanelResult {
}
}
outputNumber=oNumber;
}
@ -431,6 +433,20 @@ public class SpeedometerAnnualPanelResult {
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++) {
var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;
@ -451,6 +467,19 @@ public class SpeedometerAnnualPanelResult {
// foo could get resolved and it's defined
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 secondTable = secondDiv.children[0].children[0];
@ -471,6 +500,20 @@ public class SpeedometerAnnualPanelResult {
if (resultType == 'image') {
console.log('Result Type image: ' + i);
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 imageElement = secondDiv.getElementsByTagName(
'img').item(0);
@ -489,8 +532,30 @@ 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');
pdoc.save(filename);

View File

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

View File

@ -42,12 +42,12 @@ public class SpeedometerPanelResult {
private PerformFishAnalyticsViewController viewController;
private int requestId;
private int outputIteration = 0;
private int outputNumber = 0;
public SpeedometerPanelResult(int reqId,PerformFishAnalyticsViewController viewController,
private int outputNumber = 1;
public SpeedometerPanelResult(int reqId, PerformFishAnalyticsViewController viewController,
final DataMinerAlgorithms algorithm, String focusID, List<KPI> inputKPI, final List<KPI> outputKPI) {
GWT.log("RequestID: "+reqId);
requestId=reqId;
GWT.log("RequestID: " + reqId);
requestId = reqId;
this.viewController = viewController;
TextResource algDescr = PerformFishResources.INSTANCE.batch_SPEEDOMETER();
@ -70,7 +70,7 @@ public class SpeedometerPanelResult {
@Override
public void onClick(ClickEvent event) {
saveFilePDF(algorithm.getId(), tabTitle, tabTitle, tabDescr, requestId,outputIteration, outputNumber);
saveFilePDF(algorithm.getId(), tabTitle, tabTitle, tabDescr, requestId, outputIteration, outputNumber);
}
});
@ -83,6 +83,7 @@ public class SpeedometerPanelResult {
oIteration++;
String title = "KPI: " + kpi.getName();
HTML toBigTitle = new HTML(title);
toBigTitle.getElement().setId("KPI_Speedometer_" + requestId + "_" + oIteration);
toBigTitle.getElement().addClassName("to-big-title");
submitRequestPanel.addWidget(toBigTitle);
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,
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 " : "";
@ -210,13 +217,9 @@ public class SpeedometerPanelResult {
final String toTitle = title;
int oNumber = 0;
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()) {
case IMAGE:
PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile,
@ -239,6 +242,7 @@ public class SpeedometerPanelResult {
title += "Selected Batch ID: " + focusID + "<br>";
title += "Normalized with respect to all batches in the VRE";
String outputId = getOutputId(oIteration, title);
ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showImage(base64Content);
container.add(showResult);
@ -266,6 +270,7 @@ public class SpeedometerPanelResult {
String title = toTitle;
String outputId = getOutputId(oIteration, title);
ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showCSVFile(result, cssTableStyle);
container.add(showResult);
@ -278,13 +283,9 @@ public class SpeedometerPanelResult {
}
}
outputNumber=oNumber;
}
/**
* Remove the spinner if all DM responses are returned.
*
@ -307,7 +308,7 @@ public class SpeedometerPanelResult {
int requestId, int outputIteration, int outputNumber)/*-{
var that = this;
console.log('saveFilePDF()');
console.log('requestId: '+requestId);
console.log('requestId: ' + requestId);
console.log('OutputIteration: ' + outputIteration);
console.log('OutputNumber:' + outputNumber);
@ -355,9 +356,23 @@ public class SpeedometerPanelResult {
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++) {
var outputId = 'OutputId_'+requestId+'_'+ i + '_' + j;
var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;
console.log('OutputId: ' + outputId);
var resultOutputNumber = $doc.getElementById(outputId);
@ -375,6 +390,19 @@ public class SpeedometerPanelResult {
// foo could get resolved and it's defined
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 secondTable = secondDiv.children[0].children[0];
@ -395,6 +423,20 @@ public class SpeedometerPanelResult {
if (resultType == 'image') {
console.log('Result Type image: ' + i);
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 imageElement = secondDiv.getElementsByTagName(
'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');
pdoc.save(filename);
}-*/;
}