Search in sources :

Example 81 with ValueAxis

use of org.jfree.chart.axis.ValueAxis in project SIMVA-SoS by SESoS.

the class XYPlot method render.

/**
 * Draws a representation of the data within the dataArea region, using the
 * current renderer.
 * <P>
 * The <code>info</code> and <code>crosshairState</code> arguments may be
 * <code>null</code>.
 *
 * @param g2  the graphics device.
 * @param dataArea  the region in which the data is to be drawn.
 * @param index  the dataset index.
 * @param info  an optional object for collection dimension information.
 * @param crosshairState  collects crosshair information
 *                        (<code>null</code> permitted).
 *
 * @return A flag that indicates whether any data was actually rendered.
 */
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info, CrosshairState crosshairState) {
    boolean foundData = false;
    XYDataset dataset = getDataset(index);
    if (!DatasetUtilities.isEmptyOrNull(dataset)) {
        foundData = true;
        ValueAxis xAxis = getDomainAxisForDataset(index);
        ValueAxis yAxis = getRangeAxisForDataset(index);
        if (xAxis == null || yAxis == null) {
            // can't render anything without axes
            return foundData;
        }
        XYItemRenderer renderer = getRenderer(index);
        if (renderer == null) {
            renderer = getRenderer();
            if (renderer == null) {
                // no default renderer available
                return foundData;
            }
        }
        XYItemRendererState state = renderer.initialise(g2, dataArea, this, dataset, info);
        int passCount = renderer.getPassCount();
        SeriesRenderingOrder seriesOrder = getSeriesRenderingOrder();
        if (seriesOrder == SeriesRenderingOrder.REVERSE) {
            // render series in reverse order
            for (int pass = 0; pass < passCount; pass++) {
                int seriesCount = dataset.getSeriesCount();
                for (int series = seriesCount - 1; series >= 0; series--) {
                    int firstItem = 0;
                    int lastItem = dataset.getItemCount(series) - 1;
                    if (lastItem == -1) {
                        continue;
                    }
                    if (state.getProcessVisibleItemsOnly()) {
                        int[] itemBounds = RendererUtilities.findLiveItems(dataset, series, xAxis.getLowerBound(), xAxis.getUpperBound());
                        firstItem = Math.max(itemBounds[0] - 1, 0);
                        lastItem = Math.min(itemBounds[1] + 1, lastItem);
                    }
                    state.startSeriesPass(dataset, series, firstItem, lastItem, pass, passCount);
                    for (int item = firstItem; item <= lastItem; item++) {
                        renderer.drawItem(g2, state, dataArea, info, this, xAxis, yAxis, dataset, series, item, crosshairState, pass);
                    }
                    state.endSeriesPass(dataset, series, firstItem, lastItem, pass, passCount);
                }
            }
        } else {
            // render series in forward order
            for (int pass = 0; pass < passCount; pass++) {
                int seriesCount = dataset.getSeriesCount();
                for (int series = 0; series < seriesCount; series++) {
                    int firstItem = 0;
                    int lastItem = dataset.getItemCount(series) - 1;
                    if (state.getProcessVisibleItemsOnly()) {
                        int[] itemBounds = RendererUtilities.findLiveItems(dataset, series, xAxis.getLowerBound(), xAxis.getUpperBound());
                        firstItem = Math.max(itemBounds[0] - 1, 0);
                        lastItem = Math.min(itemBounds[1] + 1, lastItem);
                    }
                    state.startSeriesPass(dataset, series, firstItem, lastItem, pass, passCount);
                    for (int item = firstItem; item <= lastItem; item++) {
                        renderer.drawItem(g2, state, dataArea, info, this, xAxis, yAxis, dataset, series, item, crosshairState, pass);
                    }
                    state.endSeriesPass(dataset, series, firstItem, lastItem, pass, passCount);
                }
            }
        }
    }
    return foundData;
}
Also used : ValueAxis(org.jfree.chart.axis.ValueAxis) XYDataset(org.jfree.data.xy.XYDataset) XYItemRendererState(org.jfree.chart.renderer.xy.XYItemRendererState) AbstractXYItemRenderer(org.jfree.chart.renderer.xy.AbstractXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) Paint(java.awt.Paint)

Example 82 with ValueAxis

