Skip to content

Commit

Permalink
fix: Show alert limits in graphs (#2015)
Browse files Browse the repository at this point in the history
Handle case of both upper and lower alert value being less than min visible Y value.
  • Loading branch information
priyonto authored May 9, 2024
1 parent 37ef7cf commit 4c838e4
Showing 1 changed file with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1122,15 +1122,15 @@ extension TagChartsViewController {
)
}

// swiftlint:disable:next function_body_length
// swiftlint:disable:next function_body_length cyclomatic_complexity
private func calculateAlertFillIfNeeded(for view: TagChartsView) {
if let data = view.data,
let dataSet = data.dataSets.first as? LineChartDataSet {

let maxY = view.highestVisibleY
let minY = view.lowestVisibleY

let color = RuuviColor.graphFillColor.color
let colorRegular = RuuviColor.graphFillColor.color
let colorAlert = RuuviColor.graphAlertColor.color

if let upperAlertValue = view.upperAlertValue, let lowerAlertValue = view.lowerAlertValue {
Expand All @@ -1142,8 +1142,25 @@ extension TagChartsViewController {
1,
]
gradientColors = [
color.cgColor,
color.cgColor,
colorRegular.cgColor,
colorRegular.cgColor,
] as CFArray
if let gradient = CGGradient(
colorsSpace: CGColorSpaceCreateDeviceRGB(),
colors: gradientColors,
locations: colorLocations
) {
dataSet.drawFilledEnabled = true
dataSet.fill = LinearGradientFill(gradient: gradient, angle: 90)
}
} else if minY >= lowerAlertValue && minY >= upperAlertValue {
colorLocations = [
0,
1,
]
gradientColors = [
colorAlert.cgColor,
colorAlert.cgColor,
] as CFArray
if let gradient = CGGradient(
colorsSpace: CGColorSpaceCreateDeviceRGB(),
Expand All @@ -1162,8 +1179,8 @@ extension TagChartsViewController {
1,
]
gradientColors = [
color.cgColor,
color.cgColor,
colorRegular.cgColor,
colorRegular.cgColor,
colorAlert.cgColor,
colorAlert.cgColor,
] as CFArray
Expand All @@ -1186,8 +1203,8 @@ extension TagChartsViewController {
gradientColors = [
colorAlert.cgColor,
colorAlert.cgColor,
color.cgColor,
color.cgColor,
colorRegular.cgColor,
colorRegular.cgColor,
] as CFArray
if let gradient = CGGradient(
colorsSpace: CGColorSpaceCreateDeviceRGB(),
Expand All @@ -1211,8 +1228,8 @@ extension TagChartsViewController {
gradientColors = [
colorAlert.cgColor,
colorAlert.cgColor,
color.cgColor,
color.cgColor,
colorRegular.cgColor,
colorRegular.cgColor,
colorAlert.cgColor,
colorAlert.cgColor,
] as CFArray
Expand Down

0 comments on commit 4c838e4

Please sign in to comment.