Mercurial > public > stock-charts
changeset 112:a17e05c67dae 1.2.8
Merge pull request #16 from denniscm190/development
Development
committer: GitHub <noreply@github.com>
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Sat, 17 Jul 2021 12:25:39 +0100 |
parents | b0c81b2e624d (current diff) 1ffeccd51605 (diff) |
children | 71b027b75fe6 3269859fd31f |
files | |
diffstat | 9 files changed, 73 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/StockCharts/CapsuleChart/CapsuleChartStyle.swift Sat Jul 17 12:25:39 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 + } +}
--- a/Sources/StockCharts/CapsuleChart/CapsuleChartView.swift Mon Jun 28 14:01:13 2021 +0200 +++ b/Sources/StockCharts/CapsuleChart/CapsuleChartView.swift Sat Jul 17 12:25:39 2021 +0100 @@ -9,20 +9,23 @@ 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 + GeometryReader { proxy in + ZStack(alignment: .leading) { Group { Capsule() .foregroundColor(Color.gray) .opacity(0.2) Capsule() - .foregroundColor(Color.blue) + .foregroundColor(style.capsuleColor) .frame(width: proxy.size.width * percentageOfWidth) } .frame(height: 10)
--- a/Sources/StockCharts/LineChart/Helpers/ChartLabel.swift Mon Jun 28 14:01:13 2021 +0200 +++ b/Sources/StockCharts/LineChart/Helpers/ChartLabel.swift Sat Jul 17 12:25:39 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)
--- a/Sources/StockCharts/LineChart/Helpers/IndicatorPoint.swift Mon Jun 28 14:01:13 2021 +0200 +++ b/Sources/StockCharts/LineChart/Helpers/IndicatorPoint.swift Sat Jul 17 12:25:39 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) } }
--- a/Sources/StockCharts/LineChart/Helpers/LineView.swift Mon Jun 28 14:01:13 2021 +0200 +++ b/Sources/StockCharts/LineChart/Helpers/LineView.swift Sat Jul 17 12:25:39 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/StockCharts/LineChart/LineChartStyle.swift Sat Jul 17 12:25:39 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 + } +}
--- a/Sources/StockCharts/LineChart/LineChartView.swift Mon Jun 28 14:01:13 2021 +0200 +++ b/Sources/StockCharts/LineChart/LineChartView.swift Sat Jul 17 12:25:39 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) } } }
--- a/StockCharts.xcodeproj/project.pbxproj Mon Jun 28 14:01:13 2021 +0200 +++ b/StockCharts.xcodeproj/project.pbxproj Sat Jul 17 12:25:39 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 = "<group>"; }; + 954AA39D269209770006FD14 /* LineChartStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineChartStyle.swift; sourceTree = "<group>"; }; + 954AA39F26920D060006FD14 /* CapsuleChartStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapsuleChartStyle.swift; sourceTree = "<group>"; }; 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 = "<group>"; }; 95770B85263C57B5003FA924 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; @@ -69,6 +73,7 @@ isa = PBXGroup; children = ( 950857AD266BDF62005357BA /* CapsuleChartView.swift */, + 954AA39F26920D060006FD14 /* CapsuleChartStyle.swift */, ); path = CapsuleChart; sourceTree = "<group>"; @@ -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; };