Program: 69663
Project: 69663
Buggy source:
/** 
 * Internally provided to render a single legend entry
 * @param ipr
 * @param lg
 * @param la
 * @param dX
 * @param dY
 * @param dW
 * @param dItemHeight
 * @param dLeftInset
 * @param dHorizontalSpacing
 * @param se
 * @param fPaletteEntry
 * @param lirh
 * @param i data row index
 * @throws ChartException
 */
protected final void renderLegendItem(IPrimitiveRenderer ipr,Legend lg,Label la,Label valueLa,LegendItemHints lih,double dX,double dY,double dItemHeight,double dColumnWidth,double dLeftInset,double dHorizontalSpacing,Fill fPaletteEntry,LegendItemRenderingHints lirh,double dScale) throws ChartException {
  double dFullHeight=lih.getItemHeight();
  double dExtraHeight=lih.getValueHeight();
  Series se=lih.getSeries();
  int dataIndex=lih.getIndex();
  if (la != null && la.getCaption() != null && valueLa != null && valueLa.getCaption() != null) {
    valueLa.getCaption().setFont(goFactory.copyOf(la.getCaption().getFont()));
    valueLa.getCaption().setColor(goFactory.copyOf(la.getCaption().getColor()));
  }
  LegendEntryRenderingHints lerh=new LegendEntryRenderingHints(la,valueLa,dataIndex,fPaletteEntry);
  AbstractScriptHandler sh=getRunTimeContext().getScriptHandler();
  ScriptHandler.callFunction(sh,ScriptHandler.BEFORE_DRAW_LEGEND_ENTRY,la,getRunTimeContext().getScriptContext());
  getRunTimeContext().notifyStructureChange(IStructureDefinitionListener.BEFORE_DRAW_LEGEND_ENTRY,la);
  final Bounds bo=lirh.getLegendGraphicBounds();
  if (isRightToLeft()) {
    bo.setLeft((dX + dColumnWidth - dLeftInset - 1 - 3 * dItemHeight / 2) / dScale);
  }
 else {
    bo.setLeft((dX + dLeftInset + 1) / dScale);
  }
  bo.setTop((dY + 1 + (dFullHeight - dItemHeight) / 2) / dScale);
  bo.setWidth((3 * dItemHeight / 2) / dScale);
  bo.setHeight((dItemHeight - 2) / dScale);
  ScriptHandler.callFunction(sh,ScriptHandler.BEFORE_DRAW_LEGEND_ITEM,lerh,bo,getRunTimeContext().getScriptContext());
  getRunTimeContext().notifyStructureChange(IStructureDefinitionListener.BEFORE_DRAW_LEGEND_ITEM,lerh);
  if (la != null) {
    la.getCaption().setValue(EllipsisHelper.ellipsisString(la.getCaption().getValue(),lih.getValidItemLen()));
  }
  cComp.applyWrapping(xs,la,lg.getWrappingSize());
  bo.setLeft(bo.getLeft() * dScale);
  bo.setTop(bo.getTop() * dScale);
  bo.setWidth(bo.getWidth() * dScale);
  bo.setHeight(bo.getHeight() * dScale);
  final BaseRenderer br=lirh.getRenderer();
  br.renderLegendGraphic(ipr,lg,fPaletteEntry,bo);
  final TextRenderEvent tre=((EventObjectCache)ir).getEventObject(StructureSource.createLegend(lg),TextRenderEvent.class);
  double dLaAngle=la.getCaption().getFont().getRotation();
  if (isRightToLeft()) {
    dLaAngle=-dLaAngle;
  }
  double dDeltaHeight=0;
  if (dLaAngle > 0 && dLaAngle < 90) {
    dDeltaHeight=(bo.getHeight() + dFullHeight - dItemHeight) / 2;
  }
 else   if (dLaAngle < 0 && dLaAngle > -90) {
    dDeltaHeight=(bo.getHeight() - dFullHeight + dItemHeight) / 2;
  }
 else   if (dLaAngle == 0 || dLaAngle == 90 || dLaAngle == -90) {
    dDeltaHeight=bo.getHeight() / 2;
  }
  if (isRightToLeft()) {
    tre.setLocation(goFactory.createLocation(dX + dColumnWidth - dLeftInset - 3 * dItemHeight / 2 - dHorizontalSpacing,bo.getTop() + dDeltaHeight));
    tre.setTextPosition(TextRenderEvent.LEFT);
  }
 else {
    tre.setLocation(goFactory.createLocation(dX + dLeftInset + (3 * dItemHeight / 2)+ dHorizontalSpacing,bo.getTop() + dDeltaHeight));
    tre.setTextPosition(TextRenderEvent.RIGHT);
  }
  if (la.isVisible()) {
    tre.setLabel(la);
    tre.setAction(TextRenderEvent.RENDER_TEXT_AT_LOCATION);
    if (rtc.isRightToLeftText()) {
      tre.setRtlCaption();
    }
    ipr.drawText(tre);
  }
  if (valueLa != null) {
    final double dValueWidth=dColumnWidth - 2 * dLeftInset;
    Label tmpLa=goFactory.copyOf(valueLa);
    TextAlignment ta=TextAlignmentImpl.create();
    ta.setHorizontalAlignment(HorizontalAlignment.CENTER_LITERAL);
    ta.setVerticalAlignment(VerticalAlignment.CENTER_LITERAL);
    tre.setBlockAlignment(ta);
    tre.setBlockBounds(goFactory.createBounds(dX + dLeftInset + 1,dY + dFullHeight + 1,dValueWidth - 2,dExtraHeight - 1));
    tre.setLabel(tmpLa);
    tre.setAction(TextRenderEvent.RENDER_TEXT_IN_BLOCK);
    if (rtc.isRightToLeftText()) {
      tre.setRtlCaption();
    }
    ipr.drawText(tre);
  }
  la.getCaption().setValue(lih.getItemText());
  if (isInteractivityEnabled()) {
    Trigger tg;
    EList<Trigger> elTriggers=lg.getTriggers();
    Location[] loaHotspot=new Location[4];
    loaHotspot[0]=goFactory.createLocation(dX + 1,dY + 1);
    loaHotspot[1]=goFactory.createLocation(dX + dColumnWidth - 1,dY + 1);
    loaHotspot[2]=goFactory.createLocation(dX + dColumnWidth - 1,dY + dFullHeight + dExtraHeight - 1);
    loaHotspot[3]=goFactory.createLocation(dX + 1,dY + dFullHeight + dExtraHeight - 1);
    Trigger buildinTg=null;
    if (cm.getInteractivity() != null) {
      boolean customed=false;
switch (cm.getInteractivity().getLegendBehavior().getValue()) {
case LegendBehaviorType.HIGHLIGHT_SERIE:
        for (Iterator<Trigger> itr=elTriggers.iterator(); itr.hasNext(); ) {
          tg=itr.next();
          if (tg.getCondition() == TriggerCondition.ONCLICK_LITERAL || tg.getAction().getType() == ActionType.HIGHLIGHT_LITERAL) {
            customed=true;
          }
        }
      if (!customed) {
        buildinTg=goFactory.createTrigger(TriggerCondition.ONCLICK_LITERAL,goFactory.createAction(ActionType.HIGHLIGHT_LITERAL,goFactory.createSeriesValue(String.valueOf(se.getSeriesIdentifier()))));
      }
    break;
case LegendBehaviorType.TOGGLE_SERIE_VISIBILITY:
  for (Iterator<Trigger> itr=elTriggers.iterator(); itr.hasNext(); ) {
    tg=itr.next();
    if (tg.getCondition() == TriggerCondition.ONCLICK_LITERAL || tg.getAction().getType() == ActionType.TOGGLE_VISIBILITY_LITERAL) {
      customed=true;
    }
  }
if (!customed) {
  buildinTg=goFactory.createTrigger(TriggerCondition.ONCLICK_LITERAL,goFactory.createAction(ActionType.TOGGLE_VISIBILITY_LITERAL,goFactory.createSeriesValue(String.valueOf(se.getSeriesIdentifier()))));
}
break;
case LegendBehaviorType.NONE:
break;
}
}
if (!elTriggers.isEmpty() || buildinTg != null) {
final StructureSource source;
if (this.cm.getLegend().getItemType() == LegendItemType.CATEGORIES_LITERAL) {
final DataPointHints dph=new DataPointHints(la,null,null,null,null,null,null,null,null,dataIndex,null,0,null);
source=WrappedStructureSource.createSeriesDataPoint(se,dph);
}
 else {
source=StructureSource.createSeries(se);
}
final InteractionEvent iev=((EventObjectCache)ipr).getEventObject(source,InteractionEvent.class);
iev.setCursor(lg.getCursor());
for (int t=0; t < elTriggers.size(); t++) {
tg=goFactory.copyOf(elTriggers.get(t));
processTrigger(tg,WrappedStructureSource.createLegendEntry(lg,lih));
iev.addTrigger(tg);
}
if (buildinTg != null) {
processTrigger(buildinTg,WrappedStructureSource.createLegendEntry(lg,lih));
iev.addTrigger(buildinTg);
}
final PolygonRenderEvent pre=((EventObjectCache)ipr).getEventObject(source,PolygonRenderEvent.class);
pre.setPoints(loaHotspot);
iev.setHotSpot(pre);
ipr.enableInteraction(iev);
}
}
ScriptHandler.callFunction(sh,ScriptHandler.AFTER_DRAW_LEGEND_ITEM,lerh,bo,getRunTimeContext().getScriptContext());
getRunTimeContext().notifyStructureChange(IStructureDefinitionListener.AFTER_DRAW_LEGEND_ITEM,lerh);
ScriptHandler.callFunction(sh,ScriptHandler.AFTER_DRAW_LEGEND_ENTRY,la,getRunTimeContext().getScriptContext());
getRunTimeContext().notifyStructureChange(IStructureDefinitionListener.AFTER_DRAW_LEGEND_ENTRY,la);
}

