Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Opaque background color to drawing #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ When drawing tasks, arckit will intelligently resize all of the grids such that

```python
>>> task = vis.draw_task(train_set[0], width=10, height=6, label='Example')
>>> vis.output_drawing(grid, "images/arcshow_example.png") # svg/pdf/png
>>> vis.output_drawing(task, "images/arcshow_example.png") # svg/pdf/png
```

![Example of arckit output](./images/arcsave_example.png)
Expand Down
10 changes: 9 additions & 1 deletion arckit/vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
'#FFFFFF'
]

bg_color = '#EEEFF6' # White

def draw_grid(grid, xmax=10, ymax=10, padding=.5, extra_bottom_padding=0.5, group=False, add_size=True, label='', bordercol='#111111ff'):
"""
Draws a grid,
Expand Down Expand Up @@ -65,6 +67,12 @@ def draw_grid(grid, xmax=10, ymax=10, padding=.5, extra_bottom_padding=0.5, grou
drawing = drawsvg.Group()
else:
drawing = drawsvg.Drawing(xsize+padding, ysize+padding+extra_bottom_padding, origin=(-0.5*padding, -0.5*padding))
# Add background rectangle first
drawing.append(drawsvg.Rectangle(
-0.5*padding, -0.5*padding, # x, y position with extra padding
xsize+padding, ysize+padding+extra_bottom_padding, # width, height with padding
fill=bg_color # background color `bg_color`
))
drawing.set_pixel_scale(40)
# drawing = drawsvg.Group()
for j, row in enumerate(grid):
Expand Down Expand Up @@ -262,4 +270,4 @@ def output_drawing(d: drawsvg.Drawing, filename: str, context=None):
import cairosvg
cairosvg.svg2pdf(bytestring=buffer.getvalue(), write_to=filename)
else:
raise ValueError(f'Unknown file extension for {filename}')
raise ValueError(f'Unknown file extension for {filename}')