Mercurial > public > stock-charts
view Sources/InteractiveCharts/LineChart/Helpers/ChartLabel.swift @ 20:24dfde3727c1 v0.2-alpha
Make variables and structures public
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Wed, 28 Apr 2021 20:24:54 +0200 |
parents | edf2bfcd8d97 |
children |
line wrap: on
line source
// // ChartLabel.swift // InteractiveCharts // // Created by Dennis Concepción Martín on 26/4/21. // import SwiftUI public struct ChartLabel: View { var data: [Double] var dates: [String]? 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) } if let hours = self.hours { let hour = hours[indexPosition] Text(hour) } Text("\(data[indexPosition], specifier: "%.2f")") .foregroundColor(Color(.systemBlue)) } .font(.headline) } } /* 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 } }