Example usage for org.jfree.chart.urls CategoryURLGenerator CategoryURLGenerator

List of usage examples for org.jfree.chart.urls CategoryURLGenerator CategoryURLGenerator

Introduction

In this page you can find the example usage for org.jfree.chart.urls CategoryURLGenerator CategoryURLGenerator.

Prototype

CategoryURLGenerator

Source Link

Usage

From source file:org.openfaces.component.chart.impl.configuration.UrlsConfigurator.java

private void setupUrls(final GridChartView chartView, AbstractCategoryItemRenderer renderer) {
    if (chartView.getUrl() != null) {
        renderer.setItemURLGenerator(new CategoryURLGenerator() {
            public String generateURL(CategoryDataset categoryDataset, int i, int i1) {
                return chartView.getUrl();
            }/*from   w ww . java 2 s .  c om*/
        });
    } else if (chartView.getDynamicUrl() != null) {
        renderer.setItemURLGenerator(new DynamicCategoryGenerator(chartView, chartView.getDynamicUrl()));
    }
}

From source file:edu.jhuapl.graphs.jfreechart.CategoryBarGraphRenderer.java

private void setupItemGenerators() {
    setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        @Override/*ww w .  j a va 2  s .c  om*/
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            return itemProperty.get(row, column, String.class, null, GraphSource.ITEM_TOOL_TIP);
        }
    });

    setBaseItemURLGenerator(new CategoryURLGenerator() {
        @Override
        public String generateURL(CategoryDataset dataset, int series, int category) {
            return itemProperty.get(series, category, String.class, null, GraphSource.ITEM_URL);
        }
    });
}

From source file:com.greenpepper.confluence.macros.historic.AggregationExecutionChartBuilder.java

private void customizeChart(JFreeChart chart) throws IOException {
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(settings.isBorder());

    TextTitle chartTitle = chart.getTitle();
    customizeTitle(chartTitle, DEFAULT_TITLE_FONT);

    addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT);
    addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setNoDataMessage(gpUtil.getText("greenpepper.historic.nodata"));

    StackedBarRenderer renderer = new StackedBarRenderer(true);
    plot.setRenderer(renderer);/*  w  w w .j  a va 2 s . c o  m*/

    int index = 0;
    renderer.setSeriesPaint(index++, GREEN_COLOR);
    if (settings.isShowIgnored())
        renderer.setSeriesPaint(index++, Color.yellow);
    renderer.setSeriesPaint(index, Color.red);

    renderer.setToolTipGenerator(new DefaultTooltipGenerator());
    renderer.setItemURLGenerator(new CategoryURLGenerator() {

        public String generateURL(CategoryDataset data, int series, int category) {
            Comparable valueKey = data.getColumnKey(category);
            ChartLongValue value = (ChartLongValue) valueKey;
            return "javascript:" + settings.getExecutionUID() + "_showHistoricChart('" + value.getId() + "');";
        }
    });

    CategoryAxis domainAxis = plot.getDomainAxis();
    customizeAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setCategoryMargin(0.01);

    ValueAxis rangeAxis = plot.getRangeAxis();
    customizeAxis(rangeAxis);
    rangeAxis.setLowerBound(0);
    rangeAxis.setUpperBound(1.0);

    if (rangeAxis instanceof NumberAxis) {
        NumberAxis numberAxis = (NumberAxis) rangeAxis;
        numberAxis.setTickUnit(new NumberTickUnit(.10));
        numberAxis.setNumberFormatOverride(PERCENT_FORMATTER);
    }

    plot.setForegroundAlpha(0.8f);
}

From source file:com.greenpepper.confluence.macros.historic.LinearExecutionChartBuilder.java

private void customizeChart(JFreeChart chart) throws IOException {
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(settings.isBorder());

    TextTitle chartTitle = chart.getTitle();
    customizeTitle(chartTitle, DEFAULT_TITLE_FONT);

    addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT);
    addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setNoDataMessage(gpUtil.getText("greenpepper.historic.nodata"));

    CategoryItemRenderer renderer = plot.getRenderer();

    int index = 0;
    renderer.setSeriesPaint(index++, GREEN_COLOR);
    if (settings.isShowIgnored())
        renderer.setSeriesPaint(index++, Color.yellow);
    renderer.setSeriesPaint(index, Color.red);

    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    renderer.setItemURLGenerator(new CategoryURLGenerator() {

        public String generateURL(CategoryDataset data, int series, int category) {
            Comparable valueKey = data.getColumnKey(category);
            ChartLongValue value = (ChartLongValue) valueKey;
            return "javascript:" + settings.getExecutionUID() + "_showExecutionResult('" + value.getId()
                    + "');";
        }//from   w  w w. j a v a2  s .  c  o  m
    });

    CategoryAxis domainAxis = plot.getDomainAxis();
    customizeAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);

    ValueAxis rangeAxis = plot.getRangeAxis();
    customizeAxis(rangeAxis);
    rangeAxis.setLowerBound(0);

    if (rangeAxis instanceof NumberAxis) {
        ((NumberAxis) rangeAxis).setTickUnit(new NumberTickUnit(1));
    }

    plot.setForegroundAlpha(0.8f);
}