use of org.jfree.chart.axis.ValueAxis in project SIMVA-SoS by SESoS.

the class XYPlot method getRangeAxisForDataset.

/**
 * Returns the range axis for a dataset.
 *
 * @param index  the dataset index (must be &gt;= 0).
 *
 * @return The axis.
 */
public ValueAxis getRangeAxisForDataset(int index) {
    ParamChecks.requireNonNegative(index, "index");
    ValueAxis valueAxis;
    List axisIndices = (List) this.datasetToRangeAxesMap.get(new Integer(index));
    if (axisIndices != null) {
        // the first axis in the list is used for data <--> Java2D
        Integer axisIndex = (Integer) axisIndices.get(0);
        valueAxis = getRangeAxis(axisIndex.intValue());
    } else {
        valueAxis = getRangeAxis(0);
    }
    return valueAxis;
}
Also used : ValueAxis(org.jfree.chart.axis.ValueAxis) List(java.util.List) ArrayList(java.util.ArrayList)

Example 83 with ValueAxis

use of org.jfree.chart.axis.ValueAxis in project SIMVA-SoS by SESoS.

the class XYPlot method drawQuadrants.

/**
 * Draws the quadrants.
 *
 * @param g2  the graphics device.
 * @param area  the area.
 *
 * @see #setQuadrantOrigin(Point2D)
 * @see #setQuadrantPaint(int, Paint)
 */
protected void drawQuadrants(Graphics2D g2, Rectangle2D area) {
    // 0 | 1
    // --+--
    // 2 | 3
    boolean somethingToDraw = false;
    ValueAxis xAxis = getDomainAxis();
    if (xAxis == null) {
        // we can't draw quadrants without a valid x-axis
        return;
    }
    double x = xAxis.getRange().constrain(this.quadrantOrigin.getX());
    double xx = xAxis.valueToJava2D(x, area, getDomainAxisEdge());
    ValueAxis yAxis = getRangeAxis();
    if (yAxis == null) {
        // we can't draw quadrants without a valid y-axis
        return;
    }
    double y = yAxis.getRange().constrain(this.quadrantOrigin.getY());
    double yy = yAxis.valueToJava2D(y, area, getRangeAxisEdge());
    double xmin = xAxis.getLowerBound();
    double xxmin = xAxis.valueToJava2D(xmin, area, getDomainAxisEdge());
    double xmax = xAxis.getUpperBound();
    double xxmax = xAxis.valueToJava2D(xmax, area, getDomainAxisEdge());
    double ymin = yAxis.getLowerBound();
    double yymin = yAxis.valueToJava2D(ymin, area, getRangeAxisEdge());
    double ymax = yAxis.getUpperBound();
    double yymax = yAxis.valueToJava2D(ymax, area, getRangeAxisEdge());
    Rectangle2D[] r = new Rectangle2D[] { null, null, null, null };
    if (this.quadrantPaint[0] != null) {
        if (x > xmin && y < ymax) {
            if (this.orientation == PlotOrientation.HORIZONTAL) {
                r[0] = new Rectangle2D.Double(Math.min(yymax, yy), Math.min(xxmin, xx), Math.abs(yy - yymax), Math.abs(xx - xxmin));
            } else {
                // PlotOrientation.VERTICAL
                r[0] = new Rectangle2D.Double(Math.min(xxmin, xx), Math.min(yymax, yy), Math.abs(xx - xxmin), Math.abs(yy - yymax));
            }
            somethingToDraw = true;
        }
    }
    if (this.quadrantPaint[1] != null) {
        if (x < xmax && y < ymax) {
            if (this.orientation == PlotOrientation.HORIZONTAL) {
                r[1] = new Rectangle2D.Double(Math.min(yymax, yy), Math.min(xxmax, xx), Math.abs(yy - yymax), Math.abs(xx - xxmax));
            } else {
                // PlotOrientation.VERTICAL
                r[1] = new Rectangle2D.Double(Math.min(xx, xxmax), Math.min(yymax, yy), Math.abs(xx - xxmax), Math.abs(yy - yymax));
            }
            somethingToDraw = true;
        }
    }
    if (this.quadrantPaint[2] != null) {
        if (x > xmin && y > ymin) {
            if (this.orientation == PlotOrientation.HORIZONTAL) {
                r[2] = new Rectangle2D.Double(Math.min(yymin, yy), Math.min(xxmin, xx), Math.abs(yy - yymin), Math.abs(xx - xxmin));
            } else {
                // PlotOrientation.VERTICAL
                r[2] = new Rectangle2D.Double(Math.min(xxmin, xx), Math.min(yymin, yy), Math.abs(xx - xxmin), Math.abs(yy - yymin));
            }
            somethingToDraw = true;
        }
    }
    if (this.quadrantPaint[3] != null) {
        if (x < xmax && y > ymin) {
            if (this.orientation == PlotOrientation.HORIZONTAL) {
                r[3] = new Rectangle2D.Double(Math.min(yymin, yy), Math.min(xxmax, xx), Math.abs(yy - yymin), Math.abs(xx - xxmax));
            } else {
                // PlotOrientation.VERTICAL
                r[3] = new Rectangle2D.Double(Math.min(xx, xxmax), Math.min(yymin, yy), Math.abs(xx - xxmax), Math.abs(yy - yymin));
            }
            somethingToDraw = true;
        }
    }
    if (somethingToDraw) {
        Composite originalComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getBackgroundAlpha()));
        for (int i = 0; i < 4; i++) {
            if (this.quadrantPaint[i] != null && r[i] != null) {
                g2.setPaint(this.quadrantPaint[i]);
                g2.fill(r[i]);
            }
        }
        g2.setComposite(originalComposite);
    }
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) ValueAxis(org.jfree.chart.axis.ValueAxis) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint)

