Search in sources :

Example 91 with PlotOrientation

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

the class WaterfallBarRenderer 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) {
    double previous = state.getSeriesRunningTotal();
    if (column == dataset.getColumnCount() - 1) {
        previous = 0.0;
    }
    double current = 0.0;
    Number n = dataset.getValue(row, column);
    if (n != null) {
        current = previous + n.doubleValue();
    }
    state.setSeriesRunningTotal(current);
    int categoryCount = getColumnCount();
    PlotOrientation orientation = plot.getOrientation();
    double rectX = 0.0;
    double rectY = 0.0;
    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
    // Y0
    double j2dy0 = rangeAxis.valueToJava2D(previous, dataArea, rangeAxisLocation);
    // Y1
    double j2dy1 = rangeAxis.valueToJava2D(current, dataArea, rangeAxisLocation);
    double valDiff = current - previous;
    if (j2dy1 < j2dy0) {
        double temp = j2dy1;
        j2dy1 = j2dy0;
        j2dy0 = temp;
    }
    // BAR WIDTH
    double rectWidth = state.getBarWidth();
    // BAR HEIGHT
    double rectHeight = Math.max(getMinimumBarLength(), Math.abs(j2dy1 - j2dy0));
    Comparable seriesKey = dataset.getRowKey(row);
    Comparable categoryKey = dataset.getColumnKey(column);
    if (orientation == PlotOrientation.HORIZONTAL) {
        rectY = domainAxis.getCategorySeriesMiddle(categoryKey, seriesKey, dataset, getItemMargin(), dataArea, RectangleEdge.LEFT);
        rectX = j2dy0;
        rectHeight = state.getBarWidth();
        rectY = rectY - rectHeight / 2.0;
        rectWidth = Math.max(getMinimumBarLength(), Math.abs(j2dy1 - j2dy0));
    } else if (orientation == PlotOrientation.VERTICAL) {
        rectX = domainAxis.getCategorySeriesMiddle(categoryKey, seriesKey, dataset, getItemMargin(), dataArea, RectangleEdge.TOP);
        rectX = rectX - rectWidth / 2.0;
        rectY = j2dy0;
    }
    Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
    Paint seriesPaint;
    if (column == 0) {
        seriesPaint = getFirstBarPaint();
    } else if (column == categoryCount - 1) {
        seriesPaint = getLastBarPaint();
    } else {
        if (valDiff >= 0.0) {
            seriesPaint = getPositiveBarPaint();
        } else {
            seriesPaint = getNegativeBarPaint();
        }
    }
    if (getGradientPaintTransformer() != null && seriesPaint instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) seriesPaint;
        seriesPaint = getGradientPaintTransformer().transform(gp, bar);
    }
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    // draw the outline...
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        Stroke stroke = getItemOutlineStroke(row, column);
        Paint paint = getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }
    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (valDiff < 0.0));
    }
    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, bar);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Stroke(java.awt.Stroke) Rectangle2D(java.awt.geom.Rectangle2D) GradientPaint(java.awt.GradientPaint) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) EntityCollection(org.jfree.chart.entity.EntityCollection) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 92 with PlotOrientation

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

the class GanttRenderer method drawTask.

/**
 * Draws a single task.
 *
 * @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 data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 */
