CombinedDomainXYPlot : Domain Axis tick/grid alignment bug

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
GaPhi
Posts: 2
Joined: Tue Jan 10, 2012 2:53 pm
antibot: No, of course not.

CombinedDomainXYPlot : Domain Axis tick/grid alignment bug

Post by GaPhi » Tue Jan 10, 2012 3:06 pm

Hello (and happy new year) !

I use CombinedDomainXYPlot to display 2 subplots (1 range axis/subplot, 1 shared domain axis).
I noticed that domain axis ticks are not well aligned with subplots grids (only center tick/grid are well aligned) probably because axis drawing does not take into account the left and right gaps between range axis and data area.

I then had a look at the provided Demo jar file, and the same behavior is present.

It seems it is a real bug for both CombinedDomainXYPlot and CombinedRangeXYPlot (but not all the others).

Can someone fix this in one of the next releases ?
Of course, I can be beta-tester to double check your fix !

Many thanks in advance !! :P

Philippe Gressé-Lugué

GaPhi
Posts: 2
Joined: Tue Jan 10, 2012 2:53 pm
antibot: No, of course not.

Re: CombinedDomainXYPlot : Domain Axis tick/grid alignment b

Post by GaPhi » Tue Jan 24, 2012 10:48 am

Hello again,

After some investigation, it seems that the bug is that CombinedDomain/RangeXYPlot does not take into account the axis offset to set common axis location.

Then, when you use the StandardChartTheme.apply(chart) method, the value is not (0,0,0,0) but (4,4,4,4) for this insets but has no impact on common axis location.

The workaround I use is to force the insets to ZERO_INSETS after getting the standard theme but it is not as beautiful as it should be.

Can someone who masterize the drawing procedures fix this bug?

Thanks !

jylaxx
Posts: 4
Joined: Tue Aug 07, 2012 10:16 pm
antibot: No, of course not.

Re: CombinedDomainXYPlot : Domain Axis tick/grid alignment b

Post by jylaxx » Tue Aug 07, 2012 10:27 pm

I investigate the code and I propose the following fix which take care of the axisOffset :

class CombinedDomainXYPlot

Code: Select all

 
 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();
		// fix part #2
        double cursor = 0.0 ; //RectangleEdge.coordinate(dataArea, edge);
        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);
        }

    }

Locked