package com.ubx1.pdpscanner.client.views.project;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.visualization.client.AbstractDataTable;
import com.google.gwt.visualization.client.DataTable;
import com.google.gwt.visualization.client.AbstractDataTable.ColumnType;
import com.google.gwt.visualization.client.visualizations.corechart.BarChart;
import com.google.gwt.visualization.client.visualizations.corechart.Options;
import com.ubx1.pdpscanner.client.views.AbstractView;
import com.ubx1.pdpscanner.shared.FindbugsBugInstance;
import com.ubx1.pdpscanner.shared.Project;
/**
* The widget for showing the quantity of performance issues per category for a
* particular version
*
* @author wbraik
*
*/
public class PerformanceBarChart extends AbstractView {
/**
* The associated Project object
*/
protected Project project = null;
/**
* The current version to display the stats for
*/
private int version;
// View components
private BarChart chart = null;
public PerformanceBarChart(Project project) {
super(new VerticalPanel());
this.project = project;
// this.viewPanel.setStyleName("");
}
public void setVersion(int version) {
this.version = version;
}
@Override
public void buildView() {
this.viewPanel.clear();
if (this.project.getP(this.version).size() > 0) {
this.chart = new BarChart(createTestChartDataTable(),
createTestChartOptions());
this.viewPanel.add(this.chart);
}
}
/**
* Create the data table for populating the chart
*
* @return the data table for the chart
*/
private AbstractDataTable createTestChartDataTable() {
Project p = this.project;
int v = this.version;
HashMap<String, HashMap<String, ArrayList<FindbugsBugInstance>>> pMap = Project
.getFbMap(p.getP(v));
DataTable data = DataTable.create();
data.addColumn(ColumnType.STRING, "");
data.addRows(1);
data.setValue(0, 0, "");
Iterator<String> it1 = pMap.keySet().iterator();
while (it1.hasNext()) {
String abbrev = it1.next();
int col = data.addColumn(ColumnType.NUMBER,
FindbugsBugInstance.getAbbrevDescription(abbrev));
data.setValue(0, col, getAbbrevErrorCount(abbrev));
}
return data;
}
/**
* Create the options for customizing the chart
*
* @return the options for customizing the chart
*/
private Options createTestChartOptions() {
Options options = Options.create();
options.setWidth(600);
options.setHeight(400);
options.setTitle("Nombre de problèmes de performance dans les différentes catégories");
return options;
}
/**
* Get the number of performance bug instances which match an abbreviation
*
* @param abbrev
* the abbreviation
* @return the number of performance bug instances which match abbrev as
* their abbreviation
*/
private int getAbbrevErrorCount(String abbrev) {
int count = 0;
ArrayList<FindbugsBugInstance> p = this.project.getP(this.version);
for (int i = 0; i < p.size(); i++) {
if (p.get(i).getAbbrev().equals(abbrev)) {
count++;
}
}
return count;
}
}