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

柱状图新增圆角属性 #5117

Open
wants to merge 2 commits 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
2 changes: 2 additions & 0 deletions Source/Charts/Data/Implementations/ChartBaseDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ open class ChartBaseDataSet: NSObject, ChartDataSetProtocol, NSCopying
/// Colors are reused as soon as the number of Entries the DataSet represents is higher than the size of the colors array.
open var colors = [NSUIColor]()

open var cornerRadius: Double = 0

/// List representing all colors that are used for drawing the actual values for this DataSet
open var valueColors = [NSUIColor]()

Expand Down
2 changes: 2 additions & 0 deletions Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ public protocol ChartDataSetProtocol
/// Colors are reused as soon as the number of Entries the DataSet represents is higher than the size of the colors array.
var colors: [NSUIColor] { get }

var cornerRadius: Double { get }

/// - Returns: The color at the given index of the DataSet's color array.
/// This prevents out-of-bounds by performing a modulus on the color index, so colours will repeat themselves.
func color(atIndex: Int) -> NSUIColor
Expand Down
16 changes: 14 additions & 2 deletions Source/Charts/Renderers/BarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,13 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
context.setFillColor(dataSet.color(atIndex: j).cgColor)
}

context.fill(barRect)
if dataSet.cornerRadius > 0 {
let bezierPath = UIBezierPath(roundedRect: barRect,byRoundingCorners: [.topLeft, .topRight],cornerRadii:CGSize(width:dataSet.cornerRadius,height:dataSet.cornerRadius));
context.addPath(bezierPath.cgPath)
context.drawPath(using: .fill)
} else {
context.fill(barRect)
}

if drawBorder
{
Expand Down Expand Up @@ -744,7 +750,13 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer

setHighlightDrawPos(highlight: high, barRect: barRect)

context.fill(barRect)
if set.cornerRadius > 0 {
let bezierPath = UIBezierPath(roundedRect: barRect,byRoundingCorners: [.topLeft, .topRight],cornerRadii:CGSize(width:set.cornerRadius,height:set.cornerRadius));
context.addPath(bezierPath.cgPath)
context.drawPath(using: .fill)
} else {
context.fill(barRect)
}
}
}
}
Expand Down