* REQUIRED * TO FIT * CLEANLY */;
* REQUIRED TO * FIT CLEANLY */;
    private final void updateOverlayScales(AllAxes aax, double dAxisStart, double dAxisEnd, double dBlockStart,        double dBlockLength) throws PluginException, DataSetException, GenerationException, UnexpectedInputException    {        final Axis[] axa = ((ChartWithAxesImpl) cwa).getPrimaryBaseAxes();        final Axis axPrimaryBase = axa[0];        final Axis[] axaOrthogonal = ((ChartWithAxesImpl) cwa).getOrthogonalAxes(axPrimaryBase, false);        IntersectionValue iv;        AutoScale sc = null;        OneAxis oaxOverlay = null;        int iTickStyle, iAxisType, j, iTitleLocation;        int iOverlayCount = aax.getOverlayCount();        int iOrientation = aax.getOrientation();        FontDefinition fd;        double dStart, dEnd, dAxisLabelsThickness;        Label laAxisTitle;        Scale scModel;        for (int i = 0; i < iOverlayCount; i++)        {            j = iOverlayCount - i - 1; // GO BACKWARDS TO ENSURE CORRECT            // RENDERING ORDER            oaxOverlay = aax.getOverlay(j); // UPDATE A PREVIOUSLY DEFINED            // OVERLAY AXIS            fd = oaxOverlay.getLabel().getCaption().getFont(); // NEEDED TO            // AUTO            // COMPUTE            // SCALE            iTickStyle = oaxOverlay.getCombinedTickStyle();            iTitleLocation = oaxOverlay.getTitlePosition();            laAxisTitle = oaxOverlay.getTitle();            iAxisType = getAxisType(axaOrthogonal[j]);            scModel = axaOrthogonal[j].getScale();            sc = AutoScale.computeScale(ids, oaxOverlay, new DataSetIterator(getMinMax(axaOrthogonal[j], iAxisType),                iAxisType), iAxisType, dAxisStart, dAxisEnd, scModel.getMin(), scModel.getMax(),                scModel.isSetStep() ? new Double(scModel.getStep()) : null, axaOrthogonal[j].getFormatSpecifier(), lcl);            oaxOverlay.set(sc);            iv = oaxOverlay.getIntersectionValue();            // UPDATE AXIS ENDPOINTS DUE TO ITS AXIS LABEL SHIFTS            dStart = sc.getStart();            dEnd = sc.getEnd();            sc.computeTicks(ids, oaxOverlay.getLabel(), oaxOverlay.getLabelPosition(), iOrientation, dStart, dEnd,                true, null);            if (!sc.isStepFixed())            {                final Object[] oaMinMax = sc.getMinMax();                while (!sc.checkFit(ids, oaxOverlay.getLabel(), oaxOverlay.getLabelPosition()))                {                    sc.zoomOut();                    sc.updateAxisMinMax(oaMinMax[0], oaMinMax[1]);                    sc.computeTicks(ids, oaxOverlay.getLabel(), oaxOverlay.getLabelPosition(), iOrientation, dStart,                        dEnd, true, null);                }            }            dAxisLabelsThickness = sc.computeAxisLabelThickness(ids, oaxOverlay.getLabel(), iOrientation) /*                                                                                                            * REQUIRED                                                                                                            * TO FIT                                                                                                            * CLEANLY                                                                                                            */;            double dAxisTitleThickness = 0;            sc.resetShifts();            if (iOrientation == VERTICAL)            {                // COMPUTE THE THICKNESS OF THE AXIS INCLUDING AXIS LABEL BOUNDS                // AND AXIS-PLOT SPACING                double dX = 0, dX1 = 0, dX2 = 0; // Y-AXIS BAND VERTICAL                // CO-ORDINATES                final boolean bTicksLeft = (iTickStyle & TICK_LEFT) == TICK_LEFT; // 'boolean'                // FOR                // CONVENIENCE                // &                // READABILITY                final boolean bTicksRight = (iTickStyle & TICK_RIGHT) == TICK_RIGHT; // 'boolean'                // FOR                // CONVENIENCE                // &                // READABILITY                final double dAppliedYAxisPlotSpacing = dYAxisPlotSpacing;                double dDeltaX1 = 0, dDeltaX2 = 0;                if (laAxisTitle.isVisible())                {                    dAxisTitleThickness = computeBox(ids, iTitleLocation, laAxisTitle, 0, 0).getWidth() /*                                                                                                          * REQUIRED TO                                                                                                          * FIT CLEANLY                                                                                                          */;                }                // COMPUTE VALUES FOR x1, x, x2                // x = HORIZONTAL LOCATION OF Y-AXIS ALONG PLOT                // x1 = LEFT EDGE OF Y-AXIS BAND (DUE TO AXIS LABELS, TICKS,                // SPACING)                // x2 = RIGHT EDGE OF Y-AXIS BAND (DUE TO AXIS LABELS, TICKS,                // SPACING)                if (iv.getType() == IntersectionValue.MIN) // LEFT OF PLOT                {                    // NOTE: ENSURE CODE SYMMETRY WITH 'iaLabelPositions[i] ==                    // RIGHT'                    dX = dBlockStart;                    dX -= dAppliedYAxisPlotSpacing;                    dX1 = dX;                    dX2 = dX;                    if (bTicksLeft)                    {                        dX1 -= TICK_SIZE;                    }                    if (oaxOverlay.getLabelPosition() == LEFT)                    {                        dX1 -= dAxisLabelsThickness;                        dX2 += Math.max(bTicksRight ? TICK_SIZE : 0, dAppliedYAxisPlotSpacing);                    }                    else if (oaxOverlay.getLabelPosition() == RIGHT)                    {                        dX2 += Math.max((bTicksRight ? TICK_SIZE : 0) + dAxisLabelsThickness, dAppliedYAxisPlotSpacing);                    }                    if (iTitleLocation == LEFT)                    {                        dX1 -= dAxisTitleThickness;                    }                    else if (iTitleLocation == RIGHT)                    {                        dX2 += dAxisTitleThickness;                    }                    // ENSURE THAT WE DON'T GO BEHIND THE LEFT PLOT BLOCK EDGE                    if (dX1 < dBlockStart)                    {                        final double dDelta = (dBlockStart - dX1);                        dX1 = dBlockStart;                        dX += dDelta;                        dX2 += dDelta;                    }                    dDeltaX1 = dX - dX1;                    dDeltaX2 = dX2 - dX;                    dBlockStart += (dX2 - dX1); // SHIFT LEFT EDGE >>                }                else if (iv.getType() == IntersectionValue.MAX) // RIGHT                {                    // NOTE: ENSURE CODE SYMMETRY WITH 'InsersectionValue.MIN'                    dX = dBlockStart + dBlockLength;                    dX += dAppliedYAxisPlotSpacing;                    dX1 = dX;                    dX2 = dX;                    if (bTicksRight)                    {                        dX2 += TICK_SIZE;                    }                    if (oaxOverlay.getLabelPosition() == RIGHT)                    {                        dX2 += dAxisLabelsThickness;                        dX1 -= Math.max(bTicksLeft ? TICK_SIZE : 0, dAppliedYAxisPlotSpacing);                    }                    else if (oaxOverlay.getLabelPosition() == LEFT)                    {                        dX1 -= Math.max((bTicksLeft ? TICK_SIZE : 0) + dAxisLabelsThickness, dAppliedYAxisPlotSpacing);                    }                    dDeltaX1 = dX - dX1;                    dDeltaX2 = dX2 - dX;                    if (iTitleLocation == LEFT)                    {                        dX1 -= dAxisTitleThickness;                    }                    else if (iTitleLocation == RIGHT)                    {                        dX2 += dAxisTitleThickness;                    }                    // ENSURE THAT WE DON'T GO AHEAD OF THE RIGHT PLOT BLOCK                    // EDGE                    if (dX2 > dBlockStart + dBlockLength)                    {                        final double dDelta = dX2 - (dBlockStart + dBlockLength);                        dX2 = dBlockStart + dBlockLength;                        dX -= dDelta;                        dX1 -= dDelta;                    }                    dAxisLabelsThickness = dX2 - dX1; // REUSE VARIABLE                }                dBlockLength -= dAxisLabelsThickness; // SHIFT RIGHT EDGE <<                double dDelta = 0;                if (iv.getType() == IntersectionValue.MIN)                {                    dDelta = -insCA.getLeft();                }                else if (iv.getType() == IntersectionValue.MAX)                {                    dDelta = insCA.getRight();                }                oaxOverlay.setAxisCoordinate(dX + dDelta);                oaxOverlay.setTitleCoordinate((iTitleLocation == LEFT) ? dX1 + dDelta - 1 : dX2 + 1                    - dAxisTitleThickness + dDelta // dX1<=>dX<=>dX2                // INCORPORATES                    // TITLE                    );            }            else if (iOrientation == HORIZONTAL)            {                // COMPUTE THE THICKNESS OF THE AXIS INCLUDING AXIS LABEL BOUNDS                // AND AXIS-PLOT SPACING                double dY = 0, dY1 = dY, dY2 = dY, dDeltaY1 = 0, dDeltaY2 = 0; // X-AXIS                // BAND                // VERTICAL                // CO-ORDINATES                final boolean bTicksAbove = (iTickStyle & TICK_ABOVE) == TICK_ABOVE; // 'boolean'                // FOR                // CONVENIENCE                // &                // READABILITY                final boolean bTicksBelow = (iTickStyle & TICK_BELOW) == TICK_BELOW; // 'boolean'                // FOR                // CONVENIENCE                // &                // READABILITY                final double dAppliedXAxisPlotSpacing = dXAxisPlotSpacing;                if (laAxisTitle.isVisible())                {                    dAxisTitleThickness = computeBox(ids, iTitleLocation, laAxisTitle, 0, 0).getHeight() /*                                                                                                           * REQUIRED TO                                                                                                           * FIT CLEANLY                                                                                                           */;                }                // COMPUTE VALUES FOR y1, y, y2                // y = VERTICAL LOCATION OF X-AXIS ALONG PLOT                // y1 = UPPER EDGE OF X-AXIS (DUE TO AXIS LABELS, TICKS,                // SPACING)                // y2 = LOWER EDGE OF X-AXIS (DUE TO AXIS LABELS, TICKS,                // SPACING)                if (iv.getType() == IntersectionValue.MAX) // ABOVE THE PLOT                {                    dY = dBlockStart;                    dY -= dAppliedXAxisPlotSpacing;                    dY1 = dY;                    dY2 = dY;                    if (bTicksAbove)                    {                        dY1 -= TICK_SIZE;                    }                    if (oaxOverlay.getLabelPosition() == ABOVE)                    {                        dY1 -= dAxisLabelsThickness;                        dY2 += Math.max(bTicksBelow ? TICK_SIZE : 0, dAppliedXAxisPlotSpacing);                    }                    else if (oaxOverlay.getLabelPosition() == BELOW)                    {                        dY2 += Math.max((bTicksBelow ? TICK_SIZE : 0) + dAxisLabelsThickness, dAppliedXAxisPlotSpacing);                    }                    if (iTitleLocation == ABOVE)                    {                        dY1 -= dAxisTitleThickness;                    }                    else if (iTitleLocation == BELOW)                    {                        dY2 += dAxisTitleThickness;                    }                    // ENSURE THAT WE DON'T GO BEHIND THE LEFT PLOT BLOCK EDGE                    if (dY1 < dBlockStart)                    {                        final double dDelta = (dBlockStart - dY1);                        dY1 = dBlockStart;                        dY += dDelta;                        dY2 += dDelta;                    }                    dDeltaY1 = dY - dY1;                    dDeltaY2 = dY2 - dY;                    dBlockStart += (dY2 - dY1); // SHIFT TOP EDGE >>                }                else if (iv.getType() == IntersectionValue.MIN) // BELOW THE                // PLOT                {                    // NOTE: ENSURE CODE SYMMETRY WITH 'InsersectionValue.MIN'                    dY = dBlockStart + dBlockLength;                    dY += dAppliedXAxisPlotSpacing;                    dY1 = dY;                    dY2 = dY;                    if (bTicksBelow)                    {                        dY2 += TICK_SIZE;                    }                    if (oaxOverlay.getLabelPosition() == BELOW)                    {                        dY2 += dAxisLabelsThickness;                        dY1 -= Math.max(bTicksAbove ? TICK_SIZE : 0, dAppliedXAxisPlotSpacing);                    }                    else if (oaxOverlay.getLabelPosition() == ABOVE)                    {                        dY1 -= Math.max((bTicksAbove ? TICK_SIZE : 0) + dAxisLabelsThickness, dAppliedXAxisPlotSpacing);                    }                    dDeltaY1 = dY - dY1;                    dDeltaY2 = dY2 - dY;                    if (iTitleLocation == ABOVE)                    {                        dY1 -= dAxisTitleThickness;                    }                    else if (iTitleLocation == BELOW)                    {                        dY2 += dAxisTitleThickness;                    }                    // ENSURE THAT WE DON'T GO AHEAD OF THE RIGHT PLOT BLOCK                    // EDGE                    if (dY2 > dBlockStart + dBlockLength)                    {                        final double dDelta = dY2 - (dBlockStart + dBlockLength);                        dY2 = dBlockStart + dBlockLength;                        dY -= dDelta;                        dY1 -= dDelta;                    }                }                double dDelta = 0;                if (iv.getType() == IntersectionValue.MAX)                {                    dDelta = -insCA.getTop();                }                else if (iv.getType() == IntersectionValue.MIN)                {                    dDelta = insCA.getBottom();                }                oaxOverlay.setAxisCoordinate(dY + dDelta);                oaxOverlay.setTitleCoordinate((iTitleLocation == ABOVE) ? dY1 + dDelta - 1 : dY2 + 1                    - dAxisTitleThickness + dDelta // dY1<=>dX<=>dY2                // INCORPORATES                    // TITLE                    );                dBlockLength -= (dY2 - dY1); // SHIFT BOTTOM EDGE <<            }        }        aax.setBlockCordinates(dBlockStart, dBlockLength);    }