@@ -21,77 +21,21 @@ struct HeatmapView: View {
2121 weekCounts: quarter. months. map ( \. weeks. count)
2222 )
2323
24- HStack ( alignment: . top, spacing: 0 ) {
25- weekdayLabel ( layout: layout)
26- HStack ( alignment: . top, spacing: layout. monthSpacing) {
27- ForEach ( quarter. months) { month in
28- MonthCompactHeatmapView (
29- month: month,
30- maxCount: maxCount,
31- layout: layout,
32- selectedActivityKinds: selectedActivityKinds,
33- selectedDay: selectedDay,
34- onSelectDay: onSelectDay
35- )
36- }
24+ HStack ( alignment: . top, spacing: layout. monthSpacing) {
25+ ForEach ( quarter. months) { month in
26+ MonthCompactHeatmapView (
27+ month: month,
28+ maxCount: maxCount,
29+ layout: layout,
30+ selectedActivityKinds: selectedActivityKinds,
31+ selectedDay: selectedDay,
32+ onSelectDay: onSelectDay
33+ )
3734 }
3835 }
3936 . padding ( . vertical, 2 )
4037 }
4138
42- @ViewBuilder
43- private func weekdayLabel( layout: HeatmapLayout ) -> some View {
44- let labels : [ Int : String ] = [
45- 2 : String ( localized: " profile_weekday_mon " ) ,
46- 4 : String ( localized: " profile_weekday_wed " ) ,
47- 6 : String ( localized: " profile_weekday_fri " )
48- ]
49- let orderedWeekdays = Array ( 1 ... 7 )
50- let labelFontSize = smallestWeekdayLabelFontSize (
51- labels: Array ( labels. values) ,
52- layout: layout
53- )
54-
55- VStack ( alignment: . leading, spacing: layout. cellSpacing) {
56- ForEach ( orderedWeekdays, id: \. self) { weekday in
57- if let label = labels [ weekday] {
58- Text ( label)
59- . font ( . system( size: labelFontSize) )
60- . allowsTightening ( true )
61- . foregroundStyle ( . secondary)
62- . frame (
63- width: layout. cellSize,
64- height: layout. cellSize,
65- alignment: . leading
66- )
67- } else {
68- Color . clear
69- . frame (
70- width: layout. cellSize,
71- height: layout. cellSize
72- )
73- }
74- }
75- }
76- . padding ( . top, layout. weekdayTopPadding)
77- }
78-
79- private func smallestWeekdayLabelFontSize( labels: [ String ] , layout: HeatmapLayout ) -> CGFloat {
80- let captionFont = UIFont . preferredFont ( forTextStyle: . caption2)
81- let availableWidth = max ( layout. cellSize, 1 )
82-
83- let fittedSizes = labels. map { label in
84- let textWidth = max (
85- ( label as NSString ) . size ( withAttributes: [ . font: captionFont] ) . width,
86- 1
87- )
88- let widthRatio = availableWidth / textWidth
89- return captionFont. pointSize * min( widthRatio, 1 )
90- }
91-
92- return max ( ( fittedSizes. min ( ) ?? captionFont. pointSize) . rounded ( . down) , 1 )
93- }
94-
9539 private var availableWidth : CGFloat {
9640 // ProfileView의 바깥 가로 패딩(16)과 히트맵 카드 내부 패딩(12)을 합한 값
9741 let horizontalPadding : CGFloat = 16 + 12
@@ -135,18 +79,13 @@ private struct HeatmapLayout {
13579 let monthTitleSpacing : CGFloat = 6
13680
13781 init ( availableWidth: CGFloat , weekCounts: [ Int ] ) {
138- let sanitizedWeekCounts = weekCounts. filter { 0 < $0 }
139- let totalColumns = max ( sanitizedWeekCounts. reduce ( 0 , + ) , 1 )
140- let totalColumnSpacings = sanitizedWeekCounts. reduce ( 0 ) { partialResult, count in
82+ let totalColumns = max ( weekCounts. reduce ( 0 , + ) , 1 )
83+ let totalColumnSpacings = weekCounts. reduce ( 0 ) { partialResult, count in
14184 partialResult + max( count - 1 , 0 )
14285 }
143- let fixedWidth = monthSpacing * CGFloat( max ( sanitizedWeekCounts . count - 1 , 0 ) )
86+ let fixedWidth = monthSpacing * CGFloat( max ( weekCounts . count - 1 , 0 ) )
14487 + cellSpacing * CGFloat( totalColumnSpacings)
145- cellSize = max ( 0 , availableWidth - fixedWidth) / CGFloat( totalColumns + 1 )
146- }
147-
148- var weekdayTopPadding : CGFloat {
149- cellSize + monthTitleSpacing
88+ cellSize = max ( 0 , availableWidth - fixedWidth) / CGFloat( totalColumns)
15089 }
15190
15291 var cellCornerRadius : CGFloat {
0 commit comments