From 849d221320bcae7c4719f21e26bdee3e13c5401a Mon Sep 17 00:00:00 2001 From: Tiny Date: Tue, 24 Oct 2023 14:21:51 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9F=B1=E7=8A=B6=E5=9B=BE=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=9C=86=E8=A7=92=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Data/Implementations/ChartBaseDataSet.swift | 2 ++ .../Data/Interfaces/ChartDataSetProtocol.swift | 2 ++ Source/Charts/Renderers/BarChartRenderer.swift | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Source/Charts/Data/Implementations/ChartBaseDataSet.swift b/Source/Charts/Data/Implementations/ChartBaseDataSet.swift index c2915abb84..fdf8fc4044 100644 --- a/Source/Charts/Data/Implementations/ChartBaseDataSet.swift +++ b/Source/Charts/Data/Implementations/ChartBaseDataSet.swift @@ -189,6 +189,8 @@ open class ChartBaseDataSet: NSObject, ChartDataSetProtocol, NSCopying /// Colors are reused as soon as the number of Entries the DataSet represents is higher than the size of the colors array. open var colors = [NSUIColor]() + open var cornerRaidus: Double = 0 + /// List representing all colors that are used for drawing the actual values for this DataSet open var valueColors = [NSUIColor]() diff --git a/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift b/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift index 9cf80d3368..d2c2aaca25 100644 --- a/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift +++ b/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift @@ -179,6 +179,8 @@ public protocol ChartDataSetProtocol /// Colors are reused as soon as the number of Entries the DataSet represents is higher than the size of the colors array. var colors: [NSUIColor] { get } + var cornerRaidus: Double { get } + /// - Returns: The color at the given index of the DataSet's color array. /// This prevents out-of-bounds by performing a modulus on the color index, so colours will repeat themselves. func color(atIndex: Int) -> NSUIColor diff --git a/Source/Charts/Renderers/BarChartRenderer.swift b/Source/Charts/Renderers/BarChartRenderer.swift index 2aa69a828f..37276e0be0 100644 --- a/Source/Charts/Renderers/BarChartRenderer.swift +++ b/Source/Charts/Renderers/BarChartRenderer.swift @@ -379,7 +379,13 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer context.setFillColor(dataSet.color(atIndex: j).cgColor) } - context.fill(barRect) + if dataSet.cornerRaidus > 0 { + let bezierPath = UIBezierPath(roundedRect: barRect,byRoundingCorners: [.topLeft, .topRight],cornerRadii:CGSize(width:dataSet.cornerRaidus,height:dataSet.cornerRaidus)); + context.addPath(bezierPath.cgPath) + context.drawPath(using: .fill) + } else { + context.fill(barRect) + } if drawBorder { @@ -744,7 +750,13 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer setHighlightDrawPos(highlight: high, barRect: barRect) - context.fill(barRect) + if set.cornerRaidus > 0 { + let bezierPath = UIBezierPath(roundedRect: barRect,byRoundingCorners: [.topLeft, .topRight],cornerRadii:CGSize(width:set.cornerRaidus,height:set.cornerRaidus)); + context.addPath(bezierPath.cgPath) + context.drawPath(using: .fill) + } else { + context.fill(barRect) + } } } } From 4d4955ef251a8b309b04b712ccf2792ce4cbd379 Mon Sep 17 00:00:00 2001 From: Tiny Date: Tue, 24 Oct 2023 15:30:14 +0800 Subject: [PATCH 2/2] Add cornerRadius property for barchartView. --- Source/Charts/Data/Implementations/ChartBaseDataSet.swift | 2 +- Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift | 2 +- Source/Charts/Renderers/BarChartRenderer.swift | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Charts/Data/Implementations/ChartBaseDataSet.swift b/Source/Charts/Data/Implementations/ChartBaseDataSet.swift index fdf8fc4044..7ad28bf691 100644 --- a/Source/Charts/Data/Implementations/ChartBaseDataSet.swift +++ b/Source/Charts/Data/Implementations/ChartBaseDataSet.swift @@ -189,7 +189,7 @@ open class ChartBaseDataSet: NSObject, ChartDataSetProtocol, NSCopying /// Colors are reused as soon as the number of Entries the DataSet represents is higher than the size of the colors array. open var colors = [NSUIColor]() - open var cornerRaidus: Double = 0 + open var cornerRadius: Double = 0 /// List representing all colors that are used for drawing the actual values for this DataSet open var valueColors = [NSUIColor]() diff --git a/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift b/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift index d2c2aaca25..82e0ddeac6 100644 --- a/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift +++ b/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift @@ -179,7 +179,7 @@ public protocol ChartDataSetProtocol /// Colors are reused as soon as the number of Entries the DataSet represents is higher than the size of the colors array. var colors: [NSUIColor] { get } - var cornerRaidus: Double { get } + var cornerRadius: Double { get } /// - Returns: The color at the given index of the DataSet's color array. /// This prevents out-of-bounds by performing a modulus on the color index, so colours will repeat themselves. diff --git a/Source/Charts/Renderers/BarChartRenderer.swift b/Source/Charts/Renderers/BarChartRenderer.swift index 37276e0be0..acb1f11222 100644 --- a/Source/Charts/Renderers/BarChartRenderer.swift +++ b/Source/Charts/Renderers/BarChartRenderer.swift @@ -379,8 +379,8 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer context.setFillColor(dataSet.color(atIndex: j).cgColor) } - if dataSet.cornerRaidus > 0 { - let bezierPath = UIBezierPath(roundedRect: barRect,byRoundingCorners: [.topLeft, .topRight],cornerRadii:CGSize(width:dataSet.cornerRaidus,height:dataSet.cornerRaidus)); + if dataSet.cornerRadius > 0 { + let bezierPath = UIBezierPath(roundedRect: barRect,byRoundingCorners: [.topLeft, .topRight],cornerRadii:CGSize(width:dataSet.cornerRadius,height:dataSet.cornerRadius)); context.addPath(bezierPath.cgPath) context.drawPath(using: .fill) } else { @@ -750,8 +750,8 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer setHighlightDrawPos(highlight: high, barRect: barRect) - if set.cornerRaidus > 0 { - let bezierPath = UIBezierPath(roundedRect: barRect,byRoundingCorners: [.topLeft, .topRight],cornerRadii:CGSize(width:set.cornerRaidus,height:set.cornerRaidus)); + if set.cornerRadius > 0 { + let bezierPath = UIBezierPath(roundedRect: barRect,byRoundingCorners: [.topLeft, .topRight],cornerRadii:CGSize(width:set.cornerRadius,height:set.cornerRadius)); context.addPath(bezierPath.cgPath) context.drawPath(using: .fill) } else {