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