From 1d8a24a194222a8d07d059d26fcb109c07366d0c Mon Sep 17 00:00:00 2001 From: mconintet Date: Sat, 9 Jan 2016 16:23:16 +0800 Subject: [PATCH 1/2] add an option to set line cap of axis grid line --- Charts/Classes/Components/ChartAxisBase.swift | 1 + Charts/Classes/Renderers/ChartXAxisRenderer.swift | 2 ++ Charts/Classes/Renderers/ChartXAxisRendererBarChart.swift | 2 ++ .../Renderers/ChartXAxisRendererHorizontalBarChart.swift | 2 ++ Charts/Classes/Renderers/ChartYAxisRenderer.swift | 2 ++ .../Renderers/ChartYAxisRendererHorizontalBarChart.swift | 2 ++ ChartsDemo/Classes/Demos/LineChart1ViewController.m | 2 ++ 7 files changed, 13 insertions(+) diff --git a/Charts/Classes/Components/ChartAxisBase.swift b/Charts/Classes/Components/ChartAxisBase.swift index 3119844ec2..9ec2823b1b 100644 --- a/Charts/Classes/Components/ChartAxisBase.swift +++ b/Charts/Classes/Components/ChartAxisBase.swift @@ -29,6 +29,7 @@ public class ChartAxisBase: ChartComponentBase public var gridLineWidth = CGFloat(0.5) public var gridLineDashPhase = CGFloat(0.0) public var gridLineDashLengths: [CGFloat]! + public var gridLineCap = CGLineCap.Square public var drawGridLinesEnabled = true public var drawAxisLineEnabled = true diff --git a/Charts/Classes/Renderers/ChartXAxisRenderer.swift b/Charts/Classes/Renderers/ChartXAxisRenderer.swift index 4811855e7e..77f3bc90a2 100644 --- a/Charts/Classes/Renderers/ChartXAxisRenderer.swift +++ b/Charts/Classes/Renderers/ChartXAxisRenderer.swift @@ -220,6 +220,8 @@ public class ChartXAxisRenderer: ChartAxisRendererBase CGContextSetStrokeColorWithColor(context, _xAxis.gridColor.CGColor) CGContextSetLineWidth(context, _xAxis.gridLineWidth) + CGContextSetLineCap(context, _xAxis.gridLineCap) + if (_xAxis.gridLineDashLengths != nil) { CGContextSetLineDash(context, _xAxis.gridLineDashPhase, _xAxis.gridLineDashLengths, _xAxis.gridLineDashLengths.count) diff --git a/Charts/Classes/Renderers/ChartXAxisRendererBarChart.swift b/Charts/Classes/Renderers/ChartXAxisRendererBarChart.swift index 59012fba1a..1c8205836d 100644 --- a/Charts/Classes/Renderers/ChartXAxisRendererBarChart.swift +++ b/Charts/Classes/Renderers/ChartXAxisRendererBarChart.swift @@ -121,6 +121,8 @@ public class ChartXAxisRendererBarChart: ChartXAxisRenderer CGContextSetStrokeColorWithColor(context, _xAxis.gridColor.CGColor) CGContextSetLineWidth(context, _xAxis.gridLineWidth) + CGContextSetLineCap(context, _xAxis.gridLineCap) + if (_xAxis.gridLineDashLengths != nil) { CGContextSetLineDash(context, _xAxis.gridLineDashPhase, _xAxis.gridLineDashLengths, _xAxis.gridLineDashLengths.count) diff --git a/Charts/Classes/Renderers/ChartXAxisRendererHorizontalBarChart.swift b/Charts/Classes/Renderers/ChartXAxisRendererHorizontalBarChart.swift index 82bc411902..f8b61a62be 100644 --- a/Charts/Classes/Renderers/ChartXAxisRendererHorizontalBarChart.swift +++ b/Charts/Classes/Renderers/ChartXAxisRendererHorizontalBarChart.swift @@ -132,6 +132,8 @@ public class ChartXAxisRendererHorizontalBarChart: ChartXAxisRendererBarChart CGContextSetStrokeColorWithColor(context, _xAxis.gridColor.CGColor) CGContextSetLineWidth(context, _xAxis.gridLineWidth) + CGContextSetLineCap(context, _xAxis.gridLineCap) + if (_xAxis.gridLineDashLengths != nil) { CGContextSetLineDash(context, _xAxis.gridLineDashPhase, _xAxis.gridLineDashLengths, _xAxis.gridLineDashLengths.count) diff --git a/Charts/Classes/Renderers/ChartYAxisRenderer.swift b/Charts/Classes/Renderers/ChartYAxisRenderer.swift index d2ee98e4a7..3f48dfae35 100644 --- a/Charts/Classes/Renderers/ChartYAxisRenderer.swift +++ b/Charts/Classes/Renderers/ChartYAxisRenderer.swift @@ -282,6 +282,8 @@ public class ChartYAxisRenderer: ChartAxisRendererBase CGContextSetStrokeColorWithColor(context, _yAxis.gridColor.CGColor) CGContextSetLineWidth(context, _yAxis.gridLineWidth) + CGContextSetLineCap(context, _yAxis.gridLineCap) + if (_yAxis.gridLineDashLengths != nil) { CGContextSetLineDash(context, _yAxis.gridLineDashPhase, _yAxis.gridLineDashLengths, _yAxis.gridLineDashLengths.count) diff --git a/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift b/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift index 86bb20f85f..af4c3b65ea 100644 --- a/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift +++ b/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift @@ -177,6 +177,8 @@ public class ChartYAxisRendererHorizontalBarChart: ChartYAxisRenderer CGContextSetStrokeColorWithColor(context, _yAxis.gridColor.CGColor) CGContextSetLineWidth(context, _yAxis.gridLineWidth) + CGContextSetLineCap(context, _yAxis.gridLineCap) + if (_yAxis.gridLineDashLengths != nil) { CGContextSetLineDash(context, _yAxis.gridLineDashPhase, _yAxis.gridLineDashLengths, _yAxis.gridLineDashLengths.count) diff --git a/ChartsDemo/Classes/Demos/LineChart1ViewController.m b/ChartsDemo/Classes/Demos/LineChart1ViewController.m index 579fcda079..f8bd097b09 100644 --- a/ChartsDemo/Classes/Demos/LineChart1ViewController.m +++ b/ChartsDemo/Classes/Demos/LineChart1ViewController.m @@ -86,6 +86,8 @@ - (void)viewDidLoad leftAxis.customAxisMin = -50.0; leftAxis.startAtZeroEnabled = NO; leftAxis.gridLineDashLengths = @[@5.f, @5.f]; + leftAxis.gridLineWidth = 2; + leftAxis.gridLineCap = kCGLineCapRound; leftAxis.drawLimitLinesBehindDataEnabled = YES; _chartView.rightAxis.enabled = NO; From 4f21232f18f9c08fe0431750ef1b9ea7f7605dd7 Mon Sep 17 00:00:00 2001 From: mconintet Date: Sat, 9 Jan 2016 17:52:52 +0800 Subject: [PATCH 2/2] add an option to set line cap of axis grid line --- Charts/Classes/Components/ChartAxisBase.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Charts/Classes/Components/ChartAxisBase.swift b/Charts/Classes/Components/ChartAxisBase.swift index 9ec2823b1b..4de4147533 100644 --- a/Charts/Classes/Components/ChartAxisBase.swift +++ b/Charts/Classes/Components/ChartAxisBase.swift @@ -29,7 +29,7 @@ public class ChartAxisBase: ChartComponentBase public var gridLineWidth = CGFloat(0.5) public var gridLineDashPhase = CGFloat(0.0) public var gridLineDashLengths: [CGFloat]! - public var gridLineCap = CGLineCap.Square + public var gridLineCap = CGLineCap.Butt public var drawGridLinesEnabled = true public var drawAxisLineEnabled = true