Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions LoopUI/Charts/ChartsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ import os.log
open class ChartsManager {
private let log = OSLog(category: "ChartsManager")

private lazy var timeFormatter: DateFormatter = {
let formatter = DateFormatter()
let dateFormat = DateFormatter.dateFormat(fromTemplate: "j", options: 0, locale: Locale.current)!
let isAmPmTimeFormat = dateFormat.index( of: "a") != nil
formatter.dateFormat = isAmPmTimeFormat
? "h a"
: "H:mm"
return formatter
}()

public init(colors: ChartColorPalette, settings: ChartSettings, charts: [ChartProviding]) {
self.colors = colors
self.chartSettings = settings
Expand Down Expand Up @@ -105,7 +115,7 @@ open class ChartsManager {
/// - Parameter date: The new candidate date
public func updateEndDate(_ date: Date) {
if date > endDate {
var components = DateComponents(minute: 0)
let components = DateComponents(minute: 0)
endDate = min(
maxEndDate,
Calendar.current.nextDate(
Expand Down Expand Up @@ -156,14 +166,12 @@ open class ChartsManager {

// MARK: - Shared Axis


private func generateXAxisValues() {
if let endDate = charts.compactMap({ $0.endDate }).max() {
updateEndDate(endDate)
}

let timeFormatter = DateFormatter()
timeFormatter.dateFormat = "h a"

let points = [
ChartPoint(
x: ChartAxisValueDate(date: startDate, formatter: timeFormatter),
Expand Down