Skip to content

Commit

Permalink
Update ChartColorTemplates.swift
Browse files Browse the repository at this point in the history
use fallbackColor for `colorFromString()`
  • Loading branch information
liuxuan30 authored Sep 25, 2020
1 parent ec48ae1 commit b4111fd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Source/Charts/Utils/ChartColorTemplates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ open class ChartColorTemplates: NSObject

let colorString = colorString.lowercased()

let fallbackColor = NSUIColor(red: CGFloat(argb[1]) / 255.0, green: CGFloat(argb[2]) / 255.0, blue: CGFloat(argb[3]) / 255.0, alpha: CGFloat(argb[0]) / 255.0)

if colorString.hasPrefix("#")
{
var argb: [UInt] = [255, 0, 0, 0]
Expand All @@ -94,7 +96,7 @@ open class ChartColorTemplates: NSObject
var index = colorString.startIndex
let endIndex = colorString.endIndex

guard [3, 6, 8].contains(length) else { return .black }
guard [3, 6, 8].contains(length) else { return fallbackColor }

var i = length == 8 ? 0 : 1
while index < endIndex
Expand All @@ -120,7 +122,7 @@ open class ChartColorTemplates: NSObject
i += 1
}

return NSUIColor(red: CGFloat(argb[1]) / 255.0, green: CGFloat(argb[2]) / 255.0, blue: CGFloat(argb[3]) / 255.0, alpha: CGFloat(argb[0]) / 255.0)
return fallbackColor
}
else if colorString.hasPrefix("rgba")
{
Expand Down

0 comments on commit b4111fd

Please sign in to comment.