Add parameter for svg viewer to be able to generate pictures which are not get cropped
This commit is contained in:
parent
62ccd164ff
commit
5661ea5945
@ -30,16 +30,29 @@ class SVGViewer(object):
|
|||||||
|
|
||||||
PALETTE = ['#666547', '#fb2e01', '#6fcb9f', '#ffe28a', '#b9feb3',
|
PALETTE = ['#666547', '#fb2e01', '#6fcb9f', '#ffe28a', '#b9feb3',
|
||||||
'#404040', '#4cc3d9', '#7bc8a4', '#ffc65d', '#f16745']
|
'#404040', '#4cc3d9', '#7bc8a4', '#ffc65d', '#f16745']
|
||||||
DISK_HEIGHT = 3 * cm
|
DISK_HEIGHT = 2 * cm
|
||||||
SPACE_HEIGHT = 3 * cm
|
SPACE_HEIGHT = 2 * cm
|
||||||
WIDTH_MULTIPLIER = 10
|
DISKS_INTERVAL = 110
|
||||||
DISKS_INTERVAL = 150
|
|
||||||
SPACES_X_INTERVAL = 2
|
SPACES_X_INTERVAL = 2
|
||||||
STYLE = "fill:{color};stroke:black;stroke-width:5;"
|
STYLE = "fill:{color};stroke:black;stroke-width:5;"
|
||||||
|
|
||||||
def __init__(self, disks_spaces_mapping, file_path='/tmp/bareon.svg'):
|
def __init__(self, disks_spaces_mapping, file_path='/tmp/bareon.svg', fit=False):
|
||||||
self.disks_spaces_mapping = disks_spaces_mapping
|
self.disks_spaces_mapping = disks_spaces_mapping
|
||||||
self.dwg = svgwrite.Drawing(filename=file_path, debug=True)
|
max_disk_size = max([i['size'] for i in disks_spaces_mapping])
|
||||||
|
self.width_multiplier = 450.0 / max_disk_size
|
||||||
|
|
||||||
|
svg_height = len(disks_spaces_mapping) * (self.DISKS_INTERVAL + 10)
|
||||||
|
svg_width = self.width_multiplier * max_disk_size + 200
|
||||||
|
options = {}
|
||||||
|
if fit:
|
||||||
|
options = {
|
||||||
|
'preserveAspectRatio': 'none',
|
||||||
|
'viewBox': "0 0 {0} {1}".format(svg_width, svg_height) if fit else '0 0 maxY maxX'}
|
||||||
|
|
||||||
|
self.dwg = svgwrite.Drawing(
|
||||||
|
filename=file_path,
|
||||||
|
debug=True,
|
||||||
|
**options)
|
||||||
|
|
||||||
def show_me(self):
|
def show_me(self):
|
||||||
self._add_disk_with_spaces()
|
self._add_disk_with_spaces()
|
||||||
@ -60,7 +73,7 @@ class SVGViewer(object):
|
|||||||
style=self.STYLE.format(color='#f5f5f5'),
|
style=self.STYLE.format(color='#f5f5f5'),
|
||||||
ry=5,
|
ry=5,
|
||||||
rx=5,
|
rx=5,
|
||||||
size=(self.WIDTH_MULTIPLIER * disk_w_spaces['size'],
|
size=(self.width_multiplier * disk_w_spaces['size'],
|
||||||
self.DISK_HEIGHT)))
|
self.DISK_HEIGHT)))
|
||||||
|
|
||||||
last_insert = [0, 0]
|
last_insert = [0, 0]
|
||||||
@ -72,13 +85,13 @@ class SVGViewer(object):
|
|||||||
rx=5,
|
rx=5,
|
||||||
id=space['space_id'],
|
id=space['space_id'],
|
||||||
insert=last_insert,
|
insert=last_insert,
|
||||||
size=(self.WIDTH_MULTIPLIER * space['size'], self.SPACE_HEIGHT)))
|
size=(self.width_multiplier * space['size'], self.SPACE_HEIGHT)))
|
||||||
|
|
||||||
last_insert[0] += self.WIDTH_MULTIPLIER * space['size']
|
last_insert[0] += self.width_multiplier * space['size']
|
||||||
|
|
||||||
spaces_lines = ['{0} size={1}'.format(space['space_id'], space['size']) for space in disk_w_spaces['spaces']]
|
spaces_lines = ['{0} size={1}'.format(space['space_id'], space['size']) for space in disk_w_spaces['spaces']]
|
||||||
|
|
||||||
last_insert[0] = self.WIDTH_MULTIPLIER * disk_w_spaces['size']
|
last_insert[0] = self.width_multiplier * disk_w_spaces['size']
|
||||||
last_insert[0] += 10
|
last_insert[0] += 10
|
||||||
last_insert[1] += 20
|
last_insert[1] += 20
|
||||||
for space_idx, space_line in enumerate(spaces_lines):
|
for space_idx, space_line in enumerate(spaces_lines):
|
||||||
|
Loading…
Reference in New Issue
Block a user