From source file:info.novatec.testit.livingdoc.confluence.macros.historic.AggregationExecutionChartBuilder.java

@SuppressWarnings("deprecation")
private void customizeChart(JFreeChart chart) throws IOException {
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(settings.isBorder());

    TextTitle chartTitle = chart.getTitle();
    customizeTitle(chartTitle, DEFAULT_TITLE_FONT);

    addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT);
    addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setNoDataMessage(ldUtil.getText("livingdoc.historic.nodata"));

    StackedBarRenderer renderer = new StackedBarRenderer(true);
    plot.setRenderer(renderer);// w ww .  ja va2 s  . c om

    int index = 0;
    renderer.setSeriesPaint(index++, GREEN_COLOR);
    if (settings.isShowIgnored()) {
        renderer.setSeriesPaint(index++, Color.yellow);
    }
    renderer.setSeriesPaint(index, Color.red);

    renderer.setToolTipGenerator(new DefaultTooltipGenerator());
    renderer.setItemURLGenerator(new CategoryURLGenerator() {

        @Override
        public String generateURL(CategoryDataset data, int series, int category) {
            Comparable<?> valueKey = data.getColumnKey(category);
            ChartLongValue value = (ChartLongValue) valueKey;
            return "javascript:" + settings.getExecutionUID() + "_showHistoricChart('" + value.getId() + "');";
        }
    });

    CategoryAxis domainAxis = plot.getDomainAxis();
    customizeAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setCategoryMargin(0.01);

    ValueAxis rangeAxis = plot.getRangeAxis();
    customizeAxis(rangeAxis);
    rangeAxis.setLowerBound(0);
    rangeAxis.setUpperBound(1.0);

    if (rangeAxis instanceof NumberAxis) {
        NumberAxis numberAxis = (NumberAxis) rangeAxis;
        numberAxis.setTickUnit(new NumberTickUnit(.10));
        numberAxis.setNumberFormatOverride(PERCENT_FORMATTER);
    }

    plot.setForegroundAlpha(0.8f);
}

From source file:info.novatec.testit.livingdoc.confluence.macros.historic.LinearExecutionChartBuilder.java

@SuppressWarnings("deprecation")
private void customizeChart(JFreeChart chart) {
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(settings.isBorder());

    TextTitle chartTitle = chart.getTitle();
    customizeTitle(chartTitle, DEFAULT_TITLE_FONT);

    addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT);
    addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setNoDataMessage(ldUtil.getText("livingdoc.historic.nodata"));

    CategoryItemRenderer renderer = plot.getRenderer();

    int index = 0;
    renderer.setSeriesPaint(index++, GREEN_COLOR);
    if (settings.isShowIgnored()) {
        renderer.setSeriesPaint(index++, Color.yellow);
    }/*www  .ja  va2  s  .  c  o m*/
    renderer.setSeriesPaint(index, Color.red);

    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    renderer.setItemURLGenerator(new CategoryURLGenerator() {

        @Override
        public String generateURL(CategoryDataset data, int series, int category) {
            Comparable<?> valueKey = data.getColumnKey(category);
            ChartLongValue value = (ChartLongValue) valueKey;
            return "javascript:" + settings.getExecutionUID() + "_showExecutionResult('" + value.getId()
                    + "');";
        }
    });

    CategoryAxis domainAxis = plot.getDomainAxis();
    customizeAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);

    ValueAxis rangeAxis = plot.getRangeAxis();
    customizeAxis(rangeAxis);
    rangeAxis.setLowerBound(0);

    if (rangeAxis instanceof NumberAxis) {
        ((NumberAxis) rangeAxis).setTickUnit(new NumberTickUnit(1));
    }

    plot.setForegroundAlpha(0.8f);
}

From source file:org.tap4j.plugin.util.GraphHelper.java

