Skip to content

Commit

Permalink
Add inverted corners for negative values
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg committed Mar 27, 2024
1 parent c14ed45 commit 2047fe6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
18 changes: 15 additions & 3 deletions Source/Charts/Renderers/BarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,11 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer

context.setFillColor(dataSet.barShadowColor.cgColor)

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

let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: dataSet.roundedCorners,
var roundedCorners = dataSet.roundedCorners
if barRect.minY < 0 {
roundedCorners.update(with: [.bottomLeft, .bottomRight, .topLeft, .topRight])
}
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: roundedCorners,
cornerRadii: .init(width: dataSet.cornerRadius, height: dataSet.cornerRadius))
context.addPath(bezierPath.cgPath)
context.drawPath(using: .fill)
Expand Down Expand Up @@ -751,7 +759,11 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer

setHighlightDrawPos(highlight: high, barRect: barRect)

let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: set.roundedCorners,
var roundedCorners = set.roundedCorners
if barRect.minY < 0 {
roundedCorners.update(with: [.bottomLeft, .bottomRight, .topLeft, .topRight])
}
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: roundedCorners,
cornerRadii: .init(width: set.cornerRadius, height: set.cornerRadius))
context.addPath(bezierPath.cgPath)
context.drawPath(using: .fill)
Expand Down
12 changes: 10 additions & 2 deletions Source/Charts/Renderers/HorizontalBarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ open class HorizontalBarChartRenderer: BarChartRenderer

context.setFillColor(dataSet.barShadowColor.cgColor)

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

let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: dataSet.roundedCorners,
var roundedCorners = dataSet.roundedCorners
if barRect.minX < 0 {
roundedCorners.update(with: [.bottomLeft, .bottomRight, .topLeft, .topRight])
}
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: roundedCorners,
cornerRadii: .init(width: dataSet.cornerRadius, height: dataSet.cornerRadius))
context.addPath(bezierPath.cgPath)
context.drawPath(using: .fill)
Expand Down

0 comments on commit 2047fe6

Please sign in to comment.