comparison Sources/StockCharts/LineChart/Helpers/ChartLabel.swift @ 116:5057c45046c1

Add default initializers
author Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com>
date Mon, 09 Aug 2021 16:32:45 +0100
parents f53d8b9ca92b
children
comparison
equal deleted inserted replaced
115:f90a675e5e95 116:5057c45046c1
6 // 6 //
7 7
8 import SwiftUI 8 import SwiftUI
9 9
10 public struct ChartLabel: View { 10 public struct ChartLabel: View {
11 public var data: [Double] 11 public var lineChartController: LineChartController
12 public var dates: [String]?
13 public var hours: [String]?
14 public var style: LineChartStyle
15 12
16 @Binding var indexPosition: Int // Data point position 13 @Binding var indexPosition: Int // Data point position
17 14
18 public var body: some View { 15 public var body: some View {
19 HStack { 16 HStack {
20 Group { 17 if let dates = lineChartController.dates {
21 if let dates = self.dates { 18 let date = formatStringDate(dates[indexPosition])
22 let date = formatStringDate(dates[indexPosition]) 19 Text(date)
23 Text(date) 20 .opacity(0.5)
24 .opacity(0.5)
25 }
26 if let hours = self.hours {
27 let hour = hours[indexPosition]
28 Text(hour)
29 .opacity(0.5)
30 }
31
32 Text("\(data[indexPosition], specifier: "%.2f")")
33 .foregroundColor(style.labelColor)
34
35 } 21 }
36 .font(.caption) 22
23 if let hours = lineChartController.hours {
24 let hour = hours[indexPosition]
25 Text(hour)
26 .opacity(0.5)
27 }
28
29 Text("\(lineChartController.prices[indexPosition], specifier: "%.2f")")
30 .foregroundColor(lineChartController.labelColor)
37 } 31 }
38 } 32 }
39 33
40 /* 34 /*
41 Take string in format yy-MM-dd (2021-01-01) and transform it 35 Take string in format yy-MM-dd (2021-01-01) and transform it