Example 84 with ValueAxis

use of org.jfree.chart.axis.ValueAxis in project SIMVA-SoS by SESoS.

the class DefaultPolarItemRenderer method drawSeries.

/**
 * Plots the data for a given series.
 *
 * @param g2  the drawing surface.
 * @param dataArea  the data area.
 * @param info  collects plot rendering info.
 * @param plot  the plot.
 * @param dataset  the dataset.
 * @param seriesIndex  the series index.
 */
@Override
public void drawSeries(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, PolarPlot plot, XYDataset dataset, int seriesIndex) {
    final int numPoints = dataset.getItemCount(seriesIndex);
    if (numPoints == 0) {
        return;
    }
    GeneralPath poly = null;
    ValueAxis axis = plot.getAxisForDataset(plot.indexOf(dataset));
    for (int i = 0; i < numPoints; i++) {
        double theta = dataset.getXValue(seriesIndex, i);
        double radius = dataset.getYValue(seriesIndex, i);
        Point p = plot.translateToJava2D(theta, radius, axis, dataArea);
        if (poly == null) {
            poly = new GeneralPath();
            poly.moveTo(p.x, p.y);
        } else {
            poly.lineTo(p.x, p.y);
        }
    }
    assert poly != null;
    if (getConnectFirstAndLastPoint()) {
        poly.closePath();
    }
    g2.setPaint(lookupSeriesPaint(seriesIndex));
    g2.setStroke(lookupSeriesStroke(seriesIndex));
    if (isSeriesFilled(seriesIndex)) {
        Composite savedComposite = g2.getComposite();
        g2.setComposite(this.fillComposite);
        g2.fill(poly);
        g2.setComposite(savedComposite);
        if (this.drawOutlineWhenFilled) {
            // draw the outline of the filled polygon
            g2.setPaint(lookupSeriesOutlinePaint(seriesIndex));
            g2.draw(poly);
        }
    } else {
        // just the lines, no filling
        g2.draw(poly);
    }
    // draw the item shapes
    if (this.shapesVisible) {
        // setup for collecting optional entity info...
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }
        PathIterator pi = poly.getPathIterator(null);
        int i = 0;
        while (!pi.isDone()) {
            final float[] coords = new float[6];
            final int segType = pi.currentSegment(coords);
            pi.next();
            if (segType != PathIterator.SEG_LINETO && segType != PathIterator.SEG_MOVETO) {
                continue;
            }
            final int x = Math.round(coords[0]);
            final int y = Math.round(coords[1]);
            final Shape shape = ShapeUtilities.createTranslatedShape(getItemShape(seriesIndex, i++), x, y);
            Paint paint;
            if (useFillPaint) {
                paint = lookupSeriesFillPaint(seriesIndex);
            } else {
                paint = lookupSeriesPaint(seriesIndex);
            }
            g2.setPaint(paint);
            g2.fill(shape);
            if (isSeriesFilled(seriesIndex) && this.drawOutlineWhenFilled) {
                g2.setPaint(lookupSeriesOutlinePaint(seriesIndex));
                g2.setStroke(lookupSeriesOutlineStroke(seriesIndex));
                g2.draw(shape);
            }
            // data area...
            if (entities != null && AbstractXYItemRenderer.isPointInRect(dataArea, x, y)) {
                addEntity(entities, shape, dataset, seriesIndex, i - 1, x, y);
            }
        }
    }
}
Also used : Shape(java.awt.Shape) GeneralPath(java.awt.geom.GeneralPath) AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) EntityCollection(org.jfree.chart.entity.EntityCollection) PathIterator(java.awt.geom.PathIterator) ValueAxis(org.jfree.chart.axis.ValueAxis) Point(java.awt.Point) Paint(java.awt.Paint) Point(java.awt.Point) Paint(java.awt.Paint)