/**
 * Creates the graph displayed on Method results page to compare execution
 * duration and status of a test method across builds.
 * /*from   w w  w  .  j a  v  a  2  s  .  co  m*/
 * At max, 9 older builds are displayed.
 * 
 * @param req
 *            request
 * @param dataset
 *            data set to be displayed on the graph
 * @param statusMap
 *            a map with build as key and the test methods execution status
 *            (result) as the value
 * @param methodUrl
 *            URL to get to the method from a build test result page
 * @return the chart
 */
public static JFreeChart createMethodChart(StaplerRequest req, final CategoryDataset dataset,
        final Map<NumberOnlyBuildLabel, String> statusMap, final String methodUrl) {

    final JFreeChart chart = ChartFactory.createBarChart(null, // chart
            // title
            null, // unused
            " Duration (secs)", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            true // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    chart.removeLegend();

    final CategoryPlot plot = chart.getCategoryPlot();
    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());

    BarRenderer br = new BarRenderer() {

        private static final long serialVersionUID = 961671076462240008L;
        Map<String, Paint> statusPaintMap = new HashMap<String, Paint>();

        {
            statusPaintMap.put("PASS", ColorPalette.BLUE);
            statusPaintMap.put("SKIP", ColorPalette.YELLOW);
            statusPaintMap.put("FAIL", ColorPalette.RED);
        }

        /**
         * Returns the paint for an item. Overrides the default behavior
         * inherited from AbstractSeriesRenderer.
         * 
         * @param row
         *            the series.
         * @param column
         *            the category.
         * 
         * @return The item color.
         */
        public Paint getItemPaint(final int row, final int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            Paint paint = statusPaintMap.get(statusMap.get(label));
            // when the status of test method is unknown, use gray color
            return paint == null ? Color.gray : paint;
        }
    };

    br.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            if ("UNKNOWN".equals(statusMap.get(label))) {
                return "unknown";
            }
            // values are in seconds
            return dataset.getValue(row, column) + " secs";
        }
    });

    br.setBaseItemURLGenerator(new CategoryURLGenerator() {
        public String generateURL(CategoryDataset dataset, int series, int category) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(category);
            if ("UNKNOWN".equals(statusMap.get(label))) {
                // no link when method result doesn't exist
                return null;
            }
            // return label.build.getUpUrl() + label.build.getNumber() + "/" + PluginImpl.URL + "/" + methodUrl;
            return label.build.getUpUrl() + label.build.getNumber() + "/tap/" + methodUrl;
        }
    });

    br.setItemMargin(0.0);
    br.setMinimumBarLength(5);
    // set the base to be 1/100th of the maximum value displayed in the
    // graph
    br.setBase(br.findRangeBounds(dataset).getUpperBound() / 100);
    plot.setRenderer(br);

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

From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java