protected void drawTask(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, GanttCategoryDataset dataset, int row, int column) {
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
    // Y0
    Number value0 = dataset.getEndValue(row, column);
    if (value0 == null) {
        return;
    }
    double java2dValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation);
    // Y1
    Number value1 = dataset.getStartValue(row, column);
    if (value1 == null) {
        return;
    }
    double java2dValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation);
    if (java2dValue1 < java2dValue0) {
        double temp = java2dValue1;
        java2dValue1 = java2dValue0;
        java2dValue0 = temp;
        value1 = value0;
    }
    double rectStart = calculateBarW0(plot, orientation, dataArea, domainAxis, state, row, column);
    double rectBreadth = state.getBarWidth();
    double rectLength = Math.abs(java2dValue1 - java2dValue0);
    Rectangle2D bar = null;
    RectangleEdge barBase = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(java2dValue0, rectStart, rectLength, rectBreadth);
        barBase = RectangleEdge.LEFT;
    } else if (orientation == PlotOrientation.VERTICAL) {
        bar = new Rectangle2D.Double(rectStart, java2dValue1, rectBreadth, rectLength);
        barBase = RectangleEdge.BOTTOM;
    }
    Rectangle2D completeBar = null;
    Rectangle2D incompleteBar = null;
    Number percent = dataset.getPercentComplete(row, column);
    double start = getStartPercent();
    double end = getEndPercent();
    if (percent != null) {
        double p = percent.doubleValue();
        if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
            completeBar = new Rectangle2D.Double(java2dValue0, rectStart + start * rectBreadth, rectLength * p, rectBreadth * (end - start));
            incompleteBar = new Rectangle2D.Double(java2dValue0 + rectLength * p, rectStart + start * rectBreadth, rectLength * (1 - p), rectBreadth * (end - start));
        } else if (plot.getOrientation() == PlotOrientation.VERTICAL) {
            completeBar = new Rectangle2D.Double(rectStart + start * rectBreadth, java2dValue1 + rectLength * (1 - p), rectBreadth * (end - start), rectLength * p);
            incompleteBar = new Rectangle2D.Double(rectStart + start * rectBreadth, java2dValue1, rectBreadth * (end - start), rectLength * (1 - p));
        }
    }
    if (getShadowsVisible()) {
        getBarPainter().paintBarShadow(g2, this, row, column, bar, barBase, true);
    }
    getBarPainter().paintBar(g2, this, row, column, bar, barBase);
    if (completeBar != null) {
        g2.setPaint(getCompletePaint());
        g2.fill(completeBar);
    }
    if (incompleteBar != null) {
        g2.setPaint(getIncompletePaint());
        g2.fill(incompleteBar);
    }
    // draw the outline...
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        Stroke stroke = getItemOutlineStroke(row, column);
        Paint paint = getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }
    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, false);
    }
    // submit the current data point as a crosshair candidate
    int datasetIndex = plot.indexOf(dataset);
    Comparable columnKey = dataset.getColumnKey(column);
    Comparable rowKey = dataset.getRowKey(row);
    double xx = domainAxis.getCategorySeriesMiddle(columnKey, rowKey, dataset, getItemMargin(), dataArea, plot.getDomainAxisEdge());
    updateCrosshairValues(state.getCrosshairState(), dataset.getRowKey(row), dataset.getColumnKey(column), value1.doubleValue(), datasetIndex, xx, java2dValue1, orientation);
    // collect entity and tool tip information...
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, bar);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Stroke(java.awt.Stroke) Rectangle2D(java.awt.geom.Rectangle2D) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) Paint(java.awt.Paint) Paint(java.awt.Paint) EntityCollection(org.jfree.chart.entity.EntityCollection) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 93 with PlotOrientation

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

the class MinMaxCategoryRenderer 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) {
    // first check the number we are plotting...
    Number value = dataset.getValue(row, column);
    if (value != null) {
        // current data point...
        double x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
        double y1 = rangeAxis.valueToJava2D(value.doubleValue(), dataArea, plot.getRangeAxisEdge());
        Shape hotspot = new Rectangle2D.Double(x1 - 4, y1 - 4, 8.0, 8.0);
        g2.setPaint(getItemPaint(row, column));
        g2.setStroke(getItemStroke(row, column));
        PlotOrientation orient = plot.getOrientation();
        if (orient == PlotOrientation.VERTICAL) {
            this.objectIcon.paintIcon(null, g2, (int) x1, (int) y1);
        } else {
            this.objectIcon.paintIcon(null, g2, (int) y1, (int) x1);
        }
        if (this.lastCategory == column) {
            if (this.min > value.doubleValue()) {
                this.min = value.doubleValue();
            }
            if (this.max < value.doubleValue()) {
                this.max = value.doubleValue();
            }
            // last series, so we are ready to draw the min and max
            if (dataset.getRowCount() - 1 == row) {
                g2.setPaint(this.groupPaint);
                g2.setStroke(this.groupStroke);
                double minY = rangeAxis.valueToJava2D(this.min, dataArea, plot.getRangeAxisEdge());
                double maxY = rangeAxis.valueToJava2D(this.max, dataArea, plot.getRangeAxisEdge());
                if (orient == PlotOrientation.VERTICAL) {
                    g2.draw(new Line2D.Double(x1, minY, x1, maxY));
                    this.minIcon.paintIcon(null, g2, (int) x1, (int) minY);
                    this.maxIcon.paintIcon(null, g2, (int) x1, (int) maxY);
                } else {
                    g2.draw(new Line2D.Double(minY, x1, maxY, x1));
                    this.minIcon.paintIcon(null, g2, (int) minY, (int) x1);
                    this.maxIcon.paintIcon(null, g2, (int) maxY, (int) x1);
                }
            }
        } else {
            // reset the min and max
            this.lastCategory = column;
            this.min = value.doubleValue();
            this.max = value.doubleValue();
        }
        // connect to the previous point
        if (this.plotLines) {
            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(), dataArea, plot.getDomainAxisEdge());
                    double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge());
                    g2.setPaint(getItemPaint(row, column));
                    g2.setStroke(getItemStroke(row, column));
                    Line2D line;
                    if (orient == PlotOrientation.VERTICAL) {
                        line = new Line2D.Double(x0, y0, x1, y1);
                    } else {
                        line = new Line2D.Double(y0, x0, y1, x1);
                    }
                    g2.draw(line);
                }
            }
        }
        // add an item entity, if this information is being collected
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addItemEntity(entities, dataset, row, column, hotspot);
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Shape(java.awt.Shape) EntityCollection(org.jfree.chart.entity.EntityCollection) Line2D(java.awt.geom.Line2D)