Example 85 with ValueAxis

use of org.jfree.chart.axis.ValueAxis in project SIMVA-SoS by SESoS.

the class DefaultPolarItemRenderer method drawAngularGridLines.

/**
 * Draw the angular gridlines - the spokes.
 *
 * @param g2  the drawing surface.
 * @param plot  the plot (<code>null</code> not permitted).
 * @param ticks  the ticks (<code>null</code> not permitted).
 * @param dataArea  the data area.
 */
@Override
public void drawAngularGridLines(Graphics2D g2, PolarPlot plot, List ticks, Rectangle2D dataArea) {
    g2.setFont(plot.getAngleLabelFont());
    g2.setStroke(plot.getAngleGridlineStroke());
    g2.setPaint(plot.getAngleGridlinePaint());
    ValueAxis axis = plot.getAxis();
    double centerValue, outerValue;
    if (axis.isInverted()) {
        outerValue = axis.getLowerBound();
        centerValue = axis.getUpperBound();
    } else {
        outerValue = axis.getUpperBound();
        centerValue = axis.getLowerBound();
    }
    Point center = plot.translateToJava2D(0, centerValue, axis, dataArea);
    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        NumberTick tick = (NumberTick) iterator.next();
        double tickVal = tick.getNumber().doubleValue();
        Point p = plot.translateToJava2D(tickVal, outerValue, axis, dataArea);
        g2.setPaint(plot.getAngleGridlinePaint());
        g2.drawLine(center.x, center.y, p.x, p.y);
        if (plot.isAngleLabelsVisible()) {
            int x = p.x;
            int y = p.y;
            g2.setPaint(plot.getAngleLabelPaint());
            TextUtilities.drawAlignedString(tick.getText(), g2, x, y, tick.getTextAnchor());
        }
    }
}
Also used : ValueAxis(org.jfree.chart.axis.ValueAxis) NumberTick(org.jfree.chart.axis.NumberTick) PathIterator(java.awt.geom.PathIterator) Iterator(java.util.Iterator) Point(java.awt.Point) Point(java.awt.Point) Paint(java.awt.Paint)

Aggregations

ValueAxis (org.jfree.chart.axis.ValueAxis)216 XYPlot (org.jfree.chart.plot.XYPlot)77 NumberAxis (org.jfree.chart.axis.NumberAxis)50 Range (org.jfree.data.Range)40 JFreeChart (org.jfree.chart.JFreeChart)39 CategoryPlot (org.jfree.chart.plot.CategoryPlot)35 Paint (java.awt.Paint)31 CategoryAxis (org.jfree.chart.axis.CategoryAxis)30 Rectangle2D (java.awt.geom.Rectangle2D)28 CombinedDomainXYPlot (org.jfree.chart.plot.CombinedDomainXYPlot)25 Test (org.junit.Test)24 CombinedRangeXYPlot (org.jfree.chart.plot.CombinedRangeXYPlot)22 XYDataset (org.jfree.data.xy.XYDataset)22 Iterator (java.util.Iterator)20 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)18 CategoryDataset (org.jfree.data.category.CategoryDataset)17 RectangleEdge (org.jfree.ui.RectangleEdge)16 Font (java.awt.Font)14 XYSeries (org.jfree.data.xy.XYSeries)14 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)14