Example usage for org.jfree.chart.plot XYPlot addAnnotation

List of usage examples for org.jfree.chart.plot XYPlot addAnnotation

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot addAnnotation.

Prototype

public void addAnnotation(XYAnnotation annotation) 

Source Link

Document

Adds an annotation to the plot and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:org.owasp.benchmark.score.report.ScatterVulns.java

private void makeDataLabels(String category, Set<Report> toolResults, XYPlot xyplot) {
    HashMap<Point2D, String> map = makePointList(category, toolResults);
    for (Entry<Point2D, String> e : map.entrySet()) {
        if (e.getValue() != null) {
            Point2D p = e.getKey();
            String label = sort(e.getValue());
            XYTextAnnotation annotation = new XYTextAnnotation(label, p.getX(), p.getY());
            annotation.setTextAnchor(p.getX() < 3 ? TextAnchor.TOP_LEFT : TextAnchor.TOP_CENTER);
            annotation.setBackgroundPaint(Color.white);
            if (label.toCharArray()[0] == averageLabel) {
                annotation.setPaint(Color.magenta);
            } else {
                annotation.setPaint(Color.blue);
            }//  w  ww.  j  a v  a2 s.c  om
            annotation.setFont(theme.getRegularFont());
            xyplot.addAnnotation(annotation);
        }
    }
}

From source file:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java

/**
 *
 * @param fragments/* w  w w . j a va2s.  c o  m*/
 * @return
 */
public JFreeChart provideChart(List<IFileFragment> fragments) {
    String[] labels = new String[fragments.size()];
    Array[] arrays = new Array[fragments.size()];
    Array[] domains = new Array[fragments.size()];
    boolean createTIC = true;

    VariableSelectionPanel vsp = new VariableSelectionPanel();
    IFileFragment fragment = fragments.get(0);
    ArrayList<String> vars = new ArrayList<>();
    List<IVariableFragment> variables = getAggregatedVariables(fragment);

    boolean showEICChoice = false;

    for (IVariableFragment var : variables) {
        vars.add(var.getName());
    }
    Collections.sort(vars);
    vsp.setAvailableVariables(vars.toArray(new String[] {}));

    DialogDescriptor nd = new DialogDescriptor(vsp, "Select variables to plot", true, null);
    DialogDisplayer.getDefault().notify(nd);
    Object val = nd.getValue();
    if (!val.equals(DialogDescriptor.YES_OPTION) || !val.equals(DialogDescriptor.OK_OPTION)) {
        return null;
    }
    //TODO bail out, if user hits cancel
    String domainVar = vsp.getSelectedDomainVariable();
    String valueVar = vsp.getSelectedValuesVariable();
    if (domainVar.equals("mass_values") || valueVar.equals("mass_values")) {
        showEICChoice = true;
    }
    double[] minMZ = new double[] { 50.0d }, maxMZ = new double[] { 51.0d };
    if (showEICChoice) {
        TICEICChoiceDialog tcd = new TICEICChoiceDialog();
        minMZ = tcd.getMinMZ();
        maxMZ = tcd.getMaxMZ();
        DialogDescriptor nd2 = new DialogDescriptor(tcd, "Select mass range or tic", true, null);
        DialogDisplayer.getDefault().notify(nd2);
        val = nd.getValue();
        if (!val.equals(DialogDescriptor.YES_OPTION) || !val.equals(DialogDescriptor.OK_OPTION)) {
            return null;
        }

        createTIC = tcd.isTICSelected();
        labels = new String[fragments.size() * minMZ.length];
        arrays = new Array[fragments.size() * minMZ.length];
        domains = new Array[fragments.size() * minMZ.length];
    }
    List<XYAnnotation> annotations = new ArrayList<>();

    if (createTIC) {
        int i = 0;
        for (IFileFragment file : fragments) {
            fragment = file;
            labels[i] = fragment.getName() + " TIC";
            arrays[i] = fragment.getChild(valueVar).getArray();
            //Factory.getInstance().getConfiguration().getString("var.total_intensity","total_intensity")).getArray();
            boolean useRT = false;
            if (!domainVar.equals("")) {
                if (domainVar.equals("scan_acquisition_time")) {
                    domains[i] = fragment.getChild(domainVar).getArray();
                    useRT = true;
                } else {
                    domains[i] = fragment.getChild(domainVar).getArray();
                }
            }
            //                annotations.addAll(getANDIChromPeakAnnotations(fragment, useRT, valueVar));
            //                annotations.addAll(generatePeakShapes(fragment, useRT,
            //                        new Color(0, 0, 255, 192), new Color(0, 0, 255, 32), valueVar));
            //                annotations.addAll(getCSVPeakAnnotations(fragment, arrays[i],
            //                        useRT));
            //Factory.getInstance().getConfiguration().getString("var.scan_acquisition_time","scan_acquisition_time")).getArray();
            i++;
        }
    } else {
        int i = 0;
        for (IFileFragment file : fragments) {
            fragment = file;
            for (int k = 0; k < minMZ.length; k++) {
                labels[i] = fragment.getName() + " EIC:[" + minMZ[k] + "," + maxMZ[k] + ")";
                arrays[i] = MaltcmsTools.getEIC(fragment, minMZ[k], maxMZ[k], false, false);
                //Factory.getInstance().getConfiguration().getString("var.total_intensity","total_intensity")).getArray();
                if (!domainVar.equals("")) {
                    if (domainVar.equals("scan_acquisition_time")) {
                        domains[i] = fragment.getChild(domainVar).getArray();
                        //                            useRT = true;
                    } else {
                        domains[i] = fragment.getChild(domainVar).getArray();
                    }
                }
            }
            //Factory.getInstance().getConfiguration().getString("var.scan_acquisition_time","scan_acquisition_time")).getArray();
            i++;
        }
    }
    //                if (jfreechart == null) {
    XYChart xyc = null;
    if (!domainVar.equals("")) {
        xyc = new XYChart(fragments.get(0).getName(), labels, arrays, domains, domainVar, valueVar);
    } else {
        xyc = new XYChart(fragments.get(0).getName(), labels, arrays, domainVar, valueVar);
    }
    XYPlot xyp = xyc.create();
    for (XYAnnotation xya : annotations) {
        xyp.addAnnotation(xya);
    }
    //xyp.setDomainCrosshairVisible(true);
    xyp.getRenderer().setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset xyd, int i, int i1) {
            Comparable comp = xyd.getSeriesKey(i);
            double x = xyd.getXValue(i, i1);
            double y = xyd.getYValue(i, i1);
            StringBuilder sb = new StringBuilder();
            sb.append(comp);
            sb.append(": ");
            sb.append("x=");
            sb.append(x);
            sb.append(" y=");
            sb.append(y);
            return sb.toString();
        }
    });
    ChartCustomizer.setSeriesColors(xyp, 0.7f);
    ChartCustomizer.setSeriesStrokes(xyp, 2.0f);
    JFreeChart jfc2 = new JFreeChart(xyp);
    return jfc2;
}

