Skip to content

Commit 2fedfc6

Browse files
Alexeijjatie
authored andcommitted
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
1 parent d73b552 commit 2fedfc6

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ open class PieChartDataSet: ChartDataSet, IPieChartDataSet
8484
/// When valuePosition is OutsideSlice, indicates line color
8585
open var valueLineColor: NSUIColor? = NSUIColor.black
8686

87+
/// When valuePosition is OutsideSlice and enabled, line will have the same color as the slice
88+
open var useValueColorForLine: Bool = false
89+
8790
/// When valuePosition is OutsideSlice, indicates line width
8891
open var valueLineWidth: CGFloat = 1.0
8992

Source/Charts/Data/Interfaces/IPieChartDataSet.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public protocol IPieChartDataSet: IChartDataSet
3838
/// When valuePosition is OutsideSlice, indicates line color
3939
var valueLineColor: NSUIColor? { get set }
4040

41+
/// When valuePosition is OutsideSlice and enabled, line will have the same color as the slice
42+
var useValueColorForLine: Bool { get set }
43+
4144
/// When valuePosition is OutsideSlice, indicates line width
4245
var valueLineWidth: CGFloat { get set }
4346

Source/Charts/Renderers/PieChartRenderer.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,20 @@ open class PieChartRenderer: DataRenderer
438438
labelPoint = CGPoint(x: pt2.x + 5, y: pt2.y - lineHeight)
439439
}
440440

441-
if dataSet.valueLineColor != nil
441+
DrawLine: do
442442
{
443-
context.setStrokeColor(dataSet.valueLineColor!.cgColor)
443+
if dataSet.useValueColorForLine
444+
{
445+
context.setStrokeColor(dataSet.color(atIndex: j).cgColor)
446+
}
447+
else if let valueLineColor = dataSet.valueLineColor
448+
{
449+
context.setStrokeColor(valueLineColor.cgColor)
450+
}
451+
else
452+
{
453+
return
454+
}
444455
context.setLineWidth(dataSet.valueLineWidth)
445456

446457
context.move(to: CGPoint(x: pt0.x, y: pt0.y))
@@ -449,7 +460,7 @@ open class PieChartRenderer: DataRenderer
449460

450461
context.drawPath(using: CGPathDrawingMode.stroke)
451462
}
452-
463+
453464
if drawXOutside && drawYOutside
454465
{
455466
ChartUtils.drawText(

0 commit comments

Comments
 (0)