Search in sources :

Example 26 with RectangleEdge

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

the class YIntervalRenderer method drawItem.

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the plot is being drawn.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param selected  is the item selected?
 * @param pass  the pass index (ignored here).
 *
 * @since 1.2.0
 */
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, boolean selected, int pass) {
    // setup for collecting optional entity info...
    EntityCollection entities = null;
    if (state.getInfo() != null) {
        entities = state.getInfo().getOwner().getEntityCollection();
    }
    IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;
    double x = intervalDataset.getXValue(series, item);
    double yLow = intervalDataset.getStartYValue(series, item);
    double yHigh = intervalDataset.getEndYValue(series, item);
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
    double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
    double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);
    Paint p = getItemPaint(series, item, selected);
    Stroke s = getItemStroke(series, item, selected);
    Line2D line = null;
    Shape shape = getItemShape(series, item, selected);
    Shape top = null;
    Shape bottom = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(yyLow, xx, yyHigh, xx);
        top = ShapeUtilities.createTranslatedShape(shape, yyHigh, xx);
        bottom = ShapeUtilities.createTranslatedShape(shape, yyLow, xx);
    } else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(xx, yyLow, xx, yyHigh);
        top = ShapeUtilities.createTranslatedShape(shape, xx, yyHigh);
        bottom = ShapeUtilities.createTranslatedShape(shape, xx, yyLow);
    }
    g2.setPaint(p);
    g2.setStroke(s);
    g2.draw(line);
    g2.fill(top);
    g2.fill(bottom);
    // PLUS an additional item label near the lower y-value.
    if (isItemLabelVisible(series, item, selected)) {
        drawItemLabel(g2, orientation, dataset, series, item, selected, xx, yyHigh, false);
        drawAdditionalItemLabel(g2, orientation, dataset, series, item, xx, yyLow);
    }
    // add an entity for the item...
    if (entities != null) {
        addEntity(entities, line.getBounds(), dataset, series, item, selected, 0.0, 0.0);
    }
}
Also used : Stroke(java.awt.Stroke) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Shape(java.awt.Shape) EntityCollection(org.jfree.chart.entity.EntityCollection) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Example 27 with RectangleEdge

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

the class LegendTitle method fetchLegendItems.

/**
 * Fetches the latest legend items.
 */
protected void fetchLegendItems() {
    this.items.clear();
    RectangleEdge p = getPosition();
    if (RectangleEdge.isTopOrBottom(p)) {
        this.items.setArrangement(this.hLayout);
    } else {
        this.items.setArrangement(this.vLayout);
    }
    for (int s = 0; s < this.sources.length; s++) {
        LegendItemCollection legendItems = this.sources[s].getLegendItems();
        if (legendItems != null) {
            for (int i = 0; i < legendItems.getItemCount(); i++) {
                LegendItem item = legendItems.get(i);
                Block block = createLegendItemBlock(item);
                this.items.add(block);
            }
        }
    }
}
Also used : LegendItem(org.jfree.chart.LegendItem) LegendItemCollection(org.jfree.chart.LegendItemCollection) LabelBlock(org.jfree.chart.block.LabelBlock) Block(org.jfree.chart.block.Block) RectangleConstraint(org.jfree.chart.block.RectangleConstraint) Paint(java.awt.Paint) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Example 28 with RectangleEdge

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

