<!-- animal-sniffer doesn't work with 2.6.1 -->
<version>3.4.4</version>
</dependency>
- <dependency>
- <groupId>jfree</groupId>
- <artifactId>jfreechart</artifactId>
- <version>1.0.9</version>
- </dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
- <dependency>
- <groupId>jfree</groupId>
- <artifactId>jfreechart</artifactId>
- </dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts;
-
-import com.google.common.collect.Maps;
-import java.util.Map;
-import javax.annotation.CheckForNull;
-import org.sonar.api.charts.Chart;
-import org.sonar.api.server.ServerSide;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-
-@ServerSide
-public final class ChartFactory {
- private static final Logger LOG = Loggers.get(ChartFactory.class);
- private final Map<String, Chart> chartsByKey = Maps.newHashMap();
-
- public ChartFactory(Chart[] charts) {
- for (Chart chart : charts) {
- if (chartsByKey.containsKey(chart.getKey())) {
- LOG.warn("Duplicated chart key:" + chart.getKey() + ". Existing chart: " + chartsByKey.get(chart.getKey()).getClass().getCanonicalName());
-
- } else {
- chartsByKey.put(chart.getKey(), chart);
- }
- }
- }
-
- public ChartFactory() {
- // DO NOT SUPPRESS : used by picocontainer if no charts
- }
-
- @CheckForNull
- public Chart getChart(String key) {
- return chartsByKey.get(key);
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts;
-
-import com.google.common.collect.Maps;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Enumeration;
-import java.util.Map;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.jfree.chart.encoders.KeypointPNGEncoderAdapter;
-import org.sonar.api.charts.Chart;
-import org.sonar.api.charts.ChartParameters;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.server.charts.deprecated.BarChart;
-import org.sonar.server.charts.deprecated.BaseChartWeb;
-import org.sonar.server.charts.deprecated.CustomBarChart;
-import org.sonar.server.charts.deprecated.DeprecatedChart;
-import org.sonar.server.charts.deprecated.PieChart;
-import org.sonar.server.charts.deprecated.SparkLinesChart;
-import org.sonar.server.platform.Platform;
-
-public class ChartsServlet extends HttpServlet {
-
- private static final Logger LOG = Loggers.get(ChartsServlet.class);
- private static final long serialVersionUID = 669857447198433893L;
-
- @Override
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- if (isDeprecatedChart(request)) {
- deprecatedDoGet(request, response);
-
- } else {
- ChartFactory chartFactory = Platform.getInstance().getContainer().getComponentByType(ChartFactory.class);
- Chart chart = chartFactory.getChart(request.getParameter("ck"));
- if (chart != null) {
- BufferedImage image = chart.generateImage(getParams(request));
- OutputStream out = response.getOutputStream();
- try {
- response.setContentType("image/png");
- exportAsPNG(image, out);
-
- } catch (Exception e) {
- LOG.error("Generating chart " + chart.getClass().getName(), e);
-
- } finally {
- out.close();
- }
- }
- }
- }
-
- private ChartParameters getParams(HttpServletRequest request) {
- Map<String, String> map = Maps.newHashMap();
- Enumeration keys = request.getParameterNames();
- while (keys.hasMoreElements()) {
- String key = (String) keys.nextElement();
- String value = request.getParameter(key);
- map.put(key, value);
- }
- return new ChartParameters(map);
- }
-
- private void exportAsPNG(BufferedImage image, OutputStream out) throws IOException {
- KeypointPNGEncoderAdapter encoder = new KeypointPNGEncoderAdapter();
- encoder.setEncodingAlpha(true);
- encoder.encode(image, out);
- }
-
- public boolean isDeprecatedChart(HttpServletRequest request) {
- String chartType = request.getParameter(BaseChartWeb.CHART_PARAM_TYPE);
- if (BaseChartWeb.BAR_CHART_HORIZONTAL.equals(chartType) || BaseChartWeb.BAR_CHART_VERTICAL.equals(chartType) || BaseChartWeb.STACKED_BAR_CHART.equals(chartType)) {
- return true;
- }
- if (BaseChartWeb.BAR_CHART_VERTICAL_CUSTOM.equals(chartType)) {
- return true;
- }
- if (BaseChartWeb.PIE_CHART.equals(chartType)) {
- return true;
- }
- if (BaseChartWeb.SPARKLINES_CHART.equals(chartType)) {
- return true;
- }
- return false;
- }
-
- public void deprecatedDoGet(HttpServletRequest request, HttpServletResponse response) {
- Map<String, String> params = Maps.newHashMap();
- params.put(BaseChartWeb.CHART_PARAM_TYPE, request.getParameter(BaseChartWeb.CHART_PARAM_TYPE));
- params.put(BaseChartWeb.CHART_PARAM_VALUES, request.getParameter(BaseChartWeb.CHART_PARAM_VALUES));
- params.put(BaseChartWeb.CHART_PARAM_COLORS, request.getParameter(BaseChartWeb.CHART_PARAM_COLORS));
- params.put(BaseChartWeb.CHART_PARAM_RANGEMAX, request.getParameter(BaseChartWeb.CHART_PARAM_RANGEMAX));
- params.put(BaseChartWeb.CHART_PARAM_TITLE, request.getParameter(BaseChartWeb.CHART_PARAM_TITLE));
- params.put(BaseChartWeb.CHART_PARAM_DIMENSIONS, request.getParameter(BaseChartWeb.CHART_PARAM_DIMENSIONS));
- params.put(BaseChartWeb.CHART_PARAM_CATEGORIES_AXISMARGIN_VISIBLE, request.getParameter(BaseChartWeb.CHART_PARAM_CATEGORIES_AXISMARGIN_VISIBLE));
- params.put(BaseChartWeb.CHART_PARAM_RANGEAXIS_VISIBLE, request.getParameter(BaseChartWeb.CHART_PARAM_RANGEAXIS_VISIBLE));
- params.put(BaseChartWeb.CHART_PARAM_SERIES, request.getParameter(BaseChartWeb.CHART_PARAM_SERIES));
- params.put(BaseChartWeb.CHART_PARAM_CATEGORIES, request.getParameter(BaseChartWeb.CHART_PARAM_CATEGORIES));
- params.put(BaseChartWeb.CHART_PARAM_CATEGORIES_AXISMARGIN_LOWER, request.getParameter(BaseChartWeb.CHART_PARAM_CATEGORIES_AXISMARGIN_LOWER));
- params.put(BaseChartWeb.CHART_PARAM_CATEGORIES_AXISMARGIN_UPPER, request.getParameter(BaseChartWeb.CHART_PARAM_CATEGORIES_AXISMARGIN_UPPER));
- params.put(BaseChartWeb.CHART_PARAM_SERIES_AXISMARGIN_LOWER, request.getParameter(BaseChartWeb.CHART_PARAM_SERIES_AXISMARGIN_LOWER));
- params.put(BaseChartWeb.CHART_PARAM_SERIES_AXISMARGIN_UPPER, request.getParameter(BaseChartWeb.CHART_PARAM_SERIES_AXISMARGIN_UPPER));
- params.put(BaseChartWeb.CHART_PARAM_SERIES_AXISMARGIN_TICKUNIT, request.getParameter(BaseChartWeb.CHART_PARAM_SERIES_AXISMARGIN_TICKUNIT));
- params.put(BaseChartWeb.CHART_PARAM_INSETS, request.getParameter(BaseChartWeb.CHART_PARAM_INSETS));
- params.put(BaseChartWeb.CHART_PARAM_OUTLINE_RANGEGRIDLINES_VISIBLE, request.getParameter(BaseChartWeb.CHART_PARAM_OUTLINE_RANGEGRIDLINES_VISIBLE));
- params.put(BaseChartWeb.CHART_PARAM_OUTLINE_VISIBLE, request.getParameter(BaseChartWeb.CHART_PARAM_OUTLINE_VISIBLE));
-
- String chartType = params.get(BaseChartWeb.CHART_PARAM_TYPE);
-
- DeprecatedChart chart = null;
-
- if (BaseChartWeb.BAR_CHART_HORIZONTAL.equals(chartType) || BaseChartWeb.BAR_CHART_VERTICAL.equals(chartType) || BaseChartWeb.STACKED_BAR_CHART.equals(chartType)) {
- chart = new BarChart(params);
- } else if (BaseChartWeb.BAR_CHART_VERTICAL_CUSTOM.equals(chartType)) {
- chart = new CustomBarChart(params);
- } else if (BaseChartWeb.PIE_CHART.equals(chartType)) {
- chart = new PieChart(params);
- } else if (BaseChartWeb.SPARKLINES_CHART.equals(chartType)) {
- chart = new SparkLinesChart(params);
- }
-
- if (chart != null) {
- try (OutputStream out = response.getOutputStream()) {
- response.setContentType("image/png");
- chart.exportChartAsPNG(out);
- } catch (Exception e) {
- LOG.error("Generating chart " + chart.getClass().getName(), e);
- }
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts;
-
-import java.text.NumberFormat;
-import org.apache.commons.lang.StringUtils;
-import org.jfree.chart.axis.CategoryAxis;
-import org.jfree.chart.axis.NumberAxis;
-import org.jfree.chart.plot.CategoryPlot;
-import org.jfree.chart.plot.Plot;
-import org.jfree.chart.renderer.category.AreaRenderer;
-import org.jfree.data.category.DefaultCategoryDataset;
-import org.sonar.api.charts.AbstractChart;
-import org.sonar.api.charts.ChartParameters;
-
-public class DistributionAreaChart extends AbstractChart {
- private static final String PARAM_COLORS = "c";
-
- @Override
- public String getKey() {
- return "distarea";
- }
-
- @Override
- protected Plot getPlot(ChartParameters params) {
- DefaultCategoryDataset dataset = createDataset(params);
-
- CategoryAxis domainAxis = new CategoryAxis();
- domainAxis.setCategoryMargin(0.0);
- domainAxis.setLowerMargin(0.0);
- domainAxis.setUpperMargin(0.0);
-
- NumberAxis rangeAxis = new NumberAxis();
- rangeAxis.setNumberFormatOverride(NumberFormat.getIntegerInstance(params.getLocale()));
- rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
-
- AreaRenderer renderer = new AreaRenderer();
- CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
- plot.setForegroundAlpha(0.5f);
- plot.setDomainGridlinesVisible(true);
- configureColors(dataset, plot, params.getValues(PARAM_COLORS, ","));
- return plot;
- }
-
- private DefaultCategoryDataset createDataset(ChartParameters params) {
- DefaultCategoryDataset dataset = new DefaultCategoryDataset();
-
- String[] series = params.getValues("v", "|", true);
- int index = 0;
- while (index < series.length) {
- String[] pairs = StringUtils.split(series[index], ";");
- if (pairs.length == 0) {
- dataset.addValue((Number)0.0, index, "0");
-
- } else {
- for (String pair : pairs) {
- String[] keyValue = StringUtils.split(pair, "=");
- double val = Double.parseDouble(keyValue[1]);
- dataset.addValue((Number) val, index, keyValue[0]);
- }
- }
- index++;
- }
- return dataset;
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts;
-
-import java.awt.Font;
-import java.text.DecimalFormat;
-import org.apache.commons.lang.StringUtils;
-import org.jfree.chart.axis.CategoryAxis;
-import org.jfree.chart.axis.NumberAxis;
-import org.jfree.chart.plot.CategoryPlot;
-import org.jfree.chart.plot.Plot;
-import org.jfree.chart.renderer.category.BarRenderer;
-import org.jfree.data.category.DefaultCategoryDataset;
-import org.sonar.api.charts.AbstractChart;
-import org.sonar.api.charts.ChartParameters;
-
-public class DistributionBarChart extends AbstractChart {
-
- public static final String PARAM_VALUES = "v";
- public static final String PARAM_COLORS = "c";
- public static final String PARAM_Y_SUFFIX = "ysuf";
- public static final String PARAM_X_SUFFIX = "xsuf";
- public static final String PARAM_FONT_SIZE = "fs";
-
- @Override
- public String getKey() {
- return "distbar";
- }
-
- @Override
- public Plot getPlot(ChartParameters params) {
- CategoryPlot plot = generateJFreeChart(params);
- plot.setOutlinePaint(OUTLINE_COLOR);
- plot.setDomainGridlinePaint(GRID_COLOR);
- plot.setRangeGridlinePaint(GRID_COLOR);
- return plot;
- }
-
- private CategoryPlot generateJFreeChart(ChartParameters params) {
- DefaultCategoryDataset dataset = new DefaultCategoryDataset();
- CategoryPlot plot = new CategoryPlot();
-
- Font font = getFont(params.getValue(PARAM_FONT_SIZE));
- configureDomainAxis(plot, font);
- configureRangeAxis(plot, params.getValue(PARAM_Y_SUFFIX, "", true), font);
- configureRenderer(plot);
- configureValues(dataset, params.getValues(PARAM_VALUES, "|", true), params.getValue(PARAM_X_SUFFIX, "", true));
- configureColors(dataset, plot, params.getValues(PARAM_COLORS, ","));
-
- plot.setDataset(dataset);
- return plot;
- }
-
- static void configureValues(DefaultCategoryDataset dataset, String[] series, String xSuffix) {
- int index = 0;
- while (index < series.length) {
- String[] pairs = StringUtils.split(series[index], ";");
- if (pairs.length == 0) {
- dataset.addValue((Number) 0.0, index, "0");
-
- } else {
- for (String pair : pairs) {
- String[] keyValue = StringUtils.split(pair, "=");
- double val = Double.parseDouble(keyValue[1]);
- dataset.addValue((Number) val, index, keyValue[0] + xSuffix);
- }
- }
- index++;
- }
-
- }
-
- private void configureRenderer(CategoryPlot plot) {
- BarRenderer renderer = new BarRenderer();
- renderer.setDrawBarOutline(true);
- renderer.setSeriesItemLabelsVisible(0, true);
- renderer.setItemMargin(0);
- plot.setRenderer(renderer);
- }
-
- private void configureDomainAxis(CategoryPlot plot, Font font) {
- CategoryAxis categoryAxis = new CategoryAxis();
- categoryAxis.setTickMarksVisible(true);
- categoryAxis.setTickLabelFont(font);
- categoryAxis.setTickLabelPaint(OUTLINE_COLOR);
- plot.setDomainAxis(categoryAxis);
- plot.setDomainGridlinesVisible(false);
- }
-
- private Font getFont(String fontSize) {
- int size = FONT_SIZE;
- if (!StringUtils.isBlank(fontSize)) {
- size = Integer.parseInt(fontSize);
- }
- return new Font("SansSerif", Font.PLAIN, size);
- }
-
- private void configureRangeAxis(CategoryPlot plot, String valueLabelSuffix, Font font) {
- NumberAxis numberAxis = new NumberAxis();
- numberAxis.setUpperMargin(0.3);
- numberAxis.setTickLabelFont(font);
- numberAxis.setTickLabelPaint(OUTLINE_COLOR);
- String suffix = "";
- if (valueLabelSuffix != null && !"".equals(valueLabelSuffix)) {
- suffix = new StringBuilder().append("'").append(valueLabelSuffix).append("'").toString();
- }
- numberAxis.setNumberFormatOverride(new DecimalFormat("0" + suffix));
- numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
- plot.setRangeAxis(numberAxis);
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts.deprecated;
-
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.util.Map;
-import java.util.StringTokenizer;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.axis.CategoryAxis;
-import org.jfree.chart.axis.NumberAxis;
-import org.jfree.chart.axis.NumberTickUnit;
-import org.jfree.chart.plot.CategoryPlot;
-import org.jfree.chart.plot.PlotOrientation;
-import org.jfree.chart.renderer.category.BarRenderer;
-import org.jfree.chart.renderer.category.StackedBarRenderer;
-import org.jfree.chart.title.TextTitle;
-import org.jfree.data.category.DefaultCategoryDataset;
-import org.jfree.ui.RectangleInsets;
-
-public class BarChart extends BaseChartWeb implements DeprecatedChart {
-
- private BarRenderer renderer = null;
- protected DefaultCategoryDataset dataset = null;
- protected CategoryAxis categoryAxis = null;
- protected NumberAxis numberAxis = null;
-
- public BarChart(Map<String, String> params) {
- super(params);
- jfreechart = new JFreeChart(null, TextTitle.DEFAULT_FONT, new CategoryPlot(), false);
- }
-
- @Override
- protected BufferedImage getChartImage() throws IOException {
- configure();
- return getBufferedImage(jfreechart);
- }
-
- protected void configure() {
- configureChart(jfreechart, false);
- configureCategoryDataset();
- configureCategoryAxis();
- configureRenderer();
- configureRangeAxis();
- configureCategoryPlot();
- applyParams();
- }
-
- protected void configureCategoryPlot() {
- CategoryPlot plot = jfreechart.getCategoryPlot();
- plot.setNoDataMessage(DEFAULT_MESSAGE_NODATA);
- // To remove inner space around chart
- plot.setInsets(RectangleInsets.ZERO_INSETS);
- plot.setDataset(dataset);
- plot.setDomainAxis(categoryAxis);
- plot.setRenderer(renderer);
- plot.setRangeAxis(numberAxis);
- }
-
- protected void configureCategoryDataset() {
- dataset = new DefaultCategoryDataset();
- }
-
- protected void configureCategoryAxis() {
- categoryAxis = new CategoryAxis();
- categoryAxis.setLabelFont(DEFAULT_FONT);
- categoryAxis.setLabelPaint(BASE_COLOR);
- categoryAxis.setTickLabelFont(DEFAULT_FONT);
- categoryAxis.setTickLabelPaint(BASE_COLOR);
- categoryAxis.setVisible(false);
- }
-
- protected void configureRenderer() {
- if (params.get(BaseChartWeb.CHART_PARAM_TYPE).equals(BaseChartWeb.STACKED_BAR_CHART)) {
- renderer = new StackedBarRenderer();
- } else {
- renderer = new BarRenderer();
- }
- renderer.setItemMargin(0.0);
- renderer.setDrawBarOutline(false);
- }
-
- protected void configureRangeAxis() {
- numberAxis = new NumberAxis();
- numberAxis.setLabelFont(DEFAULT_FONT);
- numberAxis.setLabelPaint(BASE_COLOR);
- numberAxis.setTickLabelFont(DEFAULT_FONT);
- numberAxis.setTickLabelPaint(BASE_COLOR);
- numberAxis.setTickMarksVisible(true);
- numberAxis.setVisible(false);
- numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
- }
-
- protected void applyCommomParamsBar() {
- // -- Plot
- CategoryPlot plot = jfreechart.getCategoryPlot();
- plot.setOrientation(BaseChartWeb.BAR_CHART_VERTICAL.equals(params.get(BaseChartWeb.CHART_PARAM_TYPE))
- || BaseChartWeb.BAR_CHART_VERTICAL_CUSTOM.equals(params.get(BaseChartWeb.CHART_PARAM_TYPE)) ?
- PlotOrientation.VERTICAL :
- PlotOrientation.HORIZONTAL);
- plot.setOutlineVisible("y".equals(params.get(BaseChartWeb.CHART_PARAM_OUTLINE_VISIBLE)));
- plot.setRangeGridlinesVisible("y".equals(params.get(BaseChartWeb.CHART_PARAM_OUTLINE_RANGEGRIDLINES_VISIBLE)));
- String insetsParam = params.get(CHART_PARAM_INSETS);
- if (isParamValueValid(insetsParam)) {
- double insets = convertParamToDouble(insetsParam);
- RectangleInsets rectangleInsets = new RectangleInsets(insets, insets, insets, insets);
- plot.setInsets(rectangleInsets);
- }
-
- // -- Category Axis
- boolean categoryAxisIsVisible = "y".equals(params.get(BaseChartWeb.CHART_PARAM_CATEGORIES_AXISMARGIN_VISIBLE));
- double categoryAxisUpperMargin = convertParamToDouble(params.get(BaseChartWeb.CHART_PARAM_CATEGORIES_AXISMARGIN_UPPER), DEFAULT_CATEGORIES_AXISMARGIN);
- double categoryAxisLowerMargin = convertParamToDouble(params.get(BaseChartWeb.CHART_PARAM_CATEGORIES_AXISMARGIN_LOWER), DEFAULT_CATEGORIES_AXISMARGIN);
- categoryAxis.setVisible(categoryAxisIsVisible);
- categoryAxis.setTickLabelsVisible(categoryAxisIsVisible);
- categoryAxis.setLowerMargin(categoryAxisLowerMargin);
- categoryAxis.setUpperMargin(categoryAxisUpperMargin);
-
- // -- Range Axis
- boolean rangeAxisIsVisible = "y".equals(params.get(BaseChartWeb.CHART_PARAM_RANGEAXIS_VISIBLE));
- double rangeAxisUpperMargin = convertParamToDouble(params.get(BaseChartWeb.CHART_PARAM_SERIES_AXISMARGIN_UPPER), DEFAULT_SERIES_AXISMARGIN);
- double rangeAxisLowerMargin = convertParamToDouble(params.get(BaseChartWeb.CHART_PARAM_SERIES_AXISMARGIN_LOWER), DEFAULT_SERIES_AXISMARGIN);
- numberAxis.setTickLabelsVisible(rangeAxisIsVisible);
- numberAxis.setVisible(rangeAxisIsVisible);
- numberAxis.setLowerMargin(rangeAxisLowerMargin);
- numberAxis.setUpperMargin(rangeAxisUpperMargin);
- String rangeMax = params.get(BaseChartWeb.CHART_PARAM_RANGEMAX);
- if (isParamValueValid(rangeMax)) {
- double iRangeMax = Double.parseDouble(rangeMax);
- numberAxis.setRange(0.0, iRangeMax);
- }
- String tickUnit = params.get(BaseChartWeb.CHART_PARAM_SERIES_AXISMARGIN_TICKUNIT);
- if (isParamValueValid(tickUnit)) {
- numberAxis.setTickUnit(new NumberTickUnit(convertParamToDouble(tickUnit)));
- }
- }
-
- private void applyParams() {
- applyCommonParams();
- applyCommomParamsBar();
-
- configureColors(params.get(BaseChartWeb.CHART_PARAM_COLORS), renderer);
- addMeasures(params.get(BaseChartWeb.CHART_PARAM_VALUES));
- }
-
- private void addMeasures(String values) {
- if (values != null && values.length() > 0) {
- // Values
- StringTokenizer stValues = new StringTokenizer(values, ",");
- int nbValues = stValues.countTokens();
-
- // Categories
- String categoriesParam = params.get(BaseChartWeb.CHART_PARAM_CATEGORIES);
- String[] categoriesSplit;
- if (categoriesParam != null && categoriesParam.length() > 0) {
- categoriesSplit = categoriesParam.split(",");
- } else {
- categoriesSplit = new String[1];
- categoriesSplit[0] = BaseChartWeb.DEFAULT_NAME_CATEGORY;
- }
-
- // Series
- String seriesParam = params.get(BaseChartWeb.CHART_PARAM_SERIES);
- String[] seriesSplit;
- if (seriesParam != null && seriesParam.length() > 0) {
- seriesSplit = seriesParam.split(",");
- } else {
- seriesSplit = new String[nbValues];
- for (int i = 0; i < nbValues; i++) {
- seriesSplit[i] = BaseChartWeb.DEFAULT_NAME_SERIE + i;
- }
- }
-
- for (String currentCategory : categoriesSplit) {
- for (String currentSerie : seriesSplit) {
- double currentValue = 0.0;
- if (stValues.hasMoreTokens()) {
- try {
- currentValue = Double.parseDouble(stValues.nextToken());
- } catch (NumberFormatException e) {
- // ignore
- }
- }
- dataset.addValue(currentValue, currentSerie, currentCategory);
- }
- }
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts.deprecated;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.Transparency;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.encoders.KeypointPNGEncoderAdapter;
-import org.jfree.chart.title.LegendTitle;
-import org.jfree.chart.title.TextTitle;
-import org.jfree.ui.RectangleEdge;
-
-public abstract class BaseChart {
-
- public static final Color BASE_COLOR = new Color(51, 51, 51);
-
- protected static final Color[] COLORS = {
- new Color(5, 141, 199),
- new Color(80, 180, 50),
- new Color(237, 86, 27),
- new Color(237, 239, 0),
- new Color(36, 203, 229),
- new Color(100, 229, 114),
- new Color(255, 150, 85)
- };
-
- public static final int FONT_SIZE = 13;
-
- private int width;
- private int height;
-
- protected BaseChart(int width, int height) {
- this.width = width;
- this.height = height;
- }
-
- public int getWidth() {
- return width;
- }
-
- public int getHeight() {
- return height;
- }
-
- public void setWidth(int width) {
- this.width = width;
- }
-
- public void setHeight(int height) {
- this.height = height;
- }
-
- protected Font getFont() {
- return new Font("SansSerif", Font.PLAIN, FONT_SIZE);
- }
-
- protected void configureChart(JFreeChart chart, boolean displayLegend) {
- if (displayLegend) {
- configureChart(chart, RectangleEdge.BOTTOM);
- } else {
- configureChart(chart, null);
- }
- }
-
- protected void configureChart(JFreeChart chart, RectangleEdge legendPosition) {
- chart.setBackgroundPaint(new Color(255, 255, 255, 0));
- chart.setBackgroundImageAlpha(0.0f);
- chart.setBorderVisible(false);
- chart.setAntiAlias(true);
- chart.setTextAntiAlias(true);
-
- chart.removeLegend();
- if (legendPosition != null) {
- LegendTitle legend = new LegendTitle(chart.getPlot());
- legend.setPosition(legendPosition);
- legend.setItemPaint(BASE_COLOR);
- chart.addSubtitle(legend);
- }
- }
-
- protected void configureChartTitle(JFreeChart chart, String title) {
- if (title != null && title.length() > 0) {
- TextTitle textTitle = new TextTitle(title);
- chart.setTitle(textTitle);
- }
- }
-
- protected abstract BufferedImage getChartImage() throws IOException;
-
- protected BufferedImage getBufferedImage(JFreeChart chart) {
- return chart.createBufferedImage(getWidth(), getHeight(), Transparency.BITMASK, null);
- }
-
- public void exportChartAsPNG(OutputStream out) throws IOException {
- KeypointPNGEncoderAdapter encoder = new KeypointPNGEncoderAdapter();
- encoder.setEncodingAlpha(true);
- encoder.encode(getChartImage(), out);
- }
-
- public byte[] exportChartAsPNG() throws IOException {
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- try {
- exportChartAsPNG(output);
- } finally {
- output.close();
- }
- return output.toByteArray();
- }
-
- protected BasicStroke getDashedStroke() {
- return getDashedStroke(1f);
- }
-
- protected BasicStroke getDashedStroke(float width) {
- return new BasicStroke(width,
- BasicStroke.CAP_BUTT,
- BasicStroke.JOIN_MITER,
- 10.0f, new float[] {5.0f}, 0.0f);
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts.deprecated;
-
-import java.awt.Color;
-import java.awt.Font;
-import java.util.Map;
-import java.util.StringTokenizer;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.renderer.AbstractRenderer;
-
-public abstract class BaseChartWeb extends BaseChart {
-
- // Chart types
- public static final String BAR_CHART_HORIZONTAL = "hb";
- public static final String BAR_CHART_VERTICAL = "vb";
- public static final String BAR_CHART_VERTICAL_CUSTOM = "cvb";
- public static final String STACKED_BAR_CHART = "sb";
- public static final String PIE_CHART = "p";
- public static final String SPARKLINES_CHART = "sl";
-
- // Chart params
- public static final String CHART_PARAM_TYPE = "cht";
- public static final String CHART_PARAM_VALUES = "chv";
- public static final String CHART_PARAM_COLORS = "chc";
- public static final String CHART_PARAM_RANGEMAX = "chrm";
- public static final String CHART_PARAM_TITLE = "chti";
- public static final String CHART_PARAM_DIMENSIONS = "chdi";
- public static final String CHART_PARAM_RANGEAXIS_VISIBLE = "chrav";
- public static final String CHART_PARAM_CATEGORIES = "chca";
- public static final String CHART_PARAM_CATEGORIES_AXISMARGIN_VISIBLE = "chcav";
- public static final String CHART_PARAM_CATEGORIES_AXISMARGIN_UPPER = "chcaamu";
- public static final String CHART_PARAM_CATEGORIES_AXISMARGIN_LOWER = "chcaaml";
- public static final String CHART_PARAM_SERIES = "chse";
- public static final String CHART_PARAM_SERIES_AXISMARGIN_UPPER = "chseamu";
- public static final String CHART_PARAM_SERIES_AXISMARGIN_LOWER = "chseaml";
- public static final String CHART_PARAM_SERIES_AXISMARGIN_TICKUNIT = "chsetu";
- public static final String CHART_PARAM_INSETS = "chins";
- public static final String CHART_PARAM_OUTLINE_VISIBLE = "chov";
- public static final String CHART_PARAM_OUTLINE_RANGEGRIDLINES_VISIBLE = "chorgv";
-
- // Default labels
- public static final String DEFAULT_NAME_CATEGORY = "category";
- public static final String DEFAULT_NAME_SERIE = "serie";
- public static final String DEFAULT_MESSAGE_NODATA = "No data available";
-
- // Default values
- public static final double DEFAULT_CATEGORIES_AXISMARGIN = 0.0;
- public static final double DEFAULT_SERIES_AXISMARGIN = 0.0;
-
- // Default dimensions
- public static final int DEFAULT_WIDTH = 60;
- public static final int DEFAULT_HEIGHT = 20;
-
- // Default font
- public static final Font DEFAULT_FONT = new Font("SansSerif", Font.PLAIN, 13);
-
- protected JFreeChart jfreechart = null;
- protected Map<String, String> params = null;
-
- public BaseChartWeb(Map<String, String> params) {
- super(DEFAULT_WIDTH, DEFAULT_HEIGHT);
- this.params = params;
- }
-
- protected boolean isParamValueValid(String paramValue) {
- return paramValue != null && paramValue.length() > 0;
- }
-
- protected double convertParamToDouble(String paramValue) {
- return convertParamToDouble(paramValue, 0.0);
- }
-
- protected void configureColors(String colors, AbstractRenderer renderer) {
- try {
- if (colors != null && colors.length() > 0) {
- StringTokenizer stringTokenizer = new StringTokenizer(colors, ",");
- int i = 0;
- while (stringTokenizer.hasMoreTokens()) {
- renderer.setSeriesPaint(i, Color.decode("0x" + stringTokenizer.nextToken()));
- i++;
- }
- } else {
- configureDefaultColors(renderer);
- }
- } catch (Exception e) {
- configureDefaultColors(renderer);
- }
- }
-
- protected void configureDefaultColors(AbstractRenderer renderer) {
- for (int i=0 ; i<COLORS.length ; i++) {
- renderer.setSeriesPaint(i, COLORS[i]);
- }
- }
-
- protected double convertParamToDouble(String paramValue, double paramDefault) {
- double result = paramDefault;
- if (isParamValueValid(paramValue)) {
- try {
- result = Double.parseDouble(paramValue);
- } catch (NumberFormatException e) {
- // ignore
- }
- }
- return result;
- }
-
-
- protected void configureDimensions(String dimensions) {
- try {
- if (dimensions == null || dimensions.length() == 0) {
- // Do nothing, default dimensions are already setted
- } else if (dimensions.indexOf('x') == -1) {
- int iDim = Integer.parseInt(dimensions);
- setWidth(iDim);
- setHeight(iDim);
- } else {
- StringTokenizer st = new StringTokenizer(dimensions, "x");
- int iWidth = Integer.parseInt(st.nextToken());
- int iHeight = iWidth;
- if (st.hasMoreTokens()) {
- iHeight = Integer.parseInt(st.nextToken());
- }
- setWidth(iWidth);
- setHeight(iHeight);
- }
- } catch (NumberFormatException e) {
- // Do nothing, default dimensions are already setted
- }
- }
-
- protected void applyCommonParams() {
- configureChartTitle(jfreechart, params.get(BaseChartWeb.CHART_PARAM_TITLE));
- configureDimensions(params.get(BaseChartWeb.CHART_PARAM_DIMENSIONS));
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts.deprecated;
-
-import java.awt.Color;
-import java.awt.Paint;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.util.Map;
-import java.util.StringTokenizer;
-import org.jfree.chart.plot.CategoryPlot;
-import org.jfree.data.category.DefaultCategoryDataset;
-import org.jfree.ui.RectangleInsets;
-
-public class CustomBarChart extends BarChart {
-
- private CustomBarRenderer renderer = null;
-
- public CustomBarChart(Map<String, String> params) {
- super(params);
- }
-
- @Override
- protected BufferedImage getChartImage() throws IOException {
- configure();
- return getBufferedImage(jfreechart);
- }
-
- @Override
- protected void configure() {
- configureChart(jfreechart, false);
- configureCategoryDataset();
- configureCategoryAxis();
- configureRenderer();
- configureRangeAxis();
- configureCategoryPlot();
- applyParams();
- }
-
- @Override
- protected void configureCategoryDataset() {
- dataset = new DefaultCategoryDataset();
- }
-
- @Override
- protected void configureRenderer() {
- renderer = new CustomBarRenderer(null);
- renderer.setItemMargin(0.0);
- renderer.setDrawBarOutline(false);
- }
-
- @Override
- protected void configureCategoryPlot() {
- CategoryPlot plot = jfreechart.getCategoryPlot();
- plot.setNoDataMessage(DEFAULT_MESSAGE_NODATA);
- // To remove inner space around chart
- plot.setInsets(RectangleInsets.ZERO_INSETS);
- plot.setDataset(dataset);
- plot.setDomainAxis(categoryAxis);
- plot.setRenderer(renderer);
- plot.setRangeAxis(numberAxis);
- }
-
- protected void applyParams() {
- applyCommonParams();
- applyCommomParamsBar();
-
- configureColors(params.get(CHART_PARAM_COLORS));
- addMeasures(params.get(CHART_PARAM_VALUES));
- }
-
- private void configureColors(String colorsParam) {
- Paint[] colors = CustomBarRenderer.COLORS;
- if (colorsParam != null && colorsParam.length() > 0) {
- StringTokenizer stColors = new StringTokenizer(colorsParam, ",");
- colors = new Paint[stColors.countTokens()];
- int i = 0;
- while (stColors.hasMoreTokens()) {
- colors[i] = Color.decode("0x" + stColors.nextToken());
- i++;
- }
- }
-
- renderer.setColors(colors);
- }
-
- private void addMeasures(String values) {
- if (values != null && values.length() > 0) {
- // Values
- StringTokenizer stValues = new StringTokenizer(values, ",");
- int nbValues = stValues.countTokens();
-
- // Categories
- String categoriesParam = params.get(CHART_PARAM_CATEGORIES);
- String[] categoriesSplit;
- if (categoriesParam != null && categoriesParam.length() > 0) {
- categoriesSplit = categoriesParam.split(",");
- } else {
- categoriesSplit = new String[nbValues];
- for (int i = 0; i < nbValues; i++) {
- categoriesSplit[i] = new StringBuilder().append(DEFAULT_NAME_CATEGORY).append(i).toString();
- }
- }
-
- // Series
- String[] seriesSplit = {DEFAULT_NAME_SERIE};
- int nbSeries = 1;
-
- for (String currentCategory : categoriesSplit) {
- for (int iSeries = 0; iSeries < nbSeries; iSeries++) {
- String currentSerie = seriesSplit[iSeries];
- double currentValue = 0.0;
- if (stValues.hasMoreTokens()) {
- try {
- currentValue = Double.parseDouble(stValues.nextToken());
- } catch (NumberFormatException e) {
- // ignore
- }
- }
- dataset.addValue(currentValue, currentSerie, currentCategory);
- }
- }
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts.deprecated;
-
-import java.awt.Color;
-import java.awt.Paint;
-import org.jfree.chart.renderer.category.BarRenderer;
-
-public class CustomBarRenderer extends BarRenderer {
-
- protected static final Paint[] COLORS = {
- Color.red, Color.blue, Color.green,
- Color.yellow, Color.orange, Color.cyan,
- Color.magenta, Color.blue};
-
- /**
- * The colors.
- */
- private Paint[] colors;
-
- /**
- * Creates a new renderer.
- *
- * @param colors the colors.
- */
- public CustomBarRenderer(final Paint[] colors) {
- this.colors = colors;
- }
-
- /**
- * Returns the paint for an item. Overrides the default behaviour inherited from
- * AbstractSeriesRenderer.
- *
- * @param row the series.
- * @param column the category.
- * @return The item color.
- */
- @Override
- public Paint getItemPaint(final int row, final int column) {
- return this.colors[column % this.colors.length];
- }
-
- public Paint[] getColors() {
- return colors;
- }
-
- public void setColors(Paint[] colors) {
- this.colors = colors;
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts.deprecated;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-public interface DeprecatedChart {
-
- void exportChartAsPNG(OutputStream out) throws IOException;
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts.deprecated;
-
-import java.awt.Color;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.util.Map;
-import java.util.StringTokenizer;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.plot.PiePlot;
-import org.jfree.chart.title.TextTitle;
-import org.jfree.data.general.DefaultPieDataset;
-import org.jfree.ui.RectangleInsets;
-
-public class PieChart extends BaseChartWeb implements DeprecatedChart {
-
- private DefaultPieDataset dataset = null;
-
- public PieChart(Map<String, String> params) {
- super(params);
- jfreechart = new JFreeChart(null, TextTitle.DEFAULT_FONT, new PiePlot(), false);
- }
-
- @Override
- protected BufferedImage getChartImage() throws IOException {
- configure();
- return getBufferedImage(jfreechart);
- }
-
- private void configure() {
- configureChart(jfreechart, false);
- configureDataset();
- configurePlot();
- applyParams();
- }
-
- private void configureDataset() {
- dataset = new DefaultPieDataset();
- }
-
- private void configurePlot() {
- PiePlot plot = (PiePlot) jfreechart.getPlot();
- plot.setNoDataMessage(DEFAULT_MESSAGE_NODATA);
- plot.setInsets(RectangleInsets.ZERO_INSETS);
- plot.setDataset(dataset);
- plot.setBackgroundAlpha(0.0f);
- plot.setCircular(true);
- plot.setLabelGenerator(null);
- plot.setIgnoreNullValues(true);
- plot.setIgnoreZeroValues(true);
- plot.setShadowPaint(null);
- plot.setLabelLinkMargin(0.0);
- plot.setInteriorGap(0.02);
- plot.setMaximumLabelWidth(0.10);
- }
-
- private void configureColors(String colors) {
- try {
- if (colors != null && colors.length() > 0) {
- StringTokenizer stringTokenizer = new StringTokenizer(colors, ",");
- int i = 0;
- while (stringTokenizer.hasMoreTokens()) {
- ((PiePlot) jfreechart.getPlot()).setSectionPaint(Integer.toString(i), Color.decode("0x" + stringTokenizer.nextToken()));
- i++;
- }
- } else {
- configureDefaultColors();
- }
- } catch (Exception e) {
- configureDefaultColors();
- }
- }
-
- private void configureDefaultColors() {
- PiePlot plot = (PiePlot) jfreechart.getPlot();
- for (int i = 0; i < COLORS.length; i++) {
- plot.setSectionPaint(Integer.toString(i), COLORS[i]);
- }
- }
-
- private void applyParams() {
- applyCommonParams();
-
- configureColors(params.get(CHART_PARAM_COLORS));
- addMeasures(params.get(CHART_PARAM_VALUES));
-
- // -- Plot
- PiePlot plot = (PiePlot) jfreechart.getPlot();
- plot.setOutlineVisible(isParamValueValid(params.get(CHART_PARAM_OUTLINE_VISIBLE)) && Boolean.getBoolean(params.get(CHART_PARAM_OUTLINE_VISIBLE)));
- }
-
- private void addMeasures(String values) {
- if (values != null && values.length() > 0) {
- StringTokenizer st = new StringTokenizer(values, ",");
- int i = 0;
- while (st.hasMoreTokens()) {
- double measure = 0;
- try {
- measure = Double.parseDouble(st.nextToken());
- } catch (NumberFormatException e) {
- // ignore
- }
- dataset.setValue(Integer.toString(i), measure);
- i++;
- }
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts.deprecated;
-
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.util.Map;
-import java.util.StringTokenizer;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.axis.DateAxis;
-import org.jfree.chart.axis.DateTickUnit;
-import org.jfree.chart.axis.NumberAxis;
-import org.jfree.chart.plot.XYPlot;
-import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
-import org.jfree.chart.title.TextTitle;
-import org.jfree.data.xy.XYSeries;
-import org.jfree.data.xy.XYSeriesCollection;
-import org.jfree.ui.RectangleInsets;
-
-public class SparkLinesChart extends BaseChartWeb implements DeprecatedChart {
-
- private XYSeriesCollection dataset = null;
- private DateAxis x = null;
- private NumberAxis y = null;
- private StandardXYItemRenderer renderer = null;
-
- public SparkLinesChart(Map<String, String> params) {
- super(params);
- jfreechart = new JFreeChart(null, TextTitle.DEFAULT_FONT, new XYPlot(), false);
- }
-
- @Override
- protected BufferedImage getChartImage() throws IOException {
- configure();
- return getBufferedImage(jfreechart);
- }
-
- private void configure() {
- configureChart(jfreechart, false);
- configureXAxis();
- configureYAxis();
- configureRenderer();
- configureDataset();
- configurePlot();
- applyParams();
- }
-
- private void configureRenderer() {
- renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES);
- }
-
- private void configureYAxis() {
- y = new NumberAxis();
- y.setTickLabelsVisible(false);
- y.setTickMarksVisible(false);
- y.setAxisLineVisible(false);
- y.setNegativeArrowVisible(false);
- y.setPositiveArrowVisible(false);
- y.setVisible(false);
- }
-
- private void configureXAxis() {
- x = new DateAxis();
- x.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1));
- x.setTickLabelsVisible(false);
- x.setTickMarksVisible(false);
- x.setAxisLineVisible(false);
- x.setNegativeArrowVisible(false);
- x.setPositiveArrowVisible(false);
- x.setVisible(false);
- }
-
- private void configureDataset() {
- dataset = new XYSeriesCollection();
- }
-
- private void configurePlot() {
- XYPlot plot = (XYPlot) jfreechart.getPlot();
- plot.setInsets(RectangleInsets.ZERO_INSETS);
- plot.setDataset(dataset);
- plot.setDomainAxis(x);
- plot.setDomainGridlinesVisible(false);
- plot.setDomainCrosshairVisible(false);
- plot.setRangeGridlinesVisible(false);
- plot.setRangeCrosshairVisible(false);
- plot.setRangeAxis(y);
- plot.setRenderer(renderer);
- plot.setBackgroundAlpha(0.0f);
- }
-
- private void applyParams() {
- applyCommonParams();
-
- configureColors(params.get(CHART_PARAM_COLORS), renderer);
- addMeasures(params.get(CHART_PARAM_VALUES));
-
- // -- Plot
- XYPlot plot = (XYPlot) jfreechart.getPlot();
- plot.setOutlineVisible(isParamValueValid(params.get(CHART_PARAM_OUTLINE_VISIBLE)) && Boolean.getBoolean(params.get(CHART_PARAM_OUTLINE_VISIBLE)));
- }
-
- private void addMeasures(String values) {
- double min = Double.MAX_VALUE;
- double max = Double.MIN_VALUE;
- XYSeries series1 = new XYSeries("");
- if (values != null && values.length() > 0) {
- StringTokenizer st = new StringTokenizer(values, ",");
- while (st.hasMoreTokens()) {
- double vX = convertParamToDouble(st.nextToken());
- double vY = 0.0;
- if (st.hasMoreTokens()) {
- vY = convertParamToDouble(st.nextToken());
- }
- series1.add(vX, vY);
-
- min = vY < min ? vY : min;
- max = vY > max ? vY : max;
- }
- dataset.addSeries(series1);
- y.setRange(min-1, max+1);
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.server.charts;
-
-import javax.annotation.ParametersAreNonnullByDefault;
import org.sonar.server.activity.ws.ActivityMapping;
import org.sonar.server.authentication.AuthenticationModule;
import org.sonar.server.batch.BatchWsModule;
-import org.sonar.server.charts.ChartFactory;
-import org.sonar.server.charts.DistributionAreaChart;
-import org.sonar.server.charts.DistributionBarChart;
import org.sonar.server.component.ComponentCleanerService;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.component.ComponentService;
protected void configureLevel() {
add(
PluginDownloader.class,
- ChartFactory.class,
- DistributionBarChart.class,
- DistributionAreaChart.class,
Views.class,
ResourceTypes.class,
DefaultResourceTypes.get(),
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts;
-
-import org.apache.commons.io.FileUtils;
-import org.jfree.chart.ChartUtilities;
-import org.jfree.ui.ApplicationFrame;
-import org.jfree.ui.RefineryUtilities;
-
-import javax.swing.JPanel;
-
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import static org.junit.Assert.assertTrue;
-
-public abstract class AbstractChartTest {
- protected void assertChartSizeGreaterThan(BufferedImage img, int size) throws IOException {
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- ChartUtilities.writeBufferedImageAsPNG(output, img);
- assertTrue("PNG size in bits=" + output.size(), output.size() > size);
- }
-
- protected void assertChartSizeLesserThan(BufferedImage img, int size) throws IOException {
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- ChartUtilities.writeBufferedImageAsPNG(output, img);
- assertTrue("PNG size in bits=" + output.size(), output.size() < size);
- }
-
- protected void saveChart(BufferedImage img, String name) throws IOException {
- File target = new File("target/tmp-chart", name);
- FileUtils.forceMkdir(target.getParentFile());
- ByteArrayOutputStream imgOutput = new ByteArrayOutputStream();
- ChartUtilities.writeBufferedImageAsPNG(imgOutput, img);
- OutputStream out = new FileOutputStream(target);
- out.write(imgOutput.toByteArray());
- out.close();
-
- }
-
- protected static void displayTestPanel(BufferedImage image) {
- ApplicationFrame frame = new ApplicationFrame("testframe");
- BufferedPanel imgPanel = new BufferedPanel(image);
- frame.setContentPane(imgPanel);
- frame.pack();
- RefineryUtilities.centerFrameOnScreen(frame);
- frame.setVisible(true);
- }
-
- protected static Date stringToDate(String sDate) throws ParseException {
- SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy hh'h'mm");
- return sdf.parse(sDate);
- }
-
- private static class BufferedPanel extends JPanel {
- private final BufferedImage chartImage;
-
- public BufferedPanel(BufferedImage chartImage) {
- this.chartImage = chartImage;
- }
-
- @Override
- protected void paintComponent(Graphics graphics) {
- super.paintComponent(graphics);
- graphics.drawImage(chartImage, 0, 0, null);
- }
-
- @Override
- public Dimension getPreferredSize() {
- return new Dimension(chartImage.getWidth(), chartImage.getHeight());
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts;
-
-import org.junit.Test;
-import org.sonar.api.charts.Chart;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-public class ChartFactoryTest {
-
- @Test
- public void shouldFindChartsFromPlugins() {
- ChartFactory factory = new ChartFactory(new Chart[]{new FakeChart()});
- Chart chart = factory.getChart("fake");
- assertEquals(chart.getClass(), FakeChart.class);
-
- assertNull(factory.getChart("unknown"));
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts;
-
-import org.junit.Test;
-import org.sonar.api.charts.ChartParameters;
-
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-
-public class DistributionAreaChartTest extends AbstractChartTest {
-
- @Test
- public void oneSerie() throws IOException {
- DistributionAreaChart chart = new DistributionAreaChart();
- BufferedImage image = chart.generateImage(new ChartParameters("v=0%3D5%3B1%3D22%3B2%3D2"));
- assertChartSizeGreaterThan(image, 1000);
- saveChart(image, "DistributionAreaChartTest/oneSerie.png");
- }
-
- @Test
- public void manySeries() throws IOException {
- DistributionAreaChart chart = new DistributionAreaChart();
- BufferedImage image = chart.generateImage(new ChartParameters("v=0%3D5%3B1%3D22%3B2%3D2|0%3D7%3B1%3D15%3B2%3D4"));
- assertChartSizeGreaterThan(image, 1000);
- saveChart(image, "DistributionAreaChartTest/manySeries.png");
- }
-
- @Test
- public void manySeriesWithDifferentCategories() throws IOException {
- DistributionAreaChart chart = new DistributionAreaChart();
- BufferedImage image = chart.generateImage(new ChartParameters("v=0%3D5%3B1%3D22%3B2%3D2|2%3D7%3B4%3D15%3B9%3D4"));
- assertChartSizeGreaterThan(image, 1000);
- saveChart(image, "DistributionAreaChartTest/manySeriesWithDifferentCategories.png");
- }
-
- @Test
- public void manySeriesIncludingAnEmptySerie() throws IOException {
- // the third serie should not have the second default color, but the third one !
- DistributionAreaChart chart = new DistributionAreaChart();
- BufferedImage image = chart.generateImage(new ChartParameters("v=0%3D5%3B1%3D22%3B2%3D2||2%3D7%3B4%3D15%3B9%3D4"));
- assertChartSizeGreaterThan(image, 1000);
- saveChart(image, "DistributionAreaChartTest/manySeriesIncludingAnEmptySerie.png");
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts;
-
-import org.junit.Test;
-import org.sonar.api.charts.ChartParameters;
-
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-
-public class DistributionBarChartTest extends AbstractChartTest {
- DistributionBarChart chart = new DistributionBarChart();
-
- @Test
- public void simpleSample() throws IOException {
- BufferedImage image = chart.generateImage(new ChartParameters("v=0%3D5%3B1%3D22%3B2%3D2"));
- assertChartSizeGreaterThan(image, 1000);
- saveChart(image, "DistributionBarChartTest/simpleSample.png");
- }
-
- @Test
- public void addXSuffix() throws IOException {
- // should suffix x labels with +
- BufferedImage image = chart.generateImage(new ChartParameters("v=0%3D5%3B1%3D22%3B2%3D2&xsuf=%2B"));
- assertChartSizeGreaterThan(image, 1000);
- saveChart(image, "DistributionBarChartTest/addXSuffix.png");
- }
-
- @Test
- public void addYSuffix() throws IOException {
- // should suffix y labels with %
- BufferedImage image = chart.generateImage(new ChartParameters("v=0%3D5%3B1%3D22%3B2%3D2&ysuf=%25"));
- assertChartSizeGreaterThan(image, 1000);
- saveChart(image, "DistributionBarChartTest/addYSuffix.png");
- }
-
- @Test
- public void manySeries() throws IOException {
- BufferedImage image = chart.generateImage(new ChartParameters("v=0%3D5%3B1%3D22%3B2%3D2|0%3D7%3B1%3D15%3B2%3D4"));
- assertChartSizeGreaterThan(image, 1000);
- saveChart(image, "DistributionBarChartTest/manySeries.png");
- }
-
- @Test
- public void manySeriesIncludingAnEmptySerie() throws IOException {
- // the third serie should not have the second default color, but the third one !
- BufferedImage image = chart.generateImage(new ChartParameters("v=0%3D5%3B1%3D22%3B2%3D2||0%3D7%3B1%3D15%3B2%3D4"));
- assertChartSizeGreaterThan(image, 1000);
- saveChart(image, "DistributionBarChartTest/manySeriesIncludingAnEmptySerie.png");
- }
-
- @Test
- public void overridenSize() throws IOException {
- BufferedImage image = chart.generateImage(new ChartParameters("v=0%3D5%3B1%3D22%3B2%3D2|0%3D7%3B1%3D15%3B2%3D4&w=500&h=200"));
- assertChartSizeGreaterThan(image, 1000);
- saveChart(image, "DistributionBarChartTest/overridenSize.png");
- }
-
- @Test
- public void changeColor() throws IOException {
- BufferedImage image = chart.generateImage(new ChartParameters("v=0%3D5%3B1%3D22%3B2%3D2&c=777777&bgc=777777"));
- assertChartSizeGreaterThan(image, 1000);
- saveChart(image, "DistributionBarChartTest/changeColor.png");
- }
-
- @Test
- public void smallSize() throws IOException {
- BufferedImage image = chart.generateImage(new ChartParameters("v=0%3D5%3B1%3D22%3B2%3D2%3B4%3D22%3B5%3D22%3B6%3D22&c=777777&w=120&h=80&fs=8"));
- assertChartSizeGreaterThan(image, 500);
- saveChart(image, "DistributionBarChartTest/smallSize.png");
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts;
-
-import org.sonar.api.charts.Chart;
-import org.sonar.api.charts.ChartParameters;
-
-import java.awt.image.BufferedImage;
-
-class FakeChart implements Chart {
- public String getKey() {
- return "fake";
- }
-
- public BufferedImage generateImage(ChartParameters params) {
- return null;
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts.deprecated;
-
-import org.junit.Test;
-
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-public class BarChartTest extends BaseChartWebTest {
-
- @Test
- public void testBarChartDefaultDimensions() throws IOException {
- Map<String, String> params = getDefaultParams();
- BarChart chart = new BarChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "bar-chart-default.png");
- assertChartSizeGreaterThan(img, 100);
- }
-
- @Test
- public void testBarChartRange() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_RANGEMAX, "200");
- BarChart chart = new BarChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "bar-chart-range.png");
- assertChartSizeGreaterThan(img, 100);
- }
-
- @Test
- public void testBarChartSpecificDimensions() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_DIMENSIONS, "750x250");
- BarChart chart = new BarChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "bar-chart-specific-dimensions.png");
- assertChartSizeGreaterThan(img, 100);
- }
-
- @Test
- public void testBarChartOneValue() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_VALUES, "100");
- BarChart chart = new BarChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "bar-chart-one-value.png");
- assertChartSizeGreaterThan(img, 100);
- }
-
- @Test
- public void testBarChartOthersColors() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_COLORS, "FFFF00,9900FF");
- BarChart chart = new BarChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "bar-chart-others-colors.png");
- assertChartSizeGreaterThan(img, 100);
- }
-
- @Test
- public void testBarChartNullValues() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_VALUES, null);
- BarChart chart = new BarChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "bar-chart-null-values.png");
- assertChartSizeGreaterThan(img, 100);
- }
-
- @Test
- public void testBarChartWrongValues() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_VALUES, "wrong,value");
- BarChart chart = new BarChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "bar-chart-wrong-values.png");
- assertChartSizeGreaterThan(img, 100);
- }
-
- @Test
- public void testBarChartTitle() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_TITLE, "JFreeChart by Servlet");
- params.put(BaseChartWeb.CHART_PARAM_DIMENSIONS, "750x250");
- BarChart chart = new BarChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "bar-chart-title.png");
- assertChartSizeGreaterThan(img, 100);
- }
-
- @Test
- public void testStackedBarCharteightyTwenty() throws IOException {
- Map<String, String> params = new HashMap<>();
- params.put(BaseChartWeb.CHART_PARAM_TYPE, BaseChartWeb.STACKED_BAR_CHART);
- params.put(BaseChartWeb.CHART_PARAM_VALUES, "80,20");
- BarChart chart = new BarChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "stacked-bar-chart-80-20.png");
- assertChartSizeGreaterThan(img, 100);
- }
-
- @Test
- public void testStackedBarChartfiftyFifty() throws IOException {
- Map<String, String> params = new HashMap<>();
- params.put(BaseChartWeb.CHART_PARAM_TYPE, BaseChartWeb.STACKED_BAR_CHART);
- params.put(BaseChartWeb.CHART_PARAM_VALUES, "50,50");
- BarChart chart = new BarChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "stacked-bar-chart-50-50.png");
- assertChartSizeGreaterThan(img, 100);
- }
-
- private Map<String, String> getDefaultParams() {
- Map<String, String> params = new HashMap<>();
- params.put(BaseChartWeb.CHART_PARAM_TYPE, BaseChartWeb.BAR_CHART_HORIZONTAL);
- params.put(BaseChartWeb.CHART_PARAM_VALUES, "100,50");
- return params;
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts.deprecated;
-
-import junit.framework.TestCase;
-import org.apache.commons.io.FileUtils;
-import org.jfree.chart.ChartUtilities;
-import org.jfree.ui.ApplicationFrame;
-import org.jfree.ui.RefineryUtilities;
-
-import javax.swing.JPanel;
-
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-public abstract class BaseChartTest extends TestCase {
-
- protected void assertChartSizeGreaterThan(BufferedImage img, int size) throws IOException {
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- ChartUtilities.writeBufferedImageAsPNG(output, img, true, 0);
- assertTrue("PNG size in bits=" + output.size(), output.size() > size);
- }
-
- protected void assertChartSizeLesserThan(BufferedImage img, int size) throws IOException {
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- ChartUtilities.writeBufferedImageAsPNG(output, img, true, 0);
- assertTrue("PNG size in bits=" + output.size(), output.size() < size);
- }
-
- protected void saveChart(BufferedImage img, String name) throws IOException {
- File target = new File("target/test-tmp/chart/");
- FileUtils.forceMkdir(target);
- ByteArrayOutputStream imgOutput = new ByteArrayOutputStream();
- ChartUtilities.writeBufferedImageAsPNG(imgOutput, img, true, 0);
- OutputStream out = new FileOutputStream(new File(target, name));
- out.write(imgOutput.toByteArray());
- out.close();
-
- }
-
- protected static void displayTestPanel(BufferedImage image) {
- ApplicationFrame frame = new ApplicationFrame("testframe");
- BufferedPanel imgPanel = new BufferedPanel(image);
- frame.setContentPane(imgPanel);
- frame.pack();
- RefineryUtilities.centerFrameOnScreen(frame);
- frame.setVisible(true);
- }
-
- protected static Date stringToDate(String sDate) throws ParseException {
- SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy hh'h'mm");
- return sdf.parse(sDate);
- }
-
- private static class BufferedPanel extends JPanel {
- private final BufferedImage chartImage;
-
- public BufferedPanel(BufferedImage chartImage) {
- this.chartImage = chartImage;
- }
-
- @Override
- protected void paintComponent(Graphics graphics) {
- super.paintComponent(graphics);
- graphics.drawImage(chartImage, 0, 0, null);
- }
-
- @Override
- public Dimension getPreferredSize() {
- return new Dimension(chartImage.getWidth(), chartImage.getHeight());
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts.deprecated;
-
-import java.util.Iterator;
-import java.util.Map;
-
-public abstract class BaseChartWebTest extends BaseChartTest {
-
- protected String generateUrl(Map<String, String> params) {
- StringBuilder servletUrl = new StringBuilder("chart?");
- for (Iterator<String> keyIt = params.keySet().iterator(); keyIt.hasNext();) {
- String key = keyIt.next();
- servletUrl.append("&").append(key).append("=").append(params.get(key));
- }
- return servletUrl.toString();
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts.deprecated;
-
-import org.junit.Test;
-
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-public class CustomBarChartTest extends BaseChartWebTest {
-
- @Test
- public void testEmptyParameters() throws IOException {
- Map<String, String> params = new HashMap<>();
- CustomBarChart chart = new CustomBarChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "custom-horizontal-bar-chart-empty.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- @Test
- public void testAllParameters() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_TITLE, "JFreeChart by Servlet");
- params.put(BaseChartWeb.CHART_PARAM_DIMENSIONS, "750x250");
- params.put(BaseChartWeb.CHART_PARAM_CATEGORIES_AXISMARGIN_VISIBLE, "y");
- params.put(BaseChartWeb.CHART_PARAM_RANGEAXIS_VISIBLE, "y");
- params.put(BaseChartWeb.CHART_PARAM_TYPE, BaseChartWeb.BAR_CHART_VERTICAL_CUSTOM);
- params.put(BaseChartWeb.CHART_PARAM_VALUES, "6,2,3,7,5,1,9");
- params.put(BaseChartWeb.CHART_PARAM_SERIES, "1,2");
- params.put(BaseChartWeb.CHART_PARAM_CATEGORIES, "0+,5+,10+,20+,30+,60+,90+");
- params.put(BaseChartWeb.CHART_PARAM_COLORS, "FF0000,FF0000,FF0000,CC9900,CC9900,CC9900,00FF00,00FF00,00FF00");
- params.put(BaseChartWeb.CHART_PARAM_CATEGORIES_AXISMARGIN_UPPER, "0.05");
- params.put(BaseChartWeb.CHART_PARAM_SERIES_AXISMARGIN_UPPER, "0.05");
- params.put(BaseChartWeb.CHART_PARAM_INSETS, "20");
- CustomBarChart chart = new CustomBarChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "custom-horizontal-bar-chart-all.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- @Test
- public void testComplexityChart() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_DIMENSIONS, "150x100");
- params.put(BaseChartWeb.CHART_PARAM_CATEGORIES_AXISMARGIN_VISIBLE, "y");
- params.put(BaseChartWeb.CHART_PARAM_RANGEAXIS_VISIBLE, "y");
- params.put(BaseChartWeb.CHART_PARAM_TYPE, BaseChartWeb.BAR_CHART_VERTICAL_CUSTOM);
- params.put(BaseChartWeb.CHART_PARAM_VALUES, "6,2,3");
- params.put(BaseChartWeb.CHART_PARAM_CATEGORIES, "0+,5+,10+,20+,30+,60+,90+");
- params.put(BaseChartWeb.CHART_PARAM_COLORS, "4192D9");
- params.put(BaseChartWeb.CHART_PARAM_CATEGORIES_AXISMARGIN_UPPER, "0.05");
- params.put(BaseChartWeb.CHART_PARAM_CATEGORIES_AXISMARGIN_LOWER, "0.05");
- params.put(BaseChartWeb.CHART_PARAM_SERIES_AXISMARGIN_UPPER, "0.2");
- params.put(BaseChartWeb.CHART_PARAM_INSETS, "1");
- params.put(BaseChartWeb.CHART_PARAM_OUTLINE_RANGEGRIDLINES_VISIBLE, "y");
- params.put(BaseChartWeb.CHART_PARAM_OUTLINE_VISIBLE, "y");
- CustomBarChart chart = new CustomBarChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "custom-horizontal-bar-chart-complexity.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- private Map<String, String> getDefaultParams() {
- Map<String, String> params = new HashMap<>();
- params.put(BaseChartWeb.CHART_PARAM_TYPE, BaseChartWeb.BAR_CHART_HORIZONTAL);
- params.put(BaseChartWeb.CHART_PARAM_VALUES, "100,50");
- return params;
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts.deprecated;
-
-import org.junit.Test;
-
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-public class PieChartTest extends BaseChartWebTest {
-
- @Test
- public void testPieChartDefaultDimensions() throws IOException {
- Map<String, String> params = getDefaultParams();
- PieChart chart = new PieChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "pie-chart-default.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- @Test
- public void testPieChartSpecificDimensions() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_DIMENSIONS, "200x200");
- PieChart chart = new PieChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "pie-chart-specific-dimensions.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- @Test
- public void testPieChartOneValue() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_VALUES, "100");
- PieChart chart = new PieChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "pie-chart-one-value.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- @Test
- public void testPieChartOthersColors() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_COLORS, "FFFF00,9900FF");
- PieChart chart = new PieChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "pie-chart-others-colors.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- @Test
- public void testPieChartNullValues() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_VALUES, null);
- PieChart chart = new PieChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "pie-chart-null-values.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- @Test
- public void testPieChartWrongValues() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_VALUES, "wrong,value");
- PieChart chart = new PieChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "pie-chart-wrong-values.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- @Test
- public void testPieChartTitle() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_TITLE, "JFreeChart by Servlet");
- params.put(BaseChartWeb.CHART_PARAM_DIMENSIONS, "200x200");
- PieChart chart = new PieChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "pie-chart-title.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- private Map<String, String> getDefaultParams() {
- Map<String, String> params = new HashMap<>();
- params.put(BaseChartWeb.CHART_PARAM_TYPE, BaseChartWeb.PIE_CHART);
- params.put(BaseChartWeb.CHART_PARAM_VALUES, "100,50");
- params.put(BaseChartWeb.CHART_PARAM_DIMENSIONS, "50x50");
- return params;
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.charts.deprecated;
-
-import org.junit.Test;
-
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-public class SparkLinesChartTest extends BaseChartWebTest {
-
- @Test
- public void testSparkLinesChartDefaultDimensions() throws IOException {
- Map<String, String> params = getDefaultParams();
- SparkLinesChart chart = new SparkLinesChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "sparklines-chart-default.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- @Test
- public void testSparklinesChartSpecificDimensions() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_DIMENSIONS, "200x200");
- SparkLinesChart chart = new SparkLinesChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "sparklines-chart-specific-dimensions.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- @Test
- public void testSparklinesChartOneValue() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_VALUES, "100,100");
- SparkLinesChart chart = new SparkLinesChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "sparklines-chart-one-value.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- @Test
- public void testSparklinesChartOthersColors() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_COLORS, "9900FF");
- SparkLinesChart chart = new SparkLinesChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "sparklines-chart-others-colors.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- @Test
- public void testSparklinesChartNullValues() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_VALUES, null);
- SparkLinesChart chart = new SparkLinesChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "sparklines-chart-null-values.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- @Test
- public void testSparklinesChartWrongValues() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_VALUES, "wrong,value");
- SparkLinesChart chart = new SparkLinesChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "sparklines-chart-wrong-values.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- @Test
- public void testSparklinesChartTitle() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_TITLE, "JFreeChart by Servlet");
- params.put(BaseChartWeb.CHART_PARAM_DIMENSIONS, "200x200");
- SparkLinesChart chart = new SparkLinesChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "sparklines-chart-title.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- @Test
- public void testSparklinesChartDates() throws IOException {
- Map<String, String> params = getDefaultParams();
- params.put(BaseChartWeb.CHART_PARAM_VALUES, "20080101,1,20080201,4,20080301,3,20080401,5,20080501,5,20080601,7,20080701,7,20080801,8");
- params.put(BaseChartWeb.CHART_PARAM_DIMENSIONS, "200x200");
- SparkLinesChart chart = new SparkLinesChart(params);
- BufferedImage img = chart.getChartImage();
- saveChart(img, "sparklines-chart-dates.png");
- assertChartSizeGreaterThan(img, 50);
- }
-
- private Map<String, String> getDefaultParams() {
- Map<String, String> params = new HashMap<>();
- params.put(BaseChartWeb.CHART_PARAM_TYPE, BaseChartWeb.SPARKLINES_CHART);
- params.put(BaseChartWeb.CHART_PARAM_VALUES, "1,1,2,4,3,3,4,5,5,5,6,7,7,7,8,8");
- return params;
- }
-
-}
<url-pattern>/*</url-pattern>
</filter-mapping>
- <servlet>
- <servlet-name>chart</servlet-name>
- <servlet-class>org.sonar.server.charts.ChartsServlet</servlet-class>
- </servlet>
<servlet>
<servlet-name>static</servlet-name>
<servlet-class>org.sonar.server.plugins.StaticResourcesServlet</servlet-class>
</servlet>
- <servlet-mapping>
- <servlet-name>chart</servlet-name>
- <url-pattern>/chart</url-pattern>
- </servlet-mapping>
<servlet-mapping>
<servlet-name>static</servlet-name>
<url-pattern>/static/*</url-pattern>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>sonar-core</artifactId>
- <exclusions>
- <exclusion>
- <groupId>jfree</groupId>
- <artifactId>jcommon</artifactId>
- </exclusion>
- <exclusion>
- <groupId>jfree</groupId>
- <artifactId>jfreechart</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>sonar-plugin-api</artifactId>
- <exclusions>
- <exclusion>
- <groupId>jfree</groupId>
- <artifactId>jcommon</artifactId>
- </exclusion>
- <exclusion>
- <groupId>jfree</groupId>
- <artifactId>jfreechart</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
.addInclusion("org/codehaus/stax2/")
.addInclusion("org/codehaus/staxmate/")
.addInclusion("com/ctc/wstx/")
- .addInclusion("org/jfree/")
.addInclusion("org/slf4j/")
.addInclusion("javax/servlet/")
<artifactId>staxmate</artifactId>
</dependency>
-
- <dependency>
- <groupId>jfree</groupId>
- <artifactId>jfreechart</artifactId>
- <scope>provided</scope>
- </dependency>
-
-
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.api.charts;
-
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.plot.CategoryPlot;
-import org.jfree.chart.plot.Plot;
-import org.jfree.chart.renderer.AbstractRenderer;
-import org.jfree.chart.title.TextTitle;
-import org.jfree.data.Values2D;
-
-import java.awt.Color;
-import java.awt.image.BufferedImage;
-
-/**
- * Base implementation to generate charts with JFreechart
- *
- * @since 1.10
- * @deprecated in 4.5.1, replaced by Javascript charts
- */
-@Deprecated
-public abstract class AbstractChart implements Chart {
-
- public static final int FONT_SIZE = 13;
- public static final Color OUTLINE_COLOR = new Color(51, 51, 51);
- public static final Color GRID_COLOR = new Color(204, 204, 204);
- public static final Color[] COLORS = new Color[] { Color.decode("#4192D9"), Color.decode("#800000"), Color.decode("#A7B307"),
- Color.decode("#913C9F"), Color.decode("#329F4D") };
-
- protected abstract Plot getPlot(ChartParameters params);
-
- protected boolean hasLegend() {
- return false;
- }
-
- /**
- * Generates a JFreeChart chart using a set of parameters
- *
- * @param params the chart parameters
- * @return the generated chart
- */
- @Override
- public BufferedImage generateImage(ChartParameters params) {
- JFreeChart chart = new JFreeChart(null, TextTitle.DEFAULT_FONT, getPlot(params), hasLegend());
- improveChart(chart, params);
- return chart.createBufferedImage(params.getWidth(), params.getHeight());
- }
-
- private static void improveChart(JFreeChart jfrechart, ChartParameters params) {
- Color background = Color.decode("#" + params.getValue(ChartParameters.PARAM_BACKGROUND_COLOR, "FFFFFF", false));
- jfrechart.setBackgroundPaint(background);
-
- jfrechart.setBorderVisible(false);
- jfrechart.setAntiAlias(true);
- jfrechart.setTextAntiAlias(true);
- jfrechart.removeLegend();
- }
-
- @Override
- public String toString() {
- return getKey();
- }
-
- /**
- * Helper to set color of series. If the parameter colorsHex is null, then default Sonar colors are used.
- */
- protected void configureColors(Values2D dataset, CategoryPlot plot, String[] colorsHex) {
- Color[] colors = COLORS;
- if (colorsHex != null && colorsHex.length > 0) {
- colors = new Color[colorsHex.length];
- for (int i = 0; i < colorsHex.length; i++) {
- colors[i] = Color.decode("#" + colorsHex[i]);
- }
- }
-
- dataset.getColumnCount();
- AbstractRenderer renderer = (AbstractRenderer) plot.getRenderer();
- for (int i = 0; i < dataset.getColumnCount(); i++) {
- renderer.setSeriesPaint(i, colors[i % colors.length]);
-
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.api.charts;
-
-import org.sonar.api.server.ServerSide;
-
-import java.awt.image.BufferedImage;
-
-/**
- * Extension point to generate charts
- *
- * @since 1.10
- * @deprecated in 4.5.1, replaced by Javascript charts
- */
-@Deprecated
-@ServerSide
-public interface Chart {
- String getKey();
-
- /**
- * The method to implement to generate the chart
- *
- * @param params the chart parameters
- * @return the image generated
- */
- BufferedImage generateImage(ChartParameters params);
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.api.charts;
-
-import javax.annotation.Nullable;
-import org.apache.commons.lang.CharEncoding;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.text.StrTokenizer;
-import org.sonar.api.utils.SonarException;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-
-/**
- * The class to hold parameters to configure a chart
- * @since 1.10
- * @deprecated in 4.5.1, replaced by Javascript charts
- */
-@Deprecated
-public class ChartParameters {
- private static final String[] EMPTY = new String[0];
-
- public static final String PARAM_WIDTH = "w";
- public static final String PARAM_BACKGROUND_COLOR = "bgc";
- public static final String PARAM_HEIGHT = "h";
- public static final int MAX_WIDTH = 900;
- public static final String PARAM_LOCALE = "locale";
-
- public static final int MAX_HEIGHT = 900;
- public static final int DEFAULT_WIDTH = 200;
-
- public static final int DEFAULT_HEIGHT = 200;
-
-
- private final Map<String, String> params;
-
- /**
- * Creates a ChartParameter based on a list of parameters
- * @param params the list of parameters
- */
- public ChartParameters(Map<String, String> params) {
- this.params = params;
- }
-
- /**
- * Creates a Chartparameter based on a query string with a format key1=value1&key2=value2...
- *
- * @param queryString string
- */
- public ChartParameters(String queryString) {
- this.params = new HashMap<>();
- String[] groups = StringUtils.split(queryString, "&");
- for (String group : groups) {
- String[] keyval = StringUtils.split(group, "=");
- params.put(keyval[0], keyval[1]);
- }
- }
-
- /**
- * Shortcut to getValue with no decoding and no default value
- * @param key the param ket
- * @return the value of the param
- */
- public String getValue(String key) {
- return getValue(key, "", false);
- }
-
- /**
- * Returns the [decoded or not] value of a param from its key or the default value
- * if id does not exist
- *
- * @param key the param ket
- * @param defaultValue the default value if not exist
- * @param decode whther the value should be decoded
- * @return the value of the param
- */
-
- public String getValue(String key, String defaultValue, boolean decode) {
- String val = params.get(key);
- if (decode) {
- val = decode(val);
- }
- if (val == null) {
- val = defaultValue;
- }
- return val;
- }
-
- /**
- * Returns an array of a param values, given its key and the values delimiter
- *
- * @param key the param key
- * @param delimiter the values delimiter
- * @return the list of vaalues
- */
- public String[] getValues(String key, String delimiter) {
- String value = params.get(key);
- if (value != null) {
- return StringUtils.split(value, delimiter);
- }
- return EMPTY;
- }
-
- /**
- * Returns an array of a param values, given its key and the values delimiter
- * Values can be decoded or not
- *
- * @param key the param key
- * @param delimiter the values delimiter
- * @param decode whether to decode values
- * @return the list of vaalues
- */
- public String[] getValues(String key, String delimiter, boolean decode) {
- String value = params.get(key);
- if (value != null) {
- if (decode) {
- value = decode(value);
- }
- return new StrTokenizer(value, delimiter).setIgnoreEmptyTokens(false).getTokenArray();
- }
- return EMPTY;
- }
-
- /**
- * Get the chart width
- *
- * @return width
- */
- public int getWidth() {
- int width = Integer.parseInt(getValue(PARAM_WIDTH, Integer.toString(DEFAULT_WIDTH), false));
- return Math.min(width, MAX_WIDTH);
- }
-
- /**
- * Get the chart height
- *
- * @return height
- */
- public int getHeight() {
- int height = Integer.parseInt(getValue(PARAM_HEIGHT, Integer.toString(DEFAULT_HEIGHT), false));
- return Math.min(height, MAX_HEIGHT);
- }
-
- /**
- * Get the Locale
- *
- * @return Locale
- */
- public Locale getLocale() {
- String locale = getValue(PARAM_LOCALE);
- if (StringUtils.isNotBlank(locale)) {
- return new Locale(locale);
- }
- return Locale.ENGLISH;
- }
-
- private static String decode(@Nullable String val) {
- if (val != null) {
- try {
- val = URLDecoder.decode(val, CharEncoding.UTF_8);
- } catch (UnsupportedEncodingException e) {
- throw new SonarException("Decoding chart parameter : " + val, e);
- }
- }
- return val;
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.api.charts;
-
-import javax.annotation.ParametersAreNonnullByDefault;
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.api.charts;
-
-import org.junit.Test;
-
-import java.util.Locale;
-
-import static org.junit.Assert.*;
-
-public class ChartParametersTest {
- @Test
- public void shouldForbidHighSizeForSecurityReasons() {
- String url = ChartParameters.PARAM_WIDTH + "=100000&" + ChartParameters.PARAM_HEIGHT + "=9999999";
- ChartParameters params = new ChartParameters(url);
- assertEquals(ChartParameters.MAX_WIDTH, params.getWidth());
- assertEquals(ChartParameters.MAX_HEIGHT, params.getHeight());
- }
-
- @Test
- public void shouldReadImageSizeFromParameters() {
- String url = ChartParameters.PARAM_WIDTH + "=200&" + ChartParameters.PARAM_HEIGHT + "=300";
- ChartParameters params = new ChartParameters(url);
- assertEquals(200, params.getWidth());
- assertEquals(300, params.getHeight());
- }
-
- @Test
- public void shouldGetDefaultSizesIfNoParameters() {
- ChartParameters params = new ChartParameters("foo=bar");
- assertEquals(ChartParameters.DEFAULT_WIDTH, params.getWidth());
- assertEquals(ChartParameters.DEFAULT_HEIGHT, params.getHeight());
- }
-
- @Test
- public void shouldDecodeValue() {
- ChartParameters params = new ChartParameters("foo=0%3D10,3%3D8");
- assertEquals("0=10,3=8", params.getValue("foo", "", true));
- assertEquals("0%3D10,3%3D8", params.getValue("foo"));
- assertNull(params.getValue("bar", null, true));
- }
-
- @Test
- public void shouldDecodeValues() {
- ChartParameters params = new ChartParameters("foo=0%3D10,3%3D8|5%3D5,7%3D17");
- assertArrayEquals(new String[]{"0%3D10,3%3D8", "5%3D5,7%3D17"}, params.getValues("foo", "|"));
- assertArrayEquals(new String[]{"0=10,3=8", "5=5,7=17"}, params.getValues("foo", "|", true));
- assertArrayEquals(new String[0], params.getValues("bar", "|", true));
- }
-
- @Test
- public void getLocale() {
- ChartParameters params = new ChartParameters("foo=0&locale=fr");
- assertEquals(Locale.FRENCH, params.getLocale());
-
- params = new ChartParameters("foo=0&locale=fr-CH");
- assertEquals("fr-ch", params.getLocale().getLanguage());
-
- params = new ChartParameters("foo=0");
- assertEquals(Locale.ENGLISH, params.getLocale());
- }
-}