From source file:org.owasp.benchmark.score.report.ScatterVulns.java

private void makeLegend(String category, Set<Report> toolResults, double x, double y,
        XYSeriesCollection dataset, XYPlot xyplot) {

    char ch = ScatterHome.INITIAL_LABEL;
    int i = -2;//from   w w w  .  j  a v  a  2s.  c o  m

    // non-commercial results
    boolean printedNonCommercialLabel = false;

    for (Report r : toolResults) {
        if (!r.isCommercial()) {
            // print non commercial label if there is at least one
            // non-commercial tool
            if (!printedNonCommercialLabel) {
                XYTextAnnotation stroketext1 = new XYTextAnnotation("Non-Commercial", x, y + i * -3.3);
                stroketext1.setTextAnchor(TextAnchor.CENTER_LEFT);
                stroketext1.setBackgroundPaint(Color.white);
                stroketext1.setPaint(Color.black);
                stroketext1.setFont(theme.getRegularFont());
                xyplot.addAnnotation(stroketext1);
                i++;
                printedNonCommercialLabel = true;
            }

            OverallResults or = r.getOverallResults();
            // Special hack to make it line up better if the letter is an 'I' or 'i'
            String label = (ch == 'I' || ch == 'i' ? ch + ":  " : "" + ch + ": ");
            double score = or.getResults(category).score * 100;
            String msg = "\u25A0 " + label + r.getToolNameAndVersion() + " (" + Math.round(score) + "%)";
            XYTextAnnotation stroketext3 = new XYTextAnnotation(msg, x, y + i * -3.3);
            stroketext3.setTextAnchor(TextAnchor.CENTER_LEFT);
            stroketext3.setBackgroundPaint(Color.white);
            stroketext3.setPaint(
                    r.getToolName().replace(' ', '_').equalsIgnoreCase(focus) ? Color.green : Color.blue);
            stroketext3.setFont(theme.getRegularFont());
            xyplot.addAnnotation(stroketext3);
            i++;
            // Weak hack if there are more than 26 tools scored. This will only get us to 52.
            if (ch == 'Z')
                ch = 'a';
            else
                ch++;
        }
    }

    // commercial tools
    boolean printedCommercialLabel = false;
    double commercialTotal = 0;

    for (Report r : toolResults) {
        OverallResults or = r.getOverallResults();
        if (r.isCommercial()) {

            // print commercial label if there is at least one commercial
            // tool
            if (!printedCommercialLabel) {
                XYTextAnnotation stroketext4 = new XYTextAnnotation("Commercial", x, y + i * -3.3);
                stroketext4.setTextAnchor(TextAnchor.CENTER_LEFT);
                stroketext4.setBackgroundPaint(Color.white);
                stroketext4.setPaint(Color.black);
                stroketext4.setFont(theme.getRegularFont());
                xyplot.addAnnotation(stroketext4);
                i++;
                printedCommercialLabel = true;
            }

            commercialToolCount++;
            double score = or.getResults(category).score * 100;
            // don't show the commercial tool results if in 'show ave only mode'
            if (!BenchmarkScore.showAveOnlyMode) {
                // Special hack to make it line up better if the letter is an 'I' or 'i'
                String label = (ch == 'I' || ch == 'i' ? ch + ":  " : "" + ch + ": ");
                String msg = "\u25A0 " + label + r.getToolNameAndVersion() + " (" + Math.round(score) + "%)";
                XYTextAnnotation stroketext4 = new XYTextAnnotation(msg, x, y + i * -3.3);
                stroketext4.setTextAnchor(TextAnchor.CENTER_LEFT);
                stroketext4.setBackgroundPaint(Color.white);
                stroketext4.setPaint(Color.blue);
                stroketext4.setFont(theme.getRegularFont());
                xyplot.addAnnotation(stroketext4);
                i++; // increment the location of the label
                // Weak hack if there are more than 26 tools scored. This will only get us to 52.
                if (ch == 'Z')
                    ch = 'a';
                else
                    ch++;
            }
            commercialTotal += score;

            if (score < commercialLow) {
                commercialLow = score;
                commercialLowToolType = r.getToolType();
            }
            if (score > commercialHigh) {
                commercialHigh = score;
                commercialHighToolType = r.getToolType();
            }
        }

        // Add color emphasis to the tool of focus
        if (r.getToolName().replace(' ', '_').equalsIgnoreCase(focus)) {
            OverallResult orc = r.getOverallResults().getResults(category);
            Point2D focusPoint = new Point2D.Double(orc.falsePositiveRate * 100, orc.truePositiveRate * 100);
            Color green = new Color(0, 1, 0, 0.5f);
            makePoint(xyplot, focusPoint, 3, green);
        }
    }

    // commercial average
    if (commercialToolCount > 1 || (BenchmarkScore.showAveOnlyMode && commercialToolCount == 1)) {
        commercialAve = commercialTotal / commercialToolCount;
        XYTextAnnotation stroketext2 = new XYTextAnnotation(
                "\u25A0 " + ch + ": Commercial Average" + " (" + Math.round(commercialAve) + "%)", x,
                y + i * -3.3);
        stroketext2.setTextAnchor(TextAnchor.CENTER_LEFT);
        stroketext2.setBackgroundPaint(Color.white);
        stroketext2.setPaint(Color.magenta);
        stroketext2.setFont(theme.getRegularFont());
        xyplot.addAnnotation(stroketext2);

        Point2D averagePoint = new Point2D.Double(afr * 100, atr * 100);
        Color red = new Color(1, 0, 0, 0.5f);
        makePoint(xyplot, averagePoint, 3, red);
    }
}

