-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add basic svg image generation support, refactor constants to be uppe…
…rcase
- Loading branch information
Showing
3 changed files
with
64 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import svgwrite | ||
from utils.constants import CAL_SIZE, CSS_STYLES | ||
|
||
|
||
def generate_calendar_svg(units: int, unit_type: str = 'weeks'): | ||
""" | ||
Generate an svg calendar based on the number of weeks | ||
""" | ||
dwg = svgwrite.Drawing('calendar.svg', size=CAL_SIZE) | ||
dwg.viewbox(0, 0, 420, 594) | ||
dwg.defs.add(dwg.style(CSS_STYLES)) | ||
|
||
dwg.add(dwg.rect(size=('100%', '100%'), fill='white', class_='background')) | ||
|
||
def group(classname): | ||
return dwg.add(dwg.g(class_=classname)) | ||
squares = group('square') | ||
|
||
square_size = (8, 8) | ||
cols = 40 | ||
|
||
if unit_type == 'days': | ||
square_size = (1, 1) | ||
cols = 240 | ||
|
||
rows, leftover = divmod(units / cols, 1) | ||
rows = int(rows) + 1 | ||
|
||
for row in range(0, rows): | ||
if row == rows - 1 and leftover != 0: | ||
cols *= leftover | ||
cols = int(cols) | ||
for col in range(0, cols): | ||
xc = col * 10 + 1 | ||
yc = row * 10 + 1 | ||
square = dwg.rect(insert=(xc, yc), size=square_size) | ||
squares.add(square) | ||
|
||
dwg.save() | ||
|
||
|
||
if __name__ == '__main__': | ||
generate_calendar_svg(100) |