Search in sources :

Example 11 with AxisSpace

use of org.jfree.chart.axis.AxisSpace in project polyGembler by c-zhou.

the class HMMPanel method getChart.

public ChartPanel getChart() {
    Range range = this.updateRates();
    final JFreeChart chart = ChartFactory.createXYLineChart(null, // domain axis label
    null, // range axis label
    null, // data
    rates, PlotOrientation.VERTICAL, // include legend
    false, // tooltips?
    true, // URL generator? Not required...
    false);
    final NumberAxis domainAxis = new NumberAxis("SNP relative physical position");
    // final LogarithmicAxis rangeAxis = new LogarithmicAxis("Trans-out probability");
    final NumberAxis rangeAxis = new NumberAxis("Trans-out probability");
    AxisSpace space = new AxisSpace();
    // reserved space on the left side of the plot
    space.setRight(22);
    space.setLeft(67);
    chart.getXYPlot().setFixedRangeAxisSpace(space);
    // double fixedDemension = HMMPanel.this.getX(0, false)+shift;
    // rangeAxis.setFixedDimension(fixedDemension);
    domainAxis.setTickUnit(new NumberTickUnit(1));
    // rangeAxis.setLog10TickLabelsFlag(true);
    rangeAxis.setRange(range);
    domainAxis.setRange(new Range(1 - offset_yR, noSnps + offset_yR));
    chart.getXYPlot().setDomainAxis(domainAxis);
    chart.getXYPlot().setRangeAxis(rangeAxis);
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < rates.getSeriesCount(); i++) {
        Color c;
        if (i == 0)
            c = ca.getColor(i);
        else
            c = Color.lightGray;
        renderer.setSeriesPaint(i, c);
        if (i == 0)
            renderer.setSeriesShapesVisible(i, true);
        else
            renderer.setSeriesShapesVisible(i, false);
    }
    /**
     *		XYPolygonAnnotation a = new XYPolygonAnnotation(new double[] {5.0,
     *				   0.0, 5.0, 0.5, 6.0, 0.5, 6.0, 0.0}, null, null,Color.black) {
     *            @Override
     *            public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
     *                Graphics2D g22 = (Graphics2D) g2.create();
     *                g22.setXORMode(new Color(0xff0000));
     *                super.draw(g22, plot, dataArea, domainAxis, rangeAxis, rendererIndex, info);
     *            }
     *        };
     *		renderer.addAnnotation(a, Layer.BACKGROUND);
     */
    chart.getXYPlot().setRenderer(renderer);
    double anno_offset_x = 0.5;
    XYSeries d = rates.getSeries(0);
    for (int i = 0; i < d.getItemCount(); i++) {
        double x = d.getX(i).doubleValue();
        double y = d.getY(i).doubleValue();
        if (y > 0.1)
            chart.getXYPlot().addAnnotation((XYAnnotation) new XYTextAnnotation(String.format(formatStr2, y), x > noSnps / 2 ? (x - anno_offset_x) : (x + anno_offset_x), y));
        else
            chart.getXYPlot().addAnnotation((XYAnnotation) new XYTextAnnotation(String.format(formatStr, y), x, y + .05));
    }
    // chart.getXYPlot().getRangeAxis().get
    // chart.getXYPlot().setRangeAxis(new LogarithmicAxis("rates"));
    final ChartPanel cp = new ChartPanel(chart, // width
    this.getWidth(), // height
    150, // mindrawWidth
    this.getWidth(), // mindrawHeight
    150, // maxDrawWith
    this.getWidth(), // maxDrawHeight
    150, ChartPanel.DEFAULT_BUFFER_USED, // properties
    true, // save
    true, // print
    true, // zoom
    true, // tooltips
    true);
    {
        Range r = chart.getXYPlot().getDomainAxis().getRange();
        chart.getXYPlot().getDomainAxis().setAutoRange(false);
        chart.getXYPlot().getDomainAxis().setRange(1, r.getUpperBound());
    }
    {
        Range r = chart.getXYPlot().getRangeAxis().getRange();
        if (r.getLowerBound() < range.getUpperBound()) {
            chart.getXYPlot().getRangeAxis().setAutoRange(false);
            chart.getXYPlot().getRangeAxis().setRange(r.getLowerBound(), range.getUpperBound());
        }
    }
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderPaint(Color.WHITE);
    cp.setBorder(null);
    /**
     *		RectangleEdge edge = chart.getXYPlot().getDomainAxisEdge();
     *		Rectangle2D edge2 = cp.getScreenDataArea();
     *		double x = RectangleEdge.coordinate(edge2, edge);
     *		ValueAxis edge3 = chart.getXYPlot().getDomainAxisForDataset(0);
     *		double xx = domainAxis.valueToJava2D(3, edge2, edge);
     */
    return cp;
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) ChartPanel(org.jfree.chart.ChartPanel) XYAnnotation(org.jfree.chart.annotations.XYAnnotation) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Color(java.awt.Color) Range(org.jfree.data.Range) JFreeChart(org.jfree.chart.JFreeChart) NumberTickUnit(org.jfree.chart.axis.NumberTickUnit) XYTextAnnotation(org.jfree.chart.annotations.XYTextAnnotation) AxisSpace(org.jfree.chart.axis.AxisSpace)

