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 Mar 26, 2019
1 parent 5aadccf commit 4ed333a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ open class BarChartDataSet: BarLineScatterCandleBubbleChartDataSet, BarChartData
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/BarChartDataSetProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public protocol BarChartDataSetProtocol: BarLineScatterCandleBubbleChartDataSetP
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 @@ -323,8 +323,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.isIntinite ?
CGPoint(x: boundingBox.minX, y: boundingBox.minY) :
dataSet.gradientEnd.applying(matrix)

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

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

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 isIntinite: 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 4ed333a

Please # to comment.