Search in sources :

Example 1 with AxisLocation

use of org.jfree.chart.axis.AxisLocation in project SIMVA-SoS by SESoS.

the class XYImageAnnotation method draw.

/**
 * Draws the annotation.  This method is called by the drawing code in the
 * {@link XYPlot} class, you don't normally need to call this method
 * directly.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  if supplied, this info object will be populated with
 *              entity information.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
    PlotOrientation orientation = plot.getOrientation();
    AxisLocation domainAxisLocation = plot.getDomainAxisLocation();
    AxisLocation rangeAxisLocation = plot.getRangeAxisLocation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation);
    float j2DX = (float) domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
    float j2DY = (float) rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
    float xx = 0.0f;
    float yy = 0.0f;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = j2DY;
        yy = j2DX;
    } else if (orientation == PlotOrientation.VERTICAL) {
        xx = j2DX;
        yy = j2DY;
    }
    int w = this.image.getWidth(null);
    int h = this.image.getHeight(null);
    Rectangle2D imageRect = new Rectangle2D.Double(0, 0, w, h);
    Point2D anchorPoint = RectangleAnchor.coordinates(imageRect, this.anchor);
    xx = xx - (float) anchorPoint.getX();
    yy = yy - (float) anchorPoint.getY();
    g2.drawImage(this.image, (int) xx, (int) yy, null);
    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, new Rectangle2D.Float(xx, yy, w, h), rendererIndex, toolTip, url);
    }
}
Also used : AxisLocation(org.jfree.chart.axis.AxisLocation) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Point2D(java.awt.geom.Point2D) Rectangle2D(java.awt.geom.Rectangle2D) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 2 with AxisLocation

use of org.jfree.chart.axis.AxisLocation in project SIMVA-SoS by SESoS.

the class XYTitleAnnotation method draw.

/**
 * Draws the annotation.  This method is called by the drawing code in the
 * {@link XYPlot} class, you don't normally need to call this method
 * directly.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  if supplied, this info object will be populated with
 *              entity information.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
    PlotOrientation orientation = plot.getOrientation();
    AxisLocation domainAxisLocation = plot.getDomainAxisLocation();
    AxisLocation rangeAxisLocation = plot.getRangeAxisLocation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation);
    Range xRange = domainAxis.getRange();
    Range yRange = rangeAxis.getRange();
    double anchorX, anchorY;
    if (this.coordinateType == XYCoordinateType.RELATIVE) {
        anchorX = xRange.getLowerBound() + (this.x * xRange.getLength());
        anchorY = yRange.getLowerBound() + (this.y * yRange.getLength());
    } else {
        anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
        anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
    }
    float j2DX = (float) domainAxis.valueToJava2D(anchorX, dataArea, domainEdge);
    float j2DY = (float) rangeAxis.valueToJava2D(anchorY, dataArea, rangeEdge);
    float xx = 0.0f;
    float yy = 0.0f;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = j2DY;
        yy = j2DX;
    } else if (orientation == PlotOrientation.VERTICAL) {
        xx = j2DX;
        yy = j2DY;
    }
    double maxW = dataArea.getWidth();
    double maxH = dataArea.getHeight();
    if (this.coordinateType == XYCoordinateType.RELATIVE) {
        if (this.maxWidth > 0.0) {
            maxW = maxW * this.maxWidth;
        }
        if (this.maxHeight > 0.0) {
            maxH = maxH * this.maxHeight;
        }
    }
    if (this.coordinateType == XYCoordinateType.DATA) {
        maxW = this.maxWidth;
        maxH = this.maxHeight;
    }
    RectangleConstraint rc = new RectangleConstraint(new Range(0, maxW), new Range(0, maxH));
    Size2D size = this.title.arrange(g2, rc);
    Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width, size.height);
    Point2D anchorPoint = RectangleAnchor.coordinates(titleRect, this.anchor);
    xx = xx - (float) anchorPoint.getX();
    yy = yy - (float) anchorPoint.getY();
    titleRect.setRect(xx, yy, titleRect.getWidth(), titleRect.getHeight());
    BlockParams p = new BlockParams();
    if (info != null) {
        if (info.getOwner().getEntityCollection() != null) {
            p.setGenerateEntities(true);
        }
    }
    Object result = this.title.draw(g2, titleRect, p);
    if (info != null) {
        if (result instanceof EntityBlockResult) {
            EntityBlockResult ebr = (EntityBlockResult) result;
            info.getOwner().getEntityCollection().addAll(ebr.getEntityCollection());
        }
        String toolTip = getToolTipText();
        String url = getURL();
        if (toolTip != null || url != null) {
            addEntity(info, new Rectangle2D.Float(xx, yy, (float) size.width, (float) size.height), rendererIndex, toolTip, url);
        }
    }
}
Also used : AxisLocation(org.jfree.chart.axis.AxisLocation) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Rectangle2D(java.awt.geom.Rectangle2D) EntityBlockResult(org.jfree.chart.block.EntityBlockResult) Range(org.jfree.data.Range) BlockParams(org.jfree.chart.block.BlockParams) Size2D(org.jfree.ui.Size2D) Point2D(java.awt.geom.Point2D) RectangleConstraint(org.jfree.chart.block.RectangleConstraint) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 3 with AxisLocation

use of org.jfree.chart.axis.AxisLocation in project SIMVA-SoS by SESoS.

the class CategoryPlot method clone.

/**
 * Returns a clone of the plot.
 *
 * @return A clone.
 *
 * @throws CloneNotSupportedException  if the cloning is not supported.
 */