Example 12 with AxisSpace

use of org.jfree.chart.axis.AxisSpace in project polyGembler by c-zhou.

the class HMMSplitPanel method getChart.

public ChartPanel getChart() {
    Range range = this.updateRates();
    final JFreeChart chart = ChartFactory.createXYLineChart(null, // domain axis label
    null, // range axis label
    null, // data
    rates, PlotOrientation.VERTICAL, // include legend
    false, // tooltips?
    true, // URL generator? Not required...
    false);
    final NumberAxis domainAxis = new NumberAxis("Relative position");
    final LogarithmicAxis rangeAxis = new LogarithmicAxis("Trans-out probability");
    AxisSpace space = new AxisSpace();
    // reserved space on the left side of the plot
    space.setRight(115);
    space.setLeft(65);
    chart.getXYPlot().setFixedRangeAxisSpace(space);
    // double fixedDemension = HMMPanel.this.getX(0, false)-10;
    // rangeAxis.setFixedDimension(fixedDemension);
    domainAxis.setTickUnit(new NumberTickUnit(1));
    rangeAxis.setLog10TickLabelsFlag(true);
    rangeAxis.setRange(range);
    chart.getXYPlot().setDomainAxis(domainAxis);
    chart.getXYPlot().setRangeAxis(rangeAxis);
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < rates.getSeriesCount(); i++) {
        Color c = ca.getColor(i);
        renderer.setSeriesPaint(i, c);
        renderer.setSeriesShapesVisible(i, true);
    }
    chart.getXYPlot().setRenderer(renderer);
    // chart.getXYPlot().getRangeAxis().get
    // chart.getXYPlot().setRangeAxis(new LogarithmicAxis("rates"));
    final ChartPanel cp = new ChartPanel(chart, // width
    this.getWidth(), // height
    200, // mindrawWidth
    this.getWidth(), // mindrawHeight
    100, // maxDrawWith
    this.getWidth(), // maxDrawHeight
    400, ChartPanel.DEFAULT_BUFFER_USED, // properties
    true, // save
    true, // print
    true, // zoom
    true, // tooltips
    true);
    {
        Range r = chart.getXYPlot().getDomainAxis().getRange();
        chart.getXYPlot().getDomainAxis().setAutoRange(false);
        chart.getXYPlot().getDomainAxis().setRange(1, r.getUpperBound());
    }
    {
        Range r = chart.getXYPlot().getRangeAxis().getRange();
        if (r.getLowerBound() < range.getUpperBound()) {
            chart.getXYPlot().getRangeAxis().setAutoRange(false);
            chart.getXYPlot().getRangeAxis().setRange(r.getLowerBound(), range.getUpperBound());
        }
    }
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderPaint(Color.WHITE);
    cp.setBorder(null);
    return cp;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) ChartPanel(org.jfree.chart.ChartPanel) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Color(java.awt.Color) AxisSpace(org.jfree.chart.axis.AxisSpace) Range(org.jfree.data.Range) JFreeChart(org.jfree.chart.JFreeChart) LogarithmicAxis(org.jfree.chart.axis.LogarithmicAxis) NumberTickUnit(org.jfree.chart.axis.NumberTickUnit)

Example 13 with AxisSpace

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

