@@ -25,16 +25,26 @@ def draw(self, dr: svgwrite.Drawing, size: XY, offset: XY):
25
25
year_length_style = f"font-size:{ 110 * 3.0 / 80.0 } px; font-family:Arial;"
26
26
month_names_style = f"font-size:2.5px; font-family:Arial"
27
27
total_length_year_dict = self .poster .total_length_year_dict
28
+
29
+ is_align_monday = self .poster .github_style == "align-monday"
28
30
for year in range (self .poster .years .from_year , self .poster .years .to_year + 1 )[
29
31
::- 1
30
32
]:
31
33
start_date_weekday , _ = calendar .monthrange (year , 1 )
32
34
github_rect_first_day = datetime .date (year , 1 , 1 )
33
- # Github profile the first day start from the last Monday of the last year or the first Monday of this year
34
- # It depands on if the first day of this year is Monday or not.
35
- github_rect_day = github_rect_first_day + datetime .timedelta (
36
- - start_date_weekday
37
- )
35
+
36
+ # default GitHub svg style: the start day of each year always aligns with first day.
37
+ github_rect_day = github_rect_first_day
38
+ first_day_weekday = github_rect_first_day .weekday ()
39
+
40
+ if is_align_monday :
41
+ # This is an earlier GitHub style: the start day of each year always aligns with Monday.
42
+ # If you want to use this, please add the command-line argument "--github-style align-monday" .
43
+ github_rect_day = github_rect_first_day + datetime .timedelta (
44
+ - start_date_weekday
45
+ )
46
+ first_day_weekday = 0
47
+
38
48
year_length = total_length_year_dict .get (year , 0 )
39
49
year_length = format_float (self .poster .m2u (year_length ))
40
50
@@ -110,10 +120,19 @@ def draw(self, dr: svgwrite.Drawing, size: XY, offset: XY):
110
120
111
121
rect_x = 10.0
112
122
dom = (2.6 , 2.6 )
123
+
113
124
# add every day of this year for 53 weeks and per week has 7 days
114
125
for i in range (54 ):
115
- rect_y = offset .y + year_size + 2
116
- for j in range (7 ):
126
+ # the first day of the first week of the year may not Monday
127
+ # so we need to skip some empty spaces
128
+ if i == 0 :
129
+ rect_y = offset .y + year_size + 2 + 3.5 * first_day_weekday
130
+ else :
131
+ # the first day of the n week (n >1) must be Monday
132
+ # so set first_day_weekday = 0
133
+ first_day_weekday = 0
134
+ rect_y = offset .y + year_size + 2
135
+ for j in range (7 - first_day_weekday ):
117
136
if int (github_rect_day .year ) > year :
118
137
break
119
138
rect_y += 3.5
0 commit comments