From 2047fe6cb952c4607b48279979c349659be81295 Mon Sep 17 00:00:00 2001 From: Oleg <> Date: Wed, 27 Mar 2024 05:01:16 +0300 Subject: [PATCH] Add inverted corners for negative values --- Source/Charts/Renderers/BarChartRenderer.swift | 18 +++++++++++++++--- .../Renderers/HorizontalBarChartRenderer.swift | 12 ++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Source/Charts/Renderers/BarChartRenderer.swift b/Source/Charts/Renderers/BarChartRenderer.swift index eb2eebe819..0b9fe6d00a 100644 --- a/Source/Charts/Renderers/BarChartRenderer.swift +++ b/Source/Charts/Renderers/BarChartRenderer.swift @@ -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) @@ -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) @@ -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) diff --git a/Source/Charts/Renderers/HorizontalBarChartRenderer.swift b/Source/Charts/Renderers/HorizontalBarChartRenderer.swift index 588f45bc95..9fd9fbc284 100644 --- a/Source/Charts/Renderers/HorizontalBarChartRenderer.swift +++ b/Source/Charts/Renderers/HorizontalBarChartRenderer.swift @@ -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) @@ -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)