package com.ubx1.pdpscanner.client.views.project;
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.Options;
import com.google.gwt.visualization.client.visualizations.corechart.PieChart;
import com.ubx1.pdpscanner.client.views.AbstractView;
import com.ubx1.pdpscanner.shared.Project;
/**
* The widget for showing the ratio of commented code for a particular version
*
* @author wbraik
*
*/
public class CommentsPieChart extends AbstractView {
/**
* The associated Project object
*/
protected Project project = null;
/**
* The current version to display the stats for
*/
private int version;
// View components
private PieChart chart = null;
public CommentsPieChart(Project project) {
super(new VerticalPanel());
this.project = project;
this.viewPanel.setStyleName("commentsPieChart");
}
public void setVersion(int version) {
this.version = version;
}
@Override
public void buildView() {
this.viewPanel.clear();
if (this.project.getNcom(this.version) != -1) {
this.chart = new PieChart(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;
DataTable data = DataTable.create();
data.addColumn(ColumnType.STRING, "Commentaires");
data.addColumn(ColumnType.NUMBER,
"Pourcentage de code qui correspond à des commentaires");
data.addRows(2);
int comValue = p.getNcom(v);
int locValue = p.getNloc(v)+p.getNcom(v);
data.setValue(0, 0, "Lignes de code qui sont des commentaires");
data.setValue(0, 1, comValue);
data.setValue(1, 0, "Lignes de code qui ne sont pas des commentaires");
data.setValue(1, 1, locValue - comValue);
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(420);
options.setHeight(150);
options.setTitle("Pourcentage de lignes de code qui sont des commentaires");
options.setColors("green", "blue");
return options;
}
}