Program: 70473
Project: 70473
Buggy source:
/** 
 * Limits the Data point Label inside area including axes
 * @param cm
 * @param xs
 * @param laDataPoint
 * @param dScale
 * @param lo
 * @throws ChartException
 * @since 2.3
 */
public static void limitDataPointLabelLocation(Chart cm,IDisplayServer xs,Label laDataPoint,double dScale,Location lo) throws ChartException {
  if (lo == null || cm instanceof ChartWithoutAxes) {
    return;
  }
  ChartWithAxes cwa=(ChartWithAxes)cm;
  Plot p=cwa.getPlot();
  BoundingBox bb=Methods.computeBox(xs,IConstants.ABOVE,laDataPoint,0,0);
  Bounds boCa=p.getBounds().scaledInstance(dScale);
  if (!cwa.isTransposed()) {
    double dYmin=boCa.getTop() + bb.getHeight();
    double dY=lo.getY();
    if (dY < dYmin) {
      lo.setY(dYmin);
    }
  }
 else {
    double dCaRight=boCa.getLeft() + boCa.getWidth();
    double dXmax=dCaRight - bb.getWidth();
    double dX=lo.getX();
    if (dX > dXmax) {
      lo.setX(dXmax);
    }
  }
}

Fixed version (ground truth):
/** 
 * Limits the Data point Label inside area including axes
 * @param cm
 * @param xs
 * @param laDataPoint
 * @param dScale
 * @param lo
 * @throws ChartException
 * @since 2.3
 */
public static void limitDataPointLabelLocation(Chart cm,IDisplayServer xs,Label laDataPoint,double dScale,Location lo,Position lp) throws ChartException {
  if (lo == null || cm instanceof ChartWithoutAxes) {
    return;
  }
  ChartWithAxes cwa=(ChartWithAxes)cm;
  Plot p=cwa.getPlot();
  BoundingBox bb=Methods.computeBox(xs,IConstants.ABOVE,laDataPoint,0,0);
  Bounds boCa=p.getBounds().scaledInstance(dScale);
  double rotation=laDataPoint.getCaption().getFont().getRotation();
  int state=0;
switch (lp.getValue()) {
case Position.ABOVE:
    if (rotation > 0 && rotation < 90) {
      state=8;
    }
 else     if (rotation < 0 && rotation > -90) {
      state=2;
    }
 else {
      state=1;
    }
  break;
case Position.RIGHT:
if (rotation > 0 && rotation < 90) {
  state=8;
}
 else if (rotation < 0 && rotation > -90) {
  state=6;
}
 else {
  state=7;
}
break;
case Position.BELOW:
if (rotation > 0 && rotation < 90) {
state=4;
}
 else if (rotation < 0 && rotation > -90) {
state=6;
}
 else {
state=5;
}
break;
case Position.LEFT:
if (rotation > 0 && rotation < 90) {
state=4;
}
 else if (rotation < 0 && rotation > -90) {
state=2;
}
 else {
state=3;
}
break;
}
double dYmin, dYmax, dXmin, dXmax;
switch (state) {
case 1:
dYmin=boCa.getTop() + bb.getHeight();
dYmax=boCa.getTop() + boCa.getHeight();
dXmin=boCa.getLeft() + bb.getWidth() / 2;
dXmax=boCa.getLeft() + boCa.getWidth() - bb.getWidth() / 2;
break;
case 2:
dYmin=boCa.getTop() + bb.getHeight();
dYmax=boCa.getTop() + boCa.getHeight();
dXmin=boCa.getLeft() + bb.getWidth();
dXmax=boCa.getLeft() + boCa.getWidth();
break;
case 3:
dYmin=boCa.getTop() + bb.getHeight() / 2;
dYmax=boCa.getTop() + boCa.getHeight() - bb.getHeight() / 2;
dXmin=boCa.getLeft() + bb.getWidth();
dXmax=boCa.getLeft() + boCa.getWidth();
break;
case 4:
dYmin=boCa.getTop();
dYmax=boCa.getTop() + boCa.getHeight() - bb.getHeight();
dXmin=boCa.getLeft() + bb.getWidth();
dXmax=boCa.getLeft() + boCa.getWidth();
break;
case 5:
dYmin=boCa.getTop();
dYmax=boCa.getTop() + boCa.getHeight() - bb.getHeight();
dXmin=boCa.getLeft() + bb.getWidth() / 2;
dXmax=boCa.getLeft() + boCa.getWidth() - bb.getWidth() / 2;
break;
case 6:
dYmin=boCa.getTop();
dYmax=boCa.getTop() + boCa.getHeight() - bb.getHeight();
dXmin=boCa.getLeft();
dXmax=boCa.getLeft() + boCa.getWidth() - bb.getWidth();
break;
case 7:
dYmin=boCa.getTop() + bb.getHeight() / 2;
dYmax=boCa.getTop() + boCa.getHeight() - bb.getHeight() / 2;
dXmin=boCa.getLeft();
dXmax=boCa.getLeft() + boCa.getWidth() - bb.getWidth();
break;
case 8:
dYmin=boCa.getTop() + bb.getHeight();
dYmax=boCa.getTop() + boCa.getHeight();
dXmin=boCa.getLeft();
dXmax=boCa.getLeft() + boCa.getWidth() - bb.getWidth();
break;
default :
dYmin=lo.getY();
dYmax=lo.getY();
dXmin=lo.getX();
dXmax=lo.getX();
break;
}
if (lo.getY() < dYmin) {
lo.setY(dYmin);
}
if (lo.getY() > dYmax) {
lo.setY(dYmax);
}
if (lo.getX() < dXmin) {
lo.setX(dXmin);
}
if (lo.getX() > dXmax) {
lo.setX(dXmax);
}
}