Explorar el Código

Multiple colors for valueline (Fixes #3480) (#3709)

* 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.

* Changed variable name from matchValueLineColorToPieSlice to valueLineAutoColor

* Changed variable name from valueLineAutoColor to useValueColorForLine

* Changed variable name from valueLineAutoColor to useValueColorForLine

* fix code style

fix code style

* Changed check for useValueColorForLine with suggested

* fix code style

* Added name DrawLine: to do{} section
Alexei hace 6 años
padre
commit
2fedfc6e50

+ 3 - 0
Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift

@@ -84,6 +84,9 @@ open class PieChartDataSet: ChartDataSet, IPieChartDataSet
     /// When valuePosition is OutsideSlice, indicates line color
     /// When valuePosition is OutsideSlice, indicates line color
     open var valueLineColor: NSUIColor? = NSUIColor.black
     open var valueLineColor: NSUIColor? = NSUIColor.black
 
 
+    /// When valuePosition is OutsideSlice and enabled, line will have the same color as the slice
+    open var useValueColorForLine: Bool = false
+
     /// When valuePosition is OutsideSlice, indicates line width
     /// When valuePosition is OutsideSlice, indicates line width
     open var valueLineWidth: CGFloat = 1.0
     open var valueLineWidth: CGFloat = 1.0
 
 

+ 3 - 0
Source/Charts/Data/Interfaces/IPieChartDataSet.swift

@@ -38,6 +38,9 @@ public protocol IPieChartDataSet: IChartDataSet
     /// When valuePosition is OutsideSlice, indicates line color
     /// When valuePosition is OutsideSlice, indicates line color
     var valueLineColor: NSUIColor? { get set }
     var valueLineColor: NSUIColor? { get set }
 
 
+    /// When valuePosition is OutsideSlice and enabled, line will have the same color as the slice
+    var useValueColorForLine: Bool { get set }
+
     /// When valuePosition is OutsideSlice, indicates line width
     /// When valuePosition is OutsideSlice, indicates line width
     var valueLineWidth: CGFloat { get set }
     var valueLineWidth: CGFloat { get set }
 
 

+ 14 - 3
Source/Charts/Renderers/PieChartRenderer.swift

@@ -438,9 +438,20 @@ open class PieChartRenderer: DataRenderer
                         labelPoint = CGPoint(x: pt2.x + 5, y: pt2.y - lineHeight)
                         labelPoint = CGPoint(x: pt2.x + 5, y: pt2.y - lineHeight)
                     }
                     }
 
 
-                    if dataSet.valueLineColor != nil
+                    DrawLine: do
                     {
                     {
-                        context.setStrokeColor(dataSet.valueLineColor!.cgColor)
+                        if dataSet.useValueColorForLine
+                        {
+                            context.setStrokeColor(dataSet.color(atIndex: j).cgColor)
+                        }
+                        else if let valueLineColor = dataSet.valueLineColor
+                        {
+                            context.setStrokeColor(valueLineColor.cgColor)
+                        }
+                        else
+                        {
+                            return
+                        }
                         context.setLineWidth(dataSet.valueLineWidth)
                         context.setLineWidth(dataSet.valueLineWidth)
 
 
                         context.move(to: CGPoint(x: pt0.x, y: pt0.y))
                         context.move(to: CGPoint(x: pt0.x, y: pt0.y))
@@ -449,7 +460,7 @@ open class PieChartRenderer: DataRenderer
 
 
                         context.drawPath(using: CGPathDrawingMode.stroke)
                         context.drawPath(using: CGPathDrawingMode.stroke)
                     }
                     }
-
+                    
                     if drawXOutside && drawYOutside
                     if drawXOutside && drawYOutside
                     {
                     {
                         ChartUtils.drawText(
                         ChartUtils.drawText(