@Override
public Object clone() throws CloneNotSupportedException {
    CategoryPlot clone = (CategoryPlot) super.clone();
    clone.domainAxes = CloneUtils.cloneMapValues(this.domainAxes);
    for (CategoryAxis axis : clone.domainAxes.values()) {
        if (axis != null) {
            axis.setPlot(clone);
            axis.addChangeListener(clone);
        }
    }
    clone.rangeAxes = CloneUtils.cloneMapValues(this.rangeAxes);
    for (ValueAxis axis : clone.rangeAxes.values()) {
        if (axis != null) {
            axis.setPlot(clone);
            axis.addChangeListener(clone);
        }
    }
    // AxisLocation is immutable, so we can just copy the maps
    clone.domainAxisLocations = new HashMap<Integer, AxisLocation>(this.domainAxisLocations);
    clone.rangeAxisLocations = new HashMap<Integer, AxisLocation>(this.rangeAxisLocations);
    clone.datasets = new HashMap<Integer, CategoryDataset>(this.datasets);
    for (CategoryDataset dataset : clone.datasets.values()) {
        if (dataset != null) {
            dataset.addChangeListener(clone);
        }
    }
    clone.datasetToDomainAxesMap = new TreeMap();
    clone.datasetToDomainAxesMap.putAll(this.datasetToDomainAxesMap);
    clone.datasetToRangeAxesMap = new TreeMap();
    clone.datasetToRangeAxesMap.putAll(this.datasetToRangeAxesMap);
    clone.renderers = CloneUtils.cloneMapValues(this.renderers);
    for (CategoryItemRenderer renderer : clone.renderers.values()) {
        if (renderer != null) {
            renderer.setPlot(clone);
            renderer.addChangeListener(clone);
        }
    }
    if (this.fixedDomainAxisSpace != null) {
        clone.fixedDomainAxisSpace = (AxisSpace) ObjectUtilities.clone(this.fixedDomainAxisSpace);
    }
    if (this.fixedRangeAxisSpace != null) {
        clone.fixedRangeAxisSpace = (AxisSpace) ObjectUtilities.clone(this.fixedRangeAxisSpace);
    }
    clone.annotations = (List) ObjectUtilities.deepClone(this.annotations);
    clone.foregroundDomainMarkers = cloneMarkerMap(this.foregroundDomainMarkers);
    clone.backgroundDomainMarkers = cloneMarkerMap(this.backgroundDomainMarkers);
    clone.foregroundRangeMarkers = cloneMarkerMap(this.foregroundRangeMarkers);
    clone.backgroundRangeMarkers = cloneMarkerMap(this.backgroundRangeMarkers);
    if (this.fixedLegendItems != null) {
        clone.fixedLegendItems = (LegendItemCollection) this.fixedLegendItems.clone();
    }
    return clone;
}
Also used : AxisLocation(org.jfree.chart.axis.AxisLocation) AbstractCategoryItemRenderer(org.jfree.chart.renderer.category.AbstractCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ValueAxis(org.jfree.chart.axis.ValueAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) TreeMap(java.util.TreeMap)

Example 4 with AxisLocation

use of org.jfree.chart.axis.AxisLocation in project SIMVA-SoS by SESoS.

the class CategoryPlot method getDomainAxisEdge.

/**
 * Returns the edge for a domain axis.
 *
 * @param index  the axis index.
 *
 * @return The edge (never <code>null</code>).
 */
public RectangleEdge getDomainAxisEdge(int index) {
    RectangleEdge result;
    AxisLocation location = getDomainAxisLocation(index);
    if (location != null) {
        result = Plot.resolveDomainAxisLocation(location, this.orientation);
    } else {
        result = RectangleEdge.opposite(getDomainAxisEdge(0));
    }
    return result;
}
Also used : AxisLocation(org.jfree.chart.axis.AxisLocation) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 5 with AxisLocation

use of org.jfree.chart.axis.AxisLocation in project SIMVA-SoS by SESoS.

the class XYPlot method clone.

/**
 * Returns a clone of the plot.
 *
 * @return A clone.
 *
 * @throws CloneNotSupportedException  this can occur if some component of
 *         the plot cannot be cloned.
 */
@Override
public Object clone() throws CloneNotSupportedException {
    XYPlot clone = (XYPlot) super.clone();
    clone.domainAxes = CloneUtils.cloneMapValues(this.domainAxes);
    for (ValueAxis axis : clone.domainAxes.values()) {
        if (axis != null) {
            axis.setPlot(clone);
            axis.addChangeListener(clone);
        }
    }
    clone.rangeAxes = CloneUtils.cloneMapValues(this.rangeAxes);
    for (ValueAxis axis : clone.rangeAxes.values()) {
        if (axis != null) {
            axis.setPlot(clone);
            axis.addChangeListener(clone);
        }
    }
    clone.domainAxisLocations = new HashMap<Integer, AxisLocation>(this.domainAxisLocations);
    clone.rangeAxisLocations = new HashMap<Integer, AxisLocation>(this.rangeAxisLocations);
    // the datasets are not cloned, but listeners need to be added...
    clone.datasets = new HashMap<Integer, XYDataset>(this.datasets);
    for (XYDataset dataset : clone.datasets.values()) {
        if (dataset != null) {
            dataset.addChangeListener(clone);
        }
    }
    clone.datasetToDomainAxesMap = new TreeMap();
    clone.datasetToDomainAxesMap.putAll(this.datasetToDomainAxesMap);
    clone.datasetToRangeAxesMap = new TreeMap();
    clone.datasetToRangeAxesMap.putAll(this.datasetToRangeAxesMap);
    clone.renderers = CloneUtils.cloneMapValues(this.renderers);
    for (XYItemRenderer renderer : clone.renderers.values()) {
        if (renderer != null) {
            renderer.setPlot(clone);
            renderer.addChangeListener(clone);
        }
    }
    clone.foregroundDomainMarkers = (Map) ObjectUtilities.clone(this.foregroundDomainMarkers);
    clone.backgroundDomainMarkers = (Map) ObjectUtilities.clone(this.backgroundDomainMarkers);
    clone.foregroundRangeMarkers = (Map) ObjectUtilities.clone(this.foregroundRangeMarkers);
    clone.backgroundRangeMarkers = (Map) ObjectUtilities.clone(this.backgroundRangeMarkers);
    clone.annotations = (List) ObjectUtilities.deepClone(this.annotations);
    if (this.fixedDomainAxisSpace != null) {
        clone.fixedDomainAxisSpace = (AxisSpace) ObjectUtilities.clone(this.fixedDomainAxisSpace);
    }
    if (this.fixedRangeAxisSpace != null) {
        clone.fixedRangeAxisSpace = (AxisSpace) ObjectUtilities.clone(this.fixedRangeAxisSpace);
    }
    if (this.fixedLegendItems != null) {
        clone.fixedLegendItems = (LegendItemCollection) this.fixedLegendItems.clone();
    }
    clone.quadrantOrigin = (Point2D) ObjectUtilities.clone(this.quadrantOrigin);
    clone.quadrantPaint = this.quadrantPaint.clone();
    return clone;
}
Also used : AxisLocation(org.jfree.chart.axis.AxisLocation) ValueAxis(org.jfree.chart.axis.ValueAxis) XYDataset(org.jfree.data.xy.XYDataset) AbstractXYItemRenderer(org.jfree.chart.renderer.xy.AbstractXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) TreeMap(java.util.TreeMap)

Aggregations

AxisLocation (org.jfree.chart.axis.AxisLocation)6 RectangleEdge (org.jfree.ui.RectangleEdge)4 Rectangle2D (java.awt.geom.Rectangle2D)3 PlotOrientation (org.jfree.chart.plot.PlotOrientation)3 Point2D (java.awt.geom.Point2D)2 TreeMap (java.util.TreeMap)2 ValueAxis (org.jfree.chart.axis.ValueAxis)2 CategoryAxis (org.jfree.chart.axis.CategoryAxis)1 BlockParams (org.jfree.chart.block.BlockParams)1 EntityBlockResult (org.jfree.chart.block.EntityBlockResult)1 RectangleConstraint (org.jfree.chart.block.RectangleConstraint)1 AbstractCategoryItemRenderer (org.jfree.chart.renderer.category.AbstractCategoryItemRenderer)1 CategoryItemRenderer (org.jfree.chart.renderer.category.CategoryItemRenderer)1 AbstractXYItemRenderer (org.jfree.chart.renderer.xy.AbstractXYItemRenderer)1 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)1 Range (org.jfree.data.Range)1 CategoryDataset (org.jfree.data.category.CategoryDataset)1 XYDataset (org.jfree.data.xy.XYDataset)1 Size2D (org.jfree.ui.Size2D)1