Skip to content

Commit a29a1a1

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

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

Source/Charts/Renderers/BarChartRenderer.swift

+18-3
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,13 @@ 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 let i = buffer.firstIndex(of: barRect),
357+
let entry = dataSet.entryForIndex(i),
358+
entry.y < 0 {
359+
roundedCorners.update(with: [.bottomLeft, .bottomRight, .topLeft, .topRight])
360+
}
361+
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: roundedCorners,
356362
cornerRadii: .init(width: dataSet.cornerRadius, height: dataSet.cornerRadius))
357363
context.addPath(bezierPath.cgPath)
358364
context.drawPath(using: .fill)
@@ -383,7 +389,12 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
383389
context.setFillColor(dataSet.color(atIndex: j).cgColor)
384390
}
385391

386-
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: dataSet.roundedCorners,
392+
var roundedCorners = dataSet.roundedCorners
393+
if let entry = dataSet.entryForIndex(j),
394+
entry.y < 0 {
395+
roundedCorners.update(with: [.bottomLeft, .bottomRight, .topLeft, .topRight])
396+
}
397+
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: roundedCorners,
387398
cornerRadii: .init(width: dataSet.cornerRadius, height: dataSet.cornerRadius))
388399
context.addPath(bezierPath.cgPath)
389400
context.drawPath(using: .fill)
@@ -751,7 +762,11 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
751762

752763
setHighlightDrawPos(highlight: high, barRect: barRect)
753764

754-
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: set.roundedCorners,
765+
var roundedCorners = set.roundedCorners
766+
if e.y < 0 {
767+
roundedCorners.update(with: [.bottomLeft, .bottomRight, .topLeft, .topRight])
768+
}
769+
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: roundedCorners,
755770
cornerRadii: .init(width: set.cornerRadius, height: set.cornerRadius))
756771
context.addPath(bezierPath.cgPath)
757772
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)