Search in sources :

Example 1 with StackedAreaRenderer

use of org.jfree.chart.renderer.category.StackedAreaRenderer in project hudson-2.x by hudson.

the class Job method getBuildTimeGraph.

public Graph getBuildTimeGraph() {
    return new Graph(getLastBuild().getTimestamp(), 500, 400) {

        @Override
        protected JFreeChart createGraph() {
            class ChartLabel implements Comparable<ChartLabel> {

                final Run run;

                public ChartLabel(Run r) {
                    this.run = r;
                }

                public int compareTo(ChartLabel that) {
                    return Run.ORDER_BY_DATE.compare(that.run, run);
                }

                @Override
                public boolean equals(Object o) {
                    // on (c instanceof ChartLabel)
                    if (o == null || !ChartLabel.class.isAssignableFrom(o.getClass())) {
                        return false;
                    }
                    ChartLabel that = (ChartLabel) o;
                    return run == that.run;
                }

                public Color getColor() {
                    // TODO: consider gradation. See
                    // http://www.javadrive.jp/java2d/shape/index9.html
                    Result r = run.getResult();
                    if (r == Result.FAILURE)
                        return ColorPalette.RED;
                    else if (r == Result.UNSTABLE)
                        return ColorPalette.YELLOW;
                    else if (r == Result.ABORTED || r == Result.NOT_BUILT)
                        return ColorPalette.GREY;
                    else
                        return ColorPalette.BLUE;
                }

                @Override
                public int hashCode() {
                    return run.hashCode();
                }

                @Override
                public String toString() {
                    String l = run.getDisplayName();
                    if (run instanceof Build) {
                        String s = ((Build) run).getBuiltOnStr();
                        if (s != null)
                            l += ' ' + s;
                    }
                    return l;
                }
            }
            DataSetBuilder<String, ChartLabel> data = new DataSetBuilder<String, ChartLabel>();
            for (Run r : getBuilds()) {
                if (r.isBuilding())
                    continue;
                data.add(((double) r.getDuration()) / (1000 * 60), "min", new ChartLabel(r));
            }
            final CategoryDataset dataset = data.build();
            final JFreeChart chart = // chart
            ChartFactory.createStackedAreaChart(// chart
            null, // unused
            null, // range axis label
            Messages.Job_minutes(), // data
            dataset, // orientation
            PlotOrientation.VERTICAL, // include legend
            false, // tooltips
            true, // urls
            false);
            chart.setBackgroundPaint(Color.white);
            final CategoryPlot plot = chart.getCategoryPlot();
            // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
            plot.setBackgroundPaint(Color.WHITE);
            plot.setOutlinePaint(null);
            plot.setForegroundAlpha(0.8f);
            // plot.setDomainGridlinesVisible(true);
            // plot.setDomainGridlinePaint(Color.white);
            plot.setRangeGridlinesVisible(true);
            plot.setRangeGridlinePaint(Color.black);
            CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
            plot.setDomainAxis(domainAxis);
            domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
            domainAxis.setLowerMargin(0.0);
            domainAxis.setUpperMargin(0.0);
            domainAxis.setCategoryMargin(0.0);
            final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            ChartUtil.adjustChebyshev(dataset, rangeAxis);
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            StackedAreaRenderer ar = new StackedAreaRenderer2() {

                @Override
                public Paint getItemPaint(int row, int column) {
                    ChartLabel key = (ChartLabel) dataset.getColumnKey(column);
                    return key.getColor();
                }

                @Override
                public String generateURL(CategoryDataset dataset, int row, int column) {
                    ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
                    return String.valueOf(label.run.number);
                }

                @Override
                public String generateToolTip(CategoryDataset dataset, int row, int column) {
                    ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
                    return label.run.getDisplayName() + " : " + label.run.getDurationString();
                }
            };
            plot.setRenderer(ar);
            // crop extra space around the graph
            plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));
            return chart;
        }
    };
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) DataSetBuilder(hudson.util.DataSetBuilder) StackedAreaRenderer2(hudson.util.StackedAreaRenderer2) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer) ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) Graph(hudson.util.Graph) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) RectangleInsets(org.jfree.ui.RectangleInsets) JSONObject(net.sf.json.JSONObject)

Example 2 with StackedAreaRenderer

use of org.jfree.chart.renderer.category.StackedAreaRenderer in project violations-plugin by jenkinsci.

the class SeverityTypeDataSet method createChart.

/**
 * Create a JFree chart for this dataset.
 *
 * @return the chart.
 */
public JFreeChart createChart() {
    CategoryDataset dataset = buildDataSet();
    JFreeChart chart = // chart
    ChartFactory.createStackedAreaChart(// chart
    null, // unused
    null, // range axis label
    "count", // data
    dataset, // orientation
    PlotOrientation.VERTICAL, // include legend
    true, // tooltips
    true, // urls
    false);
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    final LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(ALPHA);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);
    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    if (Boolean.getBoolean(AbstractViolationsBuildAction.VIOLATIONS_PLUGIN_CHART_AUTORANGE_PROPERTY)) {
        rangeAxis.setAutoRange(true);
        rangeAxis.setAutoRangeIncludesZero(false);
        rangeAxis.setAutoRangeMinimumSize(50);
    }
    StackedAreaRenderer renderer = new StackedAreaRenderer2();
    plot.setRenderer(renderer);
    renderer.setSeriesPaint(2, RED);
    renderer.setSeriesPaint(1, VIOLET);
    renderer.setSeriesPaint(0, YELLOW);
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, INSET));
    return chart;
}
Also used : ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) RectangleInsets(org.jfree.ui.RectangleInsets) LegendTitle(org.jfree.chart.title.LegendTitle) StackedAreaRenderer2(hudson.util.StackedAreaRenderer2) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer)