From source file:analysis.postRun.PostRunWindow.java

/** Method which draws error bars from the given series of errors onto the given chart.
 * // w  ww  .ja va  2 s.com
 * @param chart
 *             The chart to draw the error bars on.
 * @param values
 *             The data series which the errors correspond to.
 * @param errors
 *             The data series containing all the error values at times.
 */
private void plotErrorBars(JFreeChart chart, double[][] values, double[][] errors) {
    Stroke stroke = new BasicStroke();
    Paint paint = Color.black;
    XYPlot plot = chart.getXYPlot();
    if (values.length != errors.length)
        return;
    for (int i = 0; i < values[0].length; i = i + 5) {
        double x = values[0][i];
        double y = values[1][i];
        //double dx = errors[0][i];
        double dy = errors[1][i];
        //System.out.println(dy);
        XYLineAnnotation vertical = new XYLineAnnotation(x, (y - dy), x, (y + dy), stroke, paint);
        plot.addAnnotation(vertical);
        XYLineAnnotation topBar = new XYLineAnnotation(x - 0.25, y + dy, x + 0.25, y + dy, stroke, paint);
        plot.addAnnotation(topBar);
        XYLineAnnotation bottomBar = new XYLineAnnotation(x - 0.25, y - dy, x + 0.25, y - dy, stroke, paint);
        plot.addAnnotation(bottomBar);
    }
}

