Search in sources :

Example 56 with RectangleEdge

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

the class StackedBarRenderer method drawItem.

/**
 * Draws a stacked bar for a specific item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the plot area.
 * @param plot  the plot.
 * @param domainAxis  the domain (category) axis.
 * @param rangeAxis  the range (value) axis.
 * @param dataset  the data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, boolean selected, int pass) {
    if (!isSeriesVisible(row)) {
        return;
    }
    // nothing is drawn for null values...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }
    double value = dataValue.doubleValue();
    // only needed if calculating percentages
    double total = 0.0;
    if (this.renderAsPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset, column, state.getVisibleSeriesArray());
        value = value / total;
    }
    PlotOrientation orientation = plot.getOrientation();
    double barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0;
    double positiveBase = getBase();
    double negativeBase = positiveBase;
    for (int i = 0; i < row; i++) {
        Number v = dataset.getValue(i, column);
        if (v != null && isSeriesVisible(i)) {
            double d = v.doubleValue();
            if (this.renderAsPercentages) {
                d = d / total;
            }
            if (d > 0) {
                positiveBase = positiveBase + d;
            } else {
                negativeBase = negativeBase + d;
            }
        }
    }
    double translatedBase;
    double translatedValue;
    boolean positive = (value > 0.0);
    boolean inverted = rangeAxis.isInverted();
    RectangleEdge barBase;
    if (orientation == PlotOrientation.HORIZONTAL) {
        if (positive && inverted || !positive && !inverted) {
            barBase = RectangleEdge.RIGHT;
        } else {
            barBase = RectangleEdge.LEFT;
        }
    } else {
        if (positive && !inverted || !positive && inverted) {
            barBase = RectangleEdge.BOTTOM;
        } else {
            barBase = RectangleEdge.TOP;
        }
    }
    RectangleEdge location = plot.getRangeAxisEdge();
    if (positive) {
        translatedBase = rangeAxis.valueToJava2D(positiveBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(positiveBase + value, dataArea, location);
    } else {
        translatedBase = rangeAxis.valueToJava2D(negativeBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(negativeBase + value, dataArea, location);
    }
    double barL0 = Math.min(translatedBase, translatedValue);
    double barLength = Math.max(Math.abs(translatedValue - translatedBase), getMinimumBarLength());
    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    if (pass == 0) {
        if (getShadowsVisible()) {
            boolean pegToBase = (positive && (positiveBase == getBase())) || (!positive && (negativeBase == getBase()));
            getBarPainter().paintBarShadow(g2, this, row, column, selected, bar, barBase, pegToBase);
        }
    } else if (pass == 1) {
        getBarPainter().paintBar(g2, this, row, column, selected, bar, barBase);
        // add an item entity, if this information is being collected
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addEntity(entities, bar, dataset, row, column, selected);
        }
    } else if (pass == 2) {
        CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column, selected);
        if (generator != null && isItemLabelVisible(row, column, selected)) {
            drawItemLabelForBar(g2, plot, dataset, row, column, selected, generator, bar, (value < 0.0));
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) EntityCollection(org.jfree.chart.entity.EntityCollection) Rectangle2D(java.awt.geom.Rectangle2D) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Example 57 with RectangleEdge

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

the class AreaRenderer method drawItem.

/**
 * Draw a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data plot area.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param selected  is the item selected?
 * @param pass  the pass index.
 *
 * @since 1.2.0
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, boolean selected, int pass) {
    // do nothing if item is not visible or null
    if (!getItemVisible(row, column)) {
        return;
    }
    Number value = dataset.getValue(row, column);
    if (value == null) {
        return;
    }
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge axisEdge = plot.getDomainAxisEdge();
    int count = dataset.getColumnCount();
    float x0 = (float) domainAxis.getCategoryStart(column, count, dataArea, axisEdge);
    float x1 = (float) domainAxis.getCategoryMiddle(column, count, dataArea, axisEdge);
    float x2 = (float) domainAxis.getCategoryEnd(column, count, dataArea, axisEdge);
    x0 = Math.round(x0);
    x1 = Math.round(x1);
    x2 = Math.round(x2);
    if (this.endType == AreaRendererEndType.TRUNCATE) {
        if (column == 0) {
            x0 = x1;
        } else if (column == getColumnCount() - 1) {
            x2 = x1;
        }
    }
    double yy1 = value.doubleValue();
    double yy0 = 0.0;
    if (this.endType == AreaRendererEndType.LEVEL) {
        yy0 = yy1;
    }
    if (column > 0) {
        Number n0 = dataset.getValue(row, column - 1);
        if (n0 != null) {
            yy0 = (n0.doubleValue() + yy1) / 2.0;
        }
    }
    double yy2 = 0.0;
    if (column < dataset.getColumnCount() - 1) {
        Number n2 = dataset.getValue(row, column + 1);
        if (n2 != null) {
            yy2 = (n2.doubleValue() + yy1) / 2.0;
        }
    } else if (this.endType == AreaRendererEndType.LEVEL) {
        yy2 = yy1;
    }
    RectangleEdge edge = plot.getRangeAxisEdge();
    float y0 = (float) rangeAxis.valueToJava2D(yy0, dataArea, edge);
    float y1 = (float) rangeAxis.valueToJava2D(yy1, dataArea, edge);
    float y2 = (float) rangeAxis.valueToJava2D(yy2, dataArea, edge);
    float yz = (float) rangeAxis.valueToJava2D(0.0, dataArea, edge);
    double labelXX = x1;
    double labelYY = y1;
    g2.setPaint(getItemPaint(row, column, selected));
    g2.setStroke(getItemStroke(row, column, selected));
    GeneralPath area = new GeneralPath();
    if (orientation == PlotOrientation.VERTICAL) {
        area.moveTo(x0, yz);
        area.lineTo(x0, y0);
        area.lineTo(x1, y1);
        area.lineTo(x2, y2);
        area.lineTo(x2, yz);
    } else if (orientation == PlotOrientation.HORIZONTAL) {
        area.moveTo(yz, x0);
        area.lineTo(y0, x0);
        area.lineTo(y1, x1);
        area.lineTo(y2, x2);
        area.lineTo(yz, x2);
        double temp = labelXX;
        labelXX = labelYY;
        labelYY = temp;
    }
    area.closePath();
    g2.setPaint(getItemPaint(row, column, selected));
    g2.fill(area);
    // draw the item labels if there are any...
    if (isItemLabelVisible(row, column, selected)) {
        drawItemLabel(g2, orientation, dataset, row, column, selected, labelXX, labelYY, (value.doubleValue() < 0.0));
    }
    // submit the current data point as a crosshair candidate
    int datasetIndex = plot.indexOf(dataset);
    updateCrosshairValues(state.getCrosshairState(), dataset.getRowKey(row), dataset.getColumnKey(column), yy1, datasetIndex, x1, y1, orientation);
    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addEntity(entities, area, dataset, row, column, selected);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) GeneralPath(java.awt.geom.GeneralPath) EntityCollection(org.jfree.chart.entity.EntityCollection) Paint(java.awt.Paint) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Example 58 with RectangleEdge

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

the class JFreeChartInfo method drawTitle.

/**
 * Draws a title.  The title should be drawn at the top, bottom, left or
 * right of the specified area, and the area should be updated to reflect
 * the amount of space used by the title.
 *
 * @param t  the title (<code>null</code> not permitted).
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param area  the chart area, excluding any existing titles
 *              (<code>null</code> not permitted).
 * @param entities  a flag that controls whether or not an entity
 *                  collection is returned for the title.
 *
 * @return An entity collection for the title (possibly <code>null</code>).
 */
