Skip to content

Commit e1db83c

Browse files
committed
chore: Optimize the Github svg style
1 parent 4b42c49 commit e1db83c

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

.github/workflows/run_data_sync.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,15 @@ jobs:
204204
- name: Make svg GitHub profile
205205
if: env.RUN_TYPE != 'pass'
206206
run: |
207-
python run_page/gen_svg.py --from-db --title "${{ env.TITLE }}" --type github --athlete "${{ env.ATHLETE }}" --special-distance 10 --special-distance2 20 --special-color yellow --special-color2 red --output assets/github.svg --use-localtime --min-distance 0.5
207+
python run_page/gen_svg.py --from-db --title "${{ env.TITLE }}" --type github --github-style align-firstday --athlete "${{ env.ATHLETE }}" --special-distance 10 --special-distance2 20 --special-color yellow --special-color2 red --output assets/github.svg --use-localtime --min-distance 0.5
208+
# if you want use the style:the start day of each year always aligns with Monday. please use the following script:
209+
# python run_page/gen_svg.py --from-db --title "${{ env.TITLE }}" --type github --github-style align-monday --athlete "${{ env.ATHLETE }}" --special-distance 10 --special-distance2 20 --special-color yellow --special-color2 red --output assets/github.svg --use-localtime --min-distance 0.5
208210
python run_page/gen_svg.py --from-db --title "${{ env.TITLE_GRID }}" --type grid --athlete "${{ env.ATHLETE }}" --output assets/grid.svg --special-color yellow --special-color2 red --special-distance 20 --special-distance2 40 --use-localtime --min-distance "${{ env.MIN_GRID_DISTANCE }}"
209211
python run_page/gen_svg.py --from-db --type circular --use-localtime
210-
python run_page/gen_svg.py --from-db --year $(date +"%Y") --language zh_CN --title "$(date +"%Y") Running" --type github --athlete "${{ env.ATHLETE }}" --special-distance 10 --special-distance2 20 --special-color yellow --special-color2 red --output assets/github_$(date +"%Y").svg --use-localtime --min-distance 0.5
212+
python run_page/gen_svg.py --from-db --year $(date +"%Y") --language zh_CN --title "$(date +"%Y") Running" --type github --github-style align-firstday --athlete "${{ env.ATHLETE }}" --special-distance 10 --special-distance2 20 --special-color yellow --special-color2 red --output assets/github_$(date +"%Y").svg --use-localtime --min-distance 0.5
213+
# if you want use the style:the start day of each year always aligns with Monday. please use the following script:
214+
# python run_page/gen_svg.py --from-db --year $(date +"%Y") --language zh_CN --title "$(date +"%Y") Running" --type github --github-style align-monday --athlete "${{ env.ATHLETE }}" --special-distance 10 --special-distance2 20 --special-color yellow --special-color2 red --output assets/github_$(date +"%Y").svg --use-localtime --min-distance 0.5
215+
211216

212217
- name: Save data to parqent
213218
if: env.SAVE_TO_PARQENT == 'true'

run_page/gen_svg.py

+10
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ def main():
180180
help="activities db file",
181181
)
182182

183+
args_parser.add_argument(
184+
"--github-style",
185+
dest="github_style",
186+
metavar="GITHUB_STYLE",
187+
type=str,
188+
default="align-firstday",
189+
help='github svg style; "align-firstday", "align-monday" (default: "align-firstday").',
190+
)
191+
183192
for _, drawer in drawers.items():
184193
drawer.create_args(args_parser)
185194

@@ -244,6 +253,7 @@ def main():
244253
p.drawer_type = "plain" if is_circular else "title"
245254
if args.type == "github":
246255
p.height = 55 + p.years.real_year * 43
256+
p.github_style = args.github_style
247257
# for special circular
248258
if is_circular:
249259
years = p.years.all()[:]

run_page/gpxtrackposter/github_drawer.py

+26-7
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,26 @@ def draw(self, dr: svgwrite.Drawing, size: XY, offset: XY):
2525
year_length_style = f"font-size:{110 * 3.0 / 80.0}px; font-family:Arial;"
2626
month_names_style = f"font-size:2.5px; font-family:Arial"
2727
total_length_year_dict = self.poster.total_length_year_dict
28+
29+
is_align_monday = self.poster.github_style == "align-monday"
2830
for year in range(self.poster.years.from_year, self.poster.years.to_year + 1)[
2931
::-1
3032
]:
3133
start_date_weekday, _ = calendar.monthrange(year, 1)
3234
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+
3848
year_length = total_length_year_dict.get(year, 0)
3949
year_length = format_float(self.poster.m2u(year_length))
4050

@@ -110,10 +120,19 @@ def draw(self, dr: svgwrite.Drawing, size: XY, offset: XY):
110120

111121
rect_x = 10.0
112122
dom = (2.6, 2.6)
123+
113124
# add every day of this year for 53 weeks and per week has 7 days
114125
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):
117136
if int(github_rect_day.year) > year:
118137
break
119138
rect_y += 3.5

run_page/gpxtrackposter/poster.py

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(self):
6060
self.trans = None
6161
self.set_language(None)
6262
self.tc_offset = datetime.now(pytz.timezone("Asia/Shanghai")).utcoffset()
63+
self.github_style = "align-firstday"
6364

6465
def set_language(self, language):
6566
if language:

0 commit comments

Comments
 (0)