Example 94 with PlotOrientation

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

the class IntervalBarRenderer method drawInterval.

/**
 * Draws a single interval.
 *
 * @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 data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 */
protected void drawInterval(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, IntervalCategoryDataset dataset, int row, int column) {
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    PlotOrientation orientation = plot.getOrientation();
    double rectX = 0.0;
    double rectY = 0.0;
    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
    // Y0
    Number value0 = dataset.getEndValue(row, column);
    if (value0 == null) {
        return;
    }
    double java2dValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation);
    // Y1
    Number value1 = dataset.getStartValue(row, column);
    if (value1 == null) {
        return;
    }
    double java2dValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation);
    if (java2dValue1 < java2dValue0) {
        double temp = java2dValue1;
        java2dValue1 = java2dValue0;
        java2dValue0 = temp;
    }
    // BAR WIDTH
    double rectWidth = state.getBarWidth();
    // BAR HEIGHT
    double rectHeight = Math.abs(java2dValue1 - java2dValue0);
    RectangleEdge barBase = RectangleEdge.LEFT;
    if (orientation == PlotOrientation.HORIZONTAL) {
        // BAR Y
        rectX = java2dValue0;
        rectY = calculateBarW0(getPlot(), orientation, dataArea, domainAxis, state, visibleRow, column);
        rectHeight = state.getBarWidth();
        rectWidth = Math.abs(java2dValue1 - java2dValue0);
        barBase = RectangleEdge.LEFT;
    } else if (orientation == PlotOrientation.VERTICAL) {
        // BAR X
        rectX = calculateBarW0(getPlot(), orientation, dataArea, domainAxis, state, visibleRow, column);
        rectY = java2dValue0;
        barBase = RectangleEdge.BOTTOM;
    }
    Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
    BarPainter painter = getBarPainter();
    if (getShadowsVisible()) {
        painter.paintBarShadow(g2, this, row, column, bar, barBase, false);
    }
    getBarPainter().paintBar(g2, this, row, column, bar, barBase);
    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, false);
    }
    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, bar);
    }
}
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.ui.RectangleEdge)

Example 95 with PlotOrientation

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

the class LineRenderer3D method drawRangeGridline.

/**
 * Draws a grid line against the range axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any
 *                  3D effect).
 * @param value  the value at which the grid line should be drawn.
 */
@Override
public void drawRangeGridline(Graphics2D g2, CategoryPlot plot, ValueAxis axis, Rectangle2D dataArea, double value) {
    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }
    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());
    Line2D line1 = null;
    Line2D line2 = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        double x0 = axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());
        double x1 = x0 + 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);
    } else if (orientation == PlotOrientation.VERTICAL) {
        double y0 = axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());
        double y1 = y0 - 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);
    }
    g2.setPaint(plot.getRangeGridlinePaint());
    g2.setStroke(plot.getRangeGridlineStroke());
    g2.draw(line1);
    g2.draw(line2);
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Rectangle2D(java.awt.geom.Rectangle2D) Range(org.jfree.data.Range) Line2D(java.awt.geom.Line2D)

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