From source file:com.bdb.weather.display.day.DayTemperaturePane.java

@Override
public void addAnnotations(XYPlot plot, SummaryRecord summaryRecord) {
    plot.clearAnnotations();// ww  w .  j ava2 s. co  m
    summary = summaryRecord;
    if (summaryRecord == null)
        return;

    LocalDateTime highTime = summaryRecord.getMaxOutdoorTempTime();
    Temperature outdoorHighTemp = summaryRecord.getMaxOutdoorTemp();
    LocalDateTime lowTime = summaryRecord.getMinOutdoorTempTime();
    Temperature outdoorLowTemp = summaryRecord.getMinOutdoorTemp();

    if (highTime == null || outdoorHighTemp == null || lowTime == null || outdoorLowTemp == null)
        return;

    String highAnnotation = outdoorHighTemp.toString() + " " + Temperature.getDefaultUnit() + " "
            + DisplayConstants.formatTime(highTime.toLocalTime());
    String lowAnnotation = outdoorLowTemp.toString() + " " + Temperature.getDefaultUnit() + " "
            + DisplayConstants.formatTime(lowTime.toLocalTime());

    XYTextAnnotation a = new XYTextAnnotation(highAnnotation,
            (double) TimeUtils.localDateTimeToEpochMillis(highTime), outdoorHighTemp.get());
    a.setTextAnchor(TextAnchor.BASELINE_CENTER);
    plot.addAnnotation(a);

    a = new XYTextAnnotation(lowAnnotation, TimeUtils.localDateTimeToEpochMillis(lowTime),
            outdoorLowTemp.get());
    a.setTextAnchor(TextAnchor.TOP_CENTER);
    plot.addAnnotation(a);

    highTime = summaryRecord.getMaxIndoorTempTime();
    Temperature indoorHighTemp = summaryRecord.getMaxIndoorTemp();
    lowTime = summaryRecord.getMinIndoorTempTime();
    Temperature indoorLowTemp = summaryRecord.getMinIndoorTemp();

    highAnnotation = indoorHighTemp.toString() + " " + Temperature.getDefaultUnit() + " "
            + DisplayConstants.formatTime(highTime.toLocalTime());
    lowAnnotation = indoorLowTemp + " " + Temperature.getDefaultUnit() + " "
            + DisplayConstants.formatTime(lowTime.toLocalTime());

    a = new XYTextAnnotation(highAnnotation, TimeUtils.localDateTimeToEpochMillis(highTime),
            indoorHighTemp.get());
    a.setTextAnchor(TextAnchor.BASELINE_CENTER);
    plot.addAnnotation(a);

    a = new XYTextAnnotation(lowAnnotation, TimeUtils.localDateTimeToEpochMillis(lowTime), indoorLowTemp.get());
    a.setTextAnchor(TextAnchor.TOP_CENTER);
    plot.addAnnotation(a);
}

From source file:org.esa.beam.visat.toolviews.stat.ScatterPlotPanel.java

