Search in sources :

Example 51 with ValueAxis

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

the class CategoryPlot method readObject.

/**
 * Provides serialization support.
 *
 * @param stream  the input stream.
 *
 * @throws IOException  if there is an I/O error.
 * @throws ClassNotFoundException  if there is a classpath problem.
 */
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    this.domainGridlineStroke = SerialUtilities.readStroke(stream);
    this.domainGridlinePaint = SerialUtilities.readPaint(stream);
    this.rangeGridlineStroke = SerialUtilities.readStroke(stream);
    this.rangeGridlinePaint = SerialUtilities.readPaint(stream);
    this.rangeCrosshairStroke = SerialUtilities.readStroke(stream);
    this.rangeCrosshairPaint = SerialUtilities.readPaint(stream);
    this.domainCrosshairStroke = SerialUtilities.readStroke(stream);
    this.domainCrosshairPaint = SerialUtilities.readPaint(stream);
    this.rangeMinorGridlineStroke = SerialUtilities.readStroke(stream);
    this.rangeMinorGridlinePaint = SerialUtilities.readPaint(stream);
    this.rangeZeroBaselineStroke = SerialUtilities.readStroke(stream);
    this.rangeZeroBaselinePaint = SerialUtilities.readPaint(stream);
    for (CategoryAxis xAxis : this.domainAxes.values()) {
        if (xAxis != null) {
            xAxis.setPlot(this);
            xAxis.addChangeListener(this);
        }
    }
    for (ValueAxis yAxis : this.rangeAxes.values()) {
        if (yAxis != null) {
            yAxis.setPlot(this);
            yAxis.addChangeListener(this);
        }
    }
    for (CategoryDataset dataset : this.datasets.values()) {
        if (dataset != null) {
            dataset.addChangeListener(this);
        }
    }
    for (CategoryItemRenderer renderer : this.renderers.values()) {
        if (renderer != null) {
            renderer.addChangeListener(this);
        }
    }
}
Also used : AbstractCategoryItemRenderer(org.jfree.chart.renderer.category.AbstractCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ValueAxis(org.jfree.chart.axis.ValueAxis) CategoryDataset(org.jfree.data.category.CategoryDataset)

Example 52 with ValueAxis

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

the class CategoryPlot method datasetChanged.

/**
 * Receives notification of a change to the plot's dataset.
 * <P>
 * The range axis bounds will be recalculated if necessary.
 *
 * @param event  information about the event (not used here).
 */
@Override
public void datasetChanged(DatasetChangeEvent event) {
    for (ValueAxis yAxis : this.rangeAxes.values()) {
        if (yAxis != null) {
            yAxis.configure();
        }
    }
    if (getParent() != null) {
        getParent().datasetChanged(event);
    } else {
        PlotChangeEvent e = new PlotChangeEvent(this);
        e.setType(ChartChangeEventType.DATASET_UPDATED);
        notifyListeners(e);
    }
}
Also used : PlotChangeEvent(org.jfree.chart.event.PlotChangeEvent) ValueAxis(org.jfree.chart.axis.ValueAxis)

Example 53 with ValueAxis

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

the class CategoryPlot method drawAxes.

/**
 * A utility method for drawing the plot's axes.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param dataArea  the data area.
 * @param plotState  collects information about the plot (<code>null</code>
 *                   permitted).
 *
 * @return A map containing the axis states.
 */
protected Map drawAxes(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, PlotRenderingInfo plotState) {
    AxisCollection axisCollection = new AxisCollection();
    // add domain axes to lists...
    for (CategoryAxis xAxis : this.domainAxes.values()) {
        if (xAxis != null) {
            int index = getDomainAxisIndex(xAxis);
            axisCollection.add(xAxis, getDomainAxisEdge(index));
        }
    }
    // add range axes to lists...
    for (ValueAxis yAxis : this.rangeAxes.values()) {
        if (yAxis != null) {
            int index = findRangeAxisIndex(yAxis);
            axisCollection.add(yAxis, getRangeAxisEdge(index));
        }
    }
    Map axisStateMap = new HashMap();
    // draw the top axes
    double cursor = dataArea.getMinY() - this.axisOffset.calculateTopOutset(dataArea.getHeight());
    Iterator iterator = axisCollection.getAxesAtTop().iterator();
    while (iterator.hasNext()) {
        Axis axis = (Axis) iterator.next();
        if (axis != null) {
            AxisState axisState = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.TOP, plotState);
            cursor = axisState.getCursor();
            axisStateMap.put(axis, axisState);
        }
    }
    // draw the bottom axes
    cursor = dataArea.getMaxY() + this.axisOffset.calculateBottomOutset(dataArea.getHeight());
    iterator = axisCollection.getAxesAtBottom().iterator();
    while (iterator.hasNext()) {
        Axis axis = (Axis) iterator.next();
        if (axis != null) {
            AxisState axisState = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.BOTTOM, plotState);
            cursor = axisState.getCursor();
            axisStateMap.put(axis, axisState);
        }
    }
    // draw the left axes
    cursor = dataArea.getMinX() - this.axisOffset.calculateLeftOutset(dataArea.getWidth());
    iterator = axisCollection.getAxesAtLeft().iterator();
    while (iterator.hasNext()) {
        Axis axis = (Axis) iterator.next();
        if (axis != null) {
            AxisState axisState = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.LEFT, plotState);
            cursor = axisState.getCursor();
            axisStateMap.put(axis, axisState);
        }
    }
    // draw the right axes
    cursor = dataArea.getMaxX() + this.axisOffset.calculateRightOutset(dataArea.getWidth());
    iterator = axisCollection.getAxesAtRight().iterator();
    while (iterator.hasNext()) {
        Axis axis = (Axis) iterator.next();
        if (axis != null) {
            AxisState axisState = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.RIGHT, plotState);
            cursor = axisState.getCursor();
            axisStateMap.put(axis, axisState);
        }
    }
    return axisStateMap;
}
Also used : AxisState(org.jfree.chart.axis.AxisState) AxisCollection(org.jfree.chart.axis.AxisCollection) CategoryAxis(org.jfree.chart.axis.CategoryAxis) HashMap(java.util.HashMap) ValueAxis(org.jfree.chart.axis.ValueAxis) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Paint(java.awt.Paint) CategoryAxis(org.jfree.chart.axis.CategoryAxis) Axis(org.jfree.chart.axis.Axis) ValueAxis(org.jfree.chart.axis.ValueAxis)

