fix(profile): correct heatmap month labels
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
<style>
|
<style>
|
||||||
text { font: 10px -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif; fill: #57606a; }
|
text { font: 10px -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif; fill: #57606a; }
|
||||||
</style>
|
</style>
|
||||||
<text x="30" y="10">Mar</text>
|
<text x="30" y="10">Apr</text>
|
||||||
<text x="78" y="10">May</text>
|
<text x="78" y="10">May</text>
|
||||||
<text x="138" y="10">Jun</text>
|
<text x="138" y="10">Jun</text>
|
||||||
<text x="186" y="10">Jul</text>
|
<text x="186" y="10">Jul</text>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
BIN
scripts/__pycache__/generate_heatmap_svg.cpython-314.pyc
Normal file
BIN
scripts/__pycache__/generate_heatmap_svg.cpython-314.pyc
Normal file
Binary file not shown.
@@ -55,18 +55,30 @@ def weekday_row(day):
|
|||||||
return (day.weekday() + 1) % 7
|
return (day.weekday() + 1) % 7
|
||||||
|
|
||||||
|
|
||||||
def month_labels(start, end):
|
def month_labels(grid_start, visible_start, grid_end):
|
||||||
labels = [(0, start.strftime("%b"))]
|
labels = []
|
||||||
total_weeks = ((end - start).days // 7) + 1
|
total_weeks = ((grid_end - grid_start).days // 7) + 1
|
||||||
|
|
||||||
for week in range(total_weeks):
|
for week in range(total_weeks):
|
||||||
week_start = start + timedelta(days=week * 7)
|
week_start = grid_start + timedelta(days=week * 7)
|
||||||
|
week_label = None
|
||||||
|
|
||||||
for offset in range(7):
|
for offset in range(7):
|
||||||
day = week_start + timedelta(days=offset)
|
day = week_start + timedelta(days=offset)
|
||||||
if day.day == 1 and week != 0:
|
if day < visible_start:
|
||||||
labels.append((week, day.strftime("%b")))
|
continue
|
||||||
|
|
||||||
|
if week == 0 and week_label is None:
|
||||||
|
week_label = day.strftime("%b")
|
||||||
|
|
||||||
|
if day.day == 1:
|
||||||
|
week_label = day.strftime("%b")
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if week_label is not None:
|
||||||
|
if not labels or labels[-1][1] != week_label:
|
||||||
|
labels.append((week, week_label))
|
||||||
|
|
||||||
return labels
|
return labels
|
||||||
|
|
||||||
|
|
||||||
@@ -108,7 +120,7 @@ def generate_svg(data):
|
|||||||
'</style>',
|
'</style>',
|
||||||
]
|
]
|
||||||
|
|
||||||
for week, label in month_labels(aligned_start, aligned_end):
|
for week, label in month_labels(aligned_start, start, aligned_end):
|
||||||
x = LEFT_PAD + (week * CELL)
|
x = LEFT_PAD + (week * CELL)
|
||||||
svg.append(f'<text x="{x}" y="10">{label}</text>')
|
svg.append(f'<text x="{x}" y="10">{label}</text>')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user