private void createUI() {

    final XYPlot plot = getPlot();
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setNoDataMessage(NO_DATA_MESSAGE);
    plot.setDataset(CONFIDENCE_DSINDEX, acceptableDeviationDataset);
    plot.setDataset(REGRESSION_DSINDEX, regressionDataset);
    plot.setDataset(SCATTERPOINTS_DSINDEX, scatterpointsDataset);

    plot.addAnnotation(r2Annotation);

    final DeviationRenderer identityRenderer = new DeviationRenderer(true, false);
    identityRenderer.setSeriesPaint(0, StatisticChartStyling.SAMPLE_DATA_PAINT);
    identityRenderer.setSeriesFillPaint(0, StatisticChartStyling.SAMPLE_DATA_FILL_PAINT);
    plot.setRenderer(CONFIDENCE_DSINDEX, identityRenderer);

    final DeviationRenderer regressionRenderer = new DeviationRenderer(true, false);
    regressionRenderer.setSeriesPaint(0, StatisticChartStyling.REGRESSION_DATA_PAINT);
    regressionRenderer.setSeriesFillPaint(0, StatisticChartStyling.REGRESSION_DATA_FILL_PAINT);
    plot.setRenderer(REGRESSION_DSINDEX, regressionRenderer);

    final XYErrorRenderer scatterPointsRenderer = new XYErrorRenderer();
    scatterPointsRenderer.setDrawXError(true);
    scatterPointsRenderer.setErrorStroke(new BasicStroke(1));
    scatterPointsRenderer.setErrorPaint(StatisticChartStyling.CORRELATIVE_POINT_OUTLINE_PAINT);
    scatterPointsRenderer.setSeriesShape(0, StatisticChartStyling.CORRELATIVE_POINT_SHAPE);
    scatterPointsRenderer.setSeriesOutlinePaint(0, StatisticChartStyling.CORRELATIVE_POINT_OUTLINE_PAINT);
    scatterPointsRenderer.setSeriesFillPaint(0, StatisticChartStyling.CORRELATIVE_POINT_FILL_PAINT);
    scatterPointsRenderer.setSeriesLinesVisible(0, false);
    scatterPointsRenderer.setSeriesShapesVisible(0, true);
    scatterPointsRenderer.setSeriesOutlineStroke(0, new BasicStroke(1.0f));
    scatterPointsRenderer.setSeriesToolTipGenerator(0, new XYToolTipGenerator() {
        @Override//from ww w  . j  a v a  2 s. co m
        public String generateToolTip(XYDataset dataset, int series, int item) {
            final XYIntervalSeriesCollection collection = (XYIntervalSeriesCollection) dataset;
            final Comparable key = collection.getSeriesKey(series);
            final double xValue = collection.getXValue(series, item);
            final double endYValue = collection.getEndYValue(series, item);
            final double yValue = collection.getYValue(series, item);
            return String.format("%s: mean = %6.2f, sigma = %6.2f | %s: value = %6.2f", getRasterName(), yValue,
                    endYValue - yValue, key, xValue);
        }
    });
    plot.setRenderer(SCATTERPOINTS_DSINDEX, scatterPointsRenderer);

    final boolean autoRangeIncludesZero = false;
    final boolean xLog = scatterPlotModel.xAxisLogScaled;
    final boolean yLog = scatterPlotModel.yAxisLogScaled;
    plot.setDomainAxis(
            StatisticChartStyling.updateScalingOfAxis(xLog, plot.getDomainAxis(), autoRangeIncludesZero));
    plot.setRangeAxis(
            StatisticChartStyling.updateScalingOfAxis(yLog, plot.getRangeAxis(), autoRangeIncludesZero));

    createUI(createChartPanel(chart), createInputParameterPanel(), bindingContext);

    plot.getDomainAxis().addChangeListener(domainAxisChangeListener);
    scatterPlotDisplay.setMouseWheelEnabled(true);
    scatterPlotDisplay.setMouseZoomable(true);
}

From source file:org.esa.snap.rcp.statistics.ScatterPlotPanel.java

