Package com.ubx1.pdpscanner.client.views.project

Source Code of com.ubx1.pdpscanner.client.views.project.CoverageAreaChart

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.AreaChart;
import com.google.gwt.visualization.client.visualizations.corechart.Options;
import com.ubx1.pdpscanner.client.views.AbstractView;
import com.ubx1.pdpscanner.shared.Project;

/**
* The widget for showing the evolution of the test stats through the project
* versions
*
* @author wbraik
*
*/
public class CoverageAreaChart extends AbstractView {

  /**
   * The associated Project object
   */
  protected Project project = null;

  // View components

  private AreaChart chart = null;

  public CoverageAreaChart(Project project) {

    super(new VerticalPanel());
    this.project = project;

    // this.viewPanel.setStyleName("");
  }

  @Override
  public void buildView() {

    this.viewPanel.clear();

    this.chart = new AreaChart(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;

    DataTable data = DataTable.create();
    data.addColumn(ColumnType.STRING, "Version");
    data.addColumn(ColumnType.NUMBER, "Lignes de code à tester");
    data.addColumn(ColumnType.NUMBER, "Lignes de code testées");
    data.addRows(p.getVersionCount());

    // Unavailable stats counter
    int z = 0;

    for (int i = 0; i < p.getVersionCount(); i++) {

      int locValue = p.getNloc(i + 1);
      int covValue = p.getNcovl(i + 1);

      // If no value is available for this version, don't represent it on
      // the chart
      if (locValue == -1 || covValue == -1) {
        z++;
      } else {
        // Version
        data.setValue(i - z, 0, String.valueOf(i + 1));
        // Class number
        data.setValue(i - z, 1, locValue);
        // Covered class number
        data.setValue(i - z, 2, covValue);
      }
    }

    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(900);
    options.setHeight(400);
    options.setTitle("Nombre de lignes de code testées "
        + "par rapport au nombre de lignes de code total "
        + "en fonction de la version");
    options.setColors("red", "green");

    return options;
  }
}
TOP

Related Classes of com.ubx1.pdpscanner.client.views.project.CoverageAreaChart

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.