Post

Replies

Boosts

Views

Activity

SwiftUI chart annotation not working when using chartScrollableAxes
When using the new iOS “chartScrollableAxes” feature annotation that should show on top of the chart view no longer work. When disabling “chartScrollableAxes” everything works again. Filed as FB12584128 import SwiftUI import Charts class ChartDataEntry:Identifiable { var date:Date var value:Double init(date:Date, value: Double) { self.date=date self.value=value } } struct ContentView: View { @State var rawSelectedDate: Date? var chartData = [ChartDataEntry(date: Date().yesterday.yesterday.yesterday.yesterday.startOfDay, value: 10.0), ChartDataEntry(date: Date().yesterday.yesterday.yesterday.startOfDay, value: 20.0), ChartDataEntry(date: Date().yesterday.yesterday.startOfDay, value: 30.0), ChartDataEntry(date: Date().yesterday.startOfDay, value: 40.0), ChartDataEntry(date: Date().startOfDay, value: 50.0)] var body: some View { VStack { Chart(chartData) { entry in BarMark( x: .value("Day", entry.date, unit: .day), y: .value("Values", entry.value) ) if let selectedDate { RuleMark( x: .value("Selected", selectedDate, unit: .day)) .foregroundStyle(Color.gray.opacity(0.3)) .offset(yStart: -10) .zIndex(-1) .annotation(position: .top, spacing: -10, overflowResolution: .init( x: .fit(to: .chart), y: .disabled ) ) { Text("Longer Sample Text") } } } .chartScrollableAxes(.horizontal) // <<--- when this is disabled the annotation will be shown correctly .chartXSelection(value: $rawSelectedDate) .frame(height: 300) } .padding() } var selectedDate: Date? { guard let rawSelectedDate else { return nil } return chartData.first(where: { let endOfDay = $0.date.endOfDay return ($0.date ... endOfDay).contains(rawSelectedDate) })?.date } } #Preview { ContentView() } extension Date { var yesterday: Date { return Calendar.current.date(byAdding: .day, value: -1, to: self)! } var startOfDay: Date { return Calendar.current.startOfDay(for: self) } var endOfDay: Date { var components = DateComponents() components.day = 1 components.second = -1 return Calendar.current.date(byAdding: components, to: startOfDay)! } }
9
1
2.4k
Jul ’23
How do I get the current visible data items in a chart with scrolling enabled via chartScrollableAxes
Does anyone know of to get the currently visible data items in chart (e.g. BarMarks) on iOS 17 when using chartScrollableAxes. From the WWDC23 video of session "Explore pie charts and interactivity in Swift Charts" at time 8:18 you see that the "Total sales" lists the visible time frame (e.g. May 4 - June 4, 2023) and a few seconds late when the chart scrolls the values do update.
0
0
780
Jul ’23
CWWiFiClient scanForNetworks(withSSID: nil) sometimes returns all SSIDs as nil
Hi Quinn, I have a macOS App (SwiftUI) which scans for available WifiNetworks using CWWiFiClient.shared().interface().scanForNetworks(withSSID: nil) The app is sandboxed and has "Outgoing Connections" (Client) checked. The app is Launched via a "LaunchAgents". During app init() I kickoff the scanForNetworks in a background thread. I do receive WifiNetworks but when I look at the SSID quite often all of the SSIDs are nil. If I loop the scanForNetworks() a few times with a delay of 1 second after a few tries the SSIDs will no longer be nil. Any idea why this happens? Should I file a bug report or is that expected behavior Thanks very much, Martin (your old friend from Germany)
3
0
1k
Oct ’23
Swift Chats chartScrollTargetBehavior is not working correctly when domain count is relatively small
I’m seeing a strange behavior when using chartScrollTargetBehavior and trying to scroll to a majorAlignment (.matching(DateComponents(day: 1))). let numberOfBarMarks = 10 .chartXVisibleDomain(length:3600 * 24 * numberOfBarMarks) .chartScrollTargetBehavior( .valueAligned( matching: DateComponents(hour: 0), majorAlignment: .matching(DateComponents(day: 1))) ) ) The issue is fully reproducible. I believe the issue is related to the number of bar marks being displayed in a domain. If I use 10 then the issue shows up, if I use 30 the issue doesn’t happen. Filed as FB13889037 including video and sample code.
0
0
352
Jun ’24