private void initCategoryPlot(JFreeChart chart, ChartModel chartModel,
        final IChartLinkGenerator linkGenerator) {
    initPlot(chart, chartModel);/* w  ww .  ja  v a2s . c o  m*/

    org.pentaho.chart.model.TwoAxisPlot twoAxisPlot = (org.pentaho.chart.model.TwoAxisPlot) chartModel
            .getPlot();
    CategoryPlot categoryPlot = chart.getCategoryPlot();

    Grid grid = twoAxisPlot.getGrid();
    if (twoAxisPlot.getOrientation() != Orientation.HORIZONTAL) {
        Color color = (grid.getVerticalLineColor() != null ? new Color(0x00FFFFFF & grid.getVerticalLineColor())
                : new Color(0x00FFFFFF & Grid.DEFAULT_GRID_COLOR));
        categoryPlot.setDomainGridlinesVisible(grid.getVerticalLinesVisible());
        categoryPlot.setDomainGridlinePaint(color);

        color = (grid.getHorizontalLineColor() != null ? new Color(0x00FFFFFF & grid.getHorizontalLineColor())
                : new Color(0x00FFFFFF & Grid.DEFAULT_GRID_COLOR));
        categoryPlot.setRangeGridlinesVisible(grid.getHorizontalLinesVisible());
        categoryPlot.setRangeGridlinePaint(color);
    } else {
        Color color = (grid.getHorizontalLineColor() != null
                ? new Color(0x00FFFFFF & grid.getHorizontalLineColor())
                : new Color(0x00FFFFFF & Grid.DEFAULT_GRID_COLOR));
        categoryPlot.setDomainGridlinesVisible(grid.getHorizontalLinesVisible());
        categoryPlot.setDomainGridlinePaint(color);

        color = (grid.getVerticalLineColor() != null ? new Color(0x00FFFFFF & grid.getVerticalLineColor())
                : new Color(0x00FFFFFF & Grid.DEFAULT_GRID_COLOR));
        categoryPlot.setRangeGridlinesVisible(grid.getVerticalLinesVisible());
        categoryPlot.setRangeGridlinePaint(color);
    }

    categoryPlot.setDomainGridlineStroke(new BasicStroke(1));
    categoryPlot.setRangeGridlineStroke(new BasicStroke(1));

    List<Integer> colors = getPlotColors(twoAxisPlot);

    for (int j = 0; j < categoryPlot.getDatasetCount(); j++) {
        if (linkGenerator != null) {
            categoryPlot.getRenderer(j).setBaseItemURLGenerator(new CategoryURLGenerator() {
                public String generateURL(CategoryDataset dataset, int series, int category) {
                    return linkGenerator.generateLink(dataset.getRowKey(series).toString(),
                            dataset.getColumnKey(category).toString(), dataset.getValue(series, category));
                }
            });
        }
        for (int i = 0; i < colors.size(); i++) {
            categoryPlot.getRenderer(j).setSeriesPaint(i, new Color(0x00FFFFFF & colors.get(i)));
        }
    }

    Font domainAxisFont = ChartUtils.getFont(twoAxisPlot.getDomainAxis().getFontFamily(),
            twoAxisPlot.getDomainAxis().getFontStyle(), twoAxisPlot.getDomainAxis().getFontWeight(),
            twoAxisPlot.getDomainAxis().getFontSize());
    Font rangeAxisFont = ChartUtils.getFont(twoAxisPlot.getRangeAxis().getFontFamily(),
            twoAxisPlot.getRangeAxis().getFontStyle(), twoAxisPlot.getRangeAxis().getFontWeight(),
            twoAxisPlot.getRangeAxis().getFontSize());
    Font rangeTitleFont = ChartUtils.getFont(twoAxisPlot.getRangeAxis().getLegend().getFontFamily(),
            twoAxisPlot.getRangeAxis().getLegend().getFontStyle(),
            twoAxisPlot.getRangeAxis().getLegend().getFontWeight(),
            twoAxisPlot.getRangeAxis().getLegend().getFontSize());
    Font domainTitleFont = ChartUtils.getFont(twoAxisPlot.getDomainAxis().getLegend().getFontFamily(),
            twoAxisPlot.getDomainAxis().getLegend().getFontStyle(),
            twoAxisPlot.getDomainAxis().getLegend().getFontWeight(),
            twoAxisPlot.getDomainAxis().getLegend().getFontSize());

    CategoryAxis domainAxis = categoryPlot.getDomainAxis();
    ValueAxis rangeAxis = categoryPlot.getRangeAxis();

    AxesLabels axesLabels = getAxesLabels(chartModel);
    if ((axesLabels.rangeAxisLabel.length() > 0) && (rangeTitleFont != null)) {
        rangeAxis.setLabelFont(rangeTitleFont);
    }

    if ((axesLabels.domainAxisLabel.length() > 0) && (domainTitleFont != null)) {
        domainAxis.setLabelFont(domainTitleFont);
    }

    LabelOrientation labelOrientation = twoAxisPlot.getHorizontalAxis().getLabelOrientation();
    if ((labelOrientation != null) && (labelOrientation != LabelOrientation.HORIZONTAL)) {
        if (twoAxisPlot.getOrientation() == Orientation.HORIZONTAL) {
            if (labelOrientation == LabelOrientation.VERTICAL) {
                rangeAxis.setVerticalTickLabels(true);
            }
        } else {
            switch (labelOrientation) {
            case VERTICAL:
                domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
                break;
            case DIAGONAL:
                domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
                break;
            }
        }
    }

    if (domainAxisFont != null) {
        domainAxis.setTickLabelFont(domainAxisFont);
    }
    if (rangeAxisFont != null) {
        rangeAxis.setTickLabelFont(rangeAxisFont);
    }

    Number rangeMin = twoAxisPlot.getRangeAxis().getMinValue();
    if (rangeMin != null) {
        rangeAxis.setLowerBound(rangeMin.doubleValue());
    }
    Number rangeMax = twoAxisPlot.getRangeAxis().getMaxValue();
    if (rangeMax != null) {
        rangeAxis.setUpperBound(rangeMax.doubleValue());
    }
}