Mercurial > public > lazybear
changeset 396:bd34e16b01ad
Add StockCharts package
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Sat, 08 May 2021 19:19:17 +0200 |
parents | a0cf8fe47044 |
children | 6f04495c462d |
files | LazyBear.xcodeproj/project.pbxproj LazyBear.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate LazyBear/Views/Global Helpers/LineShape.swift LazyBear/Views/Global Helpers/LineView.swift LazyBear/Views/Global Helpers/StockItem.swift LazyBear/WatchlistManagerTest.swift |
diffstat | 7 files changed, 30 insertions(+), 189 deletions(-) [+] |
line wrap: on
line diff
--- a/LazyBear.xcodeproj/project.pbxproj Fri May 07 11:43:47 2021 +0200 +++ b/LazyBear.xcodeproj/project.pbxproj Sat May 08 19:19:17 2021 +0200 @@ -58,11 +58,9 @@ 95AD4A2D26078C1400498079 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95AD4A2C26078C1400498079 /* ContentView.swift */; }; 95BD2FAE26341BD1008B6752 /* TextfieldAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95BD2FAD26341BD1008B6752 /* TextfieldAlert.swift */; }; 95BD2FB326341D36008B6752 /* BlurBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95BD2FB226341D36008B6752 /* BlurBackground.swift */; }; + 95C547CD2646F29100F96C93 /* StockCharts in Frameworks */ = {isa = PBXBuildFile; productRef = 95C547CC2646F29100F96C93 /* StockCharts */; }; 95C8C0E0262A369F0082D1D9 /* ProfileResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C8C0DF262A369F0082D1D9 /* ProfileResponse.swift */; }; 95D308F82624B3A400A39F77 /* CurrencyItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95D308F72624B3A400A39F77 /* CurrencyItem.swift */; }; - 95E6C57626345CE700AC1518 /* WatchlistManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E6C57526345CE700AC1518 /* WatchlistManagerTest.swift */; }; - 95ECCA5D2612169200A67EFA /* LineShape.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95ECCA5C2612169200A67EFA /* LineShape.swift */; }; - 95ECCA60261216D500A67EFA /* LineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95ECCA5F261216D500A67EFA /* LineView.swift */; }; 95FBE0DC2619CA7200440386 /* ProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95FBE0DB2619CA7200440386 /* ProfileView.swift */; }; /* End PBXBuildFile section */ @@ -144,9 +142,6 @@ 95BD2FB226341D36008B6752 /* BlurBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurBackground.swift; sourceTree = "<group>"; }; 95C8C0DF262A369F0082D1D9 /* ProfileResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileResponse.swift; sourceTree = "<group>"; }; 95D308F72624B3A400A39F77 /* CurrencyItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyItem.swift; sourceTree = "<group>"; }; - 95E6C57526345CE700AC1518 /* WatchlistManagerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchlistManagerTest.swift; sourceTree = "<group>"; }; - 95ECCA5C2612169200A67EFA /* LineShape.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineShape.swift; sourceTree = "<group>"; }; - 95ECCA5F261216D500A67EFA /* LineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineView.swift; sourceTree = "<group>"; }; 95FBE0DB2619CA7200440386 /* ProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileView.swift; sourceTree = "<group>"; }; /* End PBXFileReference section */ @@ -169,6 +164,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 95C547CD2646F29100F96C93 /* StockCharts in Frameworks */, 958A735225E0170900FD7ECA /* CloudKit.framework in Frameworks */, 95A4B933263E9F810056F036 /* Introspect in Frameworks */, 954D7EC2260BE70C00A13C50 /* SwiftlySearch in Frameworks */, @@ -325,7 +321,6 @@ 95672B9925DDA54800DCBE4A /* LazyBear.xcdatamodeld */, 95672B9225DDA54700DCBE4A /* Assets.xcassets */, 95672B8E25DDA54700DCBE4A /* LazyBearApp.swift */, - 95E6C57526345CE700AC1518 /* WatchlistManagerTest.swift */, 95AD4A2C26078C1400498079 /* ContentView.swift */, 95672B9725DDA54700DCBE4A /* Persistence.swift */, 950C36E2260FB6180081CF53 /* HapticsManager.swift */, @@ -359,8 +354,6 @@ isa = PBXGroup; children = ( 950272CA2635AA9F003E779D /* Company list */, - 95ECCA5F261216D500A67EFA /* LineView.swift */, - 95ECCA5C2612169200A67EFA /* LineShape.swift */, 95A5188526186F590002D27C /* PriceView.swift */, 9550444826111FC9000E0BCB /* StockRow.swift */, 9550444B26111FED000E0BCB /* StockItem.swift */, @@ -487,6 +480,7 @@ packageProductDependencies = ( 954D7EC1260BE70C00A13C50 /* SwiftlySearch */, 95A4B932263E9F810056F036 /* Introspect */, + 95C547CC2646F29100F96C93 /* StockCharts */, ); productName = LazyBear; productReference = 95672B8B25DDA54700DCBE4A /* LazyBear.app */; @@ -526,6 +520,7 @@ packageReferences = ( 954D7EC0260BE70C00A13C50 /* XCRemoteSwiftPackageReference "SwiftlySearch" */, 95A4B931263E9F810056F036 /* XCRemoteSwiftPackageReference "SwiftUI-Introspect" */, + 95C547CB2646F29100F96C93 /* XCRemoteSwiftPackageReference "StockCharts" */, ); productRefGroup = 95672B8C25DDA54700DCBE4A /* Products */; projectDirPath = ""; @@ -593,7 +588,6 @@ 9550444926111FC9000E0BCB /* StockRow.swift in Sources */, 9550444326111E7A000E0BCB /* SectorRow.swift in Sources */, 95721DB826278EC100EC527B /* CurrencyListItem.swift in Sources */, - 95ECCA60261216D500A67EFA /* LineView.swift in Sources */, 950272CD2635AACD003E779D /* ToolbarMenu.swift in Sources */, 9550443A26111B2B000E0BCB /* HomeView.swift in Sources */, 95672B9825DDA54700DCBE4A /* Persistence.swift in Sources */, @@ -604,9 +598,7 @@ 95721DA6262761E700EC527B /* CurrencyRow.swift in Sources */, 9562404C263C766D00C6C511 /* WatchlistCreator.swift in Sources */, 95672B8F25DDA54700DCBE4A /* LazyBearApp.swift in Sources */, - 95E6C57626345CE700AC1518 /* WatchlistManagerTest.swift in Sources */, 95A7C066261639E0003E2EC1 /* SearchView.swift in Sources */, - 95ECCA5D2612169200A67EFA /* LineShape.swift in Sources */, 9550444C26111FED000E0BCB /* StockItem.swift in Sources */, 95A4B937263EA5C20056F036 /* WatchlistCreatorRow.swift in Sources */, 950D0E192618AA4900D17AD7 /* CompanyList.swift in Sources */, @@ -958,6 +950,14 @@ minimumVersion = 0.1.3; }; }; + 95C547CB2646F29100F96C93 /* XCRemoteSwiftPackageReference "StockCharts" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/denniscm190/StockCharts.git"; + requirement = { + branch = "lazybear-tests"; + kind = branch; + }; + }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -971,6 +971,11 @@ package = 95A4B931263E9F810056F036 /* XCRemoteSwiftPackageReference "SwiftUI-Introspect" */; productName = Introspect; }; + 95C547CC2646F29100F96C93 /* StockCharts */ = { + isa = XCSwiftPackageProductDependency; + package = 95C547CB2646F29100F96C93 /* XCRemoteSwiftPackageReference "StockCharts" */; + productName = StockCharts; + }; /* End XCSwiftPackageProductDependency section */ /* Begin XCVersionGroup section */
--- a/LazyBear.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved Fri May 07 11:43:47 2021 +0200 +++ b/LazyBear.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved Sat May 08 19:19:17 2021 +0200 @@ -2,6 +2,15 @@ "object": { "pins": [ { + "package": "StockCharts", + "repositoryURL": "https://github.com/denniscm190/StockCharts.git", + "state": { + "branch": "lazybear-tests", + "revision": "9d93ca31e602373373c86d759092bcc0f2ca1339", + "version": null + } + }, + { "package": "SwiftlySearch", "repositoryURL": "https://github.com/thislooksfun/SwiftlySearch.git", "state": {
Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/LazyBear/Views/Global Helpers/LineShape.swift Fri May 07 11:43:47 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -// -// LineShape.swift -// LazyBear -// -// Created by Dennis Concepción Martín on 29/3/21. -// - -import SwiftUI - -struct LineShape: Shape { - var width: CGFloat - var height: CGFloat - var normalizedData: [Double] - - func path(in rect: CGRect) -> Path { - var path = Path() - - let spaceBetweenPoints = Double(width) / Double(normalizedData.count - 1) - var xPoint: Double = 0 - let initialYPoint = normalizedData.first ?? 0 * Double(height) - - path.move(to: CGPoint(x: xPoint, y: initialYPoint)) - - var firstLoop = true - for yPoint in normalizedData { - if firstLoop { - firstLoop = false - } else { - xPoint += spaceBetweenPoints - let yPoint = yPoint * Double(height) - path.addLine(to: CGPoint(x: xPoint, y: yPoint)) - } - } - - return path - } -} -
--- a/LazyBear/Views/Global Helpers/LineView.swift Fri May 07 11:43:47 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -// -// LineView.swift -// LazyBear -// -// Created by Dennis Concepción Martín on 29/3/21. -// - -import SwiftUI - -struct LineView: View { - var data: [Double] - - var body: some View { - GeometryReader { proxy in - VStack { - LineShape(width: proxy.size.width, height: proxy.size.height, normalizedData: normalize(data)) - .stroke(lineWidth: 2) - .rotationEffect(.degrees(180), anchor: .center) - .rotation3DEffect(.degrees(180), axis: (x: 0.0, y: 1.0, z: 0.0)) - } - } - } - - // Normalize data - func normalize(_ data: [Double]) -> [Double] { - var normalData = [Double]() - let min = data.min() ?? 0 - let max = data.max() ?? 0 - - for value in data { - let normal = (value - min) / (max - min) - normalData.append(normal) - } - - return normalData - } -} - -struct LineView_Previews: PreviewProvider { - static var previews: some View { - LineView(data: generateRandomSample()) - } - - static private func generateRandomSample() -> [Double] { - var randomSample = [Double]() - for _ in 1..<10 { - randomSample.append(Double.random(in: 1...100)) - } - - return randomSample - } -}
--- a/LazyBear/Views/Global Helpers/StockItem.swift Fri May 07 11:43:47 2021 +0200 +++ b/LazyBear/Views/Global Helpers/StockItem.swift Sat May 08 19:19:17 2021 +0200 @@ -6,6 +6,7 @@ // import SwiftUI +import StockCharts enum OrientationView { case horizontal, vertical @@ -69,10 +70,9 @@ Spacer() if let prices = intradayPrices?.compactMap { $0.open } { - LineView(data: prices) - .foregroundColor(company.changePercent ?? 0 < 0 ? .red: .green) + LineChartView(data: prices, dates: nil, hours: nil, dragGesture: false) .padding(.vertical) - .clipped() + .clipShape(RoundedRectangle(cornerRadius: 20)) } } @@ -104,8 +104,7 @@ Spacer() if !hidePriceView { if let prices = intradayPrices?.compactMap { $0.open } { - LineView(data: prices) - .foregroundColor(company.changePercent ?? 0 < 0 ? .red: .green) + LineChartView(data: prices, dates: nil, hours: nil, dragGesture: false) .frame(width: 80) .padding(.vertical, 10) .padding(.leading)
--- a/LazyBear/WatchlistManagerTest.swift Fri May 07 11:43:47 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -// -// WatchlistManagerTest.swift -// LazyBear -// -// Created by Dennis Concepción Martín on 24/4/21. -// - -import SwiftUI - -/* - DELETE IN PRODUCTION - */ - -struct WatchlistManagerTest: View { - @Environment(\.managedObjectContext) private var moc - @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) - var watchlistCompany: FetchedResults<WatchlistCompany> - - var body: some View { - VStack { - Button("Add company", action: addCompany) - Button("Reset Entity", action: resetCoreDataEntity) - } - } - -// private func removeCompany(at offsets: IndexSet) { -// for index in offsets { -// let company = companies[index] -// moc.delete(company) -// } -// do { -// try moc.save() -// } catch { -// // Error -// } -// } - - // Add to watchlist - private func addCompany() { - let watchlistCompany = WatchlistCompany(context: moc) - watchlistCompany.symbol = "TSLA" - watchlistCompany.name = "Tesla Inc" - watchlistCompany.watchlist = "My portfolio" - do { - try moc.save() - print("Company saved") - } catch { - print(error.localizedDescription) - } - } - -// private func removeCompany() { -// let symbols = companies.map { $0.symbol } -// let index = symbols.firstIndex(of: symbol) -// let company = companies[index!] -// moc.delete(company) -// do { -// try moc.save() -// print("Company deleted") -// } catch { -// // Error -// } -// } - - private func resetCoreDataEntity() { - for item in watchlistCompany { - moc.delete(item) - } - do { - try moc.save() - print("Company deleted") - } catch { - // Error - } - } -} - -struct WatchlistManagerTest_Previews: PreviewProvider { - static var previews: some View { - WatchlistManagerTest() - } -}