Example usage for org.jfree.data.category CategoryDataset getColumnKey

List of usage examples for org.jfree.data.category CategoryDataset getColumnKey

Introduction

In this page you can find the example usage for org.jfree.data.category CategoryDataset getColumnKey.

Prototype

public Comparable getColumnKey(int column);

Source Link

Document

Returns the column key for a given index.

Usage

From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java

public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataSet, int row, int column, int pass) {
    if (!getItemVisible(row, column)) {
        return;/*from  w  w  w. j a va2 s.com*/
    }

    Number value = dataSet.getValue(row, column);
    int visibleRow = state.getVisibleSeriesIndex(row);
    if ((value == null || visibleRow < 0)) {
        return;
    }

    LineFillItemRendererState rendererState = (LineFillItemRendererState) state;
    double currentValue = value.doubleValue();
    double currentItemXPoint = calculateItemXPoint(plot, dataSet, domainAxis, dataArea, column, visibleRow,
            state.getVisibleSeriesCount());
    double currentItemYPoint = calculateItemYPoint(plot, rangeAxis, dataArea, currentValue);

    if (isAreaAndLinePass(pass)) {
        processAreaAndLine(dataArea, plot, domainAxis, rangeAxis, dataSet, rendererState, row, column,
                currentValue, currentItemXPoint, currentItemYPoint, visibleRow);
    } else if (isShapesAndLabelsPass(pass)) {
        Shape entityArea = renderItemShapeAndLabel(g2, dataSet, row, column, plot.getOrientation(),
                currentValue, currentItemXPoint, currentItemYPoint);

        int dataSetIndex = plot.indexOf(dataSet);
        updateCrosshairValues(state.getCrosshairState(), dataSet.getRowKey(row), dataSet.getColumnKey(column),
                currentValue, dataSetIndex, currentItemXPoint, currentItemYPoint, plot.getOrientation());

        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addItemEntity(entities, dataSet, row, column, entityArea);
        }
    }

}

From source file:edu.dlnu.liuwenpeng.render.LineAndShapeRenderer.java

public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {
    ls.add(dataset.getValue(0, column).doubleValue());

    if (!getItemVisible(row, column)) {
        return;/*from w  w  w  . j  a v a  2  s .co  m*/
    }

    if (!getItemLineVisible(row, column) && !getItemShapeVisible(row, column)) {
        return;
    }

    // nothing is drawn for null...    
    Number v = dataset.getValue(row, column);
    if (v == null) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();

    // current data point...    
    double x1;
    if (this.useSeriesOffset) {
        x1 = domainAxis.getCategorySeriesMiddle(dataset.getColumnKey(column), dataset.getRowKey(row), dataset,
                this.itemMargin, dataArea, plot.getDomainAxisEdge());
    } else {
        x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    }
    double value = v.doubleValue();
    double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());

    if (pass == 0 && getItemLineVisible(row, column)) {
        if (column != 0) {
            Number previousValue = dataset.getValue(row, column - 1);
            if (previousValue != null) {
                // previous data point...    
                double previous = previousValue.doubleValue();
                double x0;
                if (this.useSeriesOffset) {
                    x0 = domainAxis.getCategorySeriesMiddle(dataset.getColumnKey(column - 1),
                            dataset.getRowKey(row), dataset, this.itemMargin, dataArea,
                            plot.getDomainAxisEdge());
                } else {
                    x0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea,
                            plot.getDomainAxisEdge());
                }
                double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge());

                Line2D line = null;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    line = new Line2D.Double(y0, x0, y1, x1);
                } else if (orientation == PlotOrientation.VERTICAL) {
                    line = new Line2D.Double(x0, y0, x1, y1);
                }
                g2.setPaint(getItemPaint(row, column));
                g2.setStroke(getItemStroke(row, column));
                g2.draw(line);
            }
        }
    }

    if (pass == 1) {
        Shape shape = getItemShape(row, column);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
        }

        if (getItemShapeVisible(row, column)) {
            if (getItemShapeFilled(row, column)) {
                if (this.useFillPaint) {
                    g2.setPaint(getItemFillPaint(row, column));
                } else {
                    g2.setPaint(getItemPaint(row, column));
                }
                g2.fill(shape);
            }
            if (this.drawOutlines) {
                if (this.useOutlinePaint) {
                    g2.setPaint(getItemOutlinePaint(row, column));
                } else {
                    g2.setPaint(getItemPaint(row, column));
                }
                g2.setStroke(getItemOutlineStroke(row, column));
                g2.draw(shape);

            }
        }

        // draw the item label if there is one...    
        if (isItemLabelVisible(row, column)) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, row, column, y1, x1, (value < 0.0));
            } else if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, row, column, x1, y1, (value < 0.0));
            }
        }

        // add an item entity, if this information is being collected    
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addItemEntity(entities, dataset, row, column, shape);
        }
    }
    if (i == dataset.getColumnCount() - 1) {
        average = GetAverage.getAverage(ls);

        double averangeline = rangeAxis.valueToJava2D(average, dataArea, plot.getRangeAxisEdge());
        double x = rangeAxis.valueToJava2D(dataset.getColumnCount() - 1, dataArea, plot.getDomainAxisEdge());
        Line2D line2d = new Line2D.Double(0, averangeline, x, averangeline);
        g2.setPaint(Color.white);
        g2.draw(line2d);
        i = 0;
        ls.clear();
    }
    i++;
}