private void createUI() {

    final XYPlot plot = getPlot();
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setNoDataMessage(NO_DATA_MESSAGE);
    int confidenceDSIndex = 0;
    int regressionDSIndex = 1;
    int scatterpointsDSIndex = 2;
    plot.setDataset(confidenceDSIndex, acceptableDeviationDataset);
    plot.setDataset(regressionDSIndex, regressionDataset);
    plot.setDataset(scatterpointsDSIndex, scatterpointsDataset);

    plot.addAnnotation(r2Annotation);

    final DeviationRenderer identityRenderer = new DeviationRenderer(true, false);
    identityRenderer.setSeriesPaint(0, StatisticChartStyling.SAMPLE_DATA_PAINT);
    identityRenderer.setSeriesFillPaint(0, StatisticChartStyling.SAMPLE_DATA_FILL_PAINT);
    plot.setRenderer(confidenceDSIndex, identityRenderer);

    final DeviationRenderer regressionRenderer = new DeviationRenderer(true, false);
    regressionRenderer.setSeriesPaint(0, StatisticChartStyling.REGRESSION_DATA_PAINT);
    regressionRenderer.setSeriesFillPaint(0, StatisticChartStyling.REGRESSION_DATA_FILL_PAINT);
    plot.setRenderer(regressionDSIndex, regressionRenderer);

    final XYErrorRenderer scatterPointsRenderer = new XYErrorRenderer();
    scatterPointsRenderer.setDrawXError(true);
    scatterPointsRenderer.setErrorStroke(new BasicStroke(1));
    scatterPointsRenderer.setErrorPaint(StatisticChartStyling.CORRELATIVE_POINT_OUTLINE_PAINT);
    scatterPointsRenderer.setSeriesShape(0, StatisticChartStyling.CORRELATIVE_POINT_SHAPE);
    scatterPointsRenderer.setSeriesOutlinePaint(0, StatisticChartStyling.CORRELATIVE_POINT_OUTLINE_PAINT);
    scatterPointsRenderer.setSeriesFillPaint(0, StatisticChartStyling.CORRELATIVE_POINT_FILL_PAINT);
    scatterPointsRenderer.setSeriesLinesVisible(0, false);
    scatterPointsRenderer.setSeriesShapesVisible(0, true);
    scatterPointsRenderer.setSeriesOutlineStroke(0, new BasicStroke(1.0f));
    scatterPointsRenderer.setSeriesToolTipGenerator(0, (dataset, series, item) -> {
        final XYIntervalSeriesCollection collection = (XYIntervalSeriesCollection) dataset;
        final Comparable key = collection.getSeriesKey(series);
        final double xValue = collection.getXValue(series, item);
        final double endYValue = collection.getEndYValue(series, item);
        final double yValue = collection.getYValue(series, item);
        return String.format("%s: mean = %6.2f, sigma = %6.2f | %s: value = %6.2f", getRasterName(), yValue,
                endYValue - yValue, key, xValue);
    });/*from  ww w. ja va 2 s  .c  om*/
    plot.setRenderer(scatterpointsDSIndex, scatterPointsRenderer);

    final boolean autoRangeIncludesZero = false;
    final boolean xLog = scatterPlotModel.xAxisLogScaled;
    final boolean yLog = scatterPlotModel.yAxisLogScaled;
    plot.setDomainAxis(
            StatisticChartStyling.updateScalingOfAxis(xLog, plot.getDomainAxis(), autoRangeIncludesZero));
    plot.setRangeAxis(
            StatisticChartStyling.updateScalingOfAxis(yLog, plot.getRangeAxis(), autoRangeIncludesZero));

    createUI(createChartPanel(chart), createInputParameterPanel(), bindingContext);

    plot.getDomainAxis().addChangeListener(domainAxisChangeListener);
    scatterPlotDisplay.setMouseWheelEnabled(true);
    scatterPlotDisplay.setMouseZoomable(true);
}

From source file:com.che.software.testato.util.jfreechart.LineChartGraphistUtil.java

/**
 * Colorized and transforms a given JFreeChart.
 * /*ww  w.jav  a  2s.  com*/
 * @author Clement HELIOU (clement.heliou@che-software.com).
 * @param lineChart the given chart.
 * @param maxAbscissaValue the max abscissa value of the chart.
 * @param xValues the x axis values list.
 * @param yValues the y axis values list.
 * @param xExcludedValues the x axis excluded values.
 * @param yExcludedValues the y axis excluded values.
 * @return the transformed chart.
 * @since August, 2011.
 */
public static JFreeChart getColorizedChartFromChart(JFreeChart lineChart, double maxAbscissaValue,
        List<MatrixResult> xValues, List<MatrixResult> yValues, List<MatrixResult> xExcludedValues,
        List<MatrixResult> yExcludedValues) {
    LOGGER.debug("getColorizedChartFromChart().");
    lineChart.setBackgroundPaint(Color.WHITE);
    XYPlot plot = (XYPlot) lineChart.getPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesStroke(2, new BasicStroke(2));
    renderer.setSeriesStroke(3, new BasicStroke(2));
    renderer.setSeriesShapesVisible(2, false);
    renderer.setSeriesShapesVisible(3, false);
    renderer.setSeriesPaint(0,
            ColorUtil.getHSBColor(ColorUtil.BLUE_COLOR[0], ColorUtil.BLUE_COLOR[1], ColorUtil.BLUE_COLOR[2]));
    renderer.setSeriesPaint(1, ColorUtil.getHSBColor(ColorUtil.ORANGE_COLOR[0], ColorUtil.ORANGE_COLOR[1],
            ColorUtil.ORANGE_COLOR[2]));
    renderer.setSeriesPaint(2, ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1],
            ColorUtil.DARK_BLUE_COLOR[2]));
    renderer.setSeriesPaint(3, ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1],
            ColorUtil.DARK_BLUE_COLOR[2]));
    plot.setRenderer(renderer);
    XYTextAnnotation low = new XYTextAnnotation(
            LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_LOW_NAME), (0.5 * maxAbscissaValue) - 1,
            maxAbscissaValue + 1),
            medium = new XYTextAnnotation(LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_MEDIUM_NAME),
                    (1.5 * maxAbscissaValue) - 2, maxAbscissaValue + 1),
            high = new XYTextAnnotation(LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_HIGH_NAME),
                    1.5 * maxAbscissaValue, maxAbscissaValue - 2);
    low.setFont(ColorUtil.TITLE_FONT);
    medium.setFont(ColorUtil.TITLE_FONT);
    high.setFont(ColorUtil.TITLE_FONT);
    low.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1],
            ColorUtil.DARK_BLUE_COLOR[2]));
    medium.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1],
            ColorUtil.DARK_BLUE_COLOR[2]));
    high.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1],
            ColorUtil.DARK_BLUE_COLOR[2]));
    plot.addAnnotation(low);
    plot.addAnnotation(medium);
    plot.addAnnotation(high);
    for (int i = 0; i < xValues.size(); i++) {
        XYTextAnnotation itemLabel = new XYTextAnnotation(xValues.get(i).getScriptLabel(),
                (yValues.get(i).getPercentage() * 100), (xValues.get(i).getPercentage() * 100) + 0.5);
        itemLabel.setFont(ColorUtil.DEFAULT_FONT);
        itemLabel.setPaint(ColorUtil.getHSBColor(ColorUtil.BLUE_COLOR[0], ColorUtil.BLUE_COLOR[1],
                ColorUtil.BLUE_COLOR[2]));
        plot.addAnnotation(itemLabel);
    }
    if (null != xExcludedValues) {
        for (int j = 0; j < xExcludedValues.size(); j++) {
            XYTextAnnotation itemLabel = new XYTextAnnotation(xExcludedValues.get(j).getScriptLabel(),
                    (yExcludedValues.get(j).getPercentage() * 100),
                    (xExcludedValues.get(j).getPercentage() * 100) + 0.5);
            itemLabel.setFont(ColorUtil.DEFAULT_FONT);
            itemLabel.setPaint(ColorUtil.getHSBColor(ColorUtil.ORANGE_COLOR[0], ColorUtil.ORANGE_COLOR[1],
                    ColorUtil.ORANGE_COLOR[2]));
            plot.addAnnotation(itemLabel);
        }
    }
    return lineChart;
}

