Mercurial > public > stock-charts
view Sources/StockCharts/LineChart/Helpers/ChartLabel.swift @ 106:0c0d38dca6d8
Change colours to native swiftUI
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Mon, 28 Jun 2021 13:48:03 +0200 |
parents | 766a1169564b |
children | f53d8b9ca92b |
line wrap: on
line source
// // ChartLabel.swift // StockCharts // // Created by Dennis Concepción Martín on 30/4/21. // import SwiftUI public struct ChartLabel: View { public var data: [Double] public var dates: [String]? public var hours: [String]? @Binding var indexPosition: Int // Data point position public var body: some View { HStack { Group { if let dates = self.dates { let date = formatStringDate(dates[indexPosition]) Text(date) .opacity(0.5) } if let hours = self.hours { let hour = hours[indexPosition] Text(hour) .opacity(0.5) } Text("\(data[indexPosition], specifier: "%.2f")") .foregroundColor(Color.blue) } .font(.caption) } } /* Take string in format yy-MM-dd (2021-01-01) and transform it to long default string format */ public func formatStringDate(_ stringDate: String) -> String { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yy-MM-dd" let date = dateFormatter.date(from: stringDate) // Format date to the final format dateFormatter.dateStyle = .long let finalDate = dateFormatter.string(from: date!) return finalDate } }