Search in sources :

Example 61 with RectangleEdge

use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.

the class CategoryPlot method calculateRangeAxisSpace.

/**
 * Calculates the space required for the range axis/axes.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param space  a carrier for the result (<code>null</code> permitted).
 *
 * @return The required space.
 */
protected AxisSpace calculateRangeAxisSpace(Graphics2D g2, Rectangle2D plotArea, AxisSpace space) {
    if (space == null) {
        space = new AxisSpace();
    }
    // reserve some space for the range axis...
    if (this.fixedRangeAxisSpace != null) {
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            space.ensureAtLeast(this.fixedRangeAxisSpace.getTop(), RectangleEdge.TOP);
            space.ensureAtLeast(this.fixedRangeAxisSpace.getBottom(), RectangleEdge.BOTTOM);
        } else if (this.orientation == PlotOrientation.VERTICAL) {
            space.ensureAtLeast(this.fixedRangeAxisSpace.getLeft(), RectangleEdge.LEFT);
            space.ensureAtLeast(this.fixedRangeAxisSpace.getRight(), RectangleEdge.RIGHT);
        }
    } else {
        // reserve space for the range axes (if any)...
        for (int i = 0; i < this.rangeAxes.size(); i++) {
            Axis yAxis = (Axis) this.rangeAxes.get(i);
            if (yAxis != null) {
                RectangleEdge edge = getRangeAxisEdge(i);
                space = yAxis.reserveSpace(g2, this, plotArea, edge, space);
            }
        }
    }
    return space;
}
Also used : AxisSpace(org.jfree.chart.axis.AxisSpace) Paint(java.awt.Paint) CategoryAxis(org.jfree.chart.axis.CategoryAxis) Axis(org.jfree.chart.axis.Axis) ValueAxis(org.jfree.chart.axis.ValueAxis) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Example 62 with RectangleEdge

use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.

the class CategoryPlot method handleClick.

/**
 * Handles a 'click' on the plot by updating the anchor value.
 *
 * @param x  x-coordinate of the click (in Java2D space).
 * @param y  y-coordinate of the click (in Java2D space).
 * @param info  information about the plot's dimensions.
 */
public void handleClick(int x, int y, PlotRenderingInfo info) {
    Rectangle2D dataArea = info.getDataArea();
    if (dataArea.contains(x, y)) {
        // set the anchor value for the range axis...
        double java2D = 0.0;
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            java2D = x;
        } else if (this.orientation == PlotOrientation.VERTICAL) {
            java2D = y;
        }
        RectangleEdge edge = Plot.resolveRangeAxisLocation(getRangeAxisLocation(), this.orientation);
        double value = getRangeAxis().java2DToValue(java2D, info.getDataArea(), edge);
        setAnchorValue(value);
        setRangeCrosshairValue(value);
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Example 63 with RectangleEdge

use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.

the class CombinedDomainXYPlot method calculateAxisSpace.

/**
 * Calculates the axis space required.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 *
 * @return The space.
 */
protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) {
    AxisSpace space = new AxisSpace();
    PlotOrientation orientation = getOrientation();
    // work out the space required by the domain axis...
    AxisSpace fixed = getFixedDomainAxisSpace();
    if (fixed != null) {
        if (orientation == PlotOrientation.HORIZONTAL) {
            space.setLeft(fixed.getLeft());
            space.setRight(fixed.getRight());
        } else if (orientation == PlotOrientation.VERTICAL) {
            space.setTop(fixed.getTop());
            space.setBottom(fixed.getBottom());
        }
    } else {
        ValueAxis xAxis = getDomainAxis();
        RectangleEdge xEdge = Plot.resolveDomainAxisLocation(getDomainAxisLocation(), orientation);
        if (xAxis != null) {
            space = xAxis.reserveSpace(g2, this, plotArea, xEdge, space);
        }
    }
    Rectangle2D adjustedPlotArea = space.shrink(plotArea, null);
    // work out the maximum height or width of the non-shared axes...
    int n = this.subplots.size();
    int totalWeight = 0;
    for (int i = 0; i < n; i++) {
        XYPlot sub = (XYPlot) this.subplots.get(i);
        totalWeight += sub.getWeight();
    }
    this.subplotAreas = new Rectangle2D[n];
    double x = adjustedPlotArea.getX();
    double y = adjustedPlotArea.getY();
    double usableSize = 0.0;
    if (orientation == PlotOrientation.HORIZONTAL) {
        usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1);
    } else if (orientation == PlotOrientation.VERTICAL) {
        usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1);
    }
    for (int i = 0; i < n; i++) {
        XYPlot plot = (XYPlot) this.subplots.get(i);
        // calculate sub-plot area
        if (orientation == PlotOrientation.HORIZONTAL) {
            double w = usableSize * plot.getWeight() / totalWeight;
            this.subplotAreas[i] = new Rectangle2D.Double(x, y, w, adjustedPlotArea.getHeight());
            x = x + w + this.gap;
        } else if (orientation == PlotOrientation.VERTICAL) {
            double h = usableSize * plot.getWeight() / totalWeight;
            this.subplotAreas[i] = new Rectangle2D.Double(x, y, adjustedPlotArea.getWidth(), h);
            y = y + h + this.gap;
        }
        AxisSpace subSpace = plot.calculateRangeAxisSpace(g2, this.subplotAreas[i], null);
        space.ensureAtLeast(subSpace);
    }
    return space;
}
Also used : ValueAxis(org.jfree.chart.axis.ValueAxis) Rectangle2D(java.awt.geom.Rectangle2D) AxisSpace(org.jfree.chart.axis.AxisSpace) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Example 64 with RectangleEdge

