Skip to content
Closed
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
3 changes: 3 additions & 0 deletions ChartsDemo-iOS/Swift/Demos/BarChartViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class BarChartViewController: DemoBaseViewController {

override func viewDidLoad() {
super.viewDidLoad()

chartView.barSettings = .init(rectCorner: [.topLeft, .topRight],
cornerRadii: CGSize(width: 4, height: 4))

// Do any additional setup after loading the view.
self.title = "Bar Chart"
Expand Down
27 changes: 27 additions & 0 deletions Source/Charts/Charts/BarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import Foundation
import CoreGraphics
import UIKit

/// Chart that draws bars.
open class BarChartView: BarLineChartViewBase, BarChartDataProvider
Expand All @@ -21,6 +22,8 @@ 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

private var _barSettings = BarSettings(rectCorner: .allCorners, cornerRadii: .zero)

internal override func initialize()
{
super.initialize()
Expand Down Expand Up @@ -183,4 +186,28 @@ open class BarChartView: BarLineChartViewBase, BarChartDataProvider

/// `true` if drawing shadows (maxvalue) for each bar is enabled, `false` ifnot
open var isDrawBarShadowEnabled: Bool { return drawBarShadowEnabled }

@objc open var barSettings: BarSettings
{
get { return _barSettings }
set
{
_barSettings = newValue
setNeedsDisplay()
}
}
}

extension BarChartView {

public class BarSettings: NSObject {
let rectCorner: UIRectCorner
let cornerRadii: CGSize

public init(rectCorner: UIRectCorner,
cornerRadii: CGSize) {
self.rectCorner = rectCorner
self.cornerRadii = cornerRadii
}
}
}
4 changes: 4 additions & 0 deletions Source/Charts/Charts/CombinedChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import CoreGraphics
/// This chart class allows the combination of lines, bars, scatter and candle data all displayed in one chart area.
open class CombinedChartView: BarLineChartViewBase, CombinedChartDataProvider
{
public var barSettings: BarChartView.BarSettings {
BarChartView.BarSettings(rectCorner: .allCorners, cornerRadii: CGSize(width: 0, height: 0))
}

/// the fill-formatter used for determining the position of the fill-line
internal var _fillFormatter: FillFormatter!

Expand Down
3 changes: 2 additions & 1 deletion Source/Charts/Interfaces/BarChartDataProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ public protocol BarChartDataProvider: BarLineScatterCandleBubbleChartDataProvide
var isDrawBarShadowEnabled: Bool { get }
var isDrawValueAboveBarEnabled: Bool { get }
var isHighlightFullBarEnabled: Bool { get }
}
var barSettings: BarChartView.BarSettings { get }
}
7 changes: 6 additions & 1 deletion Source/Charts/Renderers/BarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,12 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
context.setFillColor(dataSet.color(atIndex: j).cgColor)
}

context.fill(barRect)

let path = UIBezierPath(roundedRect: barRect,
byRoundingCorners: dataProvider.barSettings.rectCorner,
cornerRadii: dataProvider.barSettings.cornerRadii)
context.addPath(path.cgPath)
context.fillPath()

if drawBorder
{
Expand Down