Skip to content
Merged
Show file tree
Hide file tree
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
51 changes: 0 additions & 51 deletions DevLog/Resource/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -979,57 +979,6 @@
}
}
},
"profile_weekday_fri" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Fri"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "금"
}
}
}
},
"profile_weekday_mon" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Mon"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "월"
}
}
}
},
"profile_weekday_wed" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Wed"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "수"
}
}
}
},
"profile_year" : {
"extractionState" : "manual",
"localizations" : {
Expand Down
89 changes: 14 additions & 75 deletions DevLog/UI/Profile/HeatmapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,77 +21,21 @@ struct HeatmapView: View {
weekCounts: quarter.months.map(\.weeks.count)
)

HStack(alignment: .top, spacing: 0) {
weekdayLabel(layout: layout)
HStack(alignment: .top, spacing: layout.monthSpacing) {
ForEach(quarter.months) { month in
MonthCompactHeatmapView(
month: month,
maxCount: maxCount,
layout: layout,
selectedActivityKinds: selectedActivityKinds,
selectedDay: selectedDay,
onSelectDay: onSelectDay
)
}
HStack(alignment: .top, spacing: layout.monthSpacing) {
ForEach(quarter.months) { month in
MonthCompactHeatmapView(
month: month,
maxCount: maxCount,
layout: layout,
selectedActivityKinds: selectedActivityKinds,
selectedDay: selectedDay,
onSelectDay: onSelectDay
)
}
}
.padding(.vertical, 2)
}

@ViewBuilder
private func weekdayLabel(layout: HeatmapLayout) -> some View {
let labels: [Int: String] = [
2: String(localized: "profile_weekday_mon"),
4: String(localized: "profile_weekday_wed"),
6: String(localized: "profile_weekday_fri")
]
let orderedWeekdays = Array(1...7)
let labelFontSize = smallestWeekdayLabelFontSize(
labels: Array(labels.values),
layout: layout
)

VStack(alignment: .leading, spacing: layout.cellSpacing) {
ForEach(orderedWeekdays, id: \.self) { weekday in
if let label = labels[weekday] {
Text(label)
.font(.system(size: labelFontSize))
.allowsTightening(true)
.foregroundStyle(.secondary)
.frame(
width: layout.cellSize,
height: layout.cellSize,
alignment: .leading
)
} else {
Color.clear
.frame(
width: layout.cellSize,
height: layout.cellSize
)
}
}
}
.padding(.top, layout.weekdayTopPadding)
}

private func smallestWeekdayLabelFontSize(labels: [String], layout: HeatmapLayout) -> CGFloat {
let captionFont = UIFont.preferredFont(forTextStyle: .caption2)
let availableWidth = max(layout.cellSize, 1)

let fittedSizes = labels.map { label in
let textWidth = max(
(label as NSString).size(withAttributes: [.font: captionFont]).width,
1
)
let widthRatio = availableWidth / textWidth
return captionFont.pointSize * min(widthRatio, 1)
}

return max((fittedSizes.min() ?? captionFont.pointSize).rounded(.down), 1)
}

private var availableWidth: CGFloat {
// ProfileView의 바깥 가로 패딩(16)과 히트맵 카드 내부 패딩(12)을 합한 값
let horizontalPadding: CGFloat = 16 + 12
Expand Down Expand Up @@ -135,18 +79,13 @@ private struct HeatmapLayout {
let monthTitleSpacing: CGFloat = 6

init(availableWidth: CGFloat, weekCounts: [Int]) {
let sanitizedWeekCounts = weekCounts.filter { 0 < $0 }
let totalColumns = max(sanitizedWeekCounts.reduce(0, +), 1)
let totalColumnSpacings = sanitizedWeekCounts.reduce(0) { partialResult, count in
let totalColumns = max(weekCounts.reduce(0, +), 1)
let totalColumnSpacings = weekCounts.reduce(0) { partialResult, count in
partialResult + max(count - 1, 0)
}
let fixedWidth = monthSpacing * CGFloat(max(sanitizedWeekCounts.count - 1, 0))
let fixedWidth = monthSpacing * CGFloat(max(weekCounts.count - 1, 0))
+ cellSpacing * CGFloat(totalColumnSpacings)
cellSize = max(0, availableWidth - fixedWidth) / CGFloat(totalColumns + 1)
}

var weekdayTopPadding: CGFloat {
cellSize + monthTitleSpacing
cellSize = max(0, availableWidth - fixedWidth) / CGFloat(totalColumns)
Comment thread
opficdev marked this conversation as resolved.
}

var cellCornerRadius: CGFloat {
Expand Down