From source file:hudson.plugins.labeledgroupedtests.TrendGraph.java

protected JFreeChart createGraph() {
    final CategoryDataset dataset = createDataSet().build();

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart
            // title
            null, // unused
            yLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );//w w w .j a  v  a2  s.  co m

    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());
    rangeAxis.setAutoRange(true);

    StackedAreaRenderer ar = new StackedAreaRenderer2() {
        @Override
        public Paint getItemPaint(int row, int column) {
            ChartLabel key = (ChartLabel) dataset.getColumnKey(column);
            if (key.getColor() != null)
                return key.getColor();
            return super.getItemPaint(row, column);
        }

        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getURL() + relativeUrl;
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getToolTipText();
        }
    };
    plot.setRenderer(ar);

    ar.setSeriesPaint(0, ColorPalette.RED); // Skips.
    ar.setSeriesPaint(1, ColorPalette.YELLOW); // Failures.
    ar.setSeriesPaint(2, ColorPalette.BLUE); // Total.

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    return chart;
}

From source file:com.cwctravel.hudson.plugins.suitegroupedtests.TrendGraph.java

@Override
protected JFreeChart createGraph() {
    final CategoryDataset dataset = createDataSet().build();

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart
            // title
            null, // unused
            yLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );/* w  w  w .j  av a 2  s .com*/

    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());
    rangeAxis.setAutoRange(true);

    StackedAreaRenderer ar = new StackedAreaRenderer2() {
        private static final long serialVersionUID = 7962375662395944968L;

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

        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getURL() + relativeUrl;
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getToolTipText();
        }
    };
    plot.setRenderer(ar);

    ar.setSeriesPaint(0, ColorPalette.RED); // Skips.
    ar.setSeriesPaint(1, ColorPalette.YELLOW); // Failures.
    ar.setSeriesPaint(2, ColorPalette.BLUE); // Total.

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    return chart;
}

From source file:com.cwctravel.hudson.plugins.multimoduletests.TrendGraph.java

@Override
protected JFreeChart createGraph() {
    final CategoryDataset dataset = createDataSet().build();

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart
            // title
            null, // unused
            yLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );/*from w ww.  ja  v a2 s.  c om*/

    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());
    rangeAxis.setAutoRange(true);

    StackedAreaRenderer ar = new StackedAreaRenderer2() {
        private static final long serialVersionUID = 7962375662395944968L;

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

        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return prefixUrl + label.getURL() + suffixUrl;
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getToolTipText();
        }
    };
    plot.setRenderer(ar);

    ar.setSeriesPaint(0, ColorPalette.RED); // Skips.
    ar.setSeriesPaint(1, ColorPalette.YELLOW); // Failures.
    ar.setSeriesPaint(2, ColorPalette.BLUE); // Total.

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    return chart;
}

From source file:hudson.plugins.measurement_plots.Graph.java

