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

Support for rounded edges for pie chart slices #5114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ open class PieChartDataSet: ChartDataSet, PieChartDataSetProtocol
/// the color for the highlighted sector
open var highlightColor: NSUIColor? = nil

/// the width for slice stroke
open var sliceStrokeWidth: CGFloat = 0.0

/// the color for the slice stroke pattern
open var sliceLineDashPattern: [NSNumber] = [0, 0]

/// the color to fill slice
open var sliceFillColor: CGColor = UIColor.clear.cgColor

/// the line join style for the slice
open var sliceStrokeLineJoinStyle: CAShapeLayerLineJoin = .miter

// MARK: - NSCopying

open override func copy(with zone: NSZone? = nil) -> Any
Expand Down
12 changes: 12 additions & 0 deletions Source/Charts/Data/Interfaces/PieChartDataSetProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,17 @@ public protocol PieChartDataSetProtocol: ChartDataSetProtocol

/// get/sets the color for the highlighted sector
var highlightColor: NSUIColor? { get set }

/// the width for slice stroke
var sliceStrokeWidth: CGFloat { get set }

/// the color for the slice stroke pattern
var sliceLineDashPattern: [NSNumber] { get set }

/// the color to fill slice
var sliceFillColor: CGColor { get set }

/// the line join style for the slice
var sliceStrokeLineJoinStyle: CAShapeLayerLineJoin { get set }

}
10 changes: 10 additions & 0 deletions Source/Charts/Renderers/PieChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ open class PieChartRenderer: NSObject, DataRenderer
context.addPath(path)
context.fillPath(using: .evenOdd)

// to customize stroke edges for the slices
let layer = CAShapeLayer()
layer.lineWidth = dataSet.sliceStrokeWidth
layer.lineJoin = dataSet.sliceStrokeLineJoinStyle
layer.lineDashPattern = dataSet.sliceLineDashPattern
layer.fillColor = dataSet.sliceFillColor
layer.strokeColor = dataSet.color(atIndex: j).cgColor
layer.path = path
layer.render(in: context)

let axElement = createAccessibleElement(withIndex: j,
container: chart,
dataSet: dataSet)
Expand Down