Search in sources :

Example 1 with XYAnnotation

use of org.jfree.chart.annotations.XYAnnotation in project SIMVA-SoS by SESoS.

the class AbstractXYItemRenderer method drawAnnotations.

/**
 * Draws all the annotations for the specified layer.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param layer  the layer.
 * @param info  the plot rendering info.
 */
@Override
public void drawAnnotations(Graphics2D g2, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, Layer layer, PlotRenderingInfo info) {
    Iterator iterator = null;
    if (layer.equals(Layer.FOREGROUND)) {
        iterator = this.foregroundAnnotations.iterator();
    } else if (layer.equals(Layer.BACKGROUND)) {
        iterator = this.backgroundAnnotations.iterator();
    } else {
        // should not get here
        throw new RuntimeException("Unknown layer.");
    }
    while (iterator.hasNext()) {
        XYAnnotation annotation = (XYAnnotation) iterator.next();
        int index = this.plot.getIndexOf(this);
        annotation.draw(g2, this.plot, dataArea, domainAxis, rangeAxis, index, info);
    }
}
Also used : XYAnnotation(org.jfree.chart.annotations.XYAnnotation) Iterator(java.util.Iterator) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Example 2 with XYAnnotation

use of org.jfree.chart.annotations.XYAnnotation in project SIMVA-SoS by SESoS.

the class StandardChartTheme method applyToXYPlot.

/**
 * Applies the attributes of this theme to a {@link XYPlot}.
 *
 * @param plot  the plot (<code>null</code> not permitted).
 */
protected void applyToXYPlot(XYPlot plot) {
    plot.setAxisOffset(this.axisOffset);
    plot.setDomainZeroBaselinePaint(this.baselinePaint);
    plot.setRangeZeroBaselinePaint(this.baselinePaint);
    plot.setDomainGridlinePaint(this.domainGridlinePaint);
    plot.setRangeGridlinePaint(this.rangeGridlinePaint);
    plot.setDomainCrosshairPaint(this.crosshairPaint);
    plot.setRangeCrosshairPaint(this.crosshairPaint);
    plot.setShadowGenerator(this.shadowGenerator);
    // process all domain axes
    int domainAxisCount = plot.getDomainAxisCount();
    for (int i = 0; i < domainAxisCount; i++) {
        ValueAxis axis = plot.getDomainAxis(i);
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    // process all range axes
    int rangeAxisCount = plot.getRangeAxisCount();
    for (int i = 0; i < rangeAxisCount; i++) {
        ValueAxis axis = plot.getRangeAxis(i);
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    // process all renderers
    int rendererCount = plot.getRendererCount();
    for (int i = 0; i < rendererCount; i++) {
        XYItemRenderer r = plot.getRenderer(i);
        if (r != null) {
            applyToXYItemRenderer(r);
        }
    }
    // process all annotations
    Iterator iter = plot.getAnnotations().iterator();
    while (iter.hasNext()) {
        XYAnnotation a = (XYAnnotation) iter.next();
        applyToXYAnnotation(a);
    }
    if (plot instanceof CombinedDomainXYPlot) {
        CombinedDomainXYPlot cp = (CombinedDomainXYPlot) plot;
        Iterator iterator = cp.getSubplots().iterator();
        while (iterator.hasNext()) {
            XYPlot subplot = (XYPlot) iterator.next();
            if (subplot != null) {
                applyToPlot(subplot);
            }
        }
    }
    if (plot instanceof CombinedRangeXYPlot) {
        CombinedRangeXYPlot cp = (CombinedRangeXYPlot) plot;
        Iterator iterator = cp.getSubplots().iterator();
        while (iterator.hasNext()) {
            XYPlot subplot = (XYPlot) iterator.next();
            if (subplot != null) {
                applyToPlot(subplot);
            }
        }
    }
}
Also used : XYAnnotation(org.jfree.chart.annotations.XYAnnotation) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) CombinedRangeXYPlot(org.jfree.chart.plot.CombinedRangeXYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) Iterator(java.util.Iterator) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) CombinedRangeXYPlot(org.jfree.chart.plot.CombinedRangeXYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) Paint(java.awt.Paint)

Example 3 with XYAnnotation

use of org.jfree.chart.annotations.XYAnnotation in project SIMVA-SoS by SESoS.

the class XYPlot method clearAnnotations.

/**
 * Clears all the annotations and sends a {@link PlotChangeEvent} to all
 * registered listeners.
 *
 * @see #addAnnotation(XYAnnotation)
 */
public void clearAnnotations() {
    for (XYAnnotation annotation : this.annotations) {
        annotation.removeChangeListener(this);
    }
    this.annotations.clear();
    fireChangeEvent();
}
Also used : XYAnnotation(org.jfree.chart.annotations.XYAnnotation)

Example 4 with XYAnnotation

use of org.jfree.chart.annotations.XYAnnotation in project polyGembler by c-zhou.

the class HMMPanel method getChart.