protected org.jfree.chart.JFreeChart createGraph() {
    final org.jfree.data.category.CategoryDataset dataset = getDataSetBuilder().build();

    final org.jfree.chart.JFreeChart chart = org.jfree.chart.ChartFactory.createStackedAreaChart(title, // chart title
            null, // unused
            null, // range axis label
            dataset, // data
            org.jfree.chart.plot.PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );/*from w  w  w . java 2  s.c om*/

    chart.setBackgroundPaint(java.awt.Color.white);

    final org.jfree.chart.plot.CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    // plot.setDomainGridlinesVisible(true);
    // plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(java.awt.Color.black);

    org.jfree.chart.axis.CategoryAxis domainAxis = new hudson.util.ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(org.jfree.chart.axis.CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    final org.jfree.chart.axis.NumberAxis rangeAxis = (org.jfree.chart.axis.NumberAxis) plot.getRangeAxis();
    hudson.util.ChartUtil.adjustChebyshev(dataset, rangeAxis);
    rangeAxis.setStandardTickUnits(org.jfree.chart.axis.NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRange(true);

    org.jfree.chart.renderer.category.StackedAreaRenderer areaRenderer = new hudson.util.StackedAreaRenderer2() {

        @Override
        public java.awt.Paint getItemPaint(int row, int column) {
            GraphLabel key = (GraphLabel) dataset.getColumnKey(column);
            if (key.getColor() != null) {
                return key.getColor();
            }
            return super.getItemPaint(row, column);
        }

        @Override
        public String generateURL(org.jfree.data.category.CategoryDataset dataset, int row, int column) {
            GraphLabel label = (GraphLabel) dataset.getColumnKey(column);
            return label.getUrl();
        }

        @Override
        public String generateToolTip(org.jfree.data.category.CategoryDataset dataset, int row, int column) {
            GraphLabel label = (GraphLabel) dataset.getColumnKey(column);
            return label.getToolTip();
        }
    };
    plot.setRenderer(areaRenderer);
    areaRenderer.setSeriesPaint(2, hudson.util.ColorPalette.BLUE);

    // crop extra space around the graph
    plot.setInsets(new org.jfree.ui.RectangleInsets(0, 0, 0, 5.0));

    return chart;
}

From source file:hudson.tasks.test.AbstractTestResultAction.java

private JFreeChart createChart(StaplerRequest req, CategoryDataset dataset) {

    final String relPath = getRelPath(req);

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title
            null, // unused
            "count", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );/*  w  w w . j ava  2 s  .c o  m*/

    // 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.getRun().getNumber() + "/testReport/";
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            AbstractTestResultAction a = label.getRun().getAction(AbstractTestResultAction.class);
            switch (row) {
            case 0:
                return String.valueOf(Messages.AbstractTestResultAction_fail(label.getRun().getDisplayName(),
                        a.getFailCount()));
            case 1:
                return String.valueOf(Messages.AbstractTestResultAction_skip(label.getRun().getDisplayName(),
                        a.getSkipCount()));
            default:
                return String.valueOf(Messages.AbstractTestResultAction_test(label.getRun().getDisplayName(),
                        a.getTotalCount()));
            }
        }
    };
    plot.setRenderer(ar);
    ar.setSeriesPaint(0, ColorPalette.RED); // Failures.
    ar.setSeriesPaint(1, ColorPalette.YELLOW); // Skips.
    ar.setSeriesPaint(2, ColorPalette.BLUE); // Total.

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    return chart;
}

From source file:edu.cuny.jfree.chart.renderer.category.ValueListShapeRenderer.java

@Override
public void drawItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea,
        final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis,
        final CategoryDataset dataset, final int row, final int column, final int pass) {

    final ListCategoryDataset setData = (ListCategoryDataset) dataset;

    final List list = setData.getList(row, column);
    if (list == null) {
        return;/*from  ww  w. ja va2 s.  c om*/
    }

    final PlotOrientation orientation = plot.getOrientation();
    final double x = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());

    final Iterator iterator = list.iterator();
    while (iterator.hasNext()) {
        final Number value = (Number) iterator.next();
        final double y = rangeAxis.valueToJava2D(value.doubleValue(), dataArea, plot.getRangeAxisEdge());

        Shape shape = getItemShape(row, column);

        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y, x);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x, y);
        }
        if (getItemShapeVisible(row, column)) {
            if (getItemShapeFilled(row, column)) {
                g2.setPaint(getItemPaint(row, column));
                g2.fill(shape);
            } else {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(row, column));
                } else {
                    g2.setPaint(getItemPaint(row, column));
                }
                g2.setStroke(getItemOutlineStroke(row, column));
                g2.draw(shape);
            }
        }
        g2.setPaint(getItemPaint(row, column));

        if (isItemLabelVisible(row, column)) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, row, column, y, x, value.doubleValue() < 0.0D);
            } else if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, row, column, x, y, value.doubleValue() < 0.0D);
            }
        }

        if (state.getInfo() != null) {
            final EntityCollection entities = state.getEntityCollection();
            if ((entities != null) && (shape != null)) {
                String tip = null;
                final CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
                if (tipster != null) {
                    tip = tipster.generateToolTip(dataset, row, column);
                }
                String url = null;
                if (getItemURLGenerator(row, column) != null) {
                    url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
                }
                final CategoryItemEntity entity = new CategoryItemEntity(shape, tip, url, dataset,
                        dataset.getRowKey(row), dataset.getColumnKey(column));
                entities.add(entity);
            }
        }
    }
}

