Skip to content

Commit 2047fe6

Browse files
author
Oleg
committed
Add inverted corners for negative values
1 parent c14ed45 commit 2047fe6

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

Source/Charts/Renderers/BarChartRenderer.swift

+15-3
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,11 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
352352

353353
context.setFillColor(dataSet.barShadowColor.cgColor)
354354

355-
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: dataSet.roundedCorners,
355+
var roundedCorners = dataSet.roundedCorners
356+
if barRect.minY < 0 {
357+
roundedCorners.update(with: [.bottomLeft, .bottomRight, .topLeft, .topRight])
358+
}
359+
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: roundedCorners,
356360
cornerRadii: .init(width: dataSet.cornerRadius, height: dataSet.cornerRadius))
357361
context.addPath(bezierPath.cgPath)
358362
context.drawPath(using: .fill)
@@ -383,7 +387,11 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
383387
context.setFillColor(dataSet.color(atIndex: j).cgColor)
384388
}
385389

386-
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: dataSet.roundedCorners,
390+
var roundedCorners = dataSet.roundedCorners
391+
if barRect.minY < 0 {
392+
roundedCorners.update(with: [.bottomLeft, .bottomRight, .topLeft, .topRight])
393+
}
394+
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: roundedCorners,
387395
cornerRadii: .init(width: dataSet.cornerRadius, height: dataSet.cornerRadius))
388396
context.addPath(bezierPath.cgPath)
389397
context.drawPath(using: .fill)
@@ -751,7 +759,11 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
751759

752760
setHighlightDrawPos(highlight: high, barRect: barRect)
753761

754-
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: set.roundedCorners,
762+
var roundedCorners = set.roundedCorners
763+
if barRect.minY < 0 {
764+
roundedCorners.update(with: [.bottomLeft, .bottomRight, .topLeft, .topRight])
765+
}
766+
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: roundedCorners,
755767
cornerRadii: .init(width: set.cornerRadius, height: set.cornerRadius))
756768
context.addPath(bezierPath.cgPath)
757769
context.drawPath(using: .fill)

Source/Charts/Renderers/HorizontalBarChartRenderer.swift

+10-2
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@ open class HorizontalBarChartRenderer: BarChartRenderer
229229

230230
context.setFillColor(dataSet.barShadowColor.cgColor)
231231

232-
let bezierPath = UIBezierPath(roundedRect: _barShadowRectBuffer, byRoundingCorners: dataSet.roundedCorners,
232+
var roundedCorners = dataSet.roundedCorners
233+
if _barShadowRectBuffer.minX < 0 {
234+
roundedCorners.update(with: [.bottomLeft, .bottomRight, .topLeft, .topRight])
235+
}
236+
let bezierPath = UIBezierPath(roundedRect: _barShadowRectBuffer, byRoundingCorners: roundedCorners,
233237
cornerRadii: .init(width: dataSet.cornerRadius, height: dataSet.cornerRadius))
234238
context.addPath(bezierPath.cgPath)
235239
context.drawPath(using: .fill)
@@ -269,7 +273,11 @@ open class HorizontalBarChartRenderer: BarChartRenderer
269273
context.setFillColor(dataSet.color(atIndex: j).cgColor)
270274
}
271275

272-
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: dataSet.roundedCorners,
276+
var roundedCorners = dataSet.roundedCorners
277+
if barRect.minX < 0 {
278+
roundedCorners.update(with: [.bottomLeft, .bottomRight, .topLeft, .topRight])
279+
}
280+
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: roundedCorners,
273281
cornerRadii: .init(width: dataSet.cornerRadius, height: dataSet.cornerRadius))
274282
context.addPath(bezierPath.cgPath)
275283
context.drawPath(using: .fill)

0 commit comments

Comments
 (0)