Example 3 with StackedAreaRenderer

use of org.jfree.chart.renderer.category.StackedAreaRenderer in project Java-Matrix-Benchmark by lessthanoptimal.

the class OverallRelativeAreaPlot method addLibrary.

public void addLibrary(String name, int seriesIndex, double[] results) {
    for (int i = 0; i < sizeNames.length; i++) {
        double v = results[i];
        if (!Double.isNaN(v))
            dataset.addValue(v, name, sizeNames[i]);
    }
    StackedAreaRenderer renderer = (StackedAreaRenderer) plot.getRenderer();
    float STROKE_SIZE = 5f;
    // renderer.setSeriesPaint(numDataSets, OperationsVersusSizePlot.getColor(seriesIndex));
    renderer.setSeriesStroke(numDataSets, OperationsVersusSizePlot.getStroke(seriesIndex, STROKE_SIZE, STROKE_SIZE * 2));
    numDataSets++;
}
Also used : StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer)

Example 4 with StackedAreaRenderer

use of org.jfree.chart.renderer.category.StackedAreaRenderer in project hudson-2.x by hudson.

the class AbstractTestResultAction method createChart.

private JFreeChart createChart(StaplerRequest req, CategoryDataset dataset) {
    final String relPath = getRelPath(req);
    final JFreeChart chart = ChartFactory.createStackedAreaChart(// chart title
    null, // unused
    null, // range axis label
    "count", // data
    dataset, // orientation
    PlotOrientation.VERTICAL, // include legend
    false, // tooltips
    true, // urls
    false);
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    // set the background color for the chart...
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //        legend.setAnchor(StandardLegend.SOUTH);
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = chart.getCategoryPlot();
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    //        plot.setDomainGridlinesVisible(true);
    //        plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);
    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    StackedAreaRenderer ar = new StackedAreaRenderer2() {

        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            return relPath + label.build.getNumber() + "/testReport/";
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            AbstractTestResultAction a = label.build.getAction(AbstractTestResultAction.class);
            switch(row) {
                case 0:
                    return String.valueOf(Messages.AbstractTestResultAction_fail(label.build.getDisplayName(), a.getFailCount()));
                case 1:
                    return String.valueOf(Messages.AbstractTestResultAction_skip(label.build.getDisplayName(), a.getSkipCount()));
                default:
                    return String.valueOf(Messages.AbstractTestResultAction_test(label.build.getDisplayName(), a.getTotalCount()));
            }
        }
    };
    plot.setRenderer(ar);
    // Failures.
    ar.setSeriesPaint(0, ColorPalette.RED);
    // Skips.
    ar.setSeriesPaint(1, ColorPalette.YELLOW);
    // Total.
    ar.setSeriesPaint(2, ColorPalette.BLUE);
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));
    return chart;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) NumberOnlyBuildLabel(hudson.util.ChartUtil.NumberOnlyBuildLabel) CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) RectangleInsets(org.jfree.ui.RectangleInsets) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer)

Example 5 with StackedAreaRenderer

use of org.jfree.chart.renderer.category.StackedAreaRenderer in project processdash by dtuma.

the class AreaChart method createChart.

/** Create a line chart. */
public JFreeChart createChart() {
    JFreeChart chart;
    CategoryDataset catData = data.catDataSource();
    Object stacked = parameters.get("stacked");
    if (stacked != null) {
        chart = ChartFactory.createStackedAreaChart(null, null, null, catData, PlotOrientation.VERTICAL, true, true, false);
        if ("pct".equals(stacked)) {
            ((StackedAreaRenderer) chart.getCategoryPlot().getRenderer()).setRenderAsPercentages(true);
            DecimalFormat fmt = new DecimalFormat();
            fmt.setMultiplier(100);
            ((NumberAxis) chart.getCategoryPlot().getRangeAxis()).setNumberFormatOverride(fmt);
            if (parameters.get("units") == null)
                parameters.put("units", "%");
        }
    } else {
        chart = ChartFactory.createAreaChart(null, null, null, catData, PlotOrientation.VERTICAL, true, true, false);
    }
    setupCategoryChart(chart);
    Object colorScheme = parameters.get("colorScheme");
    if ("consistent".equals(colorScheme))
        configureConsistentColors(chart.getCategoryPlot(), catData);
    else if (parameters.containsKey("c1"))
        configureIndividualColors(chart.getCategoryPlot(), catData);
    return chart;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) DecimalFormat(java.text.DecimalFormat) JFreeChart(org.jfree.chart.JFreeChart) StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer)

Aggregations

StackedAreaRenderer (org.jfree.chart.renderer.category.StackedAreaRenderer)7 JFreeChart (org.jfree.chart.JFreeChart)6 NumberAxis (org.jfree.chart.axis.NumberAxis)5 CategoryPlot (org.jfree.chart.plot.CategoryPlot)5 CategoryAxis (org.jfree.chart.axis.CategoryAxis)4 CategoryDataset (org.jfree.data.category.CategoryDataset)4 RectangleInsets (org.jfree.ui.RectangleInsets)3 ShiftedCategoryAxis (hudson.util.ShiftedCategoryAxis)2 StackedAreaRenderer2 (hudson.util.StackedAreaRenderer2)2 NumberOnlyBuildLabel (hudson.util.ChartUtil.NumberOnlyBuildLabel)1 DataSetBuilder (hudson.util.DataSetBuilder)1 Graph (hudson.util.Graph)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1 JFrame (javax.swing.JFrame)1 JSONObject (net.sf.json.JSONObject)1 ChartPanel (org.jfree.chart.ChartPanel)1 ValueAxis (org.jfree.chart.axis.ValueAxis)1