Skip to content

Commit

Permalink
Multiple colors for valueline (Fixes #3480) (#3709)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Alexei authored and jjatie committed Feb 12, 2019
1 parent d73b552 commit 2fedfc6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 useValueColorForLine: Bool = false

/// When valuePosition is OutsideSlice, indicates line width
open var valueLineWidth: CGFloat = 1.0

Expand Down
3 changes: 3 additions & 0 deletions Source/Charts/Data/Interfaces/IPieChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 useValueColorForLine: Bool { get set }

/// When valuePosition is OutsideSlice, indicates line width
var valueLineWidth: CGFloat { get set }

Expand Down
17 changes: 14 additions & 3 deletions Source/Charts/Renderers/PieChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,20 @@ open class PieChartRenderer: DataRenderer
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.move(to: CGPoint(x: pt0.x, y: pt0.y))
Expand All @@ -449,7 +460,7 @@ open class PieChartRenderer: DataRenderer

context.drawPath(using: CGPathDrawingMode.stroke)
}

if drawXOutside && drawYOutside
{
ChartUtils.drawText(
Expand Down

0 comments on commit 2fedfc6

Please sign in to comment.