Skip to content

Commit

Permalink
⚡️:: Bar Radius Custom
Browse files Browse the repository at this point in the history
  • Loading branch information
rlarldud1234 committed Feb 4, 2022
1 parent 0b208ad commit a34eaec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions Source/Charts/Renderers/BarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
internal lazy var accessibilityOrderedElements: [[NSUIAccessibilityElement]] = accessibilityCreateEmptyOrderedElements()

private typealias Buffer = [CGRect]

internal let barCornerRadius = CGFloat(5.0)

@objc open weak var dataProvider: BarChartDataProvider?

Expand Down Expand Up @@ -323,7 +325,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
guard let e = dataSet.entryForIndex(i) as? BarChartDataEntry else { continue }

x = e.x

_barShadowRectBuffer.origin.x = CGFloat(x - barWidthHalf)
_barShadowRectBuffer.size.width = CGFloat(barWidth)

Expand All @@ -337,6 +339,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
_barShadowRectBuffer.size.height = viewPortHandler.contentHeight

context.setFillColor(dataSet.barShadowColor.cgColor)

context.fill(_barShadowRectBuffer)
}
}
Expand All @@ -351,7 +354,10 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
guard viewPortHandler.isInBoundsRight(barRect.origin.x) else { break }

context.setFillColor(dataSet.barShadowColor.cgColor)
context.fill(barRect)

let bezierPath = UIBezierPath(roundedRect: barRect, cornerRadius: barCornerRadius)
context.addPath(bezierPath.cgPath)
context.drawPath(using: .fill)
}
}

Expand All @@ -361,7 +367,6 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
{
context.setFillColor(dataSet.color(atIndex: 0).cgColor)
}

// In case the chart is stacked, we need to accomodate individual bars within accessibilityOrdereredElements
let isStacked = dataSet.isStacked
let stackSize = isStacked ? dataSet.stackSize : 1
Expand All @@ -379,7 +384,9 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
context.setFillColor(dataSet.color(atIndex: j).cgColor)
}

context.fill(barRect)
let bezierPath = UIBezierPath(roundedRect: barRect, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 10, height: 10))
context.addPath(bezierPath.cgPath)
context.drawPath(using: .fill)

if drawBorder
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Renderers/PieChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ open class PieChartRenderer: NSObject, DataRenderer

return element
}

public func createAccessibleHeader(usingChart chart: ChartViewBase, andData data: ChartData, withDefaultDescription defaultDescription: String) -> NSUIAccessibilityElement {
return AccessibleHeader.create(usingChart: chart, andData: data, withDefaultDescription: defaultDescription)
}
Expand Down

0 comments on commit a34eaec

Please sign in to comment.