Mercurial > public > stock-charts
changeset 103:766a1169564b
Add WatchOS compatability
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Sun, 27 Jun 2021 16:32:23 +0200 |
parents | 7e524a9cc194 |
children | 88ffe7687fb9 |
files | Package.swift Sources/StockCharts/CapsuleChart/CapsuleChartView.swift Sources/StockCharts/LineChart/Helpers/ChartLabel.swift Sources/StockCharts/LineChart/Helpers/IndicatorPoint.swift Sources/StockCharts/LineChart/Helpers/LineView.swift StockCharts.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate |
diffstat | 6 files changed, 42 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/Package.swift Tue Jun 22 16:41:53 2021 +0200 +++ b/Package.swift Sun Jun 27 16:32:23 2021 +0200 @@ -9,7 +9,7 @@ let package = Package( name: "StockCharts", platforms: [ - .iOS(.v14) + .iOS(.v14), .watchOS(.v7) ], products: [ .library(
--- a/Sources/StockCharts/CapsuleChart/CapsuleChartView.swift Tue Jun 22 16:41:53 2021 +0200 +++ b/Sources/StockCharts/CapsuleChart/CapsuleChartView.swift Sun Jun 27 16:32:23 2021 +0200 @@ -17,6 +17,7 @@ ZStack { GeometryReader { proxy in Group { + #if os(iOS) Capsule() .foregroundColor(Color(.systemGray)) .opacity(0.2) @@ -24,6 +25,16 @@ Capsule() .foregroundColor(Color(.systemBlue)) .frame(width: proxy.size.width * percentageOfWidth) + #elseif os(watchOS) + Capsule() + .foregroundColor(Color(.gray)) + .opacity(0.2) + + Capsule() + .foregroundColor(Color(.blue)) + .frame(width: proxy.size.width * percentageOfWidth) + #endif + } .frame(height: 10) }
--- a/Sources/StockCharts/LineChart/Helpers/ChartLabel.swift Tue Jun 22 16:41:53 2021 +0200 +++ b/Sources/StockCharts/LineChart/Helpers/ChartLabel.swift Sun Jun 27 16:32:23 2021 +0200 @@ -27,8 +27,16 @@ Text(hour) .opacity(0.5) } + + #if os(iOS) Text("\(data[indexPosition], specifier: "%.2f")") .foregroundColor(Color(.systemBlue)) + + #elseif os(watchOS) + Text("\(data[indexPosition], specifier: "%.2f")") + .foregroundColor(Color(.blue)) + #endif + } .font(.caption) }
--- a/Sources/StockCharts/LineChart/Helpers/IndicatorPoint.swift Tue Jun 22 16:41:53 2021 +0200 +++ b/Sources/StockCharts/LineChart/Helpers/IndicatorPoint.swift Sun Jun 27 16:32:23 2021 +0200 @@ -9,9 +9,16 @@ public struct IndicatorPoint: View { public var body: some View { + #if os(iOS) Circle() .frame(width: 20, height: 20) .foregroundColor(Color(.systemBlue)) + + #elseif os(watchOS) + Circle() + .frame(width: 20, height: 20) + .foregroundColor(Color(.blue)) + #endif } }
--- a/Sources/StockCharts/LineChart/Helpers/LineView.swift Tue Jun 22 16:41:53 2021 +0200 +++ b/Sources/StockCharts/LineChart/Helpers/LineView.swift Sun Jun 27 16:32:23 2021 +0200 @@ -58,14 +58,26 @@ Color path depending on data. */ public func colorLine() -> Color { + #if os(iOS) + let blue = Color(.systemBlue) + let teal = Color(.systemTeal) + let red = Color(.systemRed) + var color = Color(.systemGreen) + #elseif os(watchOS) + let blue = Color(.blue) + let teal = Color(.blue) + let red = Color(.red) + + var color = Color(.green) + #endif if showingIndicators { - color = Color(.systemBlue) + color = blue } else if data.first! > data.last! { - color = Color(.systemRed) + color = red } else if data.first! == data.last! { - color = Color(.systemTeal) + color = teal } return color