Program: 65782
Project: 65782
Buggy source:
/** 
 * Goals: 1. Adjust the two ends of the vertical axis to fit start/end labels 2. Compute the horizontal co-ordinate for the axis
 * @param dBlockX
 * @param dBlockWidth
 * @param aax
 * @param orthogonalAxis
 * @return
 * @throws ChartException
 * @throws IllegalArgumentException
 */
protected final double adjustHorizontal(double dBlockX,double dBlockWidth,AllAxes aax,OneAxis orthogonalAxis) throws ChartException, IllegalArgumentException {
  final OneAxis axPH=aax.areAxesSwapped() ? orthogonalAxis : aax.getPrimaryBase();
  final OneAxis axPV=aax.areAxesSwapped() ? aax.getPrimaryBase() : orthogonalAxis;
  final AutoScale scX=axPH.getScale();
  final AutoScale scY=axPV.getScale();
  final int iXLabelLocation=axPH.getLabelPosition();
  final int iYLabelLocation=axPV.getLabelPosition();
  final int iYTitleLocation=axPV.getTitlePosition();
  final Label laXAxisLabels=axPH.getLabel();
  final Label laYAxisLabels=axPV.getLabel();
  final Label laYAxisTitle=axPV.getTitle();
  final int iYTickStyle=axPV.getCombinedTickStyle();
  final IntersectionValue iv=axPV.getIntersectionValue();
  final boolean bTicksLeft=(iYTickStyle & TICK_LEFT) == TICK_LEFT;
  final boolean bTicksRight=(iYTickStyle & TICK_RIGHT) == TICK_RIGHT;
  final double dAppliedYAxisPlotSpacing=(iv.iType == IConstants.MAX || iv.iType == IConstants.MIN) && !aax.getPrimaryOrthogonal().getModelAxis().isLabelWithinAxes() ? dYAxisPlotSpacing : 0;
  double dStart=scY.getStart(), dEnd=scY.getEnd();
  scY.computeTicks(ids,laYAxisLabels,iYLabelLocation,VERTICAL,dStart,dEnd,true,aax);
  if (!scY.isStepFixed()) {
    final Object[] oaMinMax=scY.getMinMax();
    while (!scY.checkFit(ids,laYAxisLabels,iYLabelLocation)) {
      if (!scY.zoomOut()) {
        break;
      }
      scY.updateAxisMinMax(oaMinMax[0],oaMinMax[1]);
      int tickCount=scY.computeTicks(ids,laYAxisLabels,iYLabelLocation,VERTICAL,dStart,dEnd,true,aax);
      if (scY.getUnit() != null && asInteger(scY.getUnit()) == Calendar.YEAR && tickCount <= 3 || isSharedScale()) {
        break;
      }
    }
  }
  double dYAxisLabelsThickness=scY.computeAxisLabelThickness(ids,axPV.getLabel(),VERTICAL);
  double[] dDecorationThickness={0,0};
  Series[] sea=getModel().getSeries(IConstants.ORTHOGONAL);
  Map<Series,LegendItemRenderingHints> seriesRenderingHints=rtc.getSeriesRenderers();
  for (int i=0; i < sea.length; i++) {
    LegendItemRenderingHints lirh=seriesRenderingHints.get(sea[i]);
    if (lirh != null && lirh.getRenderer() instanceof AxesRenderer) {
      IAxesDecorator iad=((AxesRenderer)lirh.getRenderer()).getAxesDecorator(axPV);
      if (iad != null) {
        double[] thickness=iad.computeDecorationThickness(ids,axPV);
        if (thickness[0] > dDecorationThickness[0]) {
          dDecorationThickness[0]=thickness[0];
        }
        if (thickness[1] > dDecorationThickness[1]) {
          dDecorationThickness[1]=thickness[1];
        }
      }
    }
  }
  double dYAxisTitleThickness=0;
  if (laYAxisTitle.isVisible()) {
    final String sPreviousValue=laYAxisTitle.getCaption().getValue();
    laYAxisTitle.getCaption().setValue(rtc.externalizedMessage(sPreviousValue));
    double maxWidth=AXIS_TITLE_PERCENT * boPlot.getWidth();
    double maxHeight=boPlot.getHeight();
    if (ChartUtil.isStudyLayout(getModel())) {
      maxHeight=Math.abs(axPV.getScale().getEndPoints()[1] - axPV.getScale().getEndPoints()[0]);
    }
    LabelLimiter lblLimit=new LabelLimiter(maxWidth,maxHeight,0);
    lblLimit.computeWrapping(ids,laYAxisTitle);
    lblLimit=lblLimit.limitLabelSize(cComp,ids,laYAxisTitle,EnumSet.of(LabelLimiter.Option.FIX_HEIGHT));
    putLabelLimiter(axPV.getModelAxis().getTitle(),lblLimit);
    dYAxisTitleThickness=lblLimit.getMaxWidth();
    laYAxisTitle.getCaption().setValue(sPreviousValue);
  }
  double dX=getLocation(scX,iv), dX1=dX, dX2=dX;
  double dWTotal=Math.abs(scX.getStart() - scX.getEnd());
  if (axPV.isShowLabels() && axPV.getScale().isCategoryScale()) {
    double v=(dWTotal - dYAxisTitleThickness - 2 * getTickSize()) / 2;
    if (dYAxisLabelsThickness > v) {
      axPV.getScale().getAxisLabelInfo().dActualSize=dYAxisLabelsThickness;
      dYAxisLabelsThickness=v;
    }
  }
  if (axPV.getModelAxis().isSetLabelSpan()) {
    double dFixedLabelThickness=axPV.getModelAxis().getLabelSpan() * dPointToPixel;
    if (dFixedLabelThickness < dWTotal - 2 * getTickSize()) {
      if (dYAxisLabelsThickness + dYAxisTitleThickness > dFixedLabelThickness) {
        axPV.setShowLabels(false);
      }
      if (dYAxisTitleThickness > dFixedLabelThickness) {
        laYAxisTitle.setVisible(false);
        dYAxisTitleThickness=0;
      }
      dYAxisLabelsThickness=dFixedLabelThickness;
    }
  }
  if (iv.iType == IConstants.MIN) {
    dX=adjustHorizontalWithOrigin(dBlockX,aax,axPV,scX,iXLabelLocation,iYLabelLocation,iYTitleLocation,laXAxisLabels,bTicksLeft,bTicksRight,dAppliedYAxisPlotSpacing,dYAxisLabelsThickness,dDecorationThickness,dYAxisTitleThickness,dX,dWTotal);
  }
 else   if (iv.iType == IConstants.MAX) {
    dX=adjustHorizontalWithMaxOrigin(dBlockX,dBlockWidth,aax,axPV,scX,iXLabelLocation,iYLabelLocation,iYTitleLocation,laXAxisLabels,bTicksLeft,bTicksRight,dAppliedYAxisPlotSpacing,dYAxisLabelsThickness,dDecorationThickness,dYAxisTitleThickness,dX,dWTotal);
  }
 else {
    dX=adjustHorizontalWithValueOrigin(dBlockX,dBlockWidth,aax,axPV,scX,iXLabelLocation,iYLabelLocation,iYTitleLocation,laXAxisLabels,iv,bTicksLeft,bTicksRight,dYAxisLabelsThickness,dDecorationThickness,dYAxisTitleThickness,dX,dX1,dX2,dWTotal);
  }
  return dX;
}

