# HG changeset patch # User Dennis Concepción Martín # Date 1625413224 -3600 # Node ID f53d8b9ca92bcc3369605b4fb8fb30edfffaa1eb # Parent b0c81b2e624db4b9c51234dbb68083a9926cbfc4 Custom style implemented diff -r b0c81b2e624d -r f53d8b9ca92b Sources/StockCharts/CapsuleChart/CapsuleChartStyle.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/StockCharts/CapsuleChart/CapsuleChartStyle.swift Sun Jul 04 16:40:24 2021 +0100 @@ -0,0 +1,16 @@ +// +// CapsuleChartStyle.swift +// StockCharts +// +// Created by Dennis Concepción Martín on 04/07/2021. +// + +import SwiftUI + +public class CapsuleChartStyle { + public var capsuleColor: Color + + public init(capsuleColor: Color) { + self.capsuleColor = capsuleColor + } +} diff -r b0c81b2e624d -r f53d8b9ca92b Sources/StockCharts/CapsuleChart/CapsuleChartView.swift --- a/Sources/StockCharts/CapsuleChart/CapsuleChartView.swift Mon Jun 28 14:01:13 2021 +0200 +++ b/Sources/StockCharts/CapsuleChart/CapsuleChartView.swift Sun Jul 04 16:40:24 2021 +0100 @@ -9,10 +9,13 @@ public struct CapsuleChartView: View { public var percentageOfWidth: CGFloat + public var style: CapsuleChartStyle - public init(percentageOfWidth: CGFloat) { + public init(percentageOfWidth: CGFloat, style: CapsuleChartStyle) { self.percentageOfWidth = percentageOfWidth + self.style = style } + public var body: some View { ZStack { GeometryReader { proxy in @@ -22,7 +25,7 @@ .opacity(0.2) Capsule() - .foregroundColor(Color.blue) + .foregroundColor(style.capsuleColor) .frame(width: proxy.size.width * percentageOfWidth) } .frame(height: 10) diff -r b0c81b2e624d -r f53d8b9ca92b Sources/StockCharts/LineChart/Helpers/ChartLabel.swift --- a/Sources/StockCharts/LineChart/Helpers/ChartLabel.swift Mon Jun 28 14:01:13 2021 +0200 +++ b/Sources/StockCharts/LineChart/Helpers/ChartLabel.swift Sun Jul 04 16:40:24 2021 +0100 @@ -11,6 +11,7 @@ public var data: [Double] public var dates: [String]? public var hours: [String]? + public var style: LineChartStyle @Binding var indexPosition: Int // Data point position @@ -29,7 +30,7 @@ } Text("\(data[indexPosition], specifier: "%.2f")") - .foregroundColor(Color.blue) + .foregroundColor(style.labelColor) } .font(.caption) diff -r b0c81b2e624d -r f53d8b9ca92b Sources/StockCharts/LineChart/Helpers/IndicatorPoint.swift --- a/Sources/StockCharts/LineChart/Helpers/IndicatorPoint.swift Mon Jun 28 14:01:13 2021 +0200 +++ b/Sources/StockCharts/LineChart/Helpers/IndicatorPoint.swift Sun Jul 04 16:40:24 2021 +0100 @@ -8,9 +8,11 @@ import SwiftUI public struct IndicatorPoint: View { + public var style: LineChartStyle + public var body: some View { Circle() .frame(width: 20, height: 20) - .foregroundColor(Color.blue) + .foregroundColor(style.indicatorPointColor) } } diff -r b0c81b2e624d -r f53d8b9ca92b Sources/StockCharts/LineChart/Helpers/LineView.swift --- a/Sources/StockCharts/LineChart/Helpers/LineView.swift Mon Jun 28 14:01:13 2021 +0200 +++ b/Sources/StockCharts/LineChart/Helpers/LineView.swift Sun Jul 04 16:40:24 2021 +0100 @@ -12,6 +12,7 @@ public var dates: [String]? public var hours: [String]? public var dragGesture: Bool? + public var style: LineChartStyle @Binding var showingIndicators: Bool @Binding var indexPosition: Int @@ -26,7 +27,7 @@ } if showingIndicators { - IndicatorPoint() + IndicatorPoint(style: style) .position(x: IndicatorPointPosition.x, y: IndicatorPointPosition.y) } } @@ -58,14 +59,14 @@ Color path depending on data. */ public func colorLine() -> Color { - var color = Color.green + var color = style.uptrendLineColor if showingIndicators { - color = Color.blue + color = style.showingIndicatorLineColor } else if data.first! > data.last! { - color = Color.red + color = style.downtrendLineColor } else if data.first! == data.last! { - color = Color.blue + color = style.flatTrendLineColor } return color diff -r b0c81b2e624d -r f53d8b9ca92b Sources/StockCharts/LineChart/LineChartStyle.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/StockCharts/LineChart/LineChartStyle.swift Sun Jul 04 16:40:24 2021 +0100 @@ -0,0 +1,26 @@ +// +// LineChartStyle.swift +// StockCharts +// +// Created by Dennis Concepción Martín on 04/07/2021. +// + +import SwiftUI + +public class LineChartStyle { + public var labelColor: Color + public var indicatorPointColor: Color + public var showingIndicatorLineColor: Color + public var flatTrendLineColor: Color + public var uptrendLineColor: Color + public var downtrendLineColor: Color + + public init(labelColor: Color, indicatorPointColor: Color, showingIndicatorLineColor: Color, flatTrendLineColor: Color, uptrendLineColor: Color, downtrendLineColor: Color) { + self.labelColor = labelColor + self.indicatorPointColor = indicatorPointColor + self.showingIndicatorLineColor = showingIndicatorLineColor + self.flatTrendLineColor = flatTrendLineColor + self.uptrendLineColor = uptrendLineColor + self.downtrendLineColor = downtrendLineColor + } +} diff -r b0c81b2e624d -r f53d8b9ca92b Sources/StockCharts/LineChart/LineChartView.swift --- a/Sources/StockCharts/LineChart/LineChartView.swift Mon Jun 28 14:01:13 2021 +0200 +++ b/Sources/StockCharts/LineChart/LineChartView.swift Sun Jul 04 16:40:24 2021 +0100 @@ -12,26 +12,28 @@ public var dates: [String]? public var hours: [String]? public var dragGesture: Bool? + public var style: LineChartStyle @State var showingIndicators = false @State var indexPosition = Int() - public init(data: [Double], dates: [String]?, hours: [String]?, dragGesture: Bool?) { + public init(data: [Double], dates: [String]?, hours: [String]?, dragGesture: Bool?, style: LineChartStyle) { self.data = data self.dates = dates self.hours = hours self.dragGesture = dragGesture + self.style = style } public var body: some View { if !data.isEmpty { VStack { if dragGesture ?? true { - ChartLabel(data: data, dates: dates, hours: hours, indexPosition: $indexPosition) + ChartLabel(data: data, dates: dates, hours: hours, style: style, indexPosition: $indexPosition) .opacity(showingIndicators ? 1: 0) } - LineView(data: data, dates: dates, hours: hours, dragGesture: dragGesture, showingIndicators: $showingIndicators, indexPosition: $indexPosition) + LineView(data: data, dates: dates, hours: hours, dragGesture: dragGesture, style: style, showingIndicators: $showingIndicators, indexPosition: $indexPosition) } } } diff -r b0c81b2e624d -r f53d8b9ca92b StockCharts.xcodeproj/project.pbxproj --- a/StockCharts.xcodeproj/project.pbxproj Mon Jun 28 14:01:13 2021 +0200 +++ b/StockCharts.xcodeproj/project.pbxproj Sun Jul 04 16:40:24 2021 +0100 @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 950857AE266BDF62005357BA /* CapsuleChartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950857AD266BDF62005357BA /* CapsuleChartView.swift */; }; + 954AA39E269209770006FD14 /* LineChartStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954AA39D269209770006FD14 /* LineChartStyle.swift */; }; + 954AA3A026920D060006FD14 /* CapsuleChartStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954AA39F26920D060006FD14 /* CapsuleChartStyle.swift */; }; 95770B8B263C57B5003FA924 /* StockCharts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95770B81263C57B5003FA924 /* StockCharts.framework */; }; 95770B90263C57B5003FA924 /* StockChartsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95770B8F263C57B5003FA924 /* StockChartsTests.swift */; }; 95770B92263C57B5003FA924 /* StockCharts.h in Headers */ = {isa = PBXBuildFile; fileRef = 95770B84263C57B5003FA924 /* StockCharts.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -30,6 +32,8 @@ /* Begin PBXFileReference section */ 950857AD266BDF62005357BA /* CapsuleChartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapsuleChartView.swift; sourceTree = ""; }; + 954AA39D269209770006FD14 /* LineChartStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineChartStyle.swift; sourceTree = ""; }; + 954AA39F26920D060006FD14 /* CapsuleChartStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapsuleChartStyle.swift; sourceTree = ""; }; 95770B81263C57B5003FA924 /* StockCharts.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = StockCharts.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 95770B84263C57B5003FA924 /* StockCharts.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StockCharts.h; sourceTree = ""; }; 95770B85263C57B5003FA924 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -69,6 +73,7 @@ isa = PBXGroup; children = ( 950857AD266BDF62005357BA /* CapsuleChartView.swift */, + 954AA39F26920D060006FD14 /* CapsuleChartStyle.swift */, ); path = CapsuleChart; sourceTree = ""; @@ -134,6 +139,7 @@ isa = PBXGroup; children = ( 95770B9F263C590C003FA924 /* LineChartView.swift */, + 954AA39D269209770006FD14 /* LineChartStyle.swift */, 95770BA1263C5927003FA924 /* Helpers */, ); path = LineChart; @@ -261,10 +267,12 @@ files = ( 95770BA0263C590C003FA924 /* LineChartView.swift in Sources */, 95770BA3263C5934003FA924 /* ChartLabel.swift in Sources */, + 954AA3A026920D060006FD14 /* CapsuleChartStyle.swift in Sources */, 95770BA7263C596E003FA924 /* LinePath.swift in Sources */, 950857AE266BDF62005357BA /* CapsuleChartView.swift in Sources */, 95770BA9263C5988003FA924 /* LineView.swift in Sources */, 95770BA5263C594C003FA924 /* IndicatorPoint.swift in Sources */, + 954AA39E269209770006FD14 /* LineChartStyle.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff -r b0c81b2e624d -r f53d8b9ca92b StockCharts.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Binary file StockCharts.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed