subrascasse

Sub Rascasse: an iPhone dive log for Subsurface cloud storage, with a pure-Swift git client (GPL-2.0)
git clone https://git.schurger.org/subrascasse.git
Log | Files | Refs | README | LICENSE

commit c9fe763c24c950d8021c0f6cae73dfa03263c93a
parent 29d004212803942be0a68913dfcba3ec7cc30660
Author: Jean Schurger <jean@schurger.org>
Date:   Sat, 14 Nov 2026 00:32:08 -0500

Statistics: short year labels, horizontal bars aligned at any text size

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K7deYG3yp7VDUZJzSBkvTc

Diffstat:
MApp/Views/StatsView.swift | 44+++++++++++++++++++++++++++-----------------
1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/App/Views/StatsView.swift b/App/Views/StatsView.swift @@ -27,6 +27,8 @@ struct StatsView: View { } .chartYScale(domain: 0...(top * 1.12)) .chartYAxis(.hidden) + // Les étiquettes d'un graphique n'ont pas la place de grossir avec le texte de l'iPhone. + .dynamicTypeSize(...DynamicTypeSize.large) .chartXAxis { AxisMarks { value in AxisValueLabel { @@ -38,22 +40,31 @@ struct StatsView: View { } } - /// Barres horizontales : le nom de la tranche à gauche, le nombre au bout de la barre. + /// Barres horizontales : le nom de la tranche à gauche, le nombre au bout de la barre. Dessinées à la main plutôt + /// qu'avec un graphique : l'étiquette et sa barre restent sur la même ligne quelle que soit la taille du texte. private func rows(_ buckets: [Bucket], label: String) -> some View { - let top = Double(max(buckets.map(\.count).max() ?? 1, 1)) - return Chart(buckets) { bucket in - BarMark(x: .value("Plongées", bucket.count), y: .value(label, bucket.id), height: .fixed(20)) - .foregroundStyle(Color.accentColor.gradient) - .cornerRadius(4) - .annotation(position: .trailing, spacing: 5) { - Text("\(bucket.count)").font(.caption.monospacedDigit().weight(.medium)).foregroundStyle(.secondary) + let top = CGFloat(max(buckets.map(\.count).max() ?? 1, 1)) + return Grid(alignment: .leading, horizontalSpacing: 10, verticalSpacing: 12) { + ForEach(buckets) { bucket in + GridRow { + Text(bucket.name) + .font(.callout) + .lineLimit(1) + .fixedSize() + GeometryReader { geometry in + HStack(spacing: 6) { + RoundedRectangle(cornerRadius: 4, style: .continuous) + .fill(Color.accentColor.gradient) + .frame(width: max(bucket.count > 0 ? 3 : 0, (geometry.size.width - 40) * CGFloat(bucket.count) / top), height: 18) + Text("\(bucket.count)") + .font(.caption.monospacedDigit().weight(.medium)) + .foregroundStyle(.secondary) + .fixedSize() + } + .frame(maxHeight: .infinity, alignment: .center) + } + .frame(minHeight: 22) } - } - .chartXScale(domain: 0...(top * 1.15)) - .chartXAxis(.hidden) - .chartYAxis { - AxisMarks(preset: .extended, position: .leading) { _ in - AxisValueLabel().font(.callout).foregroundStyle(Color.primary) } } } @@ -94,7 +105,8 @@ struct StatsView: View { // Toutes les années de la première à la dernière, y compris celles sans plongée. let counts = Dictionary(grouping: dives, by: { DiveDate.year($0.when) }).mapValues(\.count) let span = (counts.keys.min() ?? 0)...(counts.keys.max() ?? 0) - let years = span.map { Bucket(id: span.count > 10 ? "’" + String(format: "%02d", $0 % 100) : String($0), count: counts[$0] ?? 0) } + // Au-delà de six années, « ’18 » plutôt que « 2018 » : sinon les étiquettes se chevauchent. + let years = span.map { Bucket(id: String($0), count: counts[$0] ?? 0, label: span.count > 6 ? "’" + String(format: "%02d", $0 % 100) : nil) } columns(years, label: "Année") .frame(height: 190) .padding(.vertical, 6) @@ -121,7 +133,6 @@ struct StatsView: View { Bucket(id: "\(Int(Double(index) * step)) à \(Int(Double(index + 1) * step)) \(units.depthUnit)", count: grouped[index]?.count ?? 0) } rows(buckets, label: "Profondeur") - .frame(height: CGFloat(buckets.count) * 36 + 8) .padding(.vertical, 6) .accessibilityLabel("Nombre de plongées par tranche de profondeur") } @@ -132,7 +143,6 @@ struct StatsView: View { let names = ["moins de 15 min", "15 à 30 min", "30 à 45 min", "45 à 60 min", "60 à 75 min", "75 min et plus"] let buckets = (0...(grouped.keys.max() ?? 0)).map { Bucket(id: names[$0], count: grouped[$0]?.count ?? 0) } rows(buckets, label: "Durée") - .frame(height: CGFloat(buckets.count) * 36 + 8) .padding(.vertical, 6) .accessibilityLabel("Nombre de plongées par tranche de durée") }