Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes the distance issue between the legend and the horizontal bar chart (Fixes #2138) #2214

Merged
merged 3 commits into from
Jan 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion Source/Charts/Charts/HorizontalBarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,67 @@ open class HorizontalBarChartView: BarChartView
self.highlighter = HorizontalBarHighlighter(chart: self)
}

internal override func calculateLegendOffsets(offsetLeft: inout CGFloat, offsetTop: inout CGFloat, offsetRight: inout CGFloat, offsetBottom: inout CGFloat)
{
guard
let legend = _legend,
legend.isEnabled,
legend.drawInside
else { return }

// setup offsets for legend
switch legend.orientation
{
case .vertical:
switch legend.horizontalAlignment
{
case .left:
offsetLeft += min(legend.neededWidth, _viewPortHandler.chartWidth * legend.maxSizePercent) + legend.xOffset

case .right:
offsetRight += min(legend.neededWidth, _viewPortHandler.chartWidth * legend.maxSizePercent) + legend.xOffset

case .center:

switch legend.verticalAlignment
{
case .top:
offsetTop += min(legend.neededHeight, _viewPortHandler.chartHeight * legend.maxSizePercent) + legend.yOffset

case .bottom:
offsetBottom += min(legend.neededHeight, _viewPortHandler.chartHeight * legend.maxSizePercent) + legend.yOffset

default:
break
}
}

case .horizontal:
switch legend.verticalAlignment
{
case .top:
offsetTop += min(legend.neededHeight, _viewPortHandler.chartHeight * legend.maxSizePercent) + legend.yOffset

// left axis equals the top x-axis in a horizontal chart
if leftAxis.isEnabled && leftAxis.isDrawLabelsEnabled
{
offsetTop += leftAxis.getRequiredHeightSpace()
}

case .bottom:
offsetBottom += min(legend.neededHeight, _viewPortHandler.chartHeight * legend.maxSizePercent) + legend.yOffset

// right axis equals the bottom x-axis in a horizontal chart
if rightAxis.isEnabled && rightAxis.isDrawLabelsEnabled
{
offsetBottom += rightAxis.getRequiredHeightSpace()
}
default:
break
}
}
}

internal override func calculateOffsets()
{
var offsetLeft: CGFloat = 0.0,
Expand Down Expand Up @@ -81,7 +142,7 @@ open class HorizontalBarChartView: BarChartView
offsetRight += self.extraRightOffset
offsetBottom += self.extraBottomOffset
offsetLeft += self.extraLeftOffset

_viewPortHandler.restrainViewPort(
offsetLeft: max(self.minOffset, offsetLeft),
offsetTop: max(self.minOffset, offsetTop),
Expand Down