afreechart/src/main/java/org/afree/chart/plot/CombinedDomainCategoryPlot.java
/**
     * Calculates the space required for the axes.
     *
     * @param canvas  the graphics device.
     * @param plotArea  the plot area.
     *
     * @return The space required for the axes.
     */
Calculates the space required for the axes.
@param canvas  the graphics device.
@param plotArea  the plot area.

@return The space required for the axes.
Calculates the space required for the axes . @param canvas the graphics device . @param plotArea the plot area . @return The space required for the axes .
protected AxisSpace calculateAxisSpace(Canvas canvas,
                                           RectShape plotArea) {
        AxisSpace space = new AxisSpace();
        PlotOrientation orientation = getOrientation();
        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 {
            CategoryAxis categoryAxis = getDomainAxis();
            RectangleEdge categoryEdge = Plot.resolveDomainAxisLocation(
                    getDomainAxisLocation(), orientation);
            if (categoryAxis != null) {
                space = categoryAxis.reserveSpace(canvas, this, plotArea,
                        categoryEdge, space);
            }
            else {
                if (getDrawSharedDomainAxis()) {
                    space = getDomainAxis().reserveSpace(canvas, this, plotArea,
                            categoryEdge, space);
                }
            }
        }
        RectShape adjustedPlotArea = space.shrink(plotArea, null);
        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();
        }
        this.subplotAreas = new RectShape[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++) {
            CategoryPlot plot = (CategoryPlot) this.subplots.get(i);
            if (orientation == PlotOrientation.HORIZONTAL) {
                double w = usableSize * plot.getWeight() / totalWeight;
                this.subplotAreas[i] = new RectShape(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 RectShape(x, y,
                        adjustedPlotArea.getWidth(), h);
                y = y + h + this.gap;
            }
            AxisSpace subSpace = plot.calculateRangeAxisSpace(canvas,
                    this.subplotAreas[i], null);
            space.ensureAtLeast(subSpace);
        }
        return space;
    }
protected AxisSpace calculateAxisSpace ( Canvas canvas , RectShape plotArea ) { AxisSpace space = new AxisSpace ( ) ; PlotOrientation orientation = getOrientation ( ) ; 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 { CategoryAxis categoryAxis = getDomainAxis ( ) ; RectangleEdge categoryEdge = Plot . resolveDomainAxisLocation ( getDomainAxisLocation ( ) , orientation ) ; if ( categoryAxis != null ) { space = categoryAxis . reserveSpace ( canvas , this , plotArea , categoryEdge , space ) ; } else { if ( getDrawSharedDomainAxis ( ) ) { space = getDomainAxis ( ) . reserveSpace ( canvas , this , plotArea , categoryEdge , space ) ; } } } RectShape adjustedPlotArea = space . shrink ( plotArea , null ) ; 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 ( ) ; } this . subplotAreas = new RectShape [ 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 ++ ) { CategoryPlot plot = ( CategoryPlot ) this . subplots . get ( i ) ; if ( orientation == PlotOrientation . HORIZONTAL ) { double w = usableSize * plot . getWeight ( ) / totalWeight ; this . subplotAreas [ i ] = new RectShape ( 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 RectShape ( x , y , adjustedPlotArea . getWidth ( ) , h ) ; y = y + h + this . gap ; } AxisSpace subSpace = plot . calculateRangeAxisSpace ( canvas , this . subplotAreas [ i ] , null ) ; space . ensureAtLeast ( subSpace ) ; } return space ; }
Calculates the space required for the axes.
Calculates the space required for the axes .
// work out the space required by the domain axis... // work out the maximum height or width of the non-shared axes... // calculate sub-plot area