the class ContourPlot method draw.

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer).
 * <P>
 * The optional <code>info</code> argument collects information about the
 * rendering of the plot (dimensions, tooltip information etc).  Just pass
 * in <code>null</code> if you do not need this information.
 *
 * @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 state from the parent plot, if there is one.
 * @param info  collects chart drawing information (<code>null</code>
 *              permitted).
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
    // if the plot area is too small, just return...
    boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
    boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
    if (b1 || b2) {
        return;
    }
    // record the plot area...
    if (info != null) {
        info.setPlotArea(area);
    }
    // adjust the drawing area for plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);
    AxisSpace space = new AxisSpace();
    space = this.domainAxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space);
    space = this.rangeAxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space);
    Rectangle2D estimatedDataArea = space.shrink(area, null);
    AxisSpace space2 = new AxisSpace();
    space2 = this.colorBar.reserveSpace(g2, this, area, estimatedDataArea, this.colorBarLocation, space2);
    Rectangle2D adjustedPlotArea = space2.shrink(area, null);
    Rectangle2D dataArea = space.shrink(adjustedPlotArea, null);
    Rectangle2D colorBarArea = space2.reserved(area, this.colorBarLocation);
    // additional dataArea modifications
    if (getDataAreaRatio() != 0.0) {
        // check whether modification is
        double ratio = getDataAreaRatio();
        Rectangle2D tmpDataArea = (Rectangle2D) dataArea.clone();
        double h = tmpDataArea.getHeight();
        double w = tmpDataArea.getWidth();
        if (ratio > 0) {
            // ratio represents pixels
            if (w * ratio <= h) {
                h = ratio * w;
            } else {
                w = h / ratio;
            }
        } else {
            // ratio represents axis units
            ratio *= -1.0;
            double xLength = getDomainAxis().getRange().getLength();
            double yLength = getRangeAxis().getRange().getLength();
            double unitRatio = yLength / xLength;
            ratio = unitRatio * ratio;
            if (w * ratio <= h) {
                h = ratio * w;
            } else {
                w = h / ratio;
            }
        }
        dataArea.setRect(tmpDataArea.getX() + tmpDataArea.getWidth() / 2 - w / 2, tmpDataArea.getY(), w, h);
    }
    if (info != null) {
        info.setDataArea(dataArea);
    }
    CrosshairState crosshairState = new CrosshairState();
    crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY);
    // draw the plot background...
    drawBackground(g2, dataArea);
    double cursor = dataArea.getMaxY();
    if (this.domainAxis != null) {
        this.domainAxis.draw(g2, cursor, adjustedPlotArea, dataArea, RectangleEdge.BOTTOM, info);
    }
    if (this.rangeAxis != null) {
        cursor = dataArea.getMinX();
        this.rangeAxis.draw(g2, cursor, adjustedPlotArea, dataArea, RectangleEdge.LEFT, info);
    }
    if (this.colorBar != null) {
        cursor = 0.0;
        this.colorBar.draw(g2, cursor, adjustedPlotArea, dataArea, colorBarArea, this.colorBarLocation);
    }
    Shape originalClip = g2.getClip();
    Composite originalComposite = g2.getComposite();
    g2.clip(dataArea);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    render(g2, dataArea, info, crosshairState);
    if (this.domainMarkers != null) {
        Iterator iterator = this.domainMarkers.iterator();
        while (iterator.hasNext()) {
            Marker marker = (Marker) iterator.next();
            drawDomainMarker(g2, this, getDomainAxis(), marker, dataArea);
        }
    }
    if (this.rangeMarkers != null) {
        Iterator iterator = this.rangeMarkers.iterator();
        while (iterator.hasNext()) {
            Marker marker = (Marker) iterator.next();
            drawRangeMarker(g2, this, getRangeAxis(), marker, dataArea);
        }
    }
    // TO DO:  these annotations only work with XYPlot, see if it is possible to
    // make ContourPlot a subclass of XYPlot (DG);
    // // draw the annotations...
    // if (this.annotations != null) {
    // Iterator iterator = this.annotations.iterator();
    // while (iterator.hasNext()) {
    // Annotation annotation = (Annotation) iterator.next();
    // if (annotation instanceof XYAnnotation) {
    // XYAnnotation xya = (XYAnnotation) annotation;
    // // get the annotation to draw itself...
    // xya.draw(g2, this, dataArea, getDomainAxis(),
    // getRangeAxis());
    // }
    // }
    // }
    g2.setClip(originalClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, dataArea);
}
Also used : Shape(java.awt.Shape) RectangularShape(java.awt.geom.RectangularShape) AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) Rectangle2D(java.awt.geom.Rectangle2D) Iterator(java.util.Iterator) RectangleInsets(org.jfree.ui.RectangleInsets) AxisSpace(org.jfree.chart.axis.AxisSpace)

Example 14 with AxisSpace

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

