Search in sources :

Example 11 with JFreeChart

use of org.jfree.chart.JFreeChart 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 12 with JFreeChart

use of org.jfree.chart.JFreeChart in project openblocks by mikaelhg.

the class CBarGraph method getOutputPanel.

public ChartPanel getOutputPanel() {
    //we return a copy of the chart because we only want to show the
    //legend in the larger view of the graph
    //not the small runtime graph block view
    JFreeChart newChart = new JFreeChart(chart.getPlot());
    newChart.getLegend().setPosition(RectangleEdge.TOP);
    newChart.getLegend().setPadding(5, 5, 5, 5);
    newChart.setBackgroundPaint(background);
    output = new ChartPanel(newChart);
    return output;
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) JFreeChart(org.jfree.chart.JFreeChart)

Example 13 with JFreeChart

use of org.jfree.chart.JFreeChart in project openblocks by mikaelhg.

the class CBarGraph method updateDomain.

public void updateDomain(String title, int seriesNum, Color background) {
    if (!lock) {
        this.chart = chartData.makeChart();
        this.background = background == null ? DEFAULT_BACKGROUND : background;
        this.chart.setBackgroundPaint(this.background);
        this.chart.setBorderPaint(null);
        if (output != null) {
            JFreeChart newChart = new JFreeChart(chart.getPlot());
            newChart.getLegend().setPosition(RectangleEdge.TOP);
            newChart.getLegend().setPadding(5, 5, 5, 5);
            newChart.setBackgroundPaint(background);
            output.setChart(newChart);
            output.invalidate();
            output.repaint();
        }
    }
}
Also used : JFreeChart(org.jfree.chart.JFreeChart)

Example 14 with JFreeChart

use of org.jfree.chart.JFreeChart in project openblocks by mikaelhg.

the class CLineGraph method updateDomain.

public void updateDomain(String title, int seriesNum, Color background) {
    if (!lock) {
        this.chartData.setSeriesNum(seriesNum);
        this.chart = chartData.makeChart();
        this.background = background == null ? DEFAULT_BACKGROUND : background;
        this.chart.setBackgroundPaint(this.background);
        this.chart.setBorderPaint(null);
        if (output != null) {
            JFreeChart newChart = new JFreeChart(chart.getPlot());
            newChart.getLegend().setPosition(RectangleEdge.TOP);
            newChart.getLegend().setPadding(5, 5, 5, 5);
            newChart.setBackgroundPaint(background);
            output.setChart(newChart);
            output.invalidate();
            output.repaint();
        }
    }
}
Also used : JFreeChart(org.jfree.chart.JFreeChart)

Example 15 with JFreeChart

use of org.jfree.chart.JFreeChart in project openblocks by mikaelhg.

the class CLineGraph method clearChart.

public void clearChart() {
    if (!lock) {
        this.chart = chartData.makeChart();
        this.chart.setBackgroundPaint(this.background);
        this.chart.setBorderPaint(null);
        if (output != null) {
            JFreeChart newChart = new JFreeChart(chart.getPlot());
            newChart.getLegend().setPosition(RectangleEdge.TOP);
            newChart.getLegend().setPadding(5, 5, 5, 5);
            newChart.setBackgroundPaint(background);
            output.setChart(newChart);
            output.invalidate();
            output.repaint();
        }
    }
}
Also used : JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

JFreeChart (org.jfree.chart.JFreeChart)178 XYPlot (org.jfree.chart.plot.XYPlot)40 NumberAxis (org.jfree.chart.axis.NumberAxis)26 Color (java.awt.Color)22 DateAxis (org.jfree.chart.axis.DateAxis)21 DecimalFormat (java.text.DecimalFormat)18 ChartPanel (org.jfree.chart.ChartPanel)17 XYSeries (org.jfree.data.xy.XYSeries)17 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)17 RectangleInsets (org.jfree.ui.RectangleInsets)17 NumberFormat (java.text.NumberFormat)16 CategoryAxis (org.jfree.chart.axis.CategoryAxis)16 CategoryPlot (org.jfree.chart.plot.CategoryPlot)16 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)13 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)13 HashMap (java.util.HashMap)12 ValueAxis (org.jfree.chart.axis.ValueAxis)12 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)11 CategoryDataset (org.jfree.data.category.CategoryDataset)11 Paint (java.awt.Paint)10