Streak Square Brightness Logic
Nucleic-Session: 129BD35A-FB15-4E39-82E2-F476950F60AD Co-authored-by: Nucleic <[email protected]>
This commit is contained in:
@@ -192,6 +192,9 @@ struct ActivityGrid: View {
|
|||||||
let weekday = cal.component(.weekday, from: today)
|
let weekday = cal.component(.weekday, from: today)
|
||||||
let startOfWeek = cal.date(byAdding: .day, value: -(weekday - 1), to: today)!
|
let startOfWeek = cal.date(byAdding: .day, value: -(weekday - 1), to: today)!
|
||||||
let gridStart = cal.date(byAdding: .day, value: -7 * (weeks - 1), to: startOfWeek)!
|
let gridStart = cal.date(byAdding: .day, value: -7 * (weeks - 1), to: startOfWeek)!
|
||||||
|
// Brightness relative to *this user's* activity, outliers excluded so a few marathon
|
||||||
|
// days don't crush the everyday range. Computed once for the whole grid (mirrors Mac).
|
||||||
|
let scale = ActivityScale(activityByDay: activityByDay)
|
||||||
return HStack(alignment: .top, spacing: gap) {
|
return HStack(alignment: .top, spacing: gap) {
|
||||||
ForEach(0..<weeks, id: \.self) { col in
|
ForEach(0..<weeks, id: \.self) { col in
|
||||||
VStack(spacing: gap) {
|
VStack(spacing: gap) {
|
||||||
@@ -202,7 +205,7 @@ struct ActivityGrid: View {
|
|||||||
RoundedRectangle(cornerRadius: 2)
|
RoundedRectangle(cornerRadius: 2)
|
||||||
.fill(isFuture ? Color.clear
|
.fill(isFuture ? Color.clear
|
||||||
: isFrozen ? Palette.frozen
|
: isFrozen ? Palette.frozen
|
||||||
: Palette.activity(level: Self.level(activityByDay[date] ?? 0)))
|
: Palette.activity(intensity: scale.intensity(for: activityByDay[date] ?? 0)))
|
||||||
.frame(width: cell, height: cell)
|
.frame(width: cell, height: cell)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,13 +213,4 @@ struct ActivityGrid: View {
|
|||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func level(_ count: Int) -> Int {
|
|
||||||
switch count {
|
|
||||||
case 0: 0
|
|
||||||
case 1...2: 1
|
|
||||||
case 3...5: 2
|
|
||||||
default: 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user