Package ch.hortis.sonar.web.charts

Source Code of ch.hortis.sonar.web.charts.ComplexityDistributionChart

/**
* This program is copyright (c) 2007 Hortis-GRC SA.
*
* This file is part of Sonar.
* Sonar is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package ch.hortis.sonar.web.charts;

import java.awt.image.BufferedImage;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.LayeredBarRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;

public class ComplexityDistributionChart extends BaseChart {
  private CategoryPlot plot;
  private DefaultCategoryDataset dataset;
 
  private String legend1, legend2;

  private static final String AXIS_LABEL = "Simple               Average               Complex";

  public ComplexityDistributionChart(String legend1, String legend2, int width, int height) {
    super(width, height);
   
    this.legend1 = legend1;
    this.legend2 = legend2;
   
    dataset = new DefaultCategoryDataset();
    plot = new CategoryPlot();

    configureDomainAxis();
    configureRangeAxis();
    configureRenderer();

    plot.setDataset(dataset);
  }

  public ComplexityDistributionChart(String serieLabel, int width, int height) {
    this(serieLabel, "", width, height);
  }

  private void configureRenderer() {
    LayeredBarRenderer renderer = new LayeredBarRenderer();
   
    renderer.setDrawBarOutline( true );
    renderer.setSeriesItemLabelsVisible( 0, true );
    renderer.setMaximumBarWidth( 0.2 );
    renderer.setSeriesBarWidth( 0, 1.2 );
    renderer.setSeriesBarWidth( 1, 0.3 );

    renderer.setSeriesPaint( 0, SERIE1_COLOR );
    renderer.setSeriesOutlinePaint( 0, SERIE_BORDER_COLOR );
    renderer.setSeriesPaint( 1, SERIE1BIS_COLOR);
    renderer.setSeriesOutlinePaint( 1, SERIE_BORDER_COLOR );
    plot.setRenderer(renderer);
  }

  private void configureDomainAxis() {
    CategoryAxis categoryAxis = new CategoryAxis();
    categoryAxis.setLabel(AXIS_LABEL);
    categoryAxis.setLabelFont(getFont());
    categoryAxis.setLabelPaint(BASE_COLOR);
    categoryAxis.setTickMarksVisible(true);
    categoryAxis.setTickLabelFont(getFont());
    categoryAxis.setTickLabelPaint(BASE_COLOR);   
    plot.setDomainAxis(categoryAxis);
    plot.setDomainGridlinesVisible(false);
  }

  private void configureRangeAxis() {
    NumberAxis numberAxis = new NumberAxis();
    numberAxis.setUpperMargin(0.3);
    numberAxis.setTickLabelFont(getFont());
    numberAxis.setTickLabelPaint(BASE_COLOR);
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.setRangeAxis(numberAxis);
  }
 
  public void addMeasure(String label, Double value1, Double value2) {
    dataset.addValue(value1, legend1, label);
    if (value2 != null) {
      dataset.addValue(value2, legend2, label);
    }
  }

  public void addMeasure(String label, Double value) {
    addMeasure(label, value, null);
 

  protected BufferedImage getChartImage() {
    plot.setOutlinePaint(BASE_COLOR);
    plot.setDomainGridlinePaint(BASE_COLOR_LIGHT);
    plot.setRangeGridlinePaint(BASE_COLOR_LIGHT);
    JFreeChart chart = new JFreeChart(null, TextTitle.DEFAULT_FONT, plot, true);
    configureChart(chart, !legend2.equals(""));
    return super.getBufferedImage(chart);
  }
}
TOP

Related Classes of ch.hortis.sonar.web.charts.ComplexityDistributionChart

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.