#1087 Combined XY Plot Axis Display Area Problem

1.0.x
open
nobody
General (896)
5
2013-05-22
2012-05-03
Anonymous
No

When I am using CombinedDomainXYPlot with a PeriodAxis, the starting and ending position of the axis seems not correct, with the starting position shifted a little bit to the left-side, and the ending position shifted to the right-side, i.e. the axis is longer than it should be, causing the ticks in between does not match exactly with the grid lines in the sub-plots.

When the same PeriodAxis is added to the sub-plots, this problem does not occur. All the demos under Combined Axis Charts in the JFreeChart 1.0.13 Demo Collection seems have these problem as well.

Discussion


  • Anonymous
    2012-05-03

    Screenshot of a problematic chart

     
    Attachments

  • Anonymous
    2012-05-15

    Found a temporary workaround for the issue.

    By overriding the draw() method and adjust dataArea before passing it to super.draw():

    dataArea.setRect(dataArea.getX()+4, dataArea.getY(), dataArea.getWidth()-8, dataArea.getHeight());

     
  • A complete fix has to take care of the axisOffset.
    I suggest a fixed code in attached file.

     
  • Well I don't find how to attach a file... so here the method Draw fix :
    //CombinedDomainXYPlot
    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);

    setFixedRangeAxisSpaceForSubplots(null);
    AxisSpace space = calculateAxisSpace(g2, area);
    Rectangle2D dataArea = space.shrink(area, null);

        this.getAxisOffset\(\).trim\(dataArea\);    // fix part \#1
    

    // set the width and height of non-shared axis of all sub-plots
    setFixedRangeAxisSpaceForSubplots(space);

    // draw the shared axis
    ValueAxis axis = getDomainAxis();
    RectangleEdge edge = getDomainAxisEdge();
    double cursor = 0.0 ; //RectangleEdge.coordinate(dataArea, edge);
    // fix part #2
    if (edge == RectangleEdge.TOP) {
    cursor = dataArea.getMinY() - this.getAxisOffset().calculateTopOutset(dataArea.getHeight());
    }
    else if (edge == RectangleEdge.BOTTOM) {
    cursor = dataArea.getMaxY() + this.getAxisOffset().calculateBottomOutset(dataArea.getHeight());
    }
    else if (edge == RectangleEdge.LEFT) {
    cursor = dataArea.getMinX() - this.getAxisOffset().calculateLeftOutset(dataArea.getWidth());
    }
    else if (edge == RectangleEdge.RIGHT) {
    cursor = dataArea.getMaxX() + this.getAxisOffset().calculateRightOutset(dataArea.getWidth());
    }
    // fix end
    AxisState axisState = axis.draw(g2, cursor, area, dataArea, edge, info);
    if (parentState == null) {
    parentState = new PlotState();
    }
    parentState.getSharedAxisStates().put(axis, axisState);

    // draw all the subplots
    for (int i = 0; i < this.subplots.size(); i++) {
    XYPlot plot = (XYPlot) this.subplots.get(i);
    PlotRenderingInfo subplotInfo = null;
    if (info != null) {
    subplotInfo = new PlotRenderingInfo(info.getOwner());
    info.addSubplotInfo(subplotInfo);
    }
    plot.draw(g2, this.subplotAreas[i], anchor, parentState,
    subplotInfo);
    }

    if (info != null) {
    info.setDataArea(dataArea);
    }

    }

     
  • rocktyt
    rocktyt
    2013-05-22

    This problem is still remained in 1.0.14, and I tried 2#'s way but no effect.