Updated Accounting Manager
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@117457 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e7d1c4166c
commit
c22b1462e8
|
@ -0,0 +1,130 @@
|
||||||
|
package org.gcube.portlets.admin.accountingmanager.client.maindata;
|
||||||
|
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.client.event.StateChangeEvent;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.AccountingChart4Job;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.AccountingChart4Portlet;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.AccountingChart4Service;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.AccountingChart4Storage;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.AccountingChart4Task;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.AccountingChartBuilder;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.AccountingChartDirector;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.AccountingChartPanel;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException;
|
||||||
|
|
||||||
|
import com.allen_sauer.gwt.log.client.Log;
|
||||||
|
import com.google.gwt.event.shared.EventBus;
|
||||||
|
import com.sencha.gxt.widget.core.client.FramedPanel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author giancarlo email: <a
|
||||||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ChartViewerPanel extends FramedPanel {
|
||||||
|
|
||||||
|
private EventBus eventBus;
|
||||||
|
|
||||||
|
public ChartViewerPanel(EventBus eventBus) {
|
||||||
|
super();
|
||||||
|
this.eventBus = eventBus;
|
||||||
|
// msgs = GWT.create(ServiceCategoryMessages.class);
|
||||||
|
init();
|
||||||
|
create();
|
||||||
|
bindToEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void init() {
|
||||||
|
forceLayoutOnResize = true;
|
||||||
|
setBodyBorder(false);
|
||||||
|
setBorders(false);
|
||||||
|
setHeaderVisible(false);
|
||||||
|
setResize(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void create() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bind to Events
|
||||||
|
private void bindToEvents() {
|
||||||
|
eventBus.addHandler(StateChangeEvent.TYPE,
|
||||||
|
new StateChangeEvent.StateChangeEventHandler() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStateChange(StateChangeEvent event) {
|
||||||
|
Log.debug("Catch Event State Change");
|
||||||
|
doStateChangeCommand(event);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doStateChangeCommand(StateChangeEvent event) {
|
||||||
|
if (event.getStateChangeType() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (event.getStateChangeType()) {
|
||||||
|
case Restore:
|
||||||
|
case Update:
|
||||||
|
onStateChange(event);
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onStateChange(StateChangeEvent event) {
|
||||||
|
if (event.getAccountingStateData() == null
|
||||||
|
|| event.getAccountingStateData().getAccountingType() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (event.getAccountingStateData().getAccountingType()) {
|
||||||
|
case JOB:
|
||||||
|
createChart(new AccountingChart4Job(event.getAccountingStateData()));
|
||||||
|
break;
|
||||||
|
case PORTLET:
|
||||||
|
createChart(new AccountingChart4Portlet(event.getAccountingStateData()));
|
||||||
|
break;
|
||||||
|
case SERVICE:
|
||||||
|
createChart(new AccountingChart4Service(event.getAccountingStateData()));
|
||||||
|
break;
|
||||||
|
case STORAGE:
|
||||||
|
createChart(new AccountingChart4Storage(event.getAccountingStateData()));
|
||||||
|
break;
|
||||||
|
case TASK:
|
||||||
|
createChart(new AccountingChart4Task(event.getAccountingStateData()));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createChart(AccountingChartBuilder chartBuilder) {
|
||||||
|
clear();
|
||||||
|
try {
|
||||||
|
AccountingChartDirector director = new AccountingChartDirector();
|
||||||
|
director.setAccountingChartBuilder(chartBuilder);
|
||||||
|
director.constructAccountingChart();
|
||||||
|
|
||||||
|
AccountingChartPanel chart = director.getAccountingChart();
|
||||||
|
|
||||||
|
if (chart != null) {
|
||||||
|
add(chart.getChart());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (AccountingManagerChartDrawException e) {
|
||||||
|
Log.error(e.getLocalizedMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
forceLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -33,7 +33,7 @@ public class MainDataPanel extends FramedPanel {
|
||||||
protected void create() {
|
protected void create() {
|
||||||
/*ChartPanel chartPanel = new ChartPanel(eventBus);
|
/*ChartPanel chartPanel = new ChartPanel(eventBus);
|
||||||
add(chartPanel);*/
|
add(chartPanel);*/
|
||||||
HightChartPanel hightChartPanel= new HightChartPanel(eventBus);
|
ChartViewerPanel hightChartPanel= new ChartViewerPanel(eventBus);
|
||||||
add(hightChartPanel);
|
add(hightChartPanel);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,180 @@
|
||||||
|
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJob;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorageData;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException;
|
||||||
|
|
||||||
|
import com.github.highcharts4gwt.client.view.widget.HighchartsLayoutPanel;
|
||||||
|
import com.github.highcharts4gwt.model.array.api.ArrayNumber;
|
||||||
|
import com.github.highcharts4gwt.model.array.api.ArrayString;
|
||||||
|
import com.github.highcharts4gwt.model.factory.api.HighchartsOptionFactory;
|
||||||
|
import com.github.highcharts4gwt.model.factory.jso.JsoHighchartsOptionFactory;
|
||||||
|
import com.github.highcharts4gwt.model.highcharts.option.api.ChartOptions;
|
||||||
|
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesArea;
|
||||||
|
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesColumn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accounting Chart 4 Job
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi" email: <a
|
||||||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AccountingChart4Job extends AccountingChartBuilder {
|
||||||
|
|
||||||
|
private AccountingStateData accountingStateData;
|
||||||
|
|
||||||
|
public AccountingChart4Job(AccountingStateData accountingStateData) {
|
||||||
|
this.accountingStateData = accountingStateData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void buildChart() throws AccountingManagerChartDrawException {
|
||||||
|
AccountingChartPanel accountingChartPanel=null;
|
||||||
|
|
||||||
|
if (accountingStateData == null
|
||||||
|
|| accountingStateData.getAccountingType() == null
|
||||||
|
|| accountingStateData.getSeriesRequest() == null
|
||||||
|
|| accountingStateData.getSeriesResponse() == null) {
|
||||||
|
accountingChartSpec.setChart(accountingChartPanel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(accountingStateData.getSeriesResponse() instanceof SeriesJob)) {
|
||||||
|
accountingChartSpec.setChart(accountingChartPanel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SeriesStorage seriesStorage = (SeriesStorage) accountingStateData
|
||||||
|
.getSeriesResponse();
|
||||||
|
|
||||||
|
double minRange = ChartTimeMeasure.calculateMinRange(accountingStateData
|
||||||
|
.getSeriesRequest().getAccountingPeriod());
|
||||||
|
|
||||||
|
double interval = ChartTimeMeasure.calculateInterval(accountingStateData
|
||||||
|
.getSeriesRequest().getAccountingPeriod());
|
||||||
|
|
||||||
|
Date dateStart = accountingStateData.getSeriesRequest()
|
||||||
|
.getAccountingPeriod().getStartDate();
|
||||||
|
|
||||||
|
HighchartsOptionFactory highchartsFactory = new JsoHighchartsOptionFactory();
|
||||||
|
ChartOptions options = highchartsFactory.createChartOptions();
|
||||||
|
options.chart().zoomType("xy");
|
||||||
|
|
||||||
|
options.title().text("Accounting Job");
|
||||||
|
|
||||||
|
options.subtitle().text("Click and drag in the plot area to zoom in");
|
||||||
|
|
||||||
|
ArrayString colors = options.colors();
|
||||||
|
// colors.setValue(0, "#cc0038");
|
||||||
|
// colors.setValue(1, "#32cd32");
|
||||||
|
|
||||||
|
// xAxis
|
||||||
|
options.xAxis().type("datetime").minRange(minRange);
|
||||||
|
|
||||||
|
// yAxis
|
||||||
|
// options.yAxis().title().text("Exchange rate");
|
||||||
|
// Highcharts.getOptions().colors[0]
|
||||||
|
String multiAxis = "[{" + " \"id\": \"DataVolume\","
|
||||||
|
+ " \"labels\": { " + " \"format\": \"{value}\","
|
||||||
|
+ " \"style\": { " + " \"color\": \""
|
||||||
|
+ colors.get(1)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " },"
|
||||||
|
+ " \"title\": { "
|
||||||
|
+ " \"text\": \"Data Volume\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(1)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " }"
|
||||||
|
+ "} , {"
|
||||||
|
+ " \"id\": \"OperationCount\", "
|
||||||
|
+ " \"title\": {"
|
||||||
|
+ " \"text\": \"Operation Count\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(0)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " },"
|
||||||
|
+ " \"labels\": {"
|
||||||
|
+ " \"format\": \"{value}\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(0)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " }," + " \"opposite\": \"true\"" + "}]";
|
||||||
|
|
||||||
|
options.setFieldAsJsonObject("yAxis", multiAxis);
|
||||||
|
|
||||||
|
// TODO does not seem to be working
|
||||||
|
String fillcolor = "{" + "\"linearGradient\": {" + "\"x1\": 0,"
|
||||||
|
+ "\"y1\": 0," + "\"x2\": 0," + "\"y2\": 1" + "},"
|
||||||
|
+ "\"stops\": [" + "[" + "0, \"#058DC7\"" + "]," + "["
|
||||||
|
+ "1, \"#FFFFFF\"" + "]" + "]" + "}";
|
||||||
|
|
||||||
|
options.plotOptions().area()
|
||||||
|
.setFieldAsJsonObject("fillColor", fillcolor).marker()
|
||||||
|
.radius(2).lineWidth(1).states().hover().lineWidth(1);
|
||||||
|
|
||||||
|
SeriesColumn seriesDataVolume = highchartsFactory.createSeriesColumn();
|
||||||
|
seriesDataVolume.name("Data Volume");
|
||||||
|
seriesDataVolume.color(colors.get(1));
|
||||||
|
seriesDataVolume.type("column");
|
||||||
|
|
||||||
|
ArrayNumber dataDataVolume = seriesDataVolume.dataAsArrayNumber();
|
||||||
|
|
||||||
|
seriesDataVolume.pointInterval(interval)
|
||||||
|
.pointStart(dateStart.getTime());
|
||||||
|
|
||||||
|
SeriesArea seriesOperationCount = highchartsFactory.createSeriesArea();
|
||||||
|
seriesOperationCount.name("Operation Count");
|
||||||
|
seriesOperationCount.yAxisAsString("OperationCount");
|
||||||
|
seriesOperationCount.color(colors.get(0));
|
||||||
|
|
||||||
|
ArrayNumber dataOperationCount = seriesOperationCount
|
||||||
|
.dataAsArrayNumber();
|
||||||
|
|
||||||
|
seriesOperationCount.pointInterval(interval).pointStart(
|
||||||
|
dateStart.getTime());
|
||||||
|
|
||||||
|
for (SeriesStorageData seriesStorageData : seriesStorage.getSeries()) {
|
||||||
|
dataDataVolume.push(seriesStorageData.getDataVolume());
|
||||||
|
dataOperationCount.push(seriesStorageData.getOperationCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
options.series().addToEnd(seriesDataVolume);
|
||||||
|
options.series().addToEnd(seriesOperationCount);
|
||||||
|
|
||||||
|
options.chart().showAxes(true);
|
||||||
|
|
||||||
|
options.legend().enabled(true);
|
||||||
|
// options.legend().layout("vertical");
|
||||||
|
// options.legend().align("left");
|
||||||
|
// options.legend().x(120);
|
||||||
|
// options.legend().verticalAlign("top");
|
||||||
|
// options.legend().y(100);
|
||||||
|
// options.legend().floating(true);
|
||||||
|
// options.legend()
|
||||||
|
// .backgroundColor(
|
||||||
|
// "(Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'white'");
|
||||||
|
|
||||||
|
HighchartsLayoutPanel highchartsLayoutPanel = new HighchartsLayoutPanel();
|
||||||
|
|
||||||
|
highchartsLayoutPanel.renderChart(options);
|
||||||
|
|
||||||
|
|
||||||
|
accountingChartPanel=new AccountingChartPanel(highchartsLayoutPanel);
|
||||||
|
|
||||||
|
accountingChartSpec.setChart(accountingChartPanel);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,179 @@
|
||||||
|
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesPortlet;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorageData;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException;
|
||||||
|
|
||||||
|
import com.github.highcharts4gwt.client.view.widget.HighchartsLayoutPanel;
|
||||||
|
import com.github.highcharts4gwt.model.array.api.ArrayNumber;
|
||||||
|
import com.github.highcharts4gwt.model.array.api.ArrayString;
|
||||||
|
import com.github.highcharts4gwt.model.factory.api.HighchartsOptionFactory;
|
||||||
|
import com.github.highcharts4gwt.model.factory.jso.JsoHighchartsOptionFactory;
|
||||||
|
import com.github.highcharts4gwt.model.highcharts.option.api.ChartOptions;
|
||||||
|
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesArea;
|
||||||
|
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesColumn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accounting Chart 4 Portlet
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi" email: <a
|
||||||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AccountingChart4Portlet extends AccountingChartBuilder {
|
||||||
|
|
||||||
|
private AccountingStateData accountingStateData;
|
||||||
|
|
||||||
|
public AccountingChart4Portlet(AccountingStateData accountingStateData) {
|
||||||
|
this.accountingStateData = accountingStateData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void buildChart() throws AccountingManagerChartDrawException {
|
||||||
|
AccountingChartPanel accountingChartPanel=null;
|
||||||
|
|
||||||
|
if (accountingStateData == null
|
||||||
|
|| accountingStateData.getAccountingType() == null
|
||||||
|
|| accountingStateData.getSeriesRequest() == null
|
||||||
|
|| accountingStateData.getSeriesResponse() == null) {
|
||||||
|
accountingChartSpec.setChart(accountingChartPanel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(accountingStateData.getSeriesResponse() instanceof SeriesPortlet)) {
|
||||||
|
accountingChartSpec.setChart(accountingChartPanel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SeriesStorage seriesStorage = (SeriesStorage) accountingStateData
|
||||||
|
.getSeriesResponse();
|
||||||
|
|
||||||
|
double minRange = ChartTimeMeasure.calculateMinRange(accountingStateData
|
||||||
|
.getSeriesRequest().getAccountingPeriod());
|
||||||
|
|
||||||
|
double interval = ChartTimeMeasure.calculateInterval(accountingStateData
|
||||||
|
.getSeriesRequest().getAccountingPeriod());
|
||||||
|
|
||||||
|
Date dateStart = accountingStateData.getSeriesRequest()
|
||||||
|
.getAccountingPeriod().getStartDate();
|
||||||
|
|
||||||
|
HighchartsOptionFactory highchartsFactory = new JsoHighchartsOptionFactory();
|
||||||
|
ChartOptions options = highchartsFactory.createChartOptions();
|
||||||
|
options.chart().zoomType("xy");
|
||||||
|
|
||||||
|
options.title().text("Accounting Portlet");
|
||||||
|
|
||||||
|
options.subtitle().text("Click and drag in the plot area to zoom in");
|
||||||
|
|
||||||
|
ArrayString colors = options.colors();
|
||||||
|
// colors.setValue(0, "#cc0038");
|
||||||
|
// colors.setValue(1, "#32cd32");
|
||||||
|
|
||||||
|
// xAxis
|
||||||
|
options.xAxis().type("datetime").minRange(minRange);
|
||||||
|
|
||||||
|
// yAxis
|
||||||
|
// options.yAxis().title().text("Exchange rate");
|
||||||
|
// Highcharts.getOptions().colors[0]
|
||||||
|
String multiAxis = "[{" + " \"id\": \"DataVolume\","
|
||||||
|
+ " \"labels\": { " + " \"format\": \"{value}\","
|
||||||
|
+ " \"style\": { " + " \"color\": \""
|
||||||
|
+ colors.get(1)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " },"
|
||||||
|
+ " \"title\": { "
|
||||||
|
+ " \"text\": \"Data Volume\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(1)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " }"
|
||||||
|
+ "} , {"
|
||||||
|
+ " \"id\": \"OperationCount\", "
|
||||||
|
+ " \"title\": {"
|
||||||
|
+ " \"text\": \"Operation Count\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(0)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " },"
|
||||||
|
+ " \"labels\": {"
|
||||||
|
+ " \"format\": \"{value}\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(0)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " }," + " \"opposite\": \"true\"" + "}]";
|
||||||
|
|
||||||
|
options.setFieldAsJsonObject("yAxis", multiAxis);
|
||||||
|
|
||||||
|
// TODO does not seem to be working
|
||||||
|
String fillcolor = "{" + "\"linearGradient\": {" + "\"x1\": 0,"
|
||||||
|
+ "\"y1\": 0," + "\"x2\": 0," + "\"y2\": 1" + "},"
|
||||||
|
+ "\"stops\": [" + "[" + "0, \"#058DC7\"" + "]," + "["
|
||||||
|
+ "1, \"#FFFFFF\"" + "]" + "]" + "}";
|
||||||
|
|
||||||
|
options.plotOptions().area()
|
||||||
|
.setFieldAsJsonObject("fillColor", fillcolor).marker()
|
||||||
|
.radius(2).lineWidth(1).states().hover().lineWidth(1);
|
||||||
|
|
||||||
|
SeriesColumn seriesDataVolume = highchartsFactory.createSeriesColumn();
|
||||||
|
seriesDataVolume.name("Data Volume");
|
||||||
|
seriesDataVolume.color(colors.get(1));
|
||||||
|
seriesDataVolume.type("column");
|
||||||
|
|
||||||
|
ArrayNumber dataDataVolume = seriesDataVolume.dataAsArrayNumber();
|
||||||
|
|
||||||
|
seriesDataVolume.pointInterval(interval)
|
||||||
|
.pointStart(dateStart.getTime());
|
||||||
|
|
||||||
|
SeriesArea seriesOperationCount = highchartsFactory.createSeriesArea();
|
||||||
|
seriesOperationCount.name("Operation Count");
|
||||||
|
seriesOperationCount.yAxisAsString("OperationCount");
|
||||||
|
seriesOperationCount.color(colors.get(0));
|
||||||
|
|
||||||
|
ArrayNumber dataOperationCount = seriesOperationCount
|
||||||
|
.dataAsArrayNumber();
|
||||||
|
|
||||||
|
seriesOperationCount.pointInterval(interval).pointStart(
|
||||||
|
dateStart.getTime());
|
||||||
|
|
||||||
|
for (SeriesStorageData seriesStorageData : seriesStorage.getSeries()) {
|
||||||
|
dataDataVolume.push(seriesStorageData.getDataVolume());
|
||||||
|
dataOperationCount.push(seriesStorageData.getOperationCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
options.series().addToEnd(seriesDataVolume);
|
||||||
|
options.series().addToEnd(seriesOperationCount);
|
||||||
|
|
||||||
|
options.chart().showAxes(true);
|
||||||
|
|
||||||
|
options.legend().enabled(true);
|
||||||
|
// options.legend().layout("vertical");
|
||||||
|
// options.legend().align("left");
|
||||||
|
// options.legend().x(120);
|
||||||
|
// options.legend().verticalAlign("top");
|
||||||
|
// options.legend().y(100);
|
||||||
|
// options.legend().floating(true);
|
||||||
|
// options.legend()
|
||||||
|
// .backgroundColor(
|
||||||
|
// "(Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'white'");
|
||||||
|
|
||||||
|
HighchartsLayoutPanel highchartsLayoutPanel = new HighchartsLayoutPanel();
|
||||||
|
|
||||||
|
highchartsLayoutPanel.renderChart(options);
|
||||||
|
|
||||||
|
accountingChartPanel=new AccountingChartPanel(highchartsLayoutPanel);
|
||||||
|
|
||||||
|
accountingChartSpec.setChart(accountingChartPanel);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,270 @@
|
||||||
|
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesService;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesServiceData;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException;
|
||||||
|
|
||||||
|
import com.github.highcharts4gwt.client.view.widget.HighchartsLayoutPanel;
|
||||||
|
import com.github.highcharts4gwt.model.array.api.ArrayNumber;
|
||||||
|
import com.github.highcharts4gwt.model.array.api.ArrayString;
|
||||||
|
import com.github.highcharts4gwt.model.factory.api.HighchartsOptionFactory;
|
||||||
|
import com.github.highcharts4gwt.model.factory.jso.JsoHighchartsOptionFactory;
|
||||||
|
import com.github.highcharts4gwt.model.highcharts.option.api.ChartOptions;
|
||||||
|
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesArea;
|
||||||
|
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesColumn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accounting Chart 4 Service
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi" email: <a
|
||||||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AccountingChart4Service extends AccountingChartBuilder {
|
||||||
|
|
||||||
|
private AccountingStateData accountingStateData;
|
||||||
|
|
||||||
|
public AccountingChart4Service(AccountingStateData accountingStateData) {
|
||||||
|
this.accountingStateData = accountingStateData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void buildChart() throws AccountingManagerChartDrawException {
|
||||||
|
AccountingChartPanel accountingChartPanel=null;
|
||||||
|
|
||||||
|
if (accountingStateData == null
|
||||||
|
|| accountingStateData.getAccountingType() == null
|
||||||
|
|| accountingStateData.getSeriesRequest() == null
|
||||||
|
|| accountingStateData.getSeriesResponse() == null) {
|
||||||
|
accountingChartSpec.setChart(accountingChartPanel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(accountingStateData.getSeriesResponse() instanceof SeriesService)) {
|
||||||
|
accountingChartSpec.setChart(accountingChartPanel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SeriesService seriesService = (SeriesService) accountingStateData
|
||||||
|
.getSeriesResponse();
|
||||||
|
|
||||||
|
double minRange = ChartTimeMeasure.calculateMinRange(accountingStateData
|
||||||
|
.getSeriesRequest().getAccountingPeriod());
|
||||||
|
|
||||||
|
double interval = ChartTimeMeasure.calculateInterval(accountingStateData
|
||||||
|
.getSeriesRequest().getAccountingPeriod());
|
||||||
|
|
||||||
|
Date dateStart = accountingStateData.getSeriesRequest()
|
||||||
|
.getAccountingPeriod().getStartDate();
|
||||||
|
|
||||||
|
HighchartsOptionFactory highchartsFactory = new JsoHighchartsOptionFactory();
|
||||||
|
ChartOptions options = highchartsFactory.createChartOptions();
|
||||||
|
options.chart().zoomType("xy");
|
||||||
|
|
||||||
|
options.title().text("Accounting Service");
|
||||||
|
|
||||||
|
options.subtitle().text("Click and drag in the plot area to zoom in");
|
||||||
|
|
||||||
|
ArrayString colors = options.colors();
|
||||||
|
// colors.setValue(0, "#cc0038");
|
||||||
|
// colors.setValue(1, "#32cd32");
|
||||||
|
|
||||||
|
// xAxis
|
||||||
|
options.xAxis().type("datetime").minRange(minRange);
|
||||||
|
|
||||||
|
// yAxis
|
||||||
|
// options.yAxis().title().text("Exchange rate");
|
||||||
|
// Highcharts.getOptions().colors[0]
|
||||||
|
|
||||||
|
/*
|
||||||
|
* String multiAxis = "[{" + " \"id\": \"OperationCount\"," +
|
||||||
|
* " \"labels\": { " + " \"format\": \"{value}\"," +
|
||||||
|
* " \"style\": { " + " \"color\": \"" + colors.get(1) + "\"" +
|
||||||
|
* " }" + " }," + " \"title\": { " +
|
||||||
|
* " \"text\": \"Operation Count\"," + " \"style\": {" +
|
||||||
|
* " \"color\": \"" + colors.get(1) + "\"" + " }" + " }" +
|
||||||
|
* "} , {" + " \"id\": \"ServiceData\", " + " \"linkedTo\": \"0\","
|
||||||
|
* +" \"gridLineWidth\": \"0\"," + " \"title\": {" +
|
||||||
|
* " \"text\": \"\"," + " \"style\": {" + " \"color\": \"" +
|
||||||
|
* colors.get(1) + "\"" + " }" + " }," + " \"labels\": {" +
|
||||||
|
* " \"format\": \"{value} ms\"," + " \"style\": {" +
|
||||||
|
* " \"color\": \"" + colors.get(1) + "\"" + " }" + " }," +
|
||||||
|
* " \"opposite\": \"true\"" //+ ", \"showFirstLabel\": \"false\"" +
|
||||||
|
* "}]";
|
||||||
|
*/
|
||||||
|
|
||||||
|
String multiAxis = "[{" + " \"id\": \"OperationCount\","
|
||||||
|
+ " \"labels\": { " + " \"format\": \"{value}\","
|
||||||
|
+ " \"style\": { " + " \"color\": \""
|
||||||
|
+ colors.get(1)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " },"
|
||||||
|
+ " \"title\": { "
|
||||||
|
+ " \"text\": \"Operation Count\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(1)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " }"
|
||||||
|
+ "} , {"
|
||||||
|
+ " \"id\": \"Duration\", "
|
||||||
|
+ " \"title\": {"
|
||||||
|
+ " \"text\": \"Duration\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(0)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " },"
|
||||||
|
+ " \"labels\": {"
|
||||||
|
+ " \"format\": \"{value} ms\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(0)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " },"
|
||||||
|
+ " \"opposite\": \"true\""
|
||||||
|
+ ", \"showFirstLabel\": \"false\""
|
||||||
|
+ "} , {"
|
||||||
|
+ " \"id\": \"MaxInvocationTime\", "
|
||||||
|
+ " \"title\": {"
|
||||||
|
+ " \"text\": \"Max Invocation Time\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(2)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " },"
|
||||||
|
+ " \"labels\": {"
|
||||||
|
+ " \"format\": \"{value} ms\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(2)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " },"
|
||||||
|
+ " \"opposite\": \"true\""
|
||||||
|
+ ", \"showFirstLabel\": \"false\""
|
||||||
|
+ "} , {"
|
||||||
|
+ " \"id\": \"MinInvocationTime\", "
|
||||||
|
+ " \"title\": {"
|
||||||
|
+ " \"text\": \"Min Invocation Time\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(3)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " },"
|
||||||
|
+ " \"labels\": {"
|
||||||
|
+ " \"format\": \"{value} ms\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(3)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " },"
|
||||||
|
+ " \"opposite\": \"true\""
|
||||||
|
+ ", \"showFirstLabel\": \"false\"" + "}]"
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
options.setFieldAsJsonObject("yAxis", multiAxis);
|
||||||
|
|
||||||
|
// TODO does not seem to be working
|
||||||
|
String fillcolor = "{" + "\"linearGradient\": {" + "\"x1\": 0,"
|
||||||
|
+ "\"y1\": 0," + "\"x2\": 0," + "\"y2\": 1" + "},"
|
||||||
|
+ "\"stops\": [" + "[" + "0, \"#058DC7\"" + "]," + "["
|
||||||
|
+ "1, \"#FFFFFF\"" + "]" + "]" + "}";
|
||||||
|
|
||||||
|
options.plotOptions().area()
|
||||||
|
.setFieldAsJsonObject("fillColor", fillcolor).marker()
|
||||||
|
.radius(2).lineWidth(1).states().hover().lineWidth(1);
|
||||||
|
|
||||||
|
SeriesColumn seriesOperationCount = highchartsFactory
|
||||||
|
.createSeriesColumn();
|
||||||
|
seriesOperationCount.name("Operation Count");
|
||||||
|
seriesOperationCount.color(colors.get(1));
|
||||||
|
seriesOperationCount.type("column");
|
||||||
|
|
||||||
|
ArrayNumber dataOperationCount = seriesOperationCount
|
||||||
|
.dataAsArrayNumber();
|
||||||
|
|
||||||
|
seriesOperationCount.pointInterval(interval).pointStart(
|
||||||
|
dateStart.getTime());
|
||||||
|
|
||||||
|
SeriesArea seriesDuration = highchartsFactory.createSeriesArea();
|
||||||
|
seriesDuration.name("Duration");
|
||||||
|
seriesDuration.color(colors.get(0));
|
||||||
|
seriesDuration.yAxisAsString("Duration");
|
||||||
|
|
||||||
|
ArrayNumber dataDuration = seriesDuration.dataAsArrayNumber();
|
||||||
|
|
||||||
|
seriesDuration.pointInterval(interval).pointStart(dateStart.getTime());
|
||||||
|
|
||||||
|
SeriesArea seriesMaxInvocationTime = highchartsFactory
|
||||||
|
.createSeriesArea();
|
||||||
|
seriesMaxInvocationTime.name("Max Invocation Time");
|
||||||
|
seriesMaxInvocationTime.color(colors.get(2));
|
||||||
|
seriesMaxInvocationTime.yAxisAsString("MaxInvocationTime");
|
||||||
|
|
||||||
|
ArrayNumber dataMaxInvocationTime = seriesMaxInvocationTime
|
||||||
|
.dataAsArrayNumber();
|
||||||
|
|
||||||
|
seriesMaxInvocationTime.pointInterval(interval).pointStart(
|
||||||
|
dateStart.getTime());
|
||||||
|
|
||||||
|
SeriesArea seriesMinInvocationTime = highchartsFactory
|
||||||
|
.createSeriesArea();
|
||||||
|
seriesMinInvocationTime.name("Min Invocation Time");
|
||||||
|
seriesMinInvocationTime.color(colors.get(3));
|
||||||
|
seriesMinInvocationTime.yAxisAsString("MinInvocationTime");
|
||||||
|
|
||||||
|
ArrayNumber dataMinInvocationTime = seriesMinInvocationTime
|
||||||
|
.dataAsArrayNumber();
|
||||||
|
|
||||||
|
seriesMinInvocationTime.pointInterval(interval).pointStart(
|
||||||
|
dateStart.getTime());
|
||||||
|
|
||||||
|
for (SeriesServiceData seriesServiceData : seriesService.getSeries()) {
|
||||||
|
dataOperationCount.push(seriesServiceData.getOperationCount());
|
||||||
|
dataDuration.push(seriesServiceData.getDuration());
|
||||||
|
dataMaxInvocationTime
|
||||||
|
.push(seriesServiceData.getMaxInvocationTime());
|
||||||
|
dataMinInvocationTime
|
||||||
|
.push(seriesServiceData.getMinInvocationTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
options.series().addToEnd(seriesOperationCount);
|
||||||
|
options.series().addToEnd(seriesDuration);
|
||||||
|
options.series().addToEnd(seriesMaxInvocationTime);
|
||||||
|
options.series().addToEnd(seriesMinInvocationTime);
|
||||||
|
|
||||||
|
options.chart().showAxes(true);
|
||||||
|
|
||||||
|
options.legend().enabled(true);
|
||||||
|
// options.legend().layout("vertical");
|
||||||
|
// options.legend().align("left");
|
||||||
|
// options.legend().x(120);
|
||||||
|
// options.legend().verticalAlign("top");
|
||||||
|
// options.legend().y(100);
|
||||||
|
// options.legend().floating(true);
|
||||||
|
// options.legend()
|
||||||
|
// .backgroundColor(
|
||||||
|
// "(Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'white'");
|
||||||
|
|
||||||
|
HighchartsLayoutPanel highchartsLayoutPanel = new HighchartsLayoutPanel();
|
||||||
|
|
||||||
|
highchartsLayoutPanel.renderChart(options);
|
||||||
|
|
||||||
|
accountingChartPanel=new AccountingChartPanel(highchartsLayoutPanel);
|
||||||
|
|
||||||
|
accountingChartSpec.setChart(accountingChartPanel);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,187 @@
|
||||||
|
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorageData;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException;
|
||||||
|
|
||||||
|
import com.github.highcharts4gwt.client.view.widget.HighchartsLayoutPanel;
|
||||||
|
import com.github.highcharts4gwt.model.array.api.ArrayNumber;
|
||||||
|
import com.github.highcharts4gwt.model.array.api.ArrayString;
|
||||||
|
import com.github.highcharts4gwt.model.factory.api.HighchartsOptionFactory;
|
||||||
|
import com.github.highcharts4gwt.model.factory.jso.JsoHighchartsOptionFactory;
|
||||||
|
import com.github.highcharts4gwt.model.highcharts.option.api.ChartOptions;
|
||||||
|
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesArea;
|
||||||
|
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesColumn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accounting Chart 4 Storage
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi" email: <a
|
||||||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AccountingChart4Storage extends AccountingChartBuilder {
|
||||||
|
|
||||||
|
private AccountingStateData accountingStateData;
|
||||||
|
|
||||||
|
public AccountingChart4Storage(AccountingStateData accountingStateData) {
|
||||||
|
this.accountingStateData = accountingStateData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void buildChart() throws AccountingManagerChartDrawException {
|
||||||
|
AccountingChartPanel accountingChartPanel=null;
|
||||||
|
|
||||||
|
if (accountingStateData == null
|
||||||
|
|| accountingStateData.getAccountingType() == null
|
||||||
|
|| accountingStateData.getSeriesRequest() == null
|
||||||
|
|| accountingStateData.getSeriesResponse() == null) {
|
||||||
|
accountingChartSpec.setChart(accountingChartPanel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(accountingStateData
|
||||||
|
.getSeriesResponse() instanceof SeriesStorage)){
|
||||||
|
accountingChartSpec.setChart(accountingChartPanel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SeriesStorage seriesStorage = (SeriesStorage) accountingStateData
|
||||||
|
.getSeriesResponse();
|
||||||
|
|
||||||
|
double minRange = ChartTimeMeasure.calculateMinRange(accountingStateData
|
||||||
|
.getSeriesRequest().getAccountingPeriod());
|
||||||
|
|
||||||
|
double interval= ChartTimeMeasure.calculateInterval(accountingStateData
|
||||||
|
.getSeriesRequest().getAccountingPeriod());
|
||||||
|
|
||||||
|
Date dateStart=accountingStateData.getSeriesRequest().getAccountingPeriod().getStartDate();
|
||||||
|
|
||||||
|
HighchartsOptionFactory highchartsFactory = new JsoHighchartsOptionFactory();
|
||||||
|
ChartOptions options = highchartsFactory.createChartOptions();
|
||||||
|
options.chart().zoomType("xy");
|
||||||
|
|
||||||
|
options.title().text("Accounting Storage");
|
||||||
|
|
||||||
|
options.subtitle().text("Click and drag in the plot area to zoom in");
|
||||||
|
|
||||||
|
ArrayString colors = options.colors();
|
||||||
|
// colors.setValue(0, "#cc0038");
|
||||||
|
// colors.setValue(1, "#32cd32");
|
||||||
|
|
||||||
|
|
||||||
|
// xAxis
|
||||||
|
options.xAxis().type("datetime").minRange(minRange);
|
||||||
|
|
||||||
|
// yAxis
|
||||||
|
// options.yAxis().title().text("Exchange rate");
|
||||||
|
// Highcharts.getOptions().colors[0]
|
||||||
|
|
||||||
|
|
||||||
|
String multiAxis = "[{" + " \"id\": \"OperationCount\","
|
||||||
|
+ " \"labels\": { " + " \"format\": \"{value}\","
|
||||||
|
+ " \"style\": { " + " \"color\": \""
|
||||||
|
+ colors.get(1)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " },"
|
||||||
|
+ " \"title\": { "
|
||||||
|
+ " \"text\": \"Operation Count\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(1)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " }"
|
||||||
|
+ "} , {"
|
||||||
|
+ " \"id\": \"DataVolume\", "
|
||||||
|
+ " \"title\": {"
|
||||||
|
+ " \"text\": \"Data Volume\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(0)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " },"
|
||||||
|
+ " \"labels\": {"
|
||||||
|
+ " \"format\": \"{value} kB\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(0)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " }," + " \"opposite\": \"true\"" + "}]";
|
||||||
|
|
||||||
|
options.setFieldAsJsonObject("yAxis", multiAxis);
|
||||||
|
|
||||||
|
// TODO does not seem to be working
|
||||||
|
String fillcolor = "{" + "\"linearGradient\": {" + "\"x1\": 0,"
|
||||||
|
+ "\"y1\": 0," + "\"x2\": 0," + "\"y2\": 1" + "},"
|
||||||
|
+ "\"stops\": [" + "[" + "0, \"#058DC7\"" + "]," + "["
|
||||||
|
+ "1, \"#FFFFFF\"" + "]" + "]" + "}";
|
||||||
|
|
||||||
|
options.plotOptions().area()
|
||||||
|
.setFieldAsJsonObject("fillColor", fillcolor).marker()
|
||||||
|
.radius(2).lineWidth(1).states().hover().lineWidth(1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SeriesColumn seriesOperationCount = highchartsFactory.createSeriesColumn();
|
||||||
|
seriesOperationCount.name("Operation Count");
|
||||||
|
seriesOperationCount.color(colors.get(1));
|
||||||
|
seriesOperationCount.type("column");
|
||||||
|
|
||||||
|
ArrayNumber dataOperationCount = seriesOperationCount
|
||||||
|
.dataAsArrayNumber();
|
||||||
|
|
||||||
|
seriesOperationCount.pointInterval(interval).pointStart(dateStart.getTime());
|
||||||
|
|
||||||
|
SeriesArea seriesDataVolume = highchartsFactory.createSeriesArea();
|
||||||
|
seriesDataVolume.name("Data Volume");
|
||||||
|
seriesDataVolume.color(colors.get(0));
|
||||||
|
seriesDataVolume.yAxisAsString("DataVolume");
|
||||||
|
|
||||||
|
|
||||||
|
ArrayNumber dataDataVolume = seriesDataVolume.dataAsArrayNumber();
|
||||||
|
|
||||||
|
|
||||||
|
seriesDataVolume.pointInterval(interval).pointStart(
|
||||||
|
dateStart.getTime());
|
||||||
|
|
||||||
|
|
||||||
|
for (SeriesStorageData seriesStorageData : seriesStorage.getSeries()) {
|
||||||
|
dataOperationCount.push(seriesStorageData.getOperationCount());
|
||||||
|
dataDataVolume.push(seriesStorageData.getDataVolume());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
options.series().addToEnd(seriesOperationCount);
|
||||||
|
options.series().addToEnd(seriesDataVolume);
|
||||||
|
|
||||||
|
options.chart().showAxes(true);
|
||||||
|
|
||||||
|
options.legend().enabled(true);
|
||||||
|
// options.legend().layout("vertical");
|
||||||
|
// options.legend().align("left");
|
||||||
|
// options.legend().x(120);
|
||||||
|
// options.legend().verticalAlign("top");
|
||||||
|
// options.legend().y(100);
|
||||||
|
// options.legend().floating(true);
|
||||||
|
// options.legend()
|
||||||
|
// .backgroundColor(
|
||||||
|
// "(Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'white'");
|
||||||
|
|
||||||
|
HighchartsLayoutPanel highchartsLayoutPanel = new HighchartsLayoutPanel();
|
||||||
|
|
||||||
|
highchartsLayoutPanel.renderChart(options);
|
||||||
|
|
||||||
|
accountingChartPanel=new AccountingChartPanel(highchartsLayoutPanel);
|
||||||
|
|
||||||
|
accountingChartSpec.setChart(accountingChartPanel);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,180 @@
|
||||||
|
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorageData;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesTask;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException;
|
||||||
|
|
||||||
|
import com.github.highcharts4gwt.client.view.widget.HighchartsLayoutPanel;
|
||||||
|
import com.github.highcharts4gwt.model.array.api.ArrayNumber;
|
||||||
|
import com.github.highcharts4gwt.model.array.api.ArrayString;
|
||||||
|
import com.github.highcharts4gwt.model.factory.api.HighchartsOptionFactory;
|
||||||
|
import com.github.highcharts4gwt.model.factory.jso.JsoHighchartsOptionFactory;
|
||||||
|
import com.github.highcharts4gwt.model.highcharts.option.api.ChartOptions;
|
||||||
|
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesArea;
|
||||||
|
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesColumn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accounting Chart 4 Task
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi" email: <a
|
||||||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AccountingChart4Task extends AccountingChartBuilder {
|
||||||
|
|
||||||
|
private AccountingStateData accountingStateData;
|
||||||
|
|
||||||
|
public AccountingChart4Task(AccountingStateData accountingStateData) {
|
||||||
|
this.accountingStateData = accountingStateData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void buildChart() throws AccountingManagerChartDrawException {
|
||||||
|
AccountingChartPanel accountingChartPanel=null;
|
||||||
|
|
||||||
|
if (accountingStateData == null
|
||||||
|
|| accountingStateData.getAccountingType() == null
|
||||||
|
|| accountingStateData.getSeriesRequest() == null
|
||||||
|
|| accountingStateData.getSeriesResponse() == null) {
|
||||||
|
accountingChartSpec.setChart(accountingChartPanel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(accountingStateData.getSeriesResponse() instanceof SeriesTask)) {
|
||||||
|
accountingChartSpec.setChart(accountingChartPanel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SeriesStorage seriesStorage = (SeriesStorage) accountingStateData
|
||||||
|
.getSeriesResponse();
|
||||||
|
|
||||||
|
double minRange = ChartTimeMeasure.calculateMinRange(accountingStateData
|
||||||
|
.getSeriesRequest().getAccountingPeriod());
|
||||||
|
|
||||||
|
double interval = ChartTimeMeasure.calculateInterval(accountingStateData
|
||||||
|
.getSeriesRequest().getAccountingPeriod());
|
||||||
|
|
||||||
|
Date dateStart = accountingStateData.getSeriesRequest()
|
||||||
|
.getAccountingPeriod().getStartDate();
|
||||||
|
|
||||||
|
HighchartsOptionFactory highchartsFactory = new JsoHighchartsOptionFactory();
|
||||||
|
ChartOptions options = highchartsFactory.createChartOptions();
|
||||||
|
options.chart().zoomType("xy");
|
||||||
|
|
||||||
|
options.title().text("Accounting Task");
|
||||||
|
|
||||||
|
options.subtitle().text("Click and drag in the plot area to zoom in");
|
||||||
|
|
||||||
|
ArrayString colors = options.colors();
|
||||||
|
// colors.setValue(0, "#cc0038");
|
||||||
|
// colors.setValue(1, "#32cd32");
|
||||||
|
|
||||||
|
// xAxis
|
||||||
|
options.xAxis().type("datetime").minRange(minRange);
|
||||||
|
|
||||||
|
// yAxis
|
||||||
|
// options.yAxis().title().text("Exchange rate");
|
||||||
|
// Highcharts.getOptions().colors[0]
|
||||||
|
String multiAxis = "[{" + " \"id\": \"DataVolume\","
|
||||||
|
+ " \"labels\": { " + " \"format\": \"{value}\","
|
||||||
|
+ " \"style\": { " + " \"color\": \""
|
||||||
|
+ colors.get(1)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " },"
|
||||||
|
+ " \"title\": { "
|
||||||
|
+ " \"text\": \"Data Volume\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(1)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " }"
|
||||||
|
+ "} , {"
|
||||||
|
+ " \"id\": \"OperationCount\", "
|
||||||
|
+ " \"title\": {"
|
||||||
|
+ " \"text\": \"Operation Count\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(0)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " },"
|
||||||
|
+ " \"labels\": {"
|
||||||
|
+ " \"format\": \"{value}\","
|
||||||
|
+ " \"style\": {"
|
||||||
|
+ " \"color\": \""
|
||||||
|
+ colors.get(0)
|
||||||
|
+ "\""
|
||||||
|
+ " }"
|
||||||
|
+ " }," + " \"opposite\": \"true\"" + "}]";
|
||||||
|
|
||||||
|
options.setFieldAsJsonObject("yAxis", multiAxis);
|
||||||
|
|
||||||
|
// TODO does not seem to be working
|
||||||
|
String fillcolor = "{" + "\"linearGradient\": {" + "\"x1\": 0,"
|
||||||
|
+ "\"y1\": 0," + "\"x2\": 0," + "\"y2\": 1" + "},"
|
||||||
|
+ "\"stops\": [" + "[" + "0, \"#058DC7\"" + "]," + "["
|
||||||
|
+ "1, \"#FFFFFF\"" + "]" + "]" + "}";
|
||||||
|
|
||||||
|
options.plotOptions().area()
|
||||||
|
.setFieldAsJsonObject("fillColor", fillcolor).marker()
|
||||||
|
.radius(2).lineWidth(1).states().hover().lineWidth(1);
|
||||||
|
|
||||||
|
SeriesColumn seriesDataVolume = highchartsFactory.createSeriesColumn();
|
||||||
|
seriesDataVolume.name("Data Volume");
|
||||||
|
seriesDataVolume.color(colors.get(1));
|
||||||
|
seriesDataVolume.type("column");
|
||||||
|
|
||||||
|
ArrayNumber dataDataVolume = seriesDataVolume.dataAsArrayNumber();
|
||||||
|
|
||||||
|
seriesDataVolume.pointInterval(interval)
|
||||||
|
.pointStart(dateStart.getTime());
|
||||||
|
|
||||||
|
SeriesArea seriesOperationCount = highchartsFactory.createSeriesArea();
|
||||||
|
seriesOperationCount.name("Operation Count");
|
||||||
|
seriesOperationCount.yAxisAsString("OperationCount");
|
||||||
|
seriesOperationCount.color(colors.get(0));
|
||||||
|
|
||||||
|
ArrayNumber dataOperationCount = seriesOperationCount
|
||||||
|
.dataAsArrayNumber();
|
||||||
|
|
||||||
|
seriesOperationCount.pointInterval(interval).pointStart(
|
||||||
|
dateStart.getTime());
|
||||||
|
|
||||||
|
for (SeriesStorageData seriesStorageData : seriesStorage.getSeries()) {
|
||||||
|
dataDataVolume.push(seriesStorageData.getDataVolume());
|
||||||
|
dataOperationCount.push(seriesStorageData.getOperationCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
options.series().addToEnd(seriesDataVolume);
|
||||||
|
options.series().addToEnd(seriesOperationCount);
|
||||||
|
|
||||||
|
options.chart().showAxes(true);
|
||||||
|
|
||||||
|
options.legend().enabled(true);
|
||||||
|
// options.legend().layout("vertical");
|
||||||
|
// options.legend().align("left");
|
||||||
|
// options.legend().x(120);
|
||||||
|
// options.legend().verticalAlign("top");
|
||||||
|
// options.legend().y(100);
|
||||||
|
// options.legend().floating(true);
|
||||||
|
// options.legend()
|
||||||
|
// .backgroundColor(
|
||||||
|
// "(Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'white'");
|
||||||
|
|
||||||
|
HighchartsLayoutPanel highchartsLayoutPanel = new HighchartsLayoutPanel();
|
||||||
|
|
||||||
|
highchartsLayoutPanel.renderChart(options);
|
||||||
|
|
||||||
|
|
||||||
|
accountingChartPanel=new AccountingChartPanel(highchartsLayoutPanel);
|
||||||
|
|
||||||
|
accountingChartSpec.setChart(accountingChartPanel);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts;
|
||||||
|
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class for build Accounting Chart
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi"
|
||||||
|
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class AccountingChartBuilder {
|
||||||
|
protected AccountingChartSpec accountingChartSpec;
|
||||||
|
|
||||||
|
public AccountingChartSpec getAccountingChartSpec(){
|
||||||
|
return accountingChartSpec;
|
||||||
|
}
|
||||||
|
public void createSpec(){
|
||||||
|
accountingChartSpec=new AccountingChartSpec();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void buildChart() throws AccountingManagerChartDrawException;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts;
|
||||||
|
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accounting Chart Director
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi"
|
||||||
|
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AccountingChartDirector {
|
||||||
|
AccountingChartBuilder accountingChartBuilder;
|
||||||
|
|
||||||
|
public void setAccountingChartBuilder(
|
||||||
|
AccountingChartBuilder accountingChartBuilder) {
|
||||||
|
this.accountingChartBuilder = accountingChartBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AccountingChartPanel getAccountingChart() {
|
||||||
|
return accountingChartBuilder.getAccountingChartSpec().getChart();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void constructAccountingChart() throws AccountingManagerChartDrawException {
|
||||||
|
accountingChartBuilder.createSpec();
|
||||||
|
accountingChartBuilder.buildChart();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts;
|
||||||
|
|
||||||
|
import com.google.gwt.user.client.ui.SimpleLayoutPanel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author giancarlo email: <a
|
||||||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AccountingChartPanel {
|
||||||
|
|
||||||
|
private SimpleLayoutPanel chart;
|
||||||
|
|
||||||
|
public AccountingChartPanel(SimpleLayoutPanel chart) {
|
||||||
|
super();
|
||||||
|
this.chart = chart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleLayoutPanel getChart() {
|
||||||
|
return chart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChart(SimpleLayoutPanel chart) {
|
||||||
|
this.chart = chart;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "AccountingChartPanel [chart=" + chart + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accounting Chart Specification
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi" email: <a
|
||||||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AccountingChartSpec {
|
||||||
|
private AccountingChartPanel chart;
|
||||||
|
|
||||||
|
public AccountingChartPanel getChart() {
|
||||||
|
return chart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChart(AccountingChartPanel chart) {
|
||||||
|
this.chart = chart;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts;
|
||||||
|
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingPeriod;
|
||||||
|
|
||||||
|
import com.allen_sauer.gwt.log.client.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author giancarlo
|
||||||
|
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ChartTimeMeasure {
|
||||||
|
|
||||||
|
public static double calculateMinRange(AccountingPeriod accountingPeriod) {
|
||||||
|
if (accountingPeriod.getPeriod() == null) {
|
||||||
|
Log.error("AccountingPeriodMode is null");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (accountingPeriod.getPeriod()) {
|
||||||
|
case DAILY:
|
||||||
|
// 1 day=24hour * 60min *60sec * 1000 millisec
|
||||||
|
return 14 * 24 * 3600 * 1000;
|
||||||
|
case HOURLY:
|
||||||
|
return 24 * 3600 * 1000;
|
||||||
|
//case MILLISECONDLY:
|
||||||
|
// return 10 * 100;
|
||||||
|
case MINUTELY:
|
||||||
|
return 10 * 60 * 1000;
|
||||||
|
case MONTHLY:
|
||||||
|
return 6 * 28 * 24 * 3600 * 1000;
|
||||||
|
//case SECONDLY:
|
||||||
|
// return 30 * 1000;
|
||||||
|
case YEARLY:
|
||||||
|
return 5 * 12 * 28 * 24 * 3600 * 1000;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double calculateInterval(AccountingPeriod accountingPeriod) {
|
||||||
|
if (accountingPeriod.getPeriod() == null) {
|
||||||
|
Log.error("AccountingPeriodMode is null");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (accountingPeriod.getPeriod()) {
|
||||||
|
case DAILY:
|
||||||
|
return 24 * 3600 * 1000;
|
||||||
|
case HOURLY:
|
||||||
|
return 3600 * 1000;
|
||||||
|
//case MILLISECONDLY:
|
||||||
|
// return 100;
|
||||||
|
case MINUTELY:
|
||||||
|
return 60 * 1000;
|
||||||
|
case MONTHLY:
|
||||||
|
return 28 * 24 * 3600 * 1000;
|
||||||
|
//case SECONDLY:
|
||||||
|
// return 1000;
|
||||||
|
case YEARLY:
|
||||||
|
return 12 * 28 * 24 * 3600 * 1000;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.admin.accountingmanager.shared.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi"
|
||||||
|
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AccountingManagerChartDrawException extends Exception {
|
||||||
|
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -8737011216478988776L;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public AccountingManagerChartDrawException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public AccountingManagerChartDrawException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public AccountingManagerChartDrawException(String message,Throwable t) {
|
||||||
|
super(message,t);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue