diff --git a/Charts/Classes/Components/ChartLimitLine.swift b/Charts/Classes/Components/ChartLimitLine.swift index 686d6c9f33..c2b4cff27e 100644 --- a/Charts/Classes/Components/ChartLimitLine.swift +++ b/Charts/Classes/Components/ChartLimitLine.swift @@ -22,8 +22,10 @@ public class ChartLimitLine: ChartComponentBase @objc public enum ChartLimitLabelPosition: Int { - case Left - case Right + case LeftTop + case LeftBottom + case RightTop + case RightBottom } /// limit / maximum (the y-value or xIndex) @@ -36,7 +38,7 @@ public class ChartLimitLine: ChartComponentBase public var valueTextColor = UIColor.blackColor() public var valueFont = UIFont.systemFontOfSize(13.0) public var label = "" - public var labelPosition = ChartLimitLabelPosition.Right + public var labelPosition = ChartLimitLabelPosition.RightTop public override init() { diff --git a/Charts/Classes/Renderers/ChartXAxisRenderer.swift b/Charts/Classes/Renderers/ChartXAxisRenderer.swift index 5df924eb55..2005a1148e 100644 --- a/Charts/Classes/Renderers/ChartXAxisRenderer.swift +++ b/Charts/Classes/Renderers/ChartXAxisRenderer.swift @@ -285,26 +285,46 @@ public class ChartXAxisRenderer: ChartAxisRendererBase var xOffset: CGFloat = l.lineWidth var yOffset: CGFloat = add / 2.0 - if (l.labelPosition == .Right) + if (l.labelPosition == .RightTop) { ChartUtils.drawText(context: context, text: label, point: CGPoint( x: position.x + xOffset, - y: viewPortHandler.contentBottom - labelLineHeight - yOffset), + y: viewPortHandler.contentTop + yOffset), align: .Left, attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } - else + else if (l.labelPosition == .RightBottom) { ChartUtils.drawText(context: context, text: label, point: CGPoint( x: position.x + xOffset, - y: viewPortHandler.contentTop + yOffset), + y: viewPortHandler.contentBottom - labelLineHeight - yOffset), align: .Left, attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } + else if (l.labelPosition == .LeftTop) + { + ChartUtils.drawText(context: context, + text: label, + point: CGPoint( + x: position.x - xOffset, + y: viewPortHandler.contentTop + yOffset), + align: .Right, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + } + else + { + ChartUtils.drawText(context: context, + text: label, + point: CGPoint( + x: position.x - xOffset, + y: viewPortHandler.contentBottom - labelLineHeight - yOffset), + align: .Right, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + } } } diff --git a/Charts/Classes/Renderers/ChartXAxisRendererHorizontalBarChart.swift b/Charts/Classes/Renderers/ChartXAxisRendererHorizontalBarChart.swift index 5945abfebf..111d1e6dbd 100644 --- a/Charts/Classes/Renderers/ChartXAxisRendererHorizontalBarChart.swift +++ b/Charts/Classes/Renderers/ChartXAxisRendererHorizontalBarChart.swift @@ -251,25 +251,45 @@ public class ChartXAxisRendererHorizontalBarChart: ChartXAxisRendererBarChart let add = CGFloat(4.0) var xOffset: CGFloat = add - var yOffset: CGFloat = l.lineWidth + labelLineHeight / 2.0 + var yOffset: CGFloat = l.lineWidth + labelLineHeight - if (l.labelPosition == .Right) + if (l.labelPosition == .RightTop) { ChartUtils.drawText(context: context, text: label, point: CGPoint( x: viewPortHandler.contentRight - xOffset, - y: position.y - yOffset - labelLineHeight), + y: position.y - yOffset), align: .Right, attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } + else if (l.labelPosition == .RightBottom) + { + ChartUtils.drawText(context: context, + text: label, + point: CGPoint( + x: viewPortHandler.contentRight - xOffset, + y: position.y + yOffset - labelLineHeight), + align: .Right, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + } + else if (l.labelPosition == .LeftTop) + { + ChartUtils.drawText(context: context, + text: label, + point: CGPoint( + x: viewPortHandler.contentLeft + xOffset, + y: position.y - yOffset), + align: .Left, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + } else { ChartUtils.drawText(context: context, text: label, point: CGPoint( x: viewPortHandler.contentLeft + xOffset, - y: position.y - yOffset - labelLineHeight), + y: position.y + yOffset - labelLineHeight), align: .Left, attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } diff --git a/Charts/Classes/Renderers/ChartYAxisRenderer.swift b/Charts/Classes/Renderers/ChartYAxisRenderer.swift index 981d4efa9b..eb6f4f9ea2 100644 --- a/Charts/Classes/Renderers/ChartYAxisRenderer.swift +++ b/Charts/Classes/Renderers/ChartYAxisRenderer.swift @@ -329,25 +329,45 @@ public class ChartYAxisRenderer: ChartAxisRendererBase let add = CGFloat(4.0) var xOffset: CGFloat = add - var yOffset: CGFloat = l.lineWidth + labelLineHeight / 2.0 + var yOffset: CGFloat = l.lineWidth + labelLineHeight - if (l.labelPosition == .Right) + if (l.labelPosition == .RightTop) { ChartUtils.drawText(context: context, text: label, point: CGPoint( x: viewPortHandler.contentRight - xOffset, - y: position.y - yOffset - labelLineHeight), + y: position.y - yOffset), align: .Right, attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } + else if (l.labelPosition == .RightBottom) + { + ChartUtils.drawText(context: context, + text: label, + point: CGPoint( + x: viewPortHandler.contentRight - xOffset, + y: position.y + yOffset - labelLineHeight), + align: .Right, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + } + else if (l.labelPosition == .LeftTop) + { + ChartUtils.drawText(context: context, + text: label, + point: CGPoint( + x: viewPortHandler.contentLeft + xOffset, + y: position.y - yOffset), + align: .Left, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + } else { ChartUtils.drawText(context: context, text: label, point: CGPoint( x: viewPortHandler.contentLeft + xOffset, - y: position.y - yOffset - labelLineHeight), + y: position.y + yOffset - labelLineHeight), align: .Left, attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } diff --git a/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift b/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift index 25abe7b80c..d81fe8c66e 100644 --- a/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift +++ b/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift @@ -255,27 +255,47 @@ public class ChartYAxisRendererHorizontalBarChart: ChartYAxisRenderer let add = CGFloat(4.0) var xOffset: CGFloat = l.lineWidth var yOffset: CGFloat = add / 2.0 - - if (l.labelPosition == .Right) + + if (l.labelPosition == .RightTop) { ChartUtils.drawText(context: context, text: label, point: CGPoint( x: position.x + xOffset, - y: viewPortHandler.contentBottom - labelLineHeight - yOffset), + y: viewPortHandler.contentTop + yOffset), align: .Left, attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } - else + else if (l.labelPosition == .RightBottom) { ChartUtils.drawText(context: context, text: label, point: CGPoint( x: position.x + xOffset, - y: viewPortHandler.contentTop + yOffset), + y: viewPortHandler.contentBottom - labelLineHeight - yOffset), align: .Left, attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) } + else if (l.labelPosition == .LeftTop) + { + ChartUtils.drawText(context: context, + text: label, + point: CGPoint( + x: position.x - xOffset, + y: viewPortHandler.contentTop + yOffset), + align: .Right, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + } + else + { + ChartUtils.drawText(context: context, + text: label, + point: CGPoint( + x: position.x - xOffset, + y: viewPortHandler.contentBottom - labelLineHeight - yOffset), + align: .Right, + attributes: [NSFontAttributeName: l.valueFont, NSForegroundColorAttributeName: l.valueTextColor]) + } } } diff --git a/ChartsDemo/Classes/Demos/LineChart1ViewController.m b/ChartsDemo/Classes/Demos/LineChart1ViewController.m index 835623216c..ee421499fc 100644 --- a/ChartsDemo/Classes/Demos/LineChart1ViewController.m +++ b/ChartsDemo/Classes/Demos/LineChart1ViewController.m @@ -62,7 +62,7 @@ - (void)viewDidLoad ChartLimitLine *llXAxis = [[ChartLimitLine alloc] initWithLimit:10.0 label:@"Index 10"]; llXAxis.lineWidth = 4.0; llXAxis.lineDashLengths = @[@(10.f), @(10.f), @(0.f)]; - llXAxis.labelPosition = ChartLimitLabelPositionRight; + llXAxis.labelPosition = ChartLimitLabelPositionRightBottom; llXAxis.valueFont = [UIFont systemFontOfSize:10.f]; [_chartView.xAxis addLimitLine:llXAxis]; @@ -70,13 +70,13 @@ - (void)viewDidLoad ChartLimitLine *ll1 = [[ChartLimitLine alloc] initWithLimit:130.0 label:@"Upper Limit"]; ll1.lineWidth = 4.0; ll1.lineDashLengths = @[@5.f, @5.f]; - ll1.labelPosition = ChartLimitLabelPositionRight; + ll1.labelPosition = ChartLimitLabelPositionRightTop; ll1.valueFont = [UIFont systemFontOfSize:10.0]; ChartLimitLine *ll2 = [[ChartLimitLine alloc] initWithLimit:-30.0 label:@"Lower Limit"]; ll2.lineWidth = 4.0; ll2.lineDashLengths = @[@5.f, @5.f]; - ll2.labelPosition = ChartLimitLabelPositionRight; + ll2.labelPosition = ChartLimitLabelPositionRightBottom; ll2.valueFont = [UIFont systemFontOfSize:10.0]; ChartYAxis *leftAxis = _chartView.leftAxis;