Fixed version (ground truth):
/** 
 * Internally provided to render a single legend entry
 * @param ipr
 * @param lg
 * @param la
 * @param dX
 * @param dY
 * @param dW
 * @param dItemHeight
 * @param dLeftInset
 * @param dHorizontalSpacing
 * @param se
 * @param fPaletteEntry
 * @param lirh
 * @param i data row index
 * @throws ChartException
 */
protected final void renderLegendItem(IPrimitiveRenderer ipr,Legend lg,Label la,Label valueLa,LegendItemHints lih,double dX,double dY,double dItemHeight,double dColumnWidth,double dLeftInset,double dHorizontalSpacing,Fill fPaletteEntry,LegendItemRenderingHints lirh,double dScale) throws ChartException {
  double dFullHeight=lih.getItemHeight();
  double dExtraHeight=lih.getValueHeight();
  Series se=lih.getSeries();
  int dataIndex=lih.getIndex();
  if (la != null && la.getCaption() != null && valueLa != null && valueLa.getCaption() != null) {
    valueLa.getCaption().setFont(goFactory.copyOf(la.getCaption().getFont()));
    valueLa.getCaption().setColor(goFactory.copyOf(la.getCaption().getColor()));
  }
  LegendEntryRenderingHints lerh=new LegendEntryRenderingHints(la,valueLa,dataIndex,fPaletteEntry);
  AbstractScriptHandler<?> sh=getRunTimeContext().getScriptHandler();
  ScriptHandler.callFunction(sh,ScriptHandler.BEFORE_DRAW_LEGEND_ENTRY,la,getRunTimeContext().getScriptContext());
  getRunTimeContext().notifyStructureChange(IStructureDefinitionListener.BEFORE_DRAW_LEGEND_ENTRY,la);
  final Bounds bo=lirh.getLegendGraphicBounds();
  if (isRightToLeft()) {
    bo.setLeft((dX + dColumnWidth - dLeftInset - 1 - 3 * dItemHeight / 2) / dScale);
  }
 else {
    bo.setLeft((dX + dLeftInset + 1) / dScale);
  }
  bo.setTop((dY + 1 + (dFullHeight - dItemHeight) / 2) / dScale);
  bo.setWidth((3 * dItemHeight / 2) / dScale);
  bo.setHeight((dItemHeight - 2) / dScale);
  ScriptHandler.callFunction(sh,ScriptHandler.BEFORE_DRAW_LEGEND_ITEM,lerh,bo,getRunTimeContext().getScriptContext());
  getRunTimeContext().notifyStructureChange(IStructureDefinitionListener.BEFORE_DRAW_LEGEND_ITEM,lerh);
  if (la != null) {
    la.getCaption().setValue(EllipsisHelper.ellipsisString(la.getCaption().getValue(),lih.getValidItemLen()));
  }
  cComp.applyWrapping(xs,la,lg.getWrappingSize());
  bo.setLeft(bo.getLeft() * dScale);
  bo.setTop(bo.getTop() * dScale);
  bo.setWidth(bo.getWidth() * dScale);
  bo.setHeight(bo.getHeight() * dScale);
  final BaseRenderer br=lirh.getRenderer();
  br.renderLegendGraphic(ipr,lg,fPaletteEntry,bo);
  final TextRenderEvent tre=((EventObjectCache)ir).getEventObject(StructureSource.createLegend(lg),TextRenderEvent.class);
  double dLaAngle=la.getCaption().getFont().getRotation();
  if (isRightToLeft()) {
    dLaAngle=-dLaAngle;
  }
  double dDeltaHeight=0;
  if (dLaAngle > 0 && dLaAngle < 90) {
    dDeltaHeight=(bo.getHeight() + dFullHeight - dItemHeight) / 2;
  }
 else   if (dLaAngle < 0 && dLaAngle > -90) {
    dDeltaHeight=(bo.getHeight() - dFullHeight + dItemHeight) / 2;
  }
 else   if (dLaAngle == 0 || dLaAngle == 90 || dLaAngle == -90) {
    dDeltaHeight=bo.getHeight() / 2;
  }
  if (isRightToLeft()) {
    tre.setLocation(goFactory.createLocation(dX + dColumnWidth - dLeftInset - 3 * dItemHeight / 2 - dHorizontalSpacing,bo.getTop() + dDeltaHeight));
    tre.setTextPosition(TextRenderEvent.LEFT);
  }
 else {
    tre.setLocation(goFactory.createLocation(dX + dLeftInset + (3 * dItemHeight / 2)+ dHorizontalSpacing,bo.getTop() + dDeltaHeight));
    tre.setTextPosition(TextRenderEvent.RIGHT);
  }
  if (la.isVisible()) {
    tre.setLabel(la);
    tre.setAction(TextRenderEvent.RENDER_TEXT_AT_LOCATION);
    if (rtc.isRightToLeftText()) {
      tre.setRtlCaption();
    }
    ipr.drawText(tre);
  }
  if (valueLa != null) {
    final double dValueWidth=dColumnWidth - 2 * dLeftInset;
    Label tmpLa=goFactory.copyOf(valueLa);
    TextAlignment ta=TextAlignmentImpl.create();
    ta.setHorizontalAlignment(HorizontalAlignment.CENTER_LITERAL);
    ta.setVerticalAlignment(VerticalAlignment.CENTER_LITERAL);
    tre.setBlockAlignment(ta);
    tre.setBlockBounds(goFactory.createBounds(dX + dLeftInset + 1,dY + dFullHeight + 1,dValueWidth - 2,dExtraHeight - 1));
    tre.setLabel(tmpLa);
    tre.setAction(TextRenderEvent.RENDER_TEXT_IN_BLOCK);
    if (rtc.isRightToLeftText()) {
      tre.setRtlCaption();
    }
    ipr.drawText(tre);
  }
  la.getCaption().setValue(lih.getItemText());
  if (isInteractivityEnabled()) {
    Trigger tg;
    EList<Trigger> elTriggers=lg.getTriggers();
    Location[] loaHotspot=new Location[4];
    loaHotspot[0]=goFactory.createLocation(dX + 1,dY + 1);
    loaHotspot[1]=goFactory.createLocation(dX + dColumnWidth - 1,dY + 1);
    loaHotspot[2]=goFactory.createLocation(dX + dColumnWidth - 1,dY + dFullHeight + dExtraHeight - 1);
    loaHotspot[3]=goFactory.createLocation(dX + 1,dY + dFullHeight + dExtraHeight - 1);
    Trigger buildinTg=null;
    if (cm.getInteractivity() != null) {
      boolean customed=false;
switch (cm.getInteractivity().getLegendBehavior().getValue()) {
case LegendBehaviorType.HIGHLIGHT_SERIE:
        for (Iterator<Trigger> itr=elTriggers.iterator(); itr.hasNext(); ) {
          tg=itr.next();
          if (tg.getCondition() == TriggerCondition.ONCLICK_LITERAL || tg.getAction().getType() == ActionType.HIGHLIGHT_LITERAL) {
            customed=true;
          }
        }
      if (!customed) {
        buildinTg=goFactory.createTrigger(TriggerCondition.ONCLICK_LITERAL,goFactory.createAction(ActionType.HIGHLIGHT_LITERAL,goFactory.createSeriesValue(String.valueOf(se.getSeriesIdentifier()))));
      }
    break;
case LegendBehaviorType.TOGGLE_SERIE_VISIBILITY:
  for (Iterator<Trigger> itr=elTriggers.iterator(); itr.hasNext(); ) {
    tg=itr.next();
    if (tg.getCondition() == TriggerCondition.ONCLICK_LITERAL || tg.getAction().getType() == ActionType.TOGGLE_VISIBILITY_LITERAL) {
      customed=true;
    }
  }
if (!customed) {
  buildinTg=goFactory.createTrigger(TriggerCondition.ONCLICK_LITERAL,goFactory.createAction(ActionType.TOGGLE_VISIBILITY_LITERAL,goFactory.createSeriesValue(String.valueOf(se.getSeriesIdentifier()))));
}
break;
case LegendBehaviorType.NONE:
break;
}
}
if (!elTriggers.isEmpty() || buildinTg != null) {
final StructureSource source;
if (this.cm.getLegend().getItemType() == LegendItemType.CATEGORIES_LITERAL) {
final DataPointHints dph=new DataPointHints(la,null,null,null,null,null,null,null,null,dataIndex,null,0,null);
source=WrappedStructureSource.createSeriesDataPoint(se,dph);
}
 else {
source=StructureSource.createSeries(se);
}
final InteractionEvent iev=((EventObjectCache)ipr).getEventObject(source,InteractionEvent.class);
iev.setCursor(lg.getCursor());
for (int t=0; t < elTriggers.size(); t++) {
tg=goFactory.copyOf(elTriggers.get(t));
processTrigger(tg,WrappedStructureSource.createLegendEntry(lg,lih));
iev.addTrigger(tg);
}
if (buildinTg != null) {
processTrigger(buildinTg,WrappedStructureSource.createLegendEntry(lg,lih));
iev.addTrigger(buildinTg);
}
final PolygonRenderEvent pre=((EventObjectCache)ipr).getEventObject(source,PolygonRenderEvent.class);
pre.setPoints(loaHotspot);
iev.setHotSpot(pre);
ipr.enableInteraction(iev);
}
}
ScriptHandler.callFunction(sh,ScriptHandler.AFTER_DRAW_LEGEND_ITEM,lerh,bo,getRunTimeContext().getScriptContext());
getRunTimeContext().notifyStructureChange(IStructureDefinitionListener.AFTER_DRAW_LEGEND_ITEM,lerh);
ScriptHandler.callFunction(sh,ScriptHandler.AFTER_DRAW_LEGEND_ENTRY,la,getRunTimeContext().getScriptContext());
getRunTimeContext().notifyStructureChange(IStructureDefinitionListener.AFTER_DRAW_LEGEND_ENTRY,la);
}