the class CategoryPlot method draw.

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer).
 * <P>
 * At your option, you may supply an instance of {@link PlotRenderingInfo}.
 * If you do, it will be populated with information about the drawing,
 * including various plot dimensions and tooltip info.
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot (including axes) should
 *              be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param state  collects info as the chart is drawn (possibly
 *               <code>null</code>).
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo state) {
    // if the plot area is too small, just return...
    boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
    boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
    if (b1 || b2) {
        return;
    }
    // record the plot area...
    if (state == null) {
        // if the incoming state is null, no information will be passed
        // back to the caller - but we create a temporary state to record
        // the plot area, since that is used later by the axes
        state = new PlotRenderingInfo(null);
    }
    state.setPlotArea(area);
    // adjust the drawing area for the plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);
    // calculate the data area...
    AxisSpace space = calculateAxisSpace(g2, area);
    Rectangle2D dataArea = space.shrink(area, null);
    this.axisOffset.trim(dataArea);
    dataArea = integerise(dataArea);
    if (dataArea.isEmpty()) {
        return;
    }
    state.setDataArea(dataArea);
    createAndAddEntity((Rectangle2D) dataArea.clone(), state, null, null);
    // default background...
    if (getRenderer() != null) {
        getRenderer().drawBackground(g2, this, dataArea);
    } else {
        drawBackground(g2, dataArea);
    }
    Map axisStateMap = drawAxes(g2, area, dataArea, state);
    // clicked - the crosshairs will be driven off this point...
    if (anchor != null && !dataArea.contains(anchor)) {
        anchor = ShapeUtilities.getPointInRectangle(anchor.getX(), anchor.getY(), dataArea);
    }
    CategoryCrosshairState crosshairState = new CategoryCrosshairState();
    crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY);
    crosshairState.setAnchor(anchor);
    // specify the anchor X and Y coordinates in Java2D space, for the
    // cases where these are not updated during rendering (i.e. no lock
    // on data)
    crosshairState.setAnchorX(Double.NaN);
    crosshairState.setAnchorY(Double.NaN);
    if (anchor != null) {
        ValueAxis rangeAxis = getRangeAxis();
        if (rangeAxis != null) {
            double y;
            if (getOrientation() == PlotOrientation.VERTICAL) {
                y = rangeAxis.java2DToValue(anchor.getY(), dataArea, getRangeAxisEdge());
            } else {
                y = rangeAxis.java2DToValue(anchor.getX(), dataArea, getRangeAxisEdge());
            }
            crosshairState.setAnchorY(y);
        }
    }
    crosshairState.setRowKey(getDomainCrosshairRowKey());
    crosshairState.setColumnKey(getDomainCrosshairColumnKey());
    crosshairState.setCrosshairY(getRangeCrosshairValue());
    // don't let anyone draw outside the data area
    Shape savedClip = g2.getClip();
    g2.clip(dataArea);
    drawDomainGridlines(g2, dataArea);
    AxisState rangeAxisState = (AxisState) axisStateMap.get(getRangeAxis());
    if (rangeAxisState == null) {
        if (parentState != null) {
            rangeAxisState = (AxisState) parentState.getSharedAxisStates().get(getRangeAxis());
        }
    }
    if (rangeAxisState != null) {
        drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());
        drawZeroRangeBaseline(g2, dataArea);
    }
    Graphics2D savedG2 = g2;
    Rectangle2D savedDataArea = dataArea;
    BufferedImage dataImage = null;
    if (this.shadowGenerator != null) {
        dataImage = new BufferedImage((int) dataArea.getWidth(), (int) dataArea.getHeight(), BufferedImage.TYPE_INT_ARGB);
        g2 = dataImage.createGraphics();
        g2.setRenderingHints(savedG2.getRenderingHints());
        dataArea = new Rectangle(0, 0, dataImage.getWidth(), dataImage.getHeight());
    }
    // draw the markers...
    for (int i = 0; i < this.renderers.size(); i++) {
        drawDomainMarkers(g2, dataArea, i, Layer.BACKGROUND);
    }
    for (int i = 0; i < this.renderers.size(); i++) {
        drawRangeMarkers(g2, dataArea, i, Layer.BACKGROUND);
    }
    // now render data items...
    boolean foundData = false;
    // set up the alpha-transparency...
    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    DatasetRenderingOrder order = getDatasetRenderingOrder();
    if (order == DatasetRenderingOrder.FORWARD) {
        // draw background annotations
        int datasetCount = this.datasets.size();
        for (int i = 0; i < datasetCount; i++) {
            CategoryItemRenderer r = getRenderer(i);
            if (r != null) {
                CategoryAxis domainAxis = getDomainAxisForDataset(i);
                ValueAxis rangeAxis = getRangeAxisForDataset(i);
                r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.BACKGROUND, state);
            }
        }
        for (int i = 0; i < datasetCount; i++) {
            foundData = render(g2, dataArea, i, state, crosshairState) || foundData;
        }
        // draw foreground annotations
        for (int i = 0; i < datasetCount; i++) {
            CategoryItemRenderer r = getRenderer(i);
            if (r != null) {
                CategoryAxis domainAxis = getDomainAxisForDataset(i);
                ValueAxis rangeAxis = getRangeAxisForDataset(i);
                r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.FOREGROUND, state);
            }
        }
    } else {
        // DatasetRenderingOrder.REVERSE
        // draw background annotations
        int datasetCount = this.datasets.size();
        for (int i = datasetCount - 1; i >= 0; i--) {
            CategoryItemRenderer r = getRenderer(i);
            if (r != null) {
                CategoryAxis domainAxis = getDomainAxisForDataset(i);
                ValueAxis rangeAxis = getRangeAxisForDataset(i);
                r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.BACKGROUND, state);
            }
        }
        for (int i = this.datasets.size() - 1; i >= 0; i--) {
            foundData = render(g2, dataArea, i, state, crosshairState) || foundData;
        }
        // draw foreground annotations
        for (int i = datasetCount - 1; i >= 0; i--) {
            CategoryItemRenderer r = getRenderer(i);
            if (r != null) {
                CategoryAxis domainAxis = getDomainAxisForDataset(i);
                ValueAxis rangeAxis = getRangeAxisForDataset(i);
                r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.FOREGROUND, state);
            }
        }
    }
    // draw the foreground markers...
    for (int i = 0; i < this.renderers.size(); i++) {
        drawDomainMarkers(g2, dataArea, i, Layer.FOREGROUND);
    }
    for (int i = 0; i < this.renderers.size(); i++) {
        drawRangeMarkers(g2, dataArea, i, Layer.FOREGROUND);
    }
    // draw the plot's annotations (if any)...
    drawAnnotations(g2, dataArea, state);
    if (this.shadowGenerator != null) {
        BufferedImage shadowImage = this.shadowGenerator.createDropShadow(dataImage);
        g2 = savedG2;
        dataArea = savedDataArea;
        g2.drawImage(shadowImage, (int) savedDataArea.getX() + this.shadowGenerator.calculateOffsetX(), (int) savedDataArea.getY() + this.shadowGenerator.calculateOffsetY(), null);
        g2.drawImage(dataImage, (int) savedDataArea.getX(), (int) savedDataArea.getY(), null);
    }
    g2.setClip(savedClip);
    g2.setComposite(originalComposite);
    if (!foundData) {
        drawNoDataMessage(g2, dataArea);
    }
    int datasetIndex = crosshairState.getDatasetIndex();
    setCrosshairDatasetIndex(datasetIndex, false);
    // draw domain crosshair if required...
    Comparable rowKey = crosshairState.getRowKey();
    Comparable columnKey = crosshairState.getColumnKey();
    setDomainCrosshairRowKey(rowKey, false);
    setDomainCrosshairColumnKey(columnKey, false);
    if (isDomainCrosshairVisible() && columnKey != null) {
        Paint paint = getDomainCrosshairPaint();
        Stroke stroke = getDomainCrosshairStroke();
        drawDomainCrosshair(g2, dataArea, this.orientation, datasetIndex, rowKey, columnKey, stroke, paint);
    }
    // draw range crosshair if required...
    ValueAxis yAxis = getRangeAxisForDataset(datasetIndex);
    RectangleEdge yAxisEdge = getRangeAxisEdge();
    if (!this.rangeCrosshairLockedOnData && anchor != null) {
        double yy;
        if (getOrientation() == PlotOrientation.VERTICAL) {
            yy = yAxis.java2DToValue(anchor.getY(), dataArea, yAxisEdge);
        } else {
            yy = yAxis.java2DToValue(anchor.getX(), dataArea, yAxisEdge);
        }
        crosshairState.setCrosshairY(yy);
    }
    setRangeCrosshairValue(crosshairState.getCrosshairY(), false);
    if (isRangeCrosshairVisible()) {
        double y = getRangeCrosshairValue();
        Paint paint = getRangeCrosshairPaint();
        Stroke stroke = getRangeCrosshairStroke();
        drawRangeCrosshair(g2, dataArea, getOrientation(), y, yAxis, stroke, paint);
    }
    // draw an outline around the plot area...
    if (isOutlineVisible()) {
        if (getRenderer() != null) {
            getRenderer().drawOutline(g2, this, dataArea);
        } else {
            drawOutline(g2, dataArea);
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) Shape(java.awt.Shape) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) Rectangle2D(java.awt.geom.Rectangle2D) Rectangle(java.awt.Rectangle) Paint(java.awt.Paint) BufferedImage(java.awt.image.BufferedImage) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D) AxisState(org.jfree.chart.axis.AxisState) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ValueAxis(org.jfree.chart.axis.ValueAxis) RectangleInsets(org.jfree.chart.util.RectangleInsets) AxisSpace(org.jfree.chart.axis.AxisSpace) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Example 29 with RectangleEdge

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

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 = null;
    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.chart.util.RectangleEdge)

Example 30 with RectangleEdge

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

the class CategoryPlot method calculateDomainAxisSpace.

/**
 * Calculates the space required for the domain 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 calculateDomainAxisSpace(Graphics2D g2, Rectangle2D plotArea, AxisSpace space) {
    if (space == null) {
        space = new AxisSpace();
    }
    // reserve some space for the domain axis...
    if (this.fixedDomainAxisSpace != null) {
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            space.ensureAtLeast(this.fixedDomainAxisSpace.getLeft(), RectangleEdge.LEFT);
            space.ensureAtLeast(this.fixedDomainAxisSpace.getRight(), RectangleEdge.RIGHT);
        } else if (this.orientation == PlotOrientation.VERTICAL) {
            space.ensureAtLeast(this.fixedDomainAxisSpace.getTop(), RectangleEdge.TOP);
            space.ensureAtLeast(this.fixedDomainAxisSpace.getBottom(), RectangleEdge.BOTTOM);
        }
    } else {
        // reserve space for the primary domain axis...
        RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(getDomainAxisLocation(), this.orientation);
        if (this.drawSharedDomainAxis) {
            space = getDomainAxis().reserveSpace(g2, this, plotArea, domainEdge, space);
        }
        // reserve space for any domain axes...
        for (int i = 0; i < this.domainAxes.size(); i++) {
            Axis xAxis = (Axis) this.domainAxes.get(i);
            if (xAxis != null) {
                RectangleEdge edge = getDomainAxisEdge(i);
                space = xAxis.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)

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