From source file:hudson.model.Job.java

public Graph getBuildTimeGraph() {
    return new Graph(getLastBuildTime(), 500, 400) {
        @Override//from w  w  w.  j  a v a2s  .  co  m
        protected JFreeChart createGraph() {
            class ChartLabel implements Comparable<ChartLabel> {
                final Run run;

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

                public int compareTo(ChartLabel that) {
                    return this.run.number - that.run.number;
                }

                @Override
                public boolean equals(Object o) {
                    // HUDSON-2682 workaround for Eclipse compilation bug
                    // 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 : getNewBuilds()) {
                if (r.isBuilding())
                    continue;
                data.add(((double) r.getDuration()) / (1000 * 60), "min", new ChartLabel(r));
            }

            final CategoryDataset dataset = data.build();

            final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart
                    // title
                    null, // unused
                    Messages.Job_minutes(), // range axis label
                    dataset, // data
                    PlotOrientation.VERTICAL, // orientation
                    false, // include legend
                    true, // tooltips
                    false // urls
            );

            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;
        }
    };
}

From source file:ro.nextreports.engine.util.chart.CylinderRenderer.java

/**
 * Draws a cylinder to represent one data item.
 * //from   w  ww. j a  v  a 2 s.c  o  m
 * @param g2 the graphics device.
 * @param state the renderer state.
 * @param dataArea the area for plotting the data.
 * @param plot the plot.
 * @param domainAxis the domain axis.
 * @param rangeAxis the range axis.
 * @param dataset the dataset.
 * @param row the row index (zero-based).
 * @param column the column index (zero-based).
 * @param pass the pass index.
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // check the value we are plotting...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    double value = dataValue.doubleValue();

    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(),
            dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());

    PlotOrientation orientation = plot.getOrientation();

    double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column);
    double[] barL0L1 = calculateBarL0L1(value);
    if (barL0L1 == null) {
        return; // the bar is not visible
    }

    RectangleEdge edge = plot.getRangeAxisEdge();
    float transL0 = (float) rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    float transL1 = (float) rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    float barL0 = Math.min(transL0, transL1);
    float barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    GeneralPath bar = new GeneralPath();
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar.moveTo(barL0, (float) barW0);
        bar.lineTo(barL0, (float) (barW0 + state.getBarWidth()));
        bar.lineTo(barL0 + barLength, (float) (barW0 + state.getBarWidth()));
        bar.lineTo(barL0 + barLength, (float) barW0);
        bar.closePath();
    } else {
        bar.moveTo((float) barW0, (float) (barL0 - getYOffset() / 2));
        bar.lineTo((float) barW0, (float) (barL0 + barLength - getYOffset() / 2));
        Arc2D arc = new Arc2D.Double(barW0, (barL0 + barLength - getYOffset()), state.getBarWidth(),
                getYOffset(), 180, 180, Arc2D.OPEN);
        bar.append(arc, true);
        bar.lineTo((float) (barW0 + state.getBarWidth()), (float) (barL0 - getYOffset() / 2));
        arc = new Arc2D.Double(barW0, (barL0 - getYOffset()), state.getBarWidth(), getYOffset(), 0, -180,
                Arc2D.OPEN);
        bar.append(arc, true);
        bar.closePath();
    }
    Paint itemPaint = getItemPaint(row, column);
    if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) itemPaint;
        itemPaint = getGradientPaintTransformer().transform(gp, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    Shape bar3dTop = new Ellipse2D.Double(barW0, barL0 - getYOffset(), state.getBarWidth(), getYOffset());
    if (itemPaint instanceof GradientPaint) {
        g2.setPaint(((GradientPaint) itemPaint).getColor2());
    }
    g2.fill(bar3dTop);

    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
        if (bar3dTop != null) {
            g2.draw(bar3dTop);
        }
    }

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar.getBounds2D(), (value < 0.0));
    }

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {

            String tip = null;
            CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
            if (tipster != null) {
                tip = tipster.generateToolTip(dataset, row, column);
            }
            String url = null;
            if (getItemURLGenerator(row, column) != null) {
                url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
            }
            CategoryItemEntity entity = new CategoryItemEntity(bar.getBounds2D(), tip, url, dataset,
                    dataset.getRowKey(row), dataset.getColumnKey(column));
            entities.add(entity);
        }
    }

}