use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.

the class CrosshairOverlay method paintOverlay.

/**
 * Paints the crosshairs in the layer.
 *
 * @param g2  the graphics target.
 * @param chartPanel  the chart panel.
 */
public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) {
    Shape savedClip = g2.getClip();
    Rectangle2D dataArea = chartPanel.getScreenDataArea();
    g2.clip(dataArea);
    JFreeChart chart = chartPanel.getChart();
    XYPlot plot = (XYPlot) chart.getPlot();
    ValueAxis xAxis = plot.getDomainAxis();
    RectangleEdge xAxisEdge = plot.getDomainAxisEdge();
    Iterator iterator = this.xCrosshairs.iterator();
    while (iterator.hasNext()) {
        Crosshair ch = (Crosshair) iterator.next();
        if (ch.isVisible()) {
            double x = ch.getValue();
            double xx = xAxis.valueToJava2D(x, dataArea, xAxisEdge);
            if (plot.getOrientation() == PlotOrientation.VERTICAL) {
                drawVerticalCrosshair(g2, dataArea, xx, ch);
            } else {
                drawHorizontalCrosshair(g2, dataArea, xx, ch);
            }
        }
    }
    ValueAxis yAxis = plot.getRangeAxis();
    RectangleEdge yAxisEdge = plot.getRangeAxisEdge();
    iterator = this.yCrosshairs.iterator();
    while (iterator.hasNext()) {
        Crosshair ch = (Crosshair) iterator.next();
        if (ch.isVisible()) {
            double y = ch.getValue();
            double yy = yAxis.valueToJava2D(y, dataArea, yAxisEdge);
            if (plot.getOrientation() == PlotOrientation.VERTICAL) {
                drawHorizontalCrosshair(g2, dataArea, yy, ch);
            } else {
                drawVerticalCrosshair(g2, dataArea, yy, ch);
            }
        }
    }
    g2.setClip(savedClip);
}
Also used : Shape(java.awt.Shape) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) Crosshair(org.jfree.chart.plot.Crosshair) Rectangle2D(java.awt.geom.Rectangle2D) Iterator(java.util.Iterator) JFreeChart(org.jfree.chart.JFreeChart) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Example 65 with RectangleEdge

use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.

the class XYLineAnnotation method draw.

/**
 * Draws the annotation.  This method is called by the {@link XYPlot}
 * class, you won't normally need to call it yourself.
 *
 * @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.
 */
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
    float j2DX1 = 0.0f;
    float j2DX2 = 0.0f;
    float j2DY1 = 0.0f;
    float j2DY2 = 0.0f;
    if (orientation == PlotOrientation.VERTICAL) {
        j2DX1 = (float) domainAxis.valueToJava2D(this.x1, dataArea, domainEdge);
        j2DY1 = (float) rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge);
        j2DX2 = (float) domainAxis.valueToJava2D(this.x2, dataArea, domainEdge);
        j2DY2 = (float) rangeAxis.valueToJava2D(this.y2, dataArea, rangeEdge);
    } else if (orientation == PlotOrientation.HORIZONTAL) {
        j2DY1 = (float) domainAxis.valueToJava2D(this.x1, dataArea, domainEdge);
        j2DX1 = (float) rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge);
        j2DY2 = (float) domainAxis.valueToJava2D(this.x2, dataArea, domainEdge);
        j2DX2 = (float) rangeAxis.valueToJava2D(this.y2, dataArea, rangeEdge);
    }
    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    Line2D line = new Line2D.Float(j2DX1, j2DY1, j2DX2, j2DY2);
    // line is clipped to avoid JRE bug 6574155, for more info
    // see JFreeChart bug 2221495
    boolean visible = ShapeUtilities.clipLine(line, dataArea);
    if (visible) {
        g2.draw(line);
    }
    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, ShapeUtilities.createLineRegion(line, 1.0f), rendererIndex, toolTip, url);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Line2D(java.awt.geom.Line2D) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Aggregations

RectangleEdge (org.jfree.chart.util.RectangleEdge)88 Rectangle2D (java.awt.geom.Rectangle2D)48 Paint (java.awt.Paint)45 PlotOrientation (org.jfree.chart.plot.PlotOrientation)44 EntityCollection (org.jfree.chart.entity.EntityCollection)33 Stroke (java.awt.Stroke)20 Shape (java.awt.Shape)18 Line2D (java.awt.geom.Line2D)17 AxisSpace (org.jfree.chart.axis.AxisSpace)15 ValueAxis (org.jfree.chart.axis.ValueAxis)15 CategoryItemLabelGenerator (org.jfree.chart.labels.CategoryItemLabelGenerator)12 GeneralPath (java.awt.geom.GeneralPath)10 AxisLocation (org.jfree.chart.axis.AxisLocation)7 IntervalXYDataset (org.jfree.data.xy.IntervalXYDataset)7 Point2D (java.awt.geom.Point2D)6 AxisState (org.jfree.chart.axis.AxisState)6 CategoryAxis (org.jfree.chart.axis.CategoryAxis)6 XYCrosshairState (org.jfree.chart.plot.XYCrosshairState)6 RectangleInsets (org.jfree.chart.util.RectangleInsets)6 GradientPaint (java.awt.GradientPaint)5