ref 17249: Save produced charts as report

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

Added PDF support for Scatter
This commit is contained in:
Giancarlo Panichi 2020-05-25 22:08:17 +02:00
parent 9177c518d1
commit 6d9089fb12
7 changed files with 302 additions and 124 deletions

View File

@ -50,11 +50,9 @@ public class BoxPlotAnnualPanelResult {
private int outputNumber = 2;
private int requestId = 0;
public BoxPlotAnnualPanelResult(int reqId, PerformFishAnnualAnalyticsViewController viewAnnualController,
PerformFishResponse thePerformFishResponse,
final DataMinerAlgorithms algorithm, String focusID, List<KPI> inputKPI, final List<KPI> outputKPI) {
PerformFishResponse thePerformFishResponse, final DataMinerAlgorithms algorithm, String focusID,
List<KPI> inputKPI, final List<KPI> outputKPI) {
GWT.log("RequestID: " + reqId);
requestId = reqId;
this.viewAnnualController = viewAnnualController;
@ -124,7 +122,8 @@ public class BoxPlotAnnualPanelResult {
* @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);
@ -225,7 +224,6 @@ public class BoxPlotAnnualPanelResult {
});
}
/**
* Append DM input table.
*
@ -249,7 +247,6 @@ public class BoxPlotAnnualPanelResult {
return dataInputsFormatter;
}
private String getOutputId(int oIteration, String title) {
if (title.startsWith("My")) {
return null;
@ -261,13 +258,8 @@ public class BoxPlotAnnualPanelResult {
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, final int oIteration) {
@ -348,7 +340,6 @@ public class BoxPlotAnnualPanelResult {
title += "<br>";
title += "Data aggregation is performed by considering farms as base units";
String outputId = getOutputId(oIteration, title);
ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showCSVFile(result, cssTableStyle);
@ -466,13 +457,21 @@ public class BoxPlotAnnualPanelResult {
yPos += 2;
pdoc.setFontSize(14);
pdoc.setFontType("bold");
pdoc.text(kpiName.textContent, xPos, yPos, 'left');
var kpiText = kpiName.textContent;
var kpiHeight = pdoc.getLineHeight(kpiText)
/ pdoc.internal.scaleFactor;
var splittedKpiName = pdoc.splitTextToSize(kpiText, (pdfWidthInMM
- lMargin - rMargin));
var kpiLines = splittedKpiName.length; // splitted text is a string array
var kpiLinesHeight = kpiLines * kpiHeight;
pdoc.text(splittedKpiName, xPos, yPos, 'left');
yPos += kpiLinesHeight;
yPos += 6;
pdoc.setFontSize(10);
pdoc.setFontType("normal");
for (var j = 1; j <= outputNumber; j++) {
var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;
@ -540,7 +539,6 @@ public class BoxPlotAnnualPanelResult {
pdoc.setFontSize(10);
pdoc.setFontType("normal");
var secondDiv = childrenTable[0].rows[1].cells[0];
var imageElement = secondDiv.getElementsByTagName(
'img').item(0);
@ -588,5 +586,4 @@ public class BoxPlotAnnualPanelResult {
}-*/;
}

View File