Fixed version (ground truth):
/** 
 * Goals: 1. Adjust the two ends of the vertical axis to fit start/end labels 2. Compute the horizontal co-ordinate for the axis
 * @param dBlockX
 * @param dBlockWidth
 * @param aax
 * @param orthogonalAxis
 * @return
 * @throws ChartException
 * @throws IllegalArgumentException
 */
protected final double adjustHorizontal(double dBlockX,double dBlockWidth,AllAxes aax,OneAxis orthogonalAxis) throws ChartException, IllegalArgumentException {
  final OneAxis axPH=aax.areAxesSwapped() ? orthogonalAxis : aax.getPrimaryBase();
  final OneAxis axPV=aax.areAxesSwapped() ? aax.getPrimaryBase() : orthogonalAxis;
  final AutoScale scX=axPH.getScale();
  final AutoScale scY=axPV.getScale();
  final int iXLabelLocation=axPH.getLabelPosition();
  final int iYLabelLocation=axPV.getLabelPosition();
  final int iYTitleLocation=axPV.getTitlePosition();
  final Label laXAxisLabels=axPH.getLabel();
  final Label laYAxisLabels=axPV.getLabel();
  final Label laYAxisTitle=axPV.getTitle();
  final int iYTickStyle=axPV.getCombinedTickStyle();
  final IntersectionValue iv=axPV.getIntersectionValue();
  final boolean bTicksLeft=(iYTickStyle & TICK_LEFT) == TICK_LEFT;
  final boolean bTicksRight=(iYTickStyle & TICK_RIGHT) == TICK_RIGHT;
  final double dAppliedYAxisPlotSpacing=(iv.iType == IConstants.MAX || iv.iType == IConstants.MIN) && !aax.getPrimaryOrthogonal().getModelAxis().isLabelWithinAxes() ? dYAxisPlotSpacing : 0;
  double dStart=scY.getStart(), dEnd=scY.getEnd();
  scY.computeTicks(ids,laYAxisLabels,iYLabelLocation,VERTICAL,dStart,dEnd,true,aax);
  if (!scY.isStepFixed()) {
    final Object[] oaMinMax=scY.getMinMax();
    while (!scY.checkFit(ids,laYAxisLabels,iYLabelLocation)) {
      if (!scY.zoomOut()) {
        break;
      }
      scY.updateAxisMinMax(oaMinMax[0],oaMinMax[1]);
      int tickCount=scY.computeTicks(ids,laYAxisLabels,iYLabelLocation,VERTICAL,dStart,dEnd,true,aax);
      if (scY.getUnit() != null && asInteger(scY.getUnit()) == Calendar.YEAR && tickCount <= 3 || isSharedScale()) {
        break;
      }
    }
  }
  double dYAxisLabelsThickness=scY.computeAxisLabelThickness(ids,axPV.getLabel(),VERTICAL);
  double[] dDecorationThickness={0,0};
  Series[] sea=getModel().getSeries(IConstants.ORTHOGONAL);
  Map<Series,LegendItemRenderingHints> seriesRenderingHints=rtc.getSeriesRenderers();
  for (int i=0; i < sea.length; i++) {
    LegendItemRenderingHints lirh=seriesRenderingHints.get(sea[i]);
    if (lirh != null && lirh.getRenderer() instanceof AxesRenderer) {
      IAxesDecorator iad=((AxesRenderer)lirh.getRenderer()).getAxesDecorator(axPV);
      if (iad != null) {
        double[] thickness=iad.computeDecorationThickness(ids,axPV);
        if (thickness[0] > dDecorationThickness[0]) {
          dDecorationThickness[0]=thickness[0];
        }
        if (thickness[1] > dDecorationThickness[1]) {
          dDecorationThickness[1]=thickness[1];
        }
      }
    }
  }
  double dYAxisTitleThickness=0;
  if (laYAxisTitle.isVisible()) {
    final String sPreviousValue=laYAxisTitle.getCaption().getValue();
    laYAxisTitle.getCaption().setValue(rtc.externalizedMessage(sPreviousValue));
    double maxWidth=AXIS_TITLE_PERCENT * boPlot.getWidth();
    double maxHeight=boPlot.getHeight();
    if (ChartUtil.isStudyLayout(getModel())) {
      maxHeight=Math.abs(axPV.getScale().getEndPoints()[1] - axPV.getScale().getEndPoints()[0]);
    }
    LabelLimiter lblLimit=new LabelLimiter(maxWidth,maxHeight,0);
    lblLimit.computeWrapping(ids,laYAxisTitle);
    lblLimit=lblLimit.limitLabelSize(cComp,ids,laYAxisTitle,EnumSet.of(LabelLimiter.Option.FIX_HEIGHT));
    putLabelLimiter(axPV.getModelAxis().getTitle(),lblLimit);
    dYAxisTitleThickness=lblLimit.getMaxWidth();
    laYAxisTitle.getCaption().setValue(sPreviousValue);
  }
  double dX=getLocation(scX,iv), dX1=dX, dX2=dX;
  double dWTotal=Math.abs(scX.getStart() - scX.getEnd());
  if (axPV.isShowLabels() && axPV.getScale().isCategoryScale()) {
    double leftTickSize=bTicksLeft ? getTickSize() : 0;
    double rightTickSize=bTicksRight ? getTickSize() : 0;
    double v=(dWTotal - dYAxisTitleThickness - leftTickSize- rightTickSize) / 2;
    if (dYAxisLabelsThickness > v) {
      axPV.getScale().getAxisLabelInfo().dActualSize=dYAxisLabelsThickness;
      dYAxisLabelsThickness=v;
    }
  }
  if (axPV.getModelAxis().isSetLabelSpan()) {
    double dFixedLabelThickness=axPV.getModelAxis().getLabelSpan() * dPointToPixel;
    if (dFixedLabelThickness < dWTotal - 2 * getTickSize()) {
      if (dYAxisLabelsThickness + dYAxisTitleThickness > dFixedLabelThickness) {
        axPV.setShowLabels(false);
      }
      if (dYAxisTitleThickness > dFixedLabelThickness) {
        laYAxisTitle.setVisible(false);
        dYAxisTitleThickness=0;
      }
      dYAxisLabelsThickness=dFixedLabelThickness;
    }
  }
  if (iv.iType == IConstants.MIN) {
    dX=adjustHorizontalWithOrigin(dBlockX,aax,axPV,scX,iXLabelLocation,iYLabelLocation,iYTitleLocation,laXAxisLabels,bTicksLeft,bTicksRight,dAppliedYAxisPlotSpacing,dYAxisLabelsThickness,dDecorationThickness,dYAxisTitleThickness,dX,dWTotal);
  }
 else   if (iv.iType == IConstants.MAX) {
    dX=adjustHorizontalWithMaxOrigin(dBlockX,dBlockWidth,aax,axPV,scX,iXLabelLocation,iYLabelLocation,iYTitleLocation,laXAxisLabels,bTicksLeft,bTicksRight,dAppliedYAxisPlotSpacing,dYAxisLabelsThickness,dDecorationThickness,dYAxisTitleThickness,dX,dWTotal);
  }
 else {
    dX=adjustHorizontalWithValueOrigin(dBlockX,dBlockWidth,aax,axPV,scX,iXLabelLocation,iYLabelLocation,iYTitleLocation,laXAxisLabels,iv,bTicksLeft,bTicksRight,dYAxisLabelsThickness,dDecorationThickness,dYAxisTitleThickness,dX,dX1,dX2,dWTotal);
  }
  return dX;
}