diff --git a/Charts/Classes/Charts/BarLineChartViewBase.swift b/Charts/Classes/Charts/BarLineChartViewBase.swift index 078a69029b..3e96f8c760 100644 --- a/Charts/Classes/Charts/BarLineChartViewBase.swift +++ b/Charts/Classes/Charts/BarLineChartViewBase.swift @@ -409,6 +409,13 @@ public class BarLineChartViewBase: ChartViewBase, UIGestureRecognizerDelegate let yOffset = _legend.textHeightMax; // It's possible that we do not need this offset anymore as it is available through the extraOffsets offsetBottom += min(_legend.neededHeight + yOffset, _viewPortHandler.chartHeight * _legend.maxSizePercent) } + else if (_legend.position == .AboveChartLeft + || _legend.position == .AboveChartRight + || _legend.position == .AboveChartCenter) + { + let yOffset = _legend.textHeightMax; // It's possible that we do not need this offset anymore as it is available through the extraOffsets + offsetTop += min(_legend.neededHeight + yOffset, _viewPortHandler.chartHeight * _legend.maxSizePercent) + } } // offsets for y-labels diff --git a/Charts/Classes/Charts/HorizontalBarChartView.swift b/Charts/Classes/Charts/HorizontalBarChartView.swift index ef5f8c5db8..4e5b9d48e6 100644 --- a/Charts/Classes/Charts/HorizontalBarChartView.swift +++ b/Charts/Classes/Charts/HorizontalBarChartView.swift @@ -59,6 +59,13 @@ public class HorizontalBarChartView: BarChartView let yOffset = _legend.textHeightMax * 2.0; // It's possible that we do not need this offset anymore as it is available through the extraOffsets offsetBottom += min(_legend.neededHeight + yOffset, _viewPortHandler.chartHeight * _legend.maxSizePercent) } + else if (_legend.position == .AboveChartLeft + || _legend.position == .AboveChartRight + || _legend.position == .AboveChartCenter) + { + let yOffset = _legend.textHeightMax * 2.0; // It's possible that we do not need this offset anymore as it is available through the extraOffsets + offsetTop += min(_legend.neededHeight + yOffset, _viewPortHandler.chartHeight * _legend.maxSizePercent) + } } // offsets for y-labels diff --git a/Charts/Classes/Charts/PieChartView.swift b/Charts/Classes/Charts/PieChartView.swift index 02d5238623..3d140508eb 100755 --- a/Charts/Classes/Charts/PieChartView.swift +++ b/Charts/Classes/Charts/PieChartView.swift @@ -340,7 +340,7 @@ public class PieChartView: PieRadarChartViewBase } } - internal override var requiredBottomOffset: CGFloat + internal override var requiredLegendOffset: CGFloat { return _legend.font.pointSize * 2.0 } diff --git a/Charts/Classes/Charts/PieRadarChartViewBase.swift b/Charts/Classes/Charts/PieRadarChartViewBase.swift index a90d66a17d..23376a5856 100755 --- a/Charts/Classes/Charts/PieRadarChartViewBase.swift +++ b/Charts/Classes/Charts/PieRadarChartViewBase.swift @@ -175,10 +175,17 @@ public class PieRadarChartViewBase: ChartViewBase || _legend.position == .BelowChartRight || _legend.position == .BelowChartCenter) { - let yOffset = self.requiredBottomOffset; // It's possible that we do not need this offset anymore as it is available through the extraOffsets + let yOffset = self.requiredLegendOffset; // It's possible that we do not need this offset anymore as it is available through the extraOffsets legendBottom = min(_legend.neededHeight + yOffset, _viewPortHandler.chartHeight * _legend.maxSizePercent) } - + else if (_legend.position == .AboveChartLeft + || _legend.position == .AboveChartRight + || _legend.position == .AboveChartCenter) + { + let yOffset = self.requiredLegendOffset; // It's possible that we do not need this offset anymore as it is available through the extraOffsets + legendTop = min(_legend.neededHeight + yOffset, _viewPortHandler.chartHeight * _legend.maxSizePercent) + } + legendLeft += self.requiredBaseOffset legendRight += self.requiredBaseOffset legendTop += self.requiredBaseOffset @@ -326,10 +333,10 @@ public class PieRadarChartViewBase: ChartViewBase fatalError("radius cannot be called on PieRadarChartViewBase") } - /// - returns: the required bottom offset for the chart. - internal var requiredBottomOffset: CGFloat + /// - returns: the required offset for the chart legend. + internal var requiredLegendOffset: CGFloat { - fatalError("requiredBottomOffset cannot be called on PieRadarChartViewBase") + fatalError("requiredLegendOffset cannot be called on PieRadarChartViewBase") } /// - returns: the base offset needed for the chart without calculating the diff --git a/Charts/Classes/Charts/RadarChartView.swift b/Charts/Classes/Charts/RadarChartView.swift index 0f39c37d20..74c6f332eb 100644 --- a/Charts/Classes/Charts/RadarChartView.swift +++ b/Charts/Classes/Charts/RadarChartView.swift @@ -256,7 +256,7 @@ public class RadarChartView: PieRadarChartViewBase } } - internal override var requiredBottomOffset: CGFloat + internal override var requiredLegendOffset: CGFloat { return _legend.font.pointSize * 4.0 } diff --git a/Charts/Classes/Components/ChartLegend.swift b/Charts/Classes/Components/ChartLegend.swift index 1d0b23c677..c76b7c7aa9 100644 --- a/Charts/Classes/Components/ChartLegend.swift +++ b/Charts/Classes/Components/ChartLegend.swift @@ -30,6 +30,9 @@ public class ChartLegend: ChartComponentBase case BelowChartRight case BelowChartCenter case PiechartCenter + case AboveChartLeft + case AboveChartRight + case AboveChartCenter } @objc @@ -235,7 +238,10 @@ public class ChartLegend: ChartComponentBase } else if (position == .BelowChartLeft || position == .BelowChartRight - || position == .BelowChartCenter) + || position == .BelowChartCenter + || position == .AboveChartLeft + || position == .AboveChartRight + || position == .AboveChartCenter) { var labels = self.labels var colors = self.colors diff --git a/Charts/Classes/Renderers/ChartLegendRenderer.swift b/Charts/Classes/Renderers/ChartLegendRenderer.swift index 4ec4300dcd..efed0ffbfc 100755 --- a/Charts/Classes/Renderers/ChartLegendRenderer.swift +++ b/Charts/Classes/Renderers/ChartLegendRenderer.swift @@ -139,13 +139,16 @@ public class ChartLegendRenderer: ChartRendererBase { case .BelowChartLeft: fallthrough case .BelowChartRight: fallthrough - case .BelowChartCenter: + case .BelowChartCenter: fallthrough + case .AboveChartLeft: fallthrough + case .AboveChartRight: fallthrough + case .AboveChartCenter: let contentWidth: CGFloat = viewPortHandler.contentWidth var originPosX: CGFloat - if (legendPosition == .BelowChartLeft) + if (legendPosition == .BelowChartLeft || legendPosition == .AboveChartLeft) { originPosX = viewPortHandler.contentLeft + xoffset @@ -154,7 +157,7 @@ public class ChartLegendRenderer: ChartRendererBase originPosX += _legend.neededWidth } } - else if (legendPosition == .BelowChartRight) + else if (legendPosition == .BelowChartRight || legendPosition == .AboveChartRight) { originPosX = viewPortHandler.contentRight - xoffset @@ -174,6 +177,12 @@ public class ChartLegendRenderer: ChartRendererBase var posX: CGFloat = originPosX var posY: CGFloat = viewPortHandler.chartHeight - yoffset - _legend.neededHeight + if (legendPosition == .AboveChartLeft + || legendPosition == .AboveChartRight + || legendPosition == .AboveChartCenter) + { + posY = 0; + } var lineIndex: Int = 0