-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Add rounded corners on the bar chart #1066 #1917
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -310,14 +310,36 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer | |
// Set the color for the currently drawn value. If the index is out of bounds, reuse colors. | ||
context.setFillColor(dataSet.color(atIndex: j).cgColor) | ||
} | ||
|
||
context.fill(barRect) | ||
|
||
if drawBorder | ||
|
||
if dataProvider.isDrawRoundedBarEnabled | ||
{ | ||
context.setStrokeColor(borderColor.cgColor) | ||
context.setLineWidth(borderWidth) | ||
context.stroke(barRect) | ||
let cornerRadius = CGSize(width: barRect.width / 2.0, height: barRect.width / 2.0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice if this was a property instead, so that we can specify a custom corner radius. |
||
#if os(OSX) | ||
let bezierPath = NSBezierPath(roundedRect: barRect, xRadius: cornerRadius.width, yRadius: cornerRadius.height) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just FYI, I came across API like |
||
context.addPath(bezierPath.cgPath) | ||
#else | ||
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: dataSet.barRoundingCorners, cornerRadii: cornerRadius) | ||
context.addPath(bezierPath.cgPath) | ||
#endif | ||
context.fillPath() | ||
|
||
if drawBorder | ||
{ | ||
bezierPath.lineWidth = borderWidth | ||
borderColor.setStroke() | ||
bezierPath.stroke() | ||
} | ||
} | ||
else | ||
{ | ||
context.fill(barRect) | ||
|
||
if drawBorder | ||
{ | ||
context.setStrokeColor(borderColor.cgColor) | ||
context.setLineWidth(borderWidth) | ||
context.stroke(barRect) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -574,7 +596,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer | |
let set = barData.getDataSetByIndex(high.dataSetIndex) as? IBarChartDataSet, | ||
set.isHighlightEnabled | ||
else { continue } | ||
|
||
if let e = set.entryForXValue(high.x, closestToY: high.y) as? BarChartDataEntry | ||
{ | ||
if !isInBoundsX(entry: e, dataSet: set) | ||
|
@@ -617,7 +639,22 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer | |
|
||
setHighlightDrawPos(highlight: high, barRect: barRect) | ||
|
||
context.fill(barRect) | ||
if dataProvider.isDrawRoundedBarEnabled | ||
{ | ||
let cornerRadius = CGSize(width: barRect.width / 2.0, height: barRect.width / 2.0) | ||
#if os(OSX) | ||
let bezierPath = NSBezierPath(roundedRect: barRect, xRadius: cornerRadius.width, yRadius: cornerRadius.height) | ||
context.addPath(bezierPath.cgPath) | ||
#else | ||
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: set.barRoundingCorners, cornerRadii: cornerRadius) | ||
context.addPath(bezierPath.cgPath) | ||
#endif | ||
context.fillPath() | ||
} | ||
else | ||
{ | ||
context.fill(barRect) | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ifnot
typo