the class CombinedDomainXYPlot method calculateAxisSpace.

/**
 * Calculates the axis space required.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 *
 * @return The space.
 */
@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 = getFixedDomainAxisSpace();
    if (fixed != null) {
        if (orientation == PlotOrientation.HORIZONTAL) {
            space.setLeft(fixed.getLeft());
            space.setRight(fixed.getRight());
        } else if (orientation == PlotOrientation.VERTICAL) {
            space.setTop(fixed.getTop());
            space.setBottom(fixed.getBottom());
        }
    } else {
        ValueAxis xAxis = getDomainAxis();
        RectangleEdge xEdge = Plot.resolveDomainAxisLocation(getDomainAxisLocation(), orientation);
        if (xAxis != null) {
            space = xAxis.reserveSpace(g2, this, plotArea, xEdge, 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++) {
        XYPlot sub = (XYPlot) this.subplots.get(i);
        totalWeight += sub.getWeight();
    }
    this.subplotAreas = new Rectangle2D[n];
    double x = adjustedPlotArea.getX();
    double y = adjustedPlotArea.getY();
    double usableSize = 0.0;
    if (orientation == PlotOrientation.HORIZONTAL) {
        usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1);
    } else if (orientation == PlotOrientation.VERTICAL) {
        usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1);
    }
    for (int i = 0; i < n; i++) {
        XYPlot plot = (XYPlot) this.subplots.get(i);
        // calculate sub-plot area
        if (orientation == PlotOrientation.HORIZONTAL) {
            double w = usableSize * plot.getWeight() / totalWeight;
            this.subplotAreas[i] = new Rectangle2D.Double(x, y, w, adjustedPlotArea.getHeight());
            x = x + w + this.gap;
        } else if (orientation == PlotOrientation.VERTICAL) {
            double h = usableSize * plot.getWeight() / totalWeight;
            this.subplotAreas[i] = new Rectangle2D.Double(x, y, adjustedPlotArea.getWidth(), h);
            y = y + h + this.gap;
        }
        AxisSpace subSpace = plot.calculateRangeAxisSpace(g2, this.subplotAreas[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 15 with AxisSpace

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

the class FastScatterPlot method draw.

/**
 * Draws the fast scatter plot on a Java 2D graphics device (such as the
 * screen or a printer).
 *
 * @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 state from the parent plot (ignored).
 * @param info  collects chart drawing information (<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);
    AxisSpace space = new AxisSpace();
    space = this.domainAxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space);
    space = this.rangeAxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space);
    Rectangle2D dataArea = space.shrink(area, null);
    if (info != null) {
        info.setDataArea(dataArea);
    }
    // draw the plot background and axes...
    drawBackground(g2, dataArea);
    AxisState domainAxisState = this.domainAxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info);
    AxisState rangeAxisState = this.rangeAxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info);
    drawDomainGridlines(g2, dataArea, domainAxisState.getTicks());
    drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());
    Shape originalClip = g2.getClip();
    Composite originalComposite = g2.getComposite();
    g2.clip(dataArea);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    render(g2, dataArea, info, null);
    g2.setClip(originalClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, dataArea);
}
Also used : AxisState(org.jfree.chart.axis.AxisState) Shape(java.awt.Shape) AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) Rectangle2D(java.awt.geom.Rectangle2D) RectangleInsets(org.jfree.ui.RectangleInsets) AxisSpace(org.jfree.chart.axis.AxisSpace)

Aggregations

AxisSpace (org.jfree.chart.axis.AxisSpace)23 RectangleEdge (org.jfree.ui.RectangleEdge)15 Rectangle2D (java.awt.geom.Rectangle2D)14 ValueAxis (org.jfree.chart.axis.ValueAxis)11 RectangleInsets (org.jfree.ui.RectangleInsets)9 AxisState (org.jfree.chart.axis.AxisState)7 AlphaComposite (java.awt.AlphaComposite)4 Composite (java.awt.Composite)4 Paint (java.awt.Paint)4 Shape (java.awt.Shape)4 CategoryAxis (org.jfree.chart.axis.CategoryAxis)4 BasicStroke (java.awt.BasicStroke)3 Stroke (java.awt.Stroke)3 NumberAxis (org.jfree.chart.axis.NumberAxis)3 Color (java.awt.Color)2 Graphics2D (java.awt.Graphics2D)2 Point2D (java.awt.geom.Point2D)2 BufferedImage (java.awt.image.BufferedImage)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2