Example 54 with ValueAxis

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

the class CombinedRangeCategoryPlot method calculateAxisSpace.

/**
 * Calculates the space required for the axes.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 *
 * @return The space required for the axes.
 */
@Override
protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) {
    AxisSpace space = new AxisSpace();
    PlotOrientation orientation = getOrientation();
    // work out the space required by the domain axis...
    AxisSpace fixed = getFixedRangeAxisSpace();
    if (fixed != null) {
        if (orientation == PlotOrientation.VERTICAL) {
            space.setLeft(fixed.getLeft());
            space.setRight(fixed.getRight());
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            space.setTop(fixed.getTop());
            space.setBottom(fixed.getBottom());
        }
    } else {
        ValueAxis valueAxis = getRangeAxis();
        RectangleEdge valueEdge = Plot.resolveRangeAxisLocation(getRangeAxisLocation(), orientation);
        if (valueAxis != null) {
            space = valueAxis.reserveSpace(g2, this, plotArea, valueEdge, space);
        }
    }
    Rectangle2D adjustedPlotArea = space.shrink(plotArea, null);
    // work out the maximum height or width of the non-shared axes...
    int n = this.subplots.size();
    int totalWeight = 0;
    for (int i = 0; i < n; i++) {
        CategoryPlot sub = (CategoryPlot) this.subplots.get(i);
        totalWeight += sub.getWeight();
    }
    // calculate plotAreas of all sub-plots, maximum vertical/horizontal
    // axis width/height
    this.subplotArea = new Rectangle2D[n];
    double x = adjustedPlotArea.getX();
    double y = adjustedPlotArea.getY();
    double usableSize = 0.0;
    if (orientation == PlotOrientation.VERTICAL) {
        usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1);
    } else if (orientation == PlotOrientation.HORIZONTAL) {
        usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1);
    }
    for (int i = 0; i < n; i++) {
        CategoryPlot plot = (CategoryPlot) this.subplots.get(i);
        // calculate sub-plot area
        if (orientation == PlotOrientation.VERTICAL) {
            double w = usableSize * plot.getWeight() / totalWeight;
            this.subplotArea[i] = new Rectangle2D.Double(x, y, w, adjustedPlotArea.getHeight());
            x = x + w + this.gap;
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            double h = usableSize * plot.getWeight() / totalWeight;
            this.subplotArea[i] = new Rectangle2D.Double(x, y, adjustedPlotArea.getWidth(), h);
            y = y + h + this.gap;
        }
        AxisSpace subSpace = plot.calculateDomainAxisSpace(g2, this.subplotArea[i], null);
        space.ensureAtLeast(subSpace);
    }
    return space;
}
Also used : ValueAxis(org.jfree.chart.axis.ValueAxis) Rectangle2D(java.awt.geom.Rectangle2D) AxisSpace(org.jfree.chart.axis.AxisSpace) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 55 with ValueAxis

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

the class CombinedRangeCategoryPlot method draw.

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer).  Will perform all the placement calculations for each
 * sub-plots and then tell these to draw themselves.
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot (including axis labels)
 *              should be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  the parent state.
 * @param info  collects information about the drawing (<code>null</code>
 *              permitted).
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
    // set up info collection...
    if (info != null) {
        info.setPlotArea(area);
    }
    // adjust the drawing area for 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);
    // set the width and height of non-shared axis of all sub-plots
    setFixedDomainAxisSpaceForSubplots(space);
    // draw the shared axis
    ValueAxis axis = getRangeAxis();
    RectangleEdge rangeEdge = getRangeAxisEdge();
    double cursor = RectangleEdge.coordinate(dataArea, rangeEdge);
    AxisState state = axis.draw(g2, cursor, area, dataArea, rangeEdge, info);
    if (parentState == null) {
        parentState = new PlotState();
    }
    parentState.getSharedAxisStates().put(axis, state);
    // draw all the charts
    for (int i = 0; i < this.subplots.size(); i++) {
        CategoryPlot plot = (CategoryPlot) this.subplots.get(i);
        PlotRenderingInfo subplotInfo = null;
        if (info != null) {
            subplotInfo = new PlotRenderingInfo(info.getOwner());
            info.addSubplotInfo(subplotInfo);
        }
        Point2D subAnchor = null;
        if (anchor != null && this.subplotArea[i].contains(anchor)) {
            subAnchor = anchor;
        }
        plot.draw(g2, this.subplotArea[i], subAnchor, parentState, subplotInfo);
    }
    if (info != null) {
        info.setDataArea(dataArea);
    }
}
Also used : AxisState(org.jfree.chart.axis.AxisState) Point2D(java.awt.geom.Point2D) ValueAxis(org.jfree.chart.axis.ValueAxis) Rectangle2D(java.awt.geom.Rectangle2D) RectangleInsets(org.jfree.ui.RectangleInsets) AxisSpace(org.jfree.chart.axis.AxisSpace) RectangleEdge(org.jfree.ui.RectangleEdge)

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