From c6e0a48f7644e31eccb85d696ea50b97248d9321 Mon Sep 17 00:00:00 2001 From: Alexei Kozachenko Date: Tue, 23 Oct 2018 23:44:11 -0400 Subject: [PATCH 1/8] Multiple colors for valueline (Fixes #3480) This change adds a flag matchValueLineColorToPieSlice to PieChartDataSet and IPieChartDataSet protocol. When enabled, valuelines will have the same color as slices they attached to. matchValueLineColorToPieSlice is set to false by default, so colors won't be changed in old projects that use Charts. --- .../Data/Implementations/Standard/PieChartDataSet.swift | 3 +++ Source/Charts/Data/Interfaces/IPieChartDataSet.swift | 3 +++ Source/Charts/Renderers/PieChartRenderer.swift | 6 +++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift index 5847796068..017b2c7dbf 100644 --- a/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift @@ -84,6 +84,9 @@ open class PieChartDataSet: ChartDataSet, IPieChartDataSet /// When valuePosition is OutsideSlice, indicates line color open var valueLineColor: NSUIColor? = NSUIColor.black + /// When valuePosition is OutsideSlice and enabled, line will have the same color as the slice + open var matchValueLineColorToPieSlice: Bool = false + /// When valuePosition is OutsideSlice, indicates line width open var valueLineWidth: CGFloat = 1.0 diff --git a/Source/Charts/Data/Interfaces/IPieChartDataSet.swift b/Source/Charts/Data/Interfaces/IPieChartDataSet.swift index 872a031170..199ea20a0d 100644 --- a/Source/Charts/Data/Interfaces/IPieChartDataSet.swift +++ b/Source/Charts/Data/Interfaces/IPieChartDataSet.swift @@ -38,6 +38,9 @@ public protocol IPieChartDataSet: IChartDataSet /// When valuePosition is OutsideSlice, indicates line color var valueLineColor: NSUIColor? { get set } + /// When valuePosition is OutsideSlice and enabled, line will have the same color as the slice + var matchValueLineColorToPieSlice: Bool { get set } + /// When valuePosition is OutsideSlice, indicates line width var valueLineWidth: CGFloat { get set } diff --git a/Source/Charts/Renderers/PieChartRenderer.swift b/Source/Charts/Renderers/PieChartRenderer.swift index c1ceb7c1fe..27f42810a3 100644 --- a/Source/Charts/Renderers/PieChartRenderer.swift +++ b/Source/Charts/Renderers/PieChartRenderer.swift @@ -440,7 +440,11 @@ open class PieChartRenderer: DataRenderer if dataSet.valueLineColor != nil { - context.setStrokeColor(dataSet.valueLineColor!.cgColor) + if dataSet.matchValueLineColorToPieSlice { + context.setStrokeColor(dataSet.color(atIndex: j).cgColor) + } else { + context.setStrokeColor(dataSet.valueLineColor!.cgColor) + } context.setLineWidth(dataSet.valueLineWidth) context.move(to: CGPoint(x: pt0.x, y: pt0.y)) From d54232073f7f236a98e7caaaef4bde1aaca7ea60 Mon Sep 17 00:00:00 2001 From: Alexei Kozachenko Date: Fri, 26 Oct 2018 21:10:35 -0400 Subject: [PATCH 2/8] Changed variable name from matchValueLineColorToPieSlice to valueLineAutoColor --- .../Charts/Data/Implementations/Standard/PieChartDataSet.swift | 2 +- Source/Charts/Data/Interfaces/IPieChartDataSet.swift | 2 +- Source/Charts/Renderers/PieChartRenderer.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift index 017b2c7dbf..505f17dd85 100644 --- a/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift @@ -85,7 +85,7 @@ open class PieChartDataSet: ChartDataSet, IPieChartDataSet open var valueLineColor: NSUIColor? = NSUIColor.black /// When valuePosition is OutsideSlice and enabled, line will have the same color as the slice - open var matchValueLineColorToPieSlice: Bool = false + open var valueLineAutoColor: Bool = false /// When valuePosition is OutsideSlice, indicates line width open var valueLineWidth: CGFloat = 1.0 diff --git a/Source/Charts/Data/Interfaces/IPieChartDataSet.swift b/Source/Charts/Data/Interfaces/IPieChartDataSet.swift index 199ea20a0d..247a348851 100644 --- a/Source/Charts/Data/Interfaces/IPieChartDataSet.swift +++ b/Source/Charts/Data/Interfaces/IPieChartDataSet.swift @@ -39,7 +39,7 @@ public protocol IPieChartDataSet: IChartDataSet var valueLineColor: NSUIColor? { get set } /// When valuePosition is OutsideSlice and enabled, line will have the same color as the slice - var matchValueLineColorToPieSlice: Bool { get set } + var valueLineAutoColor: Bool { get set } /// When valuePosition is OutsideSlice, indicates line width var valueLineWidth: CGFloat { get set } diff --git a/Source/Charts/Renderers/PieChartRenderer.swift b/Source/Charts/Renderers/PieChartRenderer.swift index 27f42810a3..2a6165c725 100644 --- a/Source/Charts/Renderers/PieChartRenderer.swift +++ b/Source/Charts/Renderers/PieChartRenderer.swift @@ -440,7 +440,7 @@ open class PieChartRenderer: DataRenderer if dataSet.valueLineColor != nil { - if dataSet.matchValueLineColorToPieSlice { + if dataSet.valueLineAutoColor { context.setStrokeColor(dataSet.color(atIndex: j).cgColor) } else { context.setStrokeColor(dataSet.valueLineColor!.cgColor) From 0edfdbb821c9846224c1cab15b960ff2aba8c90f Mon Sep 17 00:00:00 2001 From: Alexei Date: Sun, 27 Jan 2019 21:12:47 -0500 Subject: [PATCH 3/8] Changed variable name from valueLineAutoColor to useValueColorForLine --- .../Charts/Data/Implementations/Standard/PieChartDataSet.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift index 505f17dd85..205c2a8ff0 100644 --- a/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift @@ -85,7 +85,7 @@ open class PieChartDataSet: ChartDataSet, IPieChartDataSet open var valueLineColor: NSUIColor? = NSUIColor.black /// When valuePosition is OutsideSlice and enabled, line will have the same color as the slice - open var valueLineAutoColor: Bool = false + open var useValueColorForLine: Bool = false /// When valuePosition is OutsideSlice, indicates line width open var valueLineWidth: CGFloat = 1.0 From 59547e6c1adda3cecbb4a2cf861029828a94e850 Mon Sep 17 00:00:00 2001 From: Alexei Date: Mon, 28 Jan 2019 21:53:14 -0500 Subject: [PATCH 4/8] Changed variable name from valueLineAutoColor to useValueColorForLine --- Source/Charts/Data/Interfaces/IPieChartDataSet.swift | 2 +- Source/Charts/Renderers/PieChartRenderer.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Charts/Data/Interfaces/IPieChartDataSet.swift b/Source/Charts/Data/Interfaces/IPieChartDataSet.swift index 247a348851..b85249a292 100644 --- a/Source/Charts/Data/Interfaces/IPieChartDataSet.swift +++ b/Source/Charts/Data/Interfaces/IPieChartDataSet.swift @@ -39,7 +39,7 @@ public protocol IPieChartDataSet: IChartDataSet var valueLineColor: NSUIColor? { get set } /// When valuePosition is OutsideSlice and enabled, line will have the same color as the slice - var valueLineAutoColor: Bool { get set } + var useValueColorForLine: Bool { get set } /// When valuePosition is OutsideSlice, indicates line width var valueLineWidth: CGFloat { get set } diff --git a/Source/Charts/Renderers/PieChartRenderer.swift b/Source/Charts/Renderers/PieChartRenderer.swift index 2a6165c725..5c0b3bd93f 100644 --- a/Source/Charts/Renderers/PieChartRenderer.swift +++ b/Source/Charts/Renderers/PieChartRenderer.swift @@ -440,7 +440,7 @@ open class PieChartRenderer: DataRenderer if dataSet.valueLineColor != nil { - if dataSet.valueLineAutoColor { + if dataSet.useValueColorForLine { context.setStrokeColor(dataSet.color(atIndex: j).cgColor) } else { context.setStrokeColor(dataSet.valueLineColor!.cgColor) From eb42a9f0cf815faf25340ff76ba8c93a0ef06707 Mon Sep 17 00:00:00 2001 From: Xuan Date: Thu, 31 Jan 2019 09:43:24 +0800 Subject: [PATCH 5/8] fix code style fix code style --- Source/Charts/Renderers/PieChartRenderer.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/Charts/Renderers/PieChartRenderer.swift b/Source/Charts/Renderers/PieChartRenderer.swift index 5c0b3bd93f..7be31d390d 100644 --- a/Source/Charts/Renderers/PieChartRenderer.swift +++ b/Source/Charts/Renderers/PieChartRenderer.swift @@ -440,9 +440,12 @@ open class PieChartRenderer: DataRenderer if dataSet.valueLineColor != nil { - if dataSet.useValueColorForLine { + if dataSet.useValueColorForLine + { context.setStrokeColor(dataSet.color(atIndex: j).cgColor) - } else { + } + else + { context.setStrokeColor(dataSet.valueLineColor!.cgColor) } context.setLineWidth(dataSet.valueLineWidth) From 5eb909920a5177bed582d21ea748e8a54839d754 Mon Sep 17 00:00:00 2001 From: Alexei Date: Fri, 1 Feb 2019 16:04:27 -0500 Subject: [PATCH 6/8] Changed check for useValueColorForLine with suggested --- Source/Charts/Renderers/PieChartRenderer.swift | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Source/Charts/Renderers/PieChartRenderer.swift b/Source/Charts/Renderers/PieChartRenderer.swift index 7be31d390d..a1cc42f9b4 100644 --- a/Source/Charts/Renderers/PieChartRenderer.swift +++ b/Source/Charts/Renderers/PieChartRenderer.swift @@ -438,15 +438,13 @@ open class PieChartRenderer: DataRenderer labelPoint = CGPoint(x: pt2.x + 5, y: pt2.y - lineHeight) } - if dataSet.valueLineColor != nil - { - if dataSet.useValueColorForLine - { + do { + if dataSet.useValueColorForLine { context.setStrokeColor(dataSet.color(atIndex: j).cgColor) - } - else - { - context.setStrokeColor(dataSet.valueLineColor!.cgColor) + } else if let valueLineColor = dataSet.valueLineColor { + context.setStrokeColor(valueLineColor.cgColor) + } else { + return } context.setLineWidth(dataSet.valueLineWidth) @@ -456,7 +454,7 @@ open class PieChartRenderer: DataRenderer context.drawPath(using: CGPathDrawingMode.stroke) } - + if drawXOutside && drawYOutside { ChartUtils.drawText( From 9b3b066ad23c9acd8785d3964f0d3359d2e18621 Mon Sep 17 00:00:00 2001 From: Xuan Date: Mon, 4 Feb 2019 09:00:23 +0800 Subject: [PATCH 7/8] fix code style --- Source/Charts/Renderers/PieChartRenderer.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Source/Charts/Renderers/PieChartRenderer.swift b/Source/Charts/Renderers/PieChartRenderer.swift index a1cc42f9b4..704a0cb2b6 100644 --- a/Source/Charts/Renderers/PieChartRenderer.swift +++ b/Source/Charts/Renderers/PieChartRenderer.swift @@ -438,12 +438,18 @@ open class PieChartRenderer: DataRenderer labelPoint = CGPoint(x: pt2.x + 5, y: pt2.y - lineHeight) } - do { - if dataSet.useValueColorForLine { + do + { + if dataSet.useValueColorForLine + { context.setStrokeColor(dataSet.color(atIndex: j).cgColor) - } else if let valueLineColor = dataSet.valueLineColor { + } + else if let valueLineColor = dataSet.valueLineColor + { context.setStrokeColor(valueLineColor.cgColor) - } else { + } + else + { return } context.setLineWidth(dataSet.valueLineWidth) From e0f4fa6f79c495e0793d9549154c0008d836c2c7 Mon Sep 17 00:00:00 2001 From: Alexei Date: Tue, 12 Feb 2019 12:25:54 -0500 Subject: [PATCH 8/8] Added name DrawLine: to do{} section --- Source/Charts/Renderers/PieChartRenderer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Charts/Renderers/PieChartRenderer.swift b/Source/Charts/Renderers/PieChartRenderer.swift index 704a0cb2b6..e50106c351 100644 --- a/Source/Charts/Renderers/PieChartRenderer.swift +++ b/Source/Charts/Renderers/PieChartRenderer.swift @@ -438,7 +438,7 @@ open class PieChartRenderer: DataRenderer labelPoint = CGPoint(x: pt2.x + 5, y: pt2.y - lineHeight) } - do + DrawLine: do { if dataSet.useValueColorForLine {