protected EntityCollection drawTitle(Title t, Graphics2D g2, Rectangle2D area, boolean entities) {
    if (t == null) {
        throw new IllegalArgumentException("Null 't' argument.");
    }
    if (area == null) {
        throw new IllegalArgumentException("Null 'area' argument.");
    }
    Rectangle2D titleArea;
    RectangleEdge position = t.getPosition();
    double ww = area.getWidth();
    if (ww <= 0.0) {
        return null;
    }
    double hh = area.getHeight();
    if (hh <= 0.0) {
        return null;
    }
    RectangleConstraint constraint = new RectangleConstraint(ww, new Range(0.0, ww), LengthConstraintType.RANGE, hh, new Range(0.0, hh), LengthConstraintType.RANGE);
    Object retValue = null;
    BlockParams p = new BlockParams();
    p.setGenerateEntities(entities);
    if (position == RectangleEdge.TOP) {
        Size2D size = t.arrange(g2, constraint);
        titleArea = createAlignedRectangle2D(size, area, t.getHorizontalAlignment(), VerticalAlignment.TOP);
        retValue = t.draw(g2, titleArea, p);
        area.setRect(area.getX(), Math.min(area.getY() + size.height, area.getMaxY()), area.getWidth(), Math.max(area.getHeight() - size.height, 0));
    } else if (position == RectangleEdge.BOTTOM) {
        Size2D size = t.arrange(g2, constraint);
        titleArea = createAlignedRectangle2D(size, area, t.getHorizontalAlignment(), VerticalAlignment.BOTTOM);
        retValue = t.draw(g2, titleArea, p);
        area.setRect(area.getX(), area.getY(), area.getWidth(), area.getHeight() - size.height);
    } else if (position == RectangleEdge.RIGHT) {
        Size2D size = t.arrange(g2, constraint);
        titleArea = createAlignedRectangle2D(size, area, HorizontalAlignment.RIGHT, t.getVerticalAlignment());
        retValue = t.draw(g2, titleArea, p);
        area.setRect(area.getX(), area.getY(), area.getWidth() - size.width, area.getHeight());
    } else if (position == RectangleEdge.LEFT) {
        Size2D size = t.arrange(g2, constraint);
        titleArea = createAlignedRectangle2D(size, area, HorizontalAlignment.LEFT, t.getVerticalAlignment());
        retValue = t.draw(g2, titleArea, p);
        area.setRect(area.getX() + size.width, area.getY(), area.getWidth() - size.width, area.getHeight());
    } else {
        throw new RuntimeException("Unrecognised title position.");
    }
    EntityCollection result = null;
    if (retValue instanceof EntityBlockResult) {
        EntityBlockResult ebr = (EntityBlockResult) retValue;
        result = ebr.getEntityCollection();
    }
    return result;
}
Also used : Size2D(org.jfree.chart.util.Size2D) EntityCollection(org.jfree.chart.entity.EntityCollection) Rectangle2D(java.awt.geom.Rectangle2D) EntityBlockResult(org.jfree.chart.block.EntityBlockResult) RectangleConstraint(org.jfree.chart.block.RectangleConstraint) Range(org.jfree.data.Range) RectangleEdge(org.jfree.chart.util.RectangleEdge) BlockParams(org.jfree.chart.block.BlockParams)

