Skip to content

Commit

Permalink
Corrected legend to center while wrapping in both "above" and "below"
Browse files Browse the repository at this point in the history
Fixes the bug introduced by 0ee538c
  • Loading branch information
danielgindi committed Mar 31, 2016
1 parent 5430750 commit 2e41714
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void renderLegend(Canvas c) {
if (direction == Legend.LegendDirection.LEFT_TO_RIGHT)
originPosX -= mLegend.mNeededWidth;
} else // BELOW_CHART_CENTER || ABOVE_CHART_CENTER
originPosX = mViewPortHandler.contentLeft() + contentWidth / 2.f - mLegend.mNeededWidth / 2f;
originPosX = mViewPortHandler.contentLeft() + contentWidth / 2.f;

FSize[] calculatedLineSizes = mLegend.getCalculatedLineSizes();
FSize[] calculatedLabelSizes = mLegend.getCalculatedLabelSizes();
Expand All @@ -256,7 +256,10 @@ public void renderLegend(Canvas c) {
posY += labelLineHeight + labelLineSpacing;
}

if (posX == originPosX && legendPosition == Legend.LegendPosition.BELOW_CHART_CENTER && lineIndex < calculatedLineSizes.length) {
if (posX == originPosX &&
(legendPosition == Legend.LegendPosition.BELOW_CHART_CENTER ||
legendPosition == Legend.LegendPosition.ABOVE_CHART_CENTER) &&
lineIndex < calculatedLineSizes.length) {
posX += (direction == Legend.LegendDirection.RIGHT_TO_LEFT ? calculatedLineSizes[lineIndex].width : -calculatedLineSizes[lineIndex].width) / 2.f;
lineIndex++;
}
Expand Down

0 comments on commit 2e41714

Please sign in to comment.