From source file:org.owasp.benchmark.score.report.ScatterHome.java

private void makeLegend(Set<Report> toolResults, double x, double y, XYSeriesCollection dataset,
        XYPlot xyplot) {
    char ch = INITIAL_LABEL; // This is the first label in the Key with all the tools processed by this scorecard
    int i = -2; // Used to keep track of which row in the key were are processing. Helps calculate the Y axis
                // location where to put the Key entry

    boolean printedNonCommercialLabel = false;

    //non-commercial results
    for (Report r : toolResults) {
        OverallResults or = r.getOverallResults();
        if (!r.isCommercial()) {
            // print non-commercial label if there is at least one non-commercial tool
            if (!printedNonCommercialLabel) {
                XYTextAnnotation stroketext1 = new XYTextAnnotation("Non-Commercial", x, y + i * -3.3);
                stroketext1.setTextAnchor(TextAnchor.CENTER_LEFT);
                stroketext1.setBackgroundPaint(Color.white);
                stroketext1.setPaint(Color.black);
                stroketext1.setFont(theme.getRegularFont());
                xyplot.addAnnotation(stroketext1);
                i++;//w  w  w .ja v  a2s  . c  om
                printedNonCommercialLabel = true;
            }

            // Special hack to make it line up better if the letter is an 'I' or 'i'
            String label = (ch == 'I' || ch == 'i' ? ch + ":  " : "" + ch + ": ");
            double score = or.getScore() * 100;
            String msg = "\u25A0 " + label + r.getToolNameAndVersion() + " (" + Math.round(score) + "%)";
            XYTextAnnotation stroketext3 = new XYTextAnnotation(msg, x, y + i * -3.3);
            stroketext3.setTextAnchor(TextAnchor.CENTER_LEFT);
            stroketext3.setBackgroundPaint(Color.white);
            stroketext3.setPaint(Color.blue);
            stroketext3.setFont(theme.getRegularFont());
            xyplot.addAnnotation(stroketext3);
            i++;
            // Weak hack if there are more than 26 tools scored. This will only get us to 52.
            if (ch == 'Z')
                ch = 'a';
            else
                ch++;
        }
    }

    //commercial tools
    double totalScore = 0;
    boolean printedCommercialLabel = false;
    int commercialToolCount = 0;

    for (Report r : toolResults) {

        OverallResults or = r.getOverallResults();
        if (r.isCommercial()) {

            // print commercial label if there is at least one commercial tool
            if (!printedCommercialLabel) {
                XYTextAnnotation stroketext = new XYTextAnnotation("Commercial", x, y + i * -3.3);
                stroketext.setTextAnchor(TextAnchor.CENTER_LEFT);
                stroketext.setBackgroundPaint(Color.white);
                stroketext.setPaint(Color.black);
                stroketext.setFont(theme.getRegularFont());
                xyplot.addAnnotation(stroketext);
                i++;
                printedCommercialLabel = true;
            }

            commercialToolCount++;
            // Special hack to make it line up better if the letter is an 'I' or 'i'
            String label = (ch == 'I' || ch == 'i' ? ch + ":  " : "" + ch + ": ");
            double score = or.getScore() * 100;
            if (!BenchmarkScore.showAveOnlyMode) {
                String msg = "\u25A0 " + label + r.getToolNameAndVersion() + " (" + Math.round(score) + "%)";
                XYTextAnnotation stroketext4 = new XYTextAnnotation(msg, x, y + i * -3.3);
                stroketext4.setTextAnchor(TextAnchor.CENTER_LEFT);
                stroketext4.setBackgroundPaint(Color.white);
                stroketext4.setPaint(Color.blue);
                stroketext4.setFont(theme.getRegularFont());
                xyplot.addAnnotation(stroketext4);
                i++;
                // Weak hack if there are more than 26 tools scored. This will only get us to 52.
                if (ch == 'Z')
                    ch = 'a';
                else
                    ch++;
            }
            totalScore += score;
        }
        if (r.getToolName().replace(' ', '_').equalsIgnoreCase(focus)) {
            OverallResults orc = r.getOverallResults();
            Point2D focusPoint = new Point2D.Double(orc.getFalsePositiveRate() * 100,
                    orc.getTruePositiveRate() * 100);
            Color green = new Color(0, 1, 0, 0.5f);
            makePoint(xyplot, focusPoint, 3, green);
        }
    }

    //commercial average
    if (commercialToolCount > 1 || (BenchmarkScore.showAveOnlyMode && commercialToolCount == 1)) {
        double averageScore = totalScore / commercialToolCount;
        XYTextAnnotation stroketext2 = new XYTextAnnotation(
                "\u25A0 " + ch + ": Commercial Average" + " (" + Math.round(averageScore) + "%)", x,
                y + i * -3.3);
        stroketext2.setTextAnchor(TextAnchor.CENTER_LEFT);
        stroketext2.setBackgroundPaint(Color.white);
        stroketext2.setPaint(Color.magenta);
        stroketext2.setFont(theme.getRegularFont());
        xyplot.addAnnotation(stroketext2);

        Point2D averagePoint = new Point2D.Double(afr * 100, atr * 100);
        makePoint(xyplot, averagePoint, 3, Color.magenta);
    }
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JFreeChart createXYAreaChart(String xAxisLabel, String yAxisLabel, XYDataset dataset,
        boolean includeLegend) {
    JFreeChart jfreechart = ChartFactory.createXYAreaChart(null, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainPannable(true);/* w w  w.jav a2s  .com*/
    xyplot.setBackgroundPaint(null);
    xyplot.setOutlinePaint(null);
    xyplot.setForegroundAlpha(0.8F);
    xyplot.setRangeGridlinePaint(UIConstants.INTEL_DARK_GRAY);
    DateAxis dateaxis = new DateAxis(xAxisLabel);
    dateaxis.setLowerMargin(0.0D);
    dateaxis.setUpperMargin(0.0D);
    xyplot.setDomainAxis(dateaxis);
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    rangeAxis.setRangeType(RangeType.POSITIVE);
    rangeAxis.setLabelFont(UIConstants.H5_FONT);
    rangeAxis.setLabelInsets(new RectangleInsets(0, 0, 0, 0));

    if (includeLegend) {
        LegendTitle legendtitle = new LegendTitle(xyplot);
        legendtitle.setItemFont(UIConstants.H5_FONT);
        legendtitle.setBackgroundPaint(UIConstants.INTEL_WHITE);
        legendtitle.setFrame(new BlockBorder(UIConstants.INTEL_BLUE));
        legendtitle.setPosition(RectangleEdge.BOTTOM);
        XYTitleAnnotation xytitleannotation = new XYTitleAnnotation(0.97999999999999998D, 0.99999999999999998D,
                legendtitle, RectangleAnchor.TOP_RIGHT);
        // xytitleannotation.setMaxWidth(0.47999999999999998D);
        xyplot.addAnnotation(xytitleannotation);
    }

    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(1, UIConstants.INTEL_DARK_GRAY);
    xyitemrenderer.setSeriesPaint(0, NodeTypeViz.SWITCH.getColor());
    xyitemrenderer.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator("<html><b>{0}</b><br> Time: {1}<br> Data: {2}</html>",
                    Util.getHHMMSS(), new DecimalFormat("#,##0.00")));
    return jfreechart;
}