Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add corner radius in Barchart #5185

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DGCharts.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Pod::Spec.new do |s|
s.ios.deployment_target = "12.0"
s.tvos.deployment_target = "12.0"
s.osx.deployment_target = "10.13"
s.source = { :git => "https://github.com/danielgindi/Charts.git", :tag => "#{s.version}" }
s.source = { :git => "https://github.com/Khanak1521/Charts.git", :tag => "#{s.version}" }
s.default_subspec = "Core"
s.swift_version = '5.7'
s.cocoapods_version = '>= 1.5.0'
Expand Down
7 changes: 5 additions & 2 deletions Source/Charts/Charts/BarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ open class BarChartView: BarLineChartViewBase, BarChartDataProvider

/// if set to true, a grey area is drawn behind each bar that indicates the maximum value
private var _drawBarShadowEnabled = false
public var barChartCornerRedius : Int = 0

internal override func initialize()
{
super.initialize()

renderer = BarChartRenderer(dataProvider: self, animator: chartAnimator, viewPortHandler: viewPortHandler)
}

public func initializeChart() {
renderer = BarChartRenderer(dataProvider: self, animator: chartAnimator, viewPortHandler: viewPortHandler,barChartCornerRedius: self.barChartCornerRedius)

self.highlighter = BarHighlighter(chart: self)

Expand Down
10 changes: 8 additions & 2 deletions Source/Charts/Renderers/BarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer

private typealias Buffer = [CGRect]

public var barChartCornerRedius : Int = 0

@objc open weak var dataProvider: BarChartDataProvider?

@objc public init(dataProvider: BarChartDataProvider, animator: Animator, viewPortHandler: ViewPortHandler)
@objc public init(dataProvider: BarChartDataProvider, animator: Animator, viewPortHandler: ViewPortHandler, barChartCornerRedius : Int = 0)
{
super.init(animator: animator, viewPortHandler: viewPortHandler)

self.dataProvider = dataProvider
self.barChartCornerRedius = barChartCornerRedius
}

// [CGRect] per dataset
Expand Down Expand Up @@ -379,7 +382,10 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
context.setFillColor(dataSet.color(atIndex: j).cgColor)
}

context.fill(barRect)
let rectCorners: UIRectCorner = [.topLeft, .topRight]
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: rectCorners, cornerRadii: CGSize(width: self.barChartCornerRedius, height: self.barChartCornerRedius)) //(roundedRect: barRect, byRoundingCorners: rectCorners, cornerRadi: 5)
context.addPath(bezierPath.cgPath)
context.drawPath(using: .fill)

if drawBorder
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Renderers/HorizontalBarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ open class HorizontalBarChartRenderer: BarChartRenderer
var rects = [CGRect]()
}

public override init(dataProvider: BarChartDataProvider, animator: Animator, viewPortHandler: ViewPortHandler)
public override init(dataProvider: BarChartDataProvider, animator: Animator, viewPortHandler: ViewPortHandler, barChartCornerRedius : Int = 0)
{
super.init(dataProvider: dataProvider, animator: animator, viewPortHandler: viewPortHandler)
}
Expand Down