From 901d3902b0c635724aaa9cdf3f1cbc5995846e46 Mon Sep 17 00:00:00 2001 From: liuxuan30 Date: Fri, 8 Jan 2016 11:43:19 +0800 Subject: [PATCH 1/2] add support for lineCap setting for line chart and combined chart --- Charts/Classes/Charts/CombinedChartView.swift | 10 ++++++++++ Charts/Classes/Charts/LineChartView.swift | 4 ++++ Charts/Classes/Interfaces/LineChartDataProvider.swift | 2 ++ Charts/Classes/Renderers/LineChartRenderer.swift | 3 +++ 4 files changed, 19 insertions(+) diff --git a/Charts/Classes/Charts/CombinedChartView.swift b/Charts/Classes/Charts/CombinedChartView.swift index aa406c1440..c552188c16 100644 --- a/Charts/Classes/Charts/CombinedChartView.swift +++ b/Charts/Classes/Charts/CombinedChartView.swift @@ -20,6 +20,8 @@ public class CombinedChartView: BarLineChartViewBase, LineChartDataProvider, Bar /// the fill-formatter used for determining the position of the fill-line internal var _fillFormatter: ChartFillFormatter! + public var lineCapType = CGLineCap.Butt + /// enum that allows to specify the order in which the different data objects for the combined-chart are drawn @objc public enum CombinedChartDrawOrder: Int @@ -124,6 +126,14 @@ public class CombinedChartView: BarLineChartViewBase, LineChartDataProvider, Bar } } + public var lineCap: CGLineCap + { + get + { + return lineCapType + } + } + // MARK: - BarChartDataProvider public var barData: BarChartData? diff --git a/Charts/Classes/Charts/LineChartView.swift b/Charts/Classes/Charts/LineChartView.swift index ce09020d70..ed8d30bf43 100644 --- a/Charts/Classes/Charts/LineChartView.swift +++ b/Charts/Classes/Charts/LineChartView.swift @@ -17,6 +17,8 @@ import CoreGraphics /// Chart that draws lines, surfaces, circles, ... public class LineChartView: BarLineChartViewBase, LineChartDataProvider { + public var lineCapType = CGLineCap.Butt + internal override func initialize() { super.initialize() @@ -37,4 +39,6 @@ public class LineChartView: BarLineChartViewBase, LineChartDataProvider // MARK: - LineChartDataProvider public var lineData: LineChartData? { return _data as? LineChartData } + + public var lineCap: CGLineCap { return lineCapType } } \ No newline at end of file diff --git a/Charts/Classes/Interfaces/LineChartDataProvider.swift b/Charts/Classes/Interfaces/LineChartDataProvider.swift index fe3564d83d..e4c4829180 100644 --- a/Charts/Classes/Interfaces/LineChartDataProvider.swift +++ b/Charts/Classes/Interfaces/LineChartDataProvider.swift @@ -19,5 +19,7 @@ public protocol LineChartDataProvider: BarLineScatterCandleBubbleChartDataProvid { var lineData: LineChartData? { get } + optional var lineCap: CGLineCap { get } + func getAxis(axis: ChartYAxis.AxisDependency) -> ChartYAxis } \ No newline at end of file diff --git a/Charts/Classes/Renderers/LineChartRenderer.swift b/Charts/Classes/Renderers/LineChartRenderer.swift index d601fc3a25..3dd043341c 100644 --- a/Charts/Classes/Renderers/LineChartRenderer.swift +++ b/Charts/Classes/Renderers/LineChartRenderer.swift @@ -236,6 +236,7 @@ public class LineChartRenderer: LineRadarChartRenderer animator = animator else { return } + let lineCap = dataProvider?.lineCap ?? CGLineCap.Butt let valueToPixelMatrix = trans.valueToPixelMatrix let entryCount = dataSet.entryCount @@ -253,6 +254,8 @@ public class LineChartRenderer: LineRadarChartRenderer let maxx = min(max(minx + 2, dataSet.entryIndex(entry: entryTo) + 1), entryCount) CGContextSaveGState(context) + + CGContextSetLineCap(context, lineCap) // more than 1 color if (dataSet.colors.count > 1) From 6e9f64b8852a72c98aa94e0abed48c3666f0359d Mon Sep 17 00:00:00 2001 From: liuxuan30 Date: Wed, 24 Feb 2016 11:03:09 +0800 Subject: [PATCH 2/2] refactor lineCapType to latest architecture --- Charts/Classes/Charts/CombinedChartView.swift | 10 ---------- Charts/Classes/Charts/LineChartView.swift | 4 ---- .../Implementations/Standard/LineChartDataSet.swift | 3 +++ Charts/Classes/Data/Interfaces/ILineChartDataSet.swift | 3 +++ Charts/Classes/Interfaces/LineChartDataProvider.swift | 2 -- Charts/Classes/Renderers/LineChartRenderer.swift | 3 +-- ChartsRealm/Classes/Data/RealmLineDataSet.swift | 3 +++ 7 files changed, 10 insertions(+), 18 deletions(-) diff --git a/Charts/Classes/Charts/CombinedChartView.swift b/Charts/Classes/Charts/CombinedChartView.swift index c552188c16..aa406c1440 100644 --- a/Charts/Classes/Charts/CombinedChartView.swift +++ b/Charts/Classes/Charts/CombinedChartView.swift @@ -20,8 +20,6 @@ public class CombinedChartView: BarLineChartViewBase, LineChartDataProvider, Bar /// the fill-formatter used for determining the position of the fill-line internal var _fillFormatter: ChartFillFormatter! - public var lineCapType = CGLineCap.Butt - /// enum that allows to specify the order in which the different data objects for the combined-chart are drawn @objc public enum CombinedChartDrawOrder: Int @@ -126,14 +124,6 @@ public class CombinedChartView: BarLineChartViewBase, LineChartDataProvider, Bar } } - public var lineCap: CGLineCap - { - get - { - return lineCapType - } - } - // MARK: - BarChartDataProvider public var barData: BarChartData? diff --git a/Charts/Classes/Charts/LineChartView.swift b/Charts/Classes/Charts/LineChartView.swift index ed8d30bf43..ce09020d70 100644 --- a/Charts/Classes/Charts/LineChartView.swift +++ b/Charts/Classes/Charts/LineChartView.swift @@ -17,8 +17,6 @@ import CoreGraphics /// Chart that draws lines, surfaces, circles, ... public class LineChartView: BarLineChartViewBase, LineChartDataProvider { - public var lineCapType = CGLineCap.Butt - internal override func initialize() { super.initialize() @@ -39,6 +37,4 @@ public class LineChartView: BarLineChartViewBase, LineChartDataProvider // MARK: - LineChartDataProvider public var lineData: LineChartData? { return _data as? LineChartData } - - public var lineCap: CGLineCap { return lineCapType } } \ No newline at end of file diff --git a/Charts/Classes/Data/Implementations/Standard/LineChartDataSet.swift b/Charts/Classes/Data/Implementations/Standard/LineChartDataSet.swift index 6886428701..c626e5e329 100644 --- a/Charts/Classes/Data/Implementations/Standard/LineChartDataSet.swift +++ b/Charts/Classes/Data/Implementations/Standard/LineChartDataSet.swift @@ -64,6 +64,9 @@ public class LineChartDataSet: LineRadarChartDataSet, ILineChartDataSet } } + /// Line cap type, default is CGLineCap.Butt + public var lineCapType = CGLineCap.Butt + /// If true, cubic lines are drawn instead of linear public var drawCubicEnabled = false diff --git a/Charts/Classes/Data/Interfaces/ILineChartDataSet.swift b/Charts/Classes/Data/Interfaces/ILineChartDataSet.swift index f6fb8312f1..b63dcd8b28 100644 --- a/Charts/Classes/Data/Interfaces/ILineChartDataSet.swift +++ b/Charts/Classes/Data/Interfaces/ILineChartDataSet.swift @@ -25,6 +25,9 @@ public protocol ILineChartDataSet: ILineRadarChartDataSet /// **default**: 0.2 var cubicIntensity: CGFloat { get set } + /// Line cap type, default is CGLineCap.Butt + var lineCapType: CGLineCap { get set } + /// If true, cubic lines are drawn instead of linear var drawCubicEnabled: Bool { get set } diff --git a/Charts/Classes/Interfaces/LineChartDataProvider.swift b/Charts/Classes/Interfaces/LineChartDataProvider.swift index e4c4829180..fe3564d83d 100644 --- a/Charts/Classes/Interfaces/LineChartDataProvider.swift +++ b/Charts/Classes/Interfaces/LineChartDataProvider.swift @@ -19,7 +19,5 @@ public protocol LineChartDataProvider: BarLineScatterCandleBubbleChartDataProvid { var lineData: LineChartData? { get } - optional var lineCap: CGLineCap { get } - func getAxis(axis: ChartYAxis.AxisDependency) -> ChartYAxis } \ No newline at end of file diff --git a/Charts/Classes/Renderers/LineChartRenderer.swift b/Charts/Classes/Renderers/LineChartRenderer.swift index 3dd043341c..65e7145377 100644 --- a/Charts/Classes/Renderers/LineChartRenderer.swift +++ b/Charts/Classes/Renderers/LineChartRenderer.swift @@ -236,7 +236,6 @@ public class LineChartRenderer: LineRadarChartRenderer animator = animator else { return } - let lineCap = dataProvider?.lineCap ?? CGLineCap.Butt let valueToPixelMatrix = trans.valueToPixelMatrix let entryCount = dataSet.entryCount @@ -255,7 +254,7 @@ public class LineChartRenderer: LineRadarChartRenderer CGContextSaveGState(context) - CGContextSetLineCap(context, lineCap) + CGContextSetLineCap(context, dataSet.lineCapType) // more than 1 color if (dataSet.colors.count > 1) diff --git a/ChartsRealm/Classes/Data/RealmLineDataSet.swift b/ChartsRealm/Classes/Data/RealmLineDataSet.swift index 055a801b9e..9efb49414b 100644 --- a/ChartsRealm/Classes/Data/RealmLineDataSet.swift +++ b/ChartsRealm/Classes/Data/RealmLineDataSet.swift @@ -54,6 +54,9 @@ public class RealmLineDataSet: RealmLineRadarDataSet, ILineChartDataSet } } + /// Line cap type, default is CGLineCap.Butt + public var lineCapType = CGLineCap.Butt + /// If true, cubic lines are drawn instead of linear public var drawCubicEnabled = false