Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple colors for valueline (Fixes #3480) #3709

Merged
merged 8 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 8 additions & 1 deletion Source/Charts/Renderers/PieChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,14 @@ open class PieChartRenderer: DataRenderer

if dataSet.valueLineColor != nil
{
context.setStrokeColor(dataSet.valueLineColor!.cgColor)
if dataSet.useValueColorForLine
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic seems weird to me. Why do we only get to here if dataSet.valueLinColor != nil?
I would think something more like:

DrawLine: do {
    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))
    context.addLine(to: CGPoint(x: pt1.x, y: pt1.y))
    context.addLine(to: CGPoint(x: pt2.x, y: pt2.y))

    context.drawPath(using: CGPathDrawingMode.stroke)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexeiGitH would take a look?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liuxuan30 Fixed as suggested

{
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))
Expand Down