@@ -20,10 +20,14 @@ struct ContentView: View {
2020 . clipShape ( RoundedRectangle ( cornerRadius: 4 ) . inset ( by: 2 ) )
2121 . foregroundStyle ( by: . value( " Count " , contribution. count) )
2222 }
23+ . chartPlotStyle { content in
24+ content
25+ . aspectRatio ( aspectRatio, contentMode: . fit)
26+ }
2327 . chartForegroundStyleScale ( range: Gradient ( colors: colors) )
2428 . chartXAxis {
25- AxisMarks ( position: . top) { value in
26- AxisValueLabel ( )
29+ AxisMarks ( position: . top, values : . stride ( by : . month ) ) {
30+ AxisValueLabel ( format : . dateTime . month ( ) )
2731 . foregroundStyle ( Color ( . label) )
2832 }
2933 }
@@ -38,10 +42,6 @@ struct ContentView: View {
3842 }
3943 }
4044 . chartYScale ( domain: . automatic( includesZero: false , reversed: true ) )
41- . chartPlotStyle { content in
42- content
43- . aspectRatio ( aspectRatio, contentMode: . fit)
44- }
4545 . chartLegend {
4646 HStack ( spacing: 4 ) {
4747 Text ( " Less " )
@@ -61,6 +61,23 @@ struct ContentView: View {
6161
6262 // MARK: - Private
6363
64+ private func weekday( for date: Date ) -> Int {
65+ let weekday = Calendar . current. component ( . weekday, from: date)
66+ let adjustedWeekday = ( weekday == 1 ) ? 7 : ( weekday - 1 )
67+ return adjustedWeekday
68+ }
69+
70+ private var aspectRatio : Double {
71+ if contributions. isEmpty {
72+ return 1
73+ }
74+ let firstDate = contributions. first!. date
75+ let lastDate = contributions. last!. date
76+ let firstWeek = Calendar . current. component ( . weekOfYear, from: firstDate)
77+ let lastWeek = Calendar . current. component ( . weekOfYear, from: lastDate)
78+ return Double ( lastWeek - firstWeek + 1 ) / 7
79+ }
80+
6481 private var colors : [ Color ] {
6582 ( 0 ... 10 ) . map { index in
6683 if index == 0 {
@@ -80,23 +97,6 @@ struct ContentView: View {
8097 shortWeekdaySymbols. append ( sunday)
8198 return shortWeekdaySymbols
8299 } ( )
83-
84- private var aspectRatio : Double {
85- if contributions. isEmpty {
86- return 1
87- }
88- let firstDate = contributions. first!. date
89- let lastDate = contributions. last!. date
90- let firstWeek = Calendar . current. component ( . weekOfYear, from: firstDate)
91- let lastWeek = Calendar . current. component ( . weekOfYear, from: lastDate)
92- return Double ( lastWeek - firstWeek + 1 ) / 7
93- }
94-
95- private func weekday( for date: Date ) -> Int {
96- let weekday = Calendar . current. component ( . weekday, from: date)
97- let adjustedWeekday = ( weekday == 1 ) ? 7 : ( weekday - 1 )
98- return adjustedWeekday
99- }
100100}
101101
102102#Preview( traits: . sizeThatFitsLayout) {
0 commit comments