|
|
|
@ -14,11 +14,12 @@ import com.google.gwt.user.client.ui.HTMLPanel;
|
|
|
|
|
public class Chart extends HTMLPanel {
|
|
|
|
|
|
|
|
|
|
private String name;
|
|
|
|
|
|
|
|
|
|
private ReportElementData reportElementData;
|
|
|
|
|
|
|
|
|
|
public Chart(AppResources resources, String name, ReportElementData reportElementData) {
|
|
|
|
|
super("<div class='dropdown'>" + "<button class='btn dropdown-toggle' "
|
|
|
|
|
+ "type='button' style='float:right;' data-toggle='dropdown'><span class='"
|
|
|
|
|
+ "type='button' style='float:right;max-width:80px;' data-toggle='dropdown'><span class='"
|
|
|
|
|
+ resources.uiDataCss().uiDataIconSettings() + "'></span>" + "<span class='caret'></span>" + "</button>"
|
|
|
|
|
+ "<ul class='" + resources.uiDataCss().uiDataChartMenuPosition() + " dropdown-menu'>" + "<li><a id='"
|
|
|
|
|
+ name + "_ExportJPEG' href='#' download='" + reportElementData.getLabel() + ".jpeg'>Export JPEG</a>"
|
|
|
|
@ -53,15 +54,16 @@ public class Chart extends HTMLPanel {
|
|
|
|
|
var name = chart.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::name;
|
|
|
|
|
console.log('Element name: ' + name);
|
|
|
|
|
var element = this;
|
|
|
|
|
console.log('Element found: ' + element);
|
|
|
|
|
var canvas = $doc.getElementById(name);
|
|
|
|
|
console.log('Canvas: ' + canvas);
|
|
|
|
|
canvas.style.display = 'block';
|
|
|
|
|
canvas.style.visibility = 'visible';
|
|
|
|
|
canvas.width = 800;
|
|
|
|
|
canvas.height = 600;
|
|
|
|
|
|
|
|
|
|
canvas.height = 500;
|
|
|
|
|
canvas.width = 990;
|
|
|
|
|
var canvasW = canvas.width;
|
|
|
|
|
var canvasH = canvas.height;
|
|
|
|
|
console.log('Canvas dimensions: ' + canvasW + ' x ' + canvasH);
|
|
|
|
|
var w = canvas.width;
|
|
|
|
|
var h = canvas.height;
|
|
|
|
|
console.log('Canvas dimensions: ' + w + ' x ' + h);
|
|
|
|
|
|
|
|
|
|
return canvas;
|
|
|
|
|
|
|
|
|
@ -74,28 +76,24 @@ public class Chart extends HTMLPanel {
|
|
|
|
|
|
|
|
|
|
//Export JPEG
|
|
|
|
|
var elementNameJPEG = name + '_ExportJPEG';
|
|
|
|
|
console.log('ExportJPEG search: ' + elementNameJPEG);
|
|
|
|
|
var exportJPEGElement = $doc.getElementById(elementNameJPEG);
|
|
|
|
|
console.log('ExportJPEGElement: ' + exportJPEGElement);
|
|
|
|
|
exportJPEGElement.onclick = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::saveImageJPEG(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;)(this);
|
|
|
|
|
|
|
|
|
|
//Export PNG
|
|
|
|
|
var elementNamePNG = name + '_ExportPNG';
|
|
|
|
|
console.log('ExportPNG search: ' + elementNamePNG);
|
|
|
|
|
var exportPNGElement = $doc.getElementById(elementNamePNG);
|
|
|
|
|
console.log('ExportPNGElement: ' + exportPNGElement);
|
|
|
|
|
exportPNGElement.onclick = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::saveImagePNG(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;)(this);
|
|
|
|
|
|
|
|
|
|
//Export PDF
|
|
|
|
|
var elementNamePDF = name + '_ExportPDF';
|
|
|
|
|
console.log('ExportPDF search: ' + elementNamePDF);
|
|
|
|
|
var exportPDFElement = $doc.getElementById(elementNamePDF);
|
|
|
|
|
console.log('ExportPDFElement: ' + exportPDFElement);
|
|
|
|
|
exportPDFElement.onclick = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::saveFilePDF(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;Ljava/lang/String;)(this,exportPDFElement.download);
|
|
|
|
|
|
|
|
|
|
//Export CSV
|
|
|
|
|
var elementNameCSV = name + '_ExportCSV';
|
|
|
|
|
console.log('ExportCSV search: ' + elementNameCSV);
|
|
|
|
|
var exportCSVElement = $doc.getElementById(elementNameCSV);
|
|
|
|
|
console.log('ExportCSVElement: ' + exportCSVElement);
|
|
|
|
|
exportCSVElement.onclick = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::saveFileCSV(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;)(this);
|
|
|
|
@ -137,7 +135,6 @@ public class Chart extends HTMLPanel {
|
|
|
|
|
var image = canvas.toDataURL("image/png").replace("image/png",
|
|
|
|
|
"image/octet-stream");
|
|
|
|
|
this.href = image;
|
|
|
|
|
//window.open(image, '_blank');
|
|
|
|
|
};
|
|
|
|
|
}-*/;
|
|
|
|
|
|
|
|
|
@ -166,7 +163,6 @@ public class Chart extends HTMLPanel {
|
|
|
|
|
console.log('Save file csv');
|
|
|
|
|
|
|
|
|
|
var serieses = reportElementData.getSerieses();
|
|
|
|
|
console.log('Serieses: ' + serieses);
|
|
|
|
|
var seriesesLen = serieses.length;
|
|
|
|
|
console.log('Serieses lenght: ' + seriesesLen);
|
|
|
|
|
|
|
|
|
@ -203,6 +199,34 @@ public class Chart extends HTMLPanel {
|
|
|
|
|
|
|
|
|
|
}-*/;
|
|
|
|
|
|
|
|
|
|
private static native void getScales(Chart chart)/*-{
|
|
|
|
|
var reportElementData = chart.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::reportElementData;
|
|
|
|
|
|
|
|
|
|
var xAxisLabel = reportElementData.getxAxis();
|
|
|
|
|
var yAxisLabel = reportElementData.getyAxis();
|
|
|
|
|
var scalesType = {
|
|
|
|
|
xAxes : [ {
|
|
|
|
|
scaleLabel : {
|
|
|
|
|
display : true,
|
|
|
|
|
labelString : xAxisLabel
|
|
|
|
|
}
|
|
|
|
|
} ],
|
|
|
|
|
|
|
|
|
|
yAxes : [ {
|
|
|
|
|
scaleLabel : {
|
|
|
|
|
display : true,
|
|
|
|
|
labelString : yAxisLabel
|
|
|
|
|
},
|
|
|
|
|
ticks : {
|
|
|
|
|
beginAtZero : true
|
|
|
|
|
}
|
|
|
|
|
} ]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return scalesType;
|
|
|
|
|
|
|
|
|
|
}-*/;
|
|
|
|
|
|
|
|
|
|
private native void redrawChart() /*-{
|
|
|
|
|
console.log('RedrawChart()');
|
|
|
|
|
|
|
|
|
@ -244,11 +268,12 @@ public class Chart extends HTMLPanel {
|
|
|
|
|
return color;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::createMenu()();
|
|
|
|
|
|
|
|
|
|
var canvas = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::getCanvas(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;)(this);
|
|
|
|
|
console.log('Canvas: ' + canvas);
|
|
|
|
|
|
|
|
|
|
var reportElementData = this.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::reportElementData;
|
|
|
|
|
console.log('ReportElementData: ' + reportElementData);
|
|
|
|
|
|
|
|
|
|
var serieses = reportElementData.getSerieses();
|
|
|
|
|
var seriesesLen = serieses.length;
|
|
|
|
@ -257,7 +282,7 @@ public class Chart extends HTMLPanel {
|
|
|
|
|
var datasetsArray = [];
|
|
|
|
|
var labelsArray = []
|
|
|
|
|
for (var i = 0; i < seriesesLen; i++) {
|
|
|
|
|
console.log("for");
|
|
|
|
|
|
|
|
|
|
var seriesData = serieses[i];
|
|
|
|
|
console.log('SeriesData: ' + seriesData);
|
|
|
|
|
var dataRow = seriesData.getDataRow();
|
|
|
|
@ -280,7 +305,6 @@ public class Chart extends HTMLPanel {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var colorChart = getRandomColor();
|
|
|
|
|
console.log('Color: ' + colorChart);
|
|
|
|
|
|
|
|
|
|
datasetsArray.push({
|
|
|
|
|
label : seriesData.getLabel(),
|
|
|
|
@ -298,82 +322,55 @@ public class Chart extends HTMLPanel {
|
|
|
|
|
|
|
|
|
|
var label = [ reportElementData.getLabel(), ' [',
|
|
|
|
|
reportElementData.getCategory(), ']' ].filter(Boolean).join("");
|
|
|
|
|
var xAxisLabel = reportElementData.getxAxis();
|
|
|
|
|
var yAxisLabel = reportElementData.getyAxis();
|
|
|
|
|
|
|
|
|
|
var scalesType = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::getScales(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;)(this);
|
|
|
|
|
|
|
|
|
|
var ctx = canvas.getContext('2d');
|
|
|
|
|
|
|
|
|
|
console.log('Create chart');
|
|
|
|
|
|
|
|
|
|
var chart = new Chart(ctx, {
|
|
|
|
|
// The type of chart we want to create
|
|
|
|
|
type : 'bar',
|
|
|
|
|
data : barChartData,
|
|
|
|
|
backgroundColor : "#FFFFFF",
|
|
|
|
|
options : {
|
|
|
|
|
animation : false,
|
|
|
|
|
responsive : false,
|
|
|
|
|
maintainAspectRatio : true,
|
|
|
|
|
aspectRatio : 1, // width == height
|
|
|
|
|
legend : {
|
|
|
|
|
position : 'top',
|
|
|
|
|
},
|
|
|
|
|
title : {
|
|
|
|
|
display : true,
|
|
|
|
|
text : label
|
|
|
|
|
},
|
|
|
|
|
scales : {
|
|
|
|
|
xAxes : [ {
|
|
|
|
|
scaleLabel : {
|
|
|
|
|
display : true,
|
|
|
|
|
labelString : xAxisLabel
|
|
|
|
|
}
|
|
|
|
|
} ],
|
|
|
|
|
|
|
|
|
|
yAxes : [ {
|
|
|
|
|
scaleLabel : {
|
|
|
|
|
display : true,
|
|
|
|
|
labelString : yAxisLabel
|
|
|
|
|
},
|
|
|
|
|
ticks : {
|
|
|
|
|
beginAtZero : true
|
|
|
|
|
}
|
|
|
|
|
} ]
|
|
|
|
|
},
|
|
|
|
|
tooltips : {
|
|
|
|
|
var timeOut = setTimeout(function() {
|
|
|
|
|
var chart = new Chart(ctx, {
|
|
|
|
|
// The type of chart we want to create
|
|
|
|
|
type : 'bar',
|
|
|
|
|
data : barChartData,
|
|
|
|
|
backgroundColor : "#FFFFFF",
|
|
|
|
|
options : {
|
|
|
|
|
animation : false,
|
|
|
|
|
responsive : false,
|
|
|
|
|
maintainAspectRatio : false,
|
|
|
|
|
aspectRatio : 1, // width == height
|
|
|
|
|
legend : {
|
|
|
|
|
position : 'top',
|
|
|
|
|
},
|
|
|
|
|
title : {
|
|
|
|
|
display : true,
|
|
|
|
|
text : label
|
|
|
|
|
},
|
|
|
|
|
scales : scalesType,
|
|
|
|
|
tooltips : {
|
|
|
|
|
mode : 'x'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
zoom : {
|
|
|
|
|
enabled : true,
|
|
|
|
|
mode : 'xy',
|
|
|
|
|
limits : {
|
|
|
|
|
max : 20,
|
|
|
|
|
min : 0.1
|
|
|
|
|
enabled : true,
|
|
|
|
|
mode : 'point',
|
|
|
|
|
intersect : true
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
zoom : {
|
|
|
|
|
enabled : true,
|
|
|
|
|
mode : 'xy',
|
|
|
|
|
limits : {
|
|
|
|
|
max : 20,
|
|
|
|
|
min : 0.1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
console.log('Chart: ' + chart);
|
|
|
|
|
|
|
|
|
|
this.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::createMenu()();
|
|
|
|
|
chart.update();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var canvasW = canvas.width;
|
|
|
|
|
var canvasH = canvas.height;
|
|
|
|
|
console.log('Canvas dimensions: ' + canvasW + ' x ' + canvasH);
|
|
|
|
|
chart.update();
|
|
|
|
|
console.log('Canvas offset: left=' + canvas.offsetLeft + ', top='
|
|
|
|
|
+ canvas.offsetTop);
|
|
|
|
|
clearTimeout(timeOut);
|
|
|
|
|
|
|
|
|
|
//Decide whether to align left or right based on position on canvas
|
|
|
|
|
//console.log('View1:['+Chart.global+']');
|
|
|
|
|
|
|
|
|
|
//console.log('This coords:['+this.x+', '+this.y+']');
|
|
|
|
|
//if (this.x > this.chart.width / 2) {
|
|
|
|
|
// this.x -= this.xOffset + this.width;
|
|
|
|
|
//} else {
|
|
|
|
|
// this.x += this.xOffset;
|
|
|
|
|
//}
|
|
|
|
|
//console.log('This coords computed:'+this.x);
|
|
|
|
|
|
|
|
|
|
}, 300);
|
|
|
|
|
|
|
|
|
|
}-*/;
|
|
|
|
|
|
|
|
|
|