comparison LazyBear/Views/Company/Helpers/ChartHelper.swift @ 439:aa1f4b614b2b

Implementing CompanyView
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Sun, 20 Jun 2021 14:31:39 +0200
parents
children 01fa77358b82
comparison
equal deleted inserted replaced
438:7f2a24a774eb 439:aa1f4b614b2b
1 //
2 // ChartHelper.swift
3 // LazyBear
4 //
5 // Created by Dennis Concepción Martín on 20/6/21.
6 //
7
8 import SwiftUI
9
10 struct ChartHelper: View {
11 var quote: [QuoteModel]?
12 var historicalPrices: [HistoricalPricesModel]?
13
14 var body: some View {
15 CustomRectangleBox()
16 .frame(height: 270)
17 .padding(.horizontal)
18 .overlay(
19 VStack {
20 if let quote = quote?.first {
21 HStack(alignment: .center) {
22 Text("\(quote.latestPrice ?? 0, specifier: "%.2f")")
23 .foregroundColor(quote.changePercent ?? 0 < 0 ? .red: .green)
24 .fontWeight(.semibold)
25
26 Text("\(quote.changePercent ?? 0 * 100, specifier: "%.2f")%")
27 .foregroundColor(quote.changePercent ?? 0 < 0 ? .red: .green)
28 .font(.callout)
29 .fontWeight(.semibold)
30 }
31 .padding(.top)
32 }
33 }
34 )
35 }
36 }
37
38 struct ChartHelper_Previews: PreviewProvider {
39 static var previews: some View {
40 ChartHelper(
41 quote: [
42 QuoteModel(companyName: "apple inc", latestPrice: 120.3, changePercent: 0.03)
43 ],
44 historicalPrices: [
45 HistoricalPricesModel(close: 120.3, date: "2020-01-01", minute: nil)
46 ]
47 )
48 }
49 }