public ChartPanel getChart() {
    Range range = this.updateRates();
    final JFreeChart chart = ChartFactory.createXYLineChart(null, // domain axis label
    null, // range axis label
    null, // data
    rates, PlotOrientation.VERTICAL, // include legend
    false, // tooltips?
    true, // URL generator? Not required...
    false);
    final NumberAxis domainAxis = new NumberAxis("SNP relative physical position");
    // final LogarithmicAxis rangeAxis = new LogarithmicAxis("Trans-out probability");
    final NumberAxis rangeAxis = new NumberAxis("Trans-out probability");
    AxisSpace space = new AxisSpace();
    // reserved space on the left side of the plot
    space.setRight(22);
    space.setLeft(67);
    chart.getXYPlot().setFixedRangeAxisSpace(space);
    // double fixedDemension = HMMPanel.this.getX(0, false)+shift;
    // rangeAxis.setFixedDimension(fixedDemension);
    domainAxis.setTickUnit(new NumberTickUnit(1));
    // rangeAxis.setLog10TickLabelsFlag(true);
    rangeAxis.setRange(range);
    domainAxis.setRange(new Range(1 - offset_yR, noSnps + offset_yR));
    chart.getXYPlot().setDomainAxis(domainAxis);
    chart.getXYPlot().setRangeAxis(rangeAxis);
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < rates.getSeriesCount(); i++) {
        Color c;
        if (i == 0)
            c = ca.getColor(i);
        else
            c = Color.lightGray;
        renderer.setSeriesPaint(i, c);
        if (i == 0)
            renderer.setSeriesShapesVisible(i, true);
        else
            renderer.setSeriesShapesVisible(i, false);
    }
    /**
     *		XYPolygonAnnotation a = new XYPolygonAnnotation(new double[] {5.0,
     *				   0.0, 5.0, 0.5, 6.0, 0.5, 6.0, 0.0}, null, null,Color.black) {
     *            @Override
     *            public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
     *                Graphics2D g22 = (Graphics2D) g2.create();
     *                g22.setXORMode(new Color(0xff0000));
     *                super.draw(g22, plot, dataArea, domainAxis, rangeAxis, rendererIndex, info);
     *            }
     *        };
     *		renderer.addAnnotation(a, Layer.BACKGROUND);
     */
    chart.getXYPlot().setRenderer(renderer);
    double anno_offset_x = 0.5;
    XYSeries d = rates.getSeries(0);
    for (int i = 0; i < d.getItemCount(); i++) {
        double x = d.getX(i).doubleValue();
        double y = d.getY(i).doubleValue();
        if (y > 0.1)
            chart.getXYPlot().addAnnotation((XYAnnotation) new XYTextAnnotation(String.format(formatStr2, y), x > noSnps / 2 ? (x - anno_offset_x) : (x + anno_offset_x), y));
        else
            chart.getXYPlot().addAnnotation((XYAnnotation) new XYTextAnnotation(String.format(formatStr, y), x, y + .05));
    }
    // chart.getXYPlot().getRangeAxis().get
    // chart.getXYPlot().setRangeAxis(new LogarithmicAxis("rates"));
    final ChartPanel cp = new ChartPanel(chart, // width
    this.getWidth(), // height
    150, // mindrawWidth
    this.getWidth(), // mindrawHeight
    150, // maxDrawWith
    this.getWidth(), // maxDrawHeight
    150, ChartPanel.DEFAULT_BUFFER_USED, // properties
    true, // save
    true, // print
    true, // zoom
    true, // tooltips
    true);
    {
        Range r = chart.getXYPlot().getDomainAxis().getRange();
        chart.getXYPlot().getDomainAxis().setAutoRange(false);
        chart.getXYPlot().getDomainAxis().setRange(1, r.getUpperBound());
    }
    {
        Range r = chart.getXYPlot().getRangeAxis().getRange();
        if (r.getLowerBound() < range.getUpperBound()) {
            chart.getXYPlot().getRangeAxis().setAutoRange(false);
            chart.getXYPlot().getRangeAxis().setRange(r.getLowerBound(), range.getUpperBound());
        }
    }
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderPaint(Color.WHITE);
    cp.setBorder(null);
    /**
     *		RectangleEdge edge = chart.getXYPlot().getDomainAxisEdge();
     *		Rectangle2D edge2 = cp.getScreenDataArea();
     *		double x = RectangleEdge.coordinate(edge2, edge);
     *		ValueAxis edge3 = chart.getXYPlot().getDomainAxisForDataset(0);
     *		double xx = domainAxis.valueToJava2D(3, edge2, edge);
     */
    return cp;
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) ChartPanel(org.jfree.chart.ChartPanel) XYAnnotation(org.jfree.chart.annotations.XYAnnotation) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Color(java.awt.Color) Range(org.jfree.data.Range) JFreeChart(org.jfree.chart.JFreeChart) NumberTickUnit(org.jfree.chart.axis.NumberTickUnit) XYTextAnnotation(org.jfree.chart.annotations.XYTextAnnotation) AxisSpace(org.jfree.chart.axis.AxisSpace)

Example 5 with XYAnnotation

use of org.jfree.chart.annotations.XYAnnotation in project SIMVA-SoS by SESoS.

