Skip to content

Commit

Permalink
Add gradient start and gradient end to bar chart renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
larryonoff committed Jul 8, 2020
1 parent 6710367 commit 78706eb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ open class BarChartDataSet: BarLineScatterCandleBubbleChartDataSet, IBarChartDat
open var drawBarGradientEnabled = false

open var gradientPositions: [CGFloat]?


open var gradientStart: CGPoint = .infinite

open var gradientEnd: CGPoint = .infinite

/// the color used for drawing the bar-shadows. The bar shadows is a surface behind the bar that indicates the maximum value
open var barShadowColor = NSUIColor(red: 215.0/255.0, green: 215.0/255.0, blue: 215.0/255.0, alpha: 1.0)

Expand Down
4 changes: 4 additions & 0 deletions Source/Charts/Data/Interfaces/IBarChartDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public protocol IBarChartDataSet: IBarLineScatterCandleBubbleChartDataSet
var drawBarGradientEnabled: Bool { get set }

var gradientPositions: [CGFloat]? { get set }

var gradientStart: CGPoint { get set }

var gradientEnd: CGPoint { get set }
}
10 changes: 8 additions & 2 deletions Source/Charts/Renderers/BarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,14 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer

let drawBorder = dataSet.barBorderWidth > 0

let gradientStart = CGPoint(x: boundingBox.minX, y: boundingBox.minY)
let gradientEnd = CGPoint(x: boundingBox.minX, y: boundingBox.maxY)
let gradientStart = dataSet.gradientEnd.isInfinite ?
CGPoint(x: boundingBox.minX, y: boundingBox.minY) :
dataSet.gradientEnd.applying(matrix)

let gradientEnd = dataSet.gradientStart.isInfinite ?
CGPoint(x: boundingBox.minX, y: boundingBox.maxY) :
dataSet.gradientStart.applying(matrix)

var gradientColorComponents: [CGFloat] = []
var gradientLocations: [CGFloat] = []

Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Renderers/LineChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ open class LineChartRenderer: LineRadarRenderer

return filled
}

open override func drawValues(context: CGContext)
{
guard
Expand Down
8 changes: 8 additions & 0 deletions Source/Charts/Utils/ChartUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ extension Double

extension CGPoint
{
static var infinite: CGPoint {
return CGPoint(x: CGFloat.infinity, y: CGFloat.infinity)
}

var isInfinite: Bool {
return x.isInfinite || y.isInfinite
}

/// Calculates the position around a center point, depending on the distance from the center, and the angle of the position around the center.
func moving(distance: CGFloat, atAngle angle: CGFloat) -> CGPoint
{
Expand Down

0 comments on commit 78706eb

Please sign in to comment.