@ -36,6 +36,7 @@ import com.google.gwt.resources.client.TextResource;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Panel;
@ -43,8 +44,8 @@ public class ScatterAnnualPanelResult {
private PerformFishAnnualAnalyticsViewController viewAnnualController;
private int requestId;
private int outputIteration = 0;
private int outputNumber = 0;
private int outputIteration = 1;
private int outputNumber = 1;
public ScatterAnnualPanelResult(int reqId, PerformFishAnnualAnalyticsViewController viewAnnualController,
PerformFishResponse thePerformFishResponse, final DataMinerAlgorithms algorithm, String focusID,
@ -53,7 +54,6 @@ public class ScatterAnnualPanelResult {
requestId = reqId;
this.viewAnnualController = viewAnnualController;
TextResource algDescr = PerformFishResources.INSTANCE.farm_SCATTER();
String algDesrTxt = algDescr != null ? algDescr.getText() : null;
// TODO
@ -61,6 +61,7 @@ public class ScatterAnnualPanelResult {
final String tabDescr = algDesrTxt;
final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
Tab tab = viewAnnualController.createTab(tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1),
algDesrTxt, submitRequestPanel);
@ -80,7 +81,6 @@ public class ScatterAnnualPanelResult {
res.add(savePDFButton);
submitRequestPanel.addWidget(res);
int oIteration = 1;
if (inputKPI.get(0) == null || inputKPI.get(1) == null) {
submitRequestPanel
@ -91,15 +91,19 @@ public class ScatterAnnualPanelResult {
// again");
}
String titleScatter = "KPI: " + inputKPI.get(0).getName() + " vs " + inputKPI.get(1).getName();
submitRequestPanel.setTheTitle(titleScatter);
String title = "KPI: " + inputKPI.get(0).getName() + " vs " + inputKPI.get(1).getName();
HTML toBigTitle = new HTML(title);
toBigTitle.getElement().setId("KPI_ScatterAnnual_" + requestId + "_" + outputIteration);
toBigTitle.getElement().addClassName("to-big-title");
submitRequestPanel.addWidget(toBigTitle);
HorizontalPanel hp = new HorizontalPanel();
hp.getElement().addClassName("ext-horizontal-panel");
DataMinerInputParameters dmInputParams = new DataMinerInputParameters(thePerformFishResponse,
viewAnnualController.getSelectedYears(), inputKPI, outputKPI, algorithm, focusID);
callDataMinerServiceForChart(dmInputParams, submitRequestPanel, submitRequestPanel.getContainerPanel(), tab,
oIteration);
outputIteration = oIteration;
callDataMinerServiceForChart(dmInputParams, submitRequestPanel, hp, tab, outputIteration);
submitRequestPanel.addWidget(hp);
}
@ -243,9 +247,15 @@ public class ScatterAnnualPanelResult {
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 " : "";
@ -260,12 +270,8 @@ public class ScatterAnnualPanelResult {
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();
switch (outputFile.getDataType()) {
@ -286,6 +292,7 @@ public class ScatterAnnualPanelResult {
public void onSuccess(String base64Content) {
String title = toTitle;
String outputId = getOutputId(oIteration, title);
ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showImage(base64Content);
container.add(showResult);
@ -313,6 +320,7 @@ public class ScatterAnnualPanelResult {
String title = toTitle;
String outputId = getOutputId(oIteration, title);
ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showCSVFile(result, cssTableStyle);
container.add(showResult);
@ -326,7 +334,6 @@ public class ScatterAnnualPanelResult {
}
outputNumber=oNumber;
}
/**
@ -377,18 +384,18 @@ public class ScatterAnnualPanelResult {
pdoc.setFontSize(24);
var title = "PerformFish " + tTitle;
var titleHeight = pdoc.getLineHeight(title) / pdoc.internal.scaleFactor
var titleHeight = pdoc.getLineHeight(title) / pdoc.internal.scaleFactor;
var xPos = lMargin;
var yPos = tMargin;
pdoc.text(title, pageCenter, yPos, 'center');
yPos += titleHeight;
pdoc.setFontSize(10);
var lineHeight = pdoc.getLineHeight(tDescr) / pdoc.internal.scaleFactor
var lineHeight = pdoc.getLineHeight(tDescr) / pdoc.internal.scaleFactor;
var splittedAnalysisDescription = pdoc.splitTextToSize(tDescr,
(pdfWidthInMM - lMargin - rMargin));
var lines = splittedAnalysisDescription.length // splitted text is a string array
var analysisDescriptionHeight = lines * lineHeight
var lines = splittedAnalysisDescription.length;// splitted text is a string array
var analysisDescriptionHeight = lines * lineHeight;
pdoc.text(splittedAnalysisDescription, xPos, yPos, 'left');
yPos += analysisDescriptionHeight;
@ -399,6 +406,29 @@ public class ScatterAnnualPanelResult {
for (var i = 1; i <= outputIteration; i++) {
var kpiId = 'KPI_ScatterAnnual_' + requestId + '_' + i;
console.log('kpiId: ' + kpiId);
var kpiName = $doc.getElementById(kpiId);
yPos += 2;
pdoc.setFontSize(14);
pdoc.setFontType("bold");
var kpiText = kpiName.textContent;
var kpiHeight = pdoc.getLineHeight(kpiText)
/ pdoc.internal.scaleFactor;
var splittedKpiName = pdoc.splitTextToSize(kpiText, (pdfWidthInMM
- lMargin - rMargin));
var kpiLines = splittedKpiName.length; // splitted text is a string array
var kpiLinesHeight = kpiLines * kpiHeight;
pdoc.text(splittedKpiName, xPos, yPos, 'left');
yPos += kpiLinesHeight;
yPos += 6;
pdoc.setFontSize(10);
pdoc.setFontType("normal");
for (var j = 1; j <= outputNumber; j++) {
var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;
@ -419,6 +449,19 @@ public class ScatterAnnualPanelResult {
// 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];
@ -439,6 +482,20 @@ public class ScatterAnnualPanelResult {
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);
@ -457,7 +514,29 @@ public class ScatterAnnualPanelResult {
}
}
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');

View File

@ -441,12 +441,22 @@ public class SpeedometerAnnualPanelResult {
yPos += 2;
pdoc.setFontSize(14);
pdoc.setFontType("bold");
pdoc.text(kpiName.textContent, xPos, yPos, 'left');
var kpiText = kpiName.textContent;
var kpiHeight = pdoc.getLineHeight(kpiText)
/ pdoc.internal.scaleFactor;
var splittedKpiName = pdoc.splitTextToSize(kpiText, (pdfWidthInMM
- lMargin - rMargin));
var kpiLines = splittedKpiName.length; // splitted text is a string array
var kpiLinesHeight = kpiLines * kpiHeight;
pdoc.text(splittedKpiName, xPos, yPos, 'left');
yPos += kpiLinesHeight;
yPos += 6;
pdoc.setFontSize(10);
pdoc.setFontType("normal");
for (var j = 1; j <= outputNumber; j++) {
var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;

View File

@ -199,7 +199,6 @@ public class BoxPlotPanelResult {
}
private String getOutputId(int oIteration, String title) {
if (title.startsWith("My")) {
String outputId = "OutputId_" + requestId + "_" + oIteration + "_" + 1;
@ -214,8 +213,6 @@ public class BoxPlotPanelResult {
}
private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
final DataMinerAlgorithms chartType, List<KPI> inputKPIs, List<KPI> outputKPIs, final String focusID,
final Panel container, boolean displayError, final int oIteration) {
@ -309,8 +306,6 @@ public class BoxPlotPanelResult {
}
}
private void displayingOrderedBoxPlot(final DataMinerResponse dmResponse, String title, final Panel container,
@ -413,13 +408,21 @@ public class BoxPlotPanelResult {
yPos += 2;
pdoc.setFontSize(14);
pdoc.setFontType("bold");
pdoc.text(kpiName.textContent, xPos, yPos, 'left');
var kpiText = kpiName.textContent;
var kpiHeight = pdoc.getLineHeight(kpiText)
/ pdoc.internal.scaleFactor;
var splittedKpiName = pdoc.splitTextToSize(kpiText, (pdfWidthInMM
- lMargin - rMargin));
var kpiLines = splittedKpiName.length; // splitted text is a string array
var kpiLinesHeight = kpiLines * kpiHeight;
pdoc.text(splittedKpiName, xPos, yPos, 'left');
yPos += kpiLinesHeight;
yPos += 6;
pdoc.setFontSize(10);
pdoc.setFontType("normal");
for (var j = 1; j <= outputNumber; j++) {
var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;
@ -487,7 +490,6 @@ public class BoxPlotPanelResult {
pdoc.setFontSize(10);
pdoc.setFontType("normal");
var secondDiv = childrenTable[0].rows[1].cells[0];
var imageElement = secondDiv.getElementsByTagName(
'img').item(0);

View File

@ -33,6 +33,7 @@ import com.google.gwt.resources.client.TextResource;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Panel;
@ -40,8 +41,8 @@ public class ScatterPanelResult {
private PerformFishAnalyticsViewController viewController;
private int requestId = 0;
private int outputIteration = 0;
private int outputNumber = 0;
private int outputIteration = 1;
private int outputNumber = 1;
public ScatterPanelResult(int reqId, PerformFishAnalyticsViewController viewController,
final DataMinerAlgorithms algorithm, String focusID, List<KPI> inputKPI, final List<KPI> outputKPI) {
@ -76,7 +77,6 @@ public class ScatterPanelResult {
res.add(savePDFButton);
submitRequestPanel.addWidget(res);
int oIteration = 1;
if (inputKPI.get(0) == null || inputKPI.get(1) == null) {
submitRequestPanel
@ -87,13 +87,17 @@ public class ScatterPanelResult {
// again");
}
String titleScatter = "KPI: " + inputKPI.get(0).getName() + " vs " + inputKPI.get(1).getName();
submitRequestPanel.setTheTitle(titleScatter);
String title = "KPI: " + inputKPI.get(0).getName() + " vs " + inputKPI.get(1).getName();
HTML toBigTitle = new HTML(title);
toBigTitle.getElement().setId("KPI_Scatter_" + requestId + "_" + outputIteration);
toBigTitle.getElement().addClassName("to-big-title");
submitRequestPanel.addWidget(toBigTitle);
HorizontalPanel hp = new HorizontalPanel();
hp.getElement().addClassName("ext-horizontal-panel");
callDataMinerServiceForChart(viewController.getPerformFishResponse(), POPULATION_LEVEL.BATCH, inputKPI,
outputKPI, algorithm, focusID, submitRequestPanel, submitRequestPanel.getContainerPanel(), tab,
oIteration);
outputIteration = oIteration;
outputKPI, algorithm, focusID, submitRequestPanel, hp, tab, outputIteration);
submitRequestPanel.addWidget(hp);
}
@ -193,9 +197,15 @@ public class ScatterPanelResult {
});
}
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,11 +220,8 @@ public class ScatterPanelResult {
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();
switch (outputFile.getDataType()) {
case IMAGE:
@ -234,11 +241,11 @@ public class ScatterPanelResult {
public void onSuccess(String base64Content) {
String title = toTitle;
String outputId = getOutputId(oIteration, title);
ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showImage(base64Content);
container.add(showResult);
}
});
break;
@ -262,6 +269,7 @@ public class ScatterPanelResult {
String title = toTitle;
String outputId = getOutputId(oIteration, title);
ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showCSVFile(result, cssTableStyle);
container.add(showResult);
@ -275,12 +283,8 @@ public class ScatterPanelResult {
}
outputNumber=oNumber;
}
/**
* Remove the spinner if all DM responses are returned.
*
@ -351,6 +355,29 @@ public class ScatterPanelResult {
for (var i = 1; i <= outputIteration; i++) {
var kpiId = 'KPI_Scatter_' + requestId + '_' + i;
console.log('kpiId: ' + kpiId);
var kpiName = $doc.getElementById(kpiId);
yPos += 2;
pdoc.setFontSize(14);
pdoc.setFontType("bold");
var kpiText = kpiName.textContent;
var kpiHeight = pdoc.getLineHeight(kpiText)
/ pdoc.internal.scaleFactor;
var splittedKpiName = pdoc.splitTextToSize(kpiText, (pdfWidthInMM
- lMargin - rMargin));
var kpiLines = splittedKpiName.length; // splitted text is a string array
var kpiLinesHeight = kpiLines * kpiHeight;
pdoc.text(splittedKpiName, xPos, yPos, 'left');
yPos += kpiLinesHeight;
yPos += 6;
pdoc.setFontSize(10);
pdoc.setFontType("normal");
for (var j = 1; j <= outputNumber; j++) {
var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;
@ -371,6 +398,19 @@ public class ScatterPanelResult {
// 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];
@ -391,6 +431,20 @@ public class ScatterPanelResult {
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);
@ -409,7 +463,29 @@ public class ScatterPanelResult {
}
}
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');

View File

@ -364,7 +364,16 @@ public class SpeedometerPanelResult {
yPos += 2;
pdoc.setFontSize(14);
pdoc.setFontType("bold");
pdoc.text(kpiName.textContent, xPos, yPos, 'left');
var kpiText = kpiName.textContent;
var kpiHeight = pdoc.getLineHeight(kpiText)
/ pdoc.internal.scaleFactor;
var splittedKpiName = pdoc.splitTextToSize(kpiText, (pdfWidthInMM
- lMargin - rMargin));
var kpiLines = splittedKpiName.length; // splitted text is a string array
var kpiLinesHeight = kpiLines * kpiHeight;
pdoc.text(splittedKpiName, xPos, yPos, 'left');
yPos += kpiLinesHeight;
yPos += 6;
pdoc.setFontSize(10);

View File

@ -92,6 +92,11 @@ public class SubmitRequestPanel extends Composite {
theTitle.setHTML("");
}
public void addTheTitleClassName(String className){
theTitle.getElement().addClassName(className);
}
/**
* Gets the panel.
*