the class XYPlot method getDataRange.

/**
 * Returns the range for the specified axis.
 *
 * @param axis  the axis.
 *
 * @return The range.
 */
@Override
public Range getDataRange(ValueAxis axis) {
    Range result = null;
    List<XYDataset> mappedDatasets = new ArrayList<XYDataset>();
    List<XYAnnotation> includedAnnotations = new ArrayList<XYAnnotation>();
    boolean isDomainAxis = true;
    // is it a domain axis?
    int domainIndex = getDomainAxisIndex(axis);
    if (domainIndex >= 0) {
        isDomainAxis = true;
        mappedDatasets.addAll(getDatasetsMappedToDomainAxis(domainIndex));
        if (domainIndex == 0) {
            // grab the plot's annotations
            Iterator iterator = this.annotations.iterator();
            while (iterator.hasNext()) {
                XYAnnotation annotation = (XYAnnotation) iterator.next();
                if (annotation instanceof XYAnnotationBoundsInfo) {
                    includedAnnotations.add(annotation);
                }
            }
        }
    }
    // or is it a range axis?
    int rangeIndex = getRangeAxisIndex(axis);
    if (rangeIndex >= 0) {
        isDomainAxis = false;
        mappedDatasets.addAll(getDatasetsMappedToRangeAxis(rangeIndex));
        if (rangeIndex == 0) {
            Iterator iterator = this.annotations.iterator();
            while (iterator.hasNext()) {
                XYAnnotation annotation = (XYAnnotation) iterator.next();
                if (annotation instanceof XYAnnotationBoundsInfo) {
                    includedAnnotations.add(annotation);
                }
            }
        }
    }
    // of the ranges.
    for (XYDataset d : mappedDatasets) {
        if (d != null) {
            XYItemRenderer r = getRendererForDataset(d);
            if (isDomainAxis) {
                if (r != null) {
                    result = Range.combine(result, r.findDomainBounds(d));
                } else {
                    result = Range.combine(result, DatasetUtilities.findDomainBounds(d));
                }
            } else {
                if (r != null) {
                    result = Range.combine(result, r.findRangeBounds(d));
                } else {
                    result = Range.combine(result, DatasetUtilities.findRangeBounds(d));
                }
            }
            // getAnnotations() method but it should
            if (r instanceof AbstractXYItemRenderer) {
                AbstractXYItemRenderer rr = (AbstractXYItemRenderer) r;
                Collection c = rr.getAnnotations();
                Iterator i = c.iterator();
                while (i.hasNext()) {
                    XYAnnotation a = (XYAnnotation) i.next();
                    if (a instanceof XYAnnotationBoundsInfo) {
                        includedAnnotations.add(a);
                    }
                }
            }
        }
    }
    Iterator it = includedAnnotations.iterator();
    while (it.hasNext()) {
        XYAnnotationBoundsInfo xyabi = (XYAnnotationBoundsInfo) it.next();
        if (xyabi.getIncludeInDataBounds()) {
            if (isDomainAxis) {
                result = Range.combine(result, xyabi.getXRange());
            } else {
                result = Range.combine(result, xyabi.getYRange());
            }
        }
    }
    return result;
}
Also used : XYAnnotation(org.jfree.chart.annotations.XYAnnotation) AbstractXYItemRenderer(org.jfree.chart.renderer.xy.AbstractXYItemRenderer) ArrayList(java.util.ArrayList) XYAnnotationBoundsInfo(org.jfree.chart.annotations.XYAnnotationBoundsInfo) Range(org.jfree.data.Range) Paint(java.awt.Paint) Iterator(java.util.Iterator) LegendItemCollection(org.jfree.chart.LegendItemCollection) Collection(java.util.Collection) AxisCollection(org.jfree.chart.axis.AxisCollection) XYDataset(org.jfree.data.xy.XYDataset) AbstractXYItemRenderer(org.jfree.chart.renderer.xy.AbstractXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer)

Aggregations

XYAnnotation (org.jfree.chart.annotations.XYAnnotation)7 Paint (java.awt.Paint)4 Iterator (java.util.Iterator)4 GradientPaint (java.awt.GradientPaint)2 ValueAxis (org.jfree.chart.axis.ValueAxis)2 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)2 Range (org.jfree.data.Range)2 Color (java.awt.Color)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 ChartPanel (org.jfree.chart.ChartPanel)1 JFreeChart (org.jfree.chart.JFreeChart)1 LegendItemCollection (org.jfree.chart.LegendItemCollection)1 XYAnnotationBoundsInfo (org.jfree.chart.annotations.XYAnnotationBoundsInfo)1 XYTextAnnotation (org.jfree.chart.annotations.XYTextAnnotation)1 AxisCollection (org.jfree.chart.axis.AxisCollection)1 AxisSpace (org.jfree.chart.axis.AxisSpace)1 NumberAxis (org.jfree.chart.axis.NumberAxis)1 NumberTickUnit (org.jfree.chart.axis.NumberTickUnit)1 CombinedDomainXYPlot (org.jfree.chart.plot.CombinedDomainXYPlot)1