Search in sources :

Example 26 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.

the class StandardXYItemRenderer 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 data is being drawn.
 * @param info  collects information about the drawing.
 * @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 crosshairState  crosshair information for the plot
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
    boolean itemVisible = getItemVisible(series, item);
    // setup for collecting optional entity info...
    Shape entityArea = null;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }
    PlotOrientation orientation = plot.getOrientation();
    Paint paint = getItemPaint(series, item);
    Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);
    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(x1) || Double.isNaN(y1)) {
        itemVisible = false;
    }
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
    if (getPlotLines()) {
        if (this.drawSeriesLineAsPath) {
            State s = (State) state;
            if (s.getSeriesIndex() != series) {
                // we are starting a new series path
                s.seriesPath.reset();
                s.lastPointGood = false;
                s.setSeriesIndex(series);
            }
            // update path to reflect latest point
            if (itemVisible && !Double.isNaN(transX1) && !Double.isNaN(transY1)) {
                float x = (float) transX1;
                float y = (float) transY1;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    x = (float) transY1;
                    y = (float) transX1;
                }
                if (s.isLastPointGood()) {
                    // TODO: check threshold
                    s.seriesPath.lineTo(x, y);
                } else {
                    s.seriesPath.moveTo(x, y);
                }
                s.setLastPointGood(true);
            } else {
                s.setLastPointGood(false);
            }
            if (item == dataset.getItemCount(series) - 1) {
                if (s.seriesIndex == series) {
                    // draw path
                    g2.setStroke(lookupSeriesStroke(series));
                    g2.setPaint(lookupSeriesPaint(series));
                    g2.draw(s.seriesPath);
                }
            }
        } else if (item != 0 && itemVisible) {
            // get the previous data point...
            double x0 = dataset.getXValue(series, item - 1);
            double y0 = dataset.getYValue(series, item - 1);
            if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
                boolean drawLine = true;
                if (getPlotDiscontinuous()) {
                    // only draw a line if the gap between the current and
                    // previous data point is within the threshold
                    int numX = dataset.getItemCount(series);
                    double minX = dataset.getXValue(series, 0);
                    double maxX = dataset.getXValue(series, numX - 1);
                    if (this.gapThresholdType == UnitType.ABSOLUTE) {
                        drawLine = Math.abs(x1 - x0) <= this.gapThreshold;
                    } else {
                        drawLine = Math.abs(x1 - x0) <= ((maxX - minX) / numX * getGapThreshold());
                    }
                }
                if (drawLine) {
                    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);
                    // only draw if we have good values
                    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) {
                        return;
                    }
                    if (orientation == PlotOrientation.HORIZONTAL) {
                        state.workingLine.setLine(transY0, transX0, transY1, transX1);
                    } else if (orientation == PlotOrientation.VERTICAL) {
                        state.workingLine.setLine(transX0, transY0, transX1, transY1);
                    }
                    if (state.workingLine.intersects(dataArea)) {
                        g2.draw(state.workingLine);
                    }
                }
            }
        }
    }
    // to do for non-visible items...
    if (!itemVisible) {
        return;
    }
    if (getBaseShapesVisible()) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;
    }
    if (getPlotImages()) {
        Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
            g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
            entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(), image.getWidth(null), image.getHeight(null));
        }
    }
    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }
    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0));
    }
    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation);
    // add an entity for the item...
    if (entities != null && isPointInRect(dataArea, xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Stroke(java.awt.Stroke) Shape(java.awt.Shape) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) Point(java.awt.Point) Image(java.awt.Image) Point(java.awt.Point) Paint(java.awt.Paint) EntityCollection(org.jfree.chart.entity.EntityCollection) CrosshairState(org.jfree.chart.plot.CrosshairState) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 27 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.

the class LevelRenderer method calculateItemWidth.

/**
 * Calculates the bar width and stores it in the renderer state.
 *
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
protected void calculateItemWidth(CategoryPlot plot, Rectangle2D dataArea, int rendererIndex, CategoryItemRendererState state) {
    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset dataset = plot.getDataset(rendererIndex);
    if (dataset != null) {
        int columns = dataset.getColumnCount();
        int rows = state.getVisibleSeriesCount() >= 0 ? state.getVisibleSeriesCount() : dataset.getRowCount();
        double space = 0.0;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        } else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaximumItemWidth();
        double categoryMargin = 0.0;
        double currentItemMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }
        if (rows > 1) {
            currentItemMargin = getItemMargin();
        }
        double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin() - categoryMargin - currentItemMargin);
        if ((rows * columns) > 0) {
            state.setBarWidth(Math.min(used / (rows * columns), maxWidth));
        } else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint)

Example 28 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.

the class LevelRenderer method drawItem.

/**
 * Draws the bar for a single (series, category) data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data 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 pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {
    // nothing is drawn if the row index is not included in the list with
    // the indices of the visible rows...
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    // nothing is drawn for null values...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }
    double value = dataValue.doubleValue();
    PlotOrientation orientation = plot.getOrientation();
    double barW0 = calculateBarW0(plot, orientation, dataArea, domainAxis, state, visibleRow, column);
    RectangleEdge edge = plot.getRangeAxisEdge();
    double barL = rangeAxis.valueToJava2D(value, dataArea, edge);
    // draw the bar...
    Line2D line;
    double x, y;
    if (orientation == PlotOrientation.HORIZONTAL) {
        x = barL;
        y = barW0 + state.getBarWidth() / 2.0;
        line = new Line2D.Double(barL, barW0, barL, barW0 + state.getBarWidth());
    } else {
        x = barW0 + state.getBarWidth() / 2.0;
        y = barL;
        line = new Line2D.Double(barW0, barL, barW0 + state.getBarWidth(), barL);
    }
    Stroke itemStroke = getItemStroke(row, column);
    Paint itemPaint = getItemPaint(row, column);
    g2.setStroke(itemStroke);
    g2.setPaint(itemPaint);
    g2.draw(line);
    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, orientation, dataset, row, column, x, y, (value < 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), value, datasetIndex, barW0, barL, orientation);
    // collect entity and tool tip information...
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, line.getBounds());
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Stroke(java.awt.Stroke) EntityCollection(org.jfree.chart.entity.EntityCollection) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 29 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.

the class LineRenderer3D method drawDomainGridline.

/**
 * Draws a grid line against the domain axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area for plotting data (not yet adjusted for any
 *                  3D effect).
 * @param value  the Java2D value at which the grid line should be drawn.
 */
@Override
public void drawDomainGridline(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, double value) {
    Line2D line1 = null;
    Line2D line2 = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        double y0 = value;
        double y1 = value - getYOffset();
        double x0 = dataArea.getMinX();
        double x1 = x0 + getXOffset();
        double x2 = dataArea.getMaxX();
        line1 = new Line2D.Double(x0, y0, x1, y1);
        line2 = new Line2D.Double(x1, y1, x2, y1);
    } else if (orientation == PlotOrientation.VERTICAL) {
        double x0 = value;
        double x1 = value + getXOffset();
        double y0 = dataArea.getMaxY();
        double y1 = y0 - getYOffset();
        double y2 = dataArea.getMinY();
        line1 = new Line2D.Double(x0, y0, x1, y1);
        line2 = new Line2D.Double(x1, y1, x1, y2);
    }
    g2.setPaint(plot.getDomainGridlinePaint());
    g2.setStroke(plot.getDomainGridlineStroke());
    g2.draw(line1);
    g2.draw(line2);
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Line2D(java.awt.geom.Line2D)

Example 30 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.

the class LineRenderer3D method drawItem.

/**
 * Draw a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area in which the data is drawn.
 * @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 pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {
    if (!getItemVisible(row, column)) {
        return;
    }
    // nothing is drawn for null...
    Number v = dataset.getValue(row, column);
    if (v == null) {
        return;
    }
    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());
    PlotOrientation orientation = plot.getOrientation();
    // current data point...
    double x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), adjusted, plot.getDomainAxisEdge());
    double value = v.doubleValue();
    double y1 = rangeAxis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());
    Shape shape = getItemShape(row, column);
    if (orientation == PlotOrientation.HORIZONTAL) {
        shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
    } else if (orientation == PlotOrientation.VERTICAL) {
        shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
    }
    if (pass == 0 && getItemLineVisible(row, column)) {
        if (column != 0) {
            Number previousValue = dataset.getValue(row, column - 1);
            if (previousValue != null) {
                // previous data point...
                double previous = previousValue.doubleValue();
                double x0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), adjusted, plot.getDomainAxisEdge());
                double y0 = rangeAxis.valueToJava2D(previous, adjusted, plot.getRangeAxisEdge());
                double x2 = x0 + getXOffset();
                double y2 = y0 - getYOffset();
                double x3 = x1 + getXOffset();
                double y3 = y1 - getYOffset();
                GeneralPath clip = new GeneralPath();
                if (orientation == PlotOrientation.HORIZONTAL) {
                    clip.moveTo((float) y0, (float) x0);
                    clip.lineTo((float) y1, (float) x1);
                    clip.lineTo((float) y3, (float) x3);
                    clip.lineTo((float) y2, (float) x2);
                    clip.lineTo((float) y0, (float) x0);
                    clip.closePath();
                } else if (orientation == PlotOrientation.VERTICAL) {
                    clip.moveTo((float) x0, (float) y0);
                    clip.lineTo((float) x1, (float) y1);
                    clip.lineTo((float) x3, (float) y3);
                    clip.lineTo((float) x2, (float) y2);
                    clip.lineTo((float) x0, (float) y0);
                    clip.closePath();
                }
                g2.setPaint(getItemPaint(row, column));
                g2.fill(clip);
                g2.setStroke(getItemOutlineStroke(row, column));
                g2.setPaint(getItemOutlinePaint(row, column));
                g2.draw(clip);
            }
        }
    }
    // draw the item label if there is one...
    if (pass == 1 && isItemLabelVisible(row, column)) {
        if (orientation == PlotOrientation.HORIZONTAL) {
            drawItemLabel(g2, orientation, dataset, row, column, y1, x1, (value < 0.0));
        } else if (orientation == PlotOrientation.VERTICAL) {
            drawItemLabel(g2, orientation, dataset, row, column, x1, y1, (value < 0.0));
        }
    }
    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, shape);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Shape(java.awt.Shape) GeneralPath(java.awt.geom.GeneralPath) EntityCollection(org.jfree.chart.entity.EntityCollection) Rectangle2D(java.awt.geom.Rectangle2D)

Aggregations

PlotOrientation (org.jfree.chart.plot.PlotOrientation)100 Paint (java.awt.Paint)52 RectangleEdge (org.jfree.ui.RectangleEdge)49 Rectangle2D (java.awt.geom.Rectangle2D)40 EntityCollection (org.jfree.chart.entity.EntityCollection)39 Line2D (java.awt.geom.Line2D)29 Stroke (java.awt.Stroke)20 Shape (java.awt.Shape)19 GeneralPath (java.awt.geom.GeneralPath)14 Range (org.jfree.data.Range)14 GradientPaint (java.awt.GradientPaint)13 JFreeChart (org.jfree.chart.JFreeChart)11 CategoryAxis (org.jfree.chart.axis.CategoryAxis)11 CategoryDataset (org.jfree.data.category.CategoryDataset)11 Point2D (java.awt.geom.Point2D)9 CategoryItemLabelGenerator (org.jfree.chart.labels.CategoryItemLabelGenerator)9 IntervalXYDataset (org.jfree.data.xy.IntervalXYDataset)7 AlphaComposite (java.awt.AlphaComposite)6 BasicStroke (java.awt.BasicStroke)6 Composite (java.awt.Composite)6