Search in sources :

Example 1 with XYAnnotationBoundsInfo

use of org.jfree.chart.annotations.XYAnnotationBoundsInfo 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

Paint (java.awt.Paint)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 LegendItemCollection (org.jfree.chart.LegendItemCollection)1 XYAnnotation (org.jfree.chart.annotations.XYAnnotation)1 XYAnnotationBoundsInfo (org.jfree.chart.annotations.XYAnnotationBoundsInfo)1 AxisCollection (org.jfree.chart.axis.AxisCollection)1 AbstractXYItemRenderer (org.jfree.chart.renderer.xy.AbstractXYItemRenderer)1 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)1 Range (org.jfree.data.Range)1 XYDataset (org.jfree.data.xy.XYDataset)1