Example 59 with RectangleEdge

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

the class CategoryPlot method getRangeAxisEdge.

/**
 * Returns the edge for a range axis.
 *
 * @param index  the axis index.
 *
 * @return The edge.
 */
public RectangleEdge getRangeAxisEdge(int index) {
    AxisLocation location = getRangeAxisLocation(index);
    RectangleEdge result = Plot.resolveRangeAxisLocation(location, this.orientation);
    if (result == null) {
        result = RectangleEdge.opposite(getRangeAxisEdge(0));
    }
    return result;
}
Also used : AxisLocation(org.jfree.chart.axis.AxisLocation) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Example 60 with RectangleEdge

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

the class CategoryPlot method drawDomainGridlines.

/**
 * Draws the domain gridlines for the plot, if they are visible.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 *
 * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List)
 */
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea) {
    if (!isDomainGridlinesVisible()) {
        return;
    }
    CategoryAnchor anchor = getDomainGridlinePosition();
    RectangleEdge domainAxisEdge = getDomainAxisEdge();
    CategoryDataset dataset = getDataset();
    if (dataset == null) {
        return;
    }
    CategoryAxis axis = getDomainAxis();
    if (axis != null) {
        int columnCount = dataset.getColumnCount();
        for (int c = 0; c < columnCount; c++) {
            double xx = axis.getCategoryJava2DCoordinate(anchor, c, columnCount, dataArea, domainAxisEdge);
            CategoryItemRenderer renderer1 = getRenderer();
            if (renderer1 != null) {
                renderer1.drawDomainLine(g2, this, dataArea, xx, getDomainGridlinePaint(), getDomainGridlineStroke());
            }
        }
    }
}
Also used : CategoryAnchor(org.jfree.chart.axis.CategoryAnchor) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) SelectableCategoryDataset(org.jfree.data.category.SelectableCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint) 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