Use class instead of type selector

for memory usage diagrams. This allows a better separation between
different SVG usages.
This commit is contained in:
Carsten Grohmann 2020-04-07 17:26:29 +02:00
parent a8772ab94e
commit d670dbef45
2 changed files with 6 additions and 4 deletions

View File

@ -53,7 +53,7 @@
display: inline-block; display: inline-block;
} }
svg { .mem-usage__svg {
display: block; display: block;
max-height: 200px; max-height: 200px;
} }

View File

@ -1092,13 +1092,14 @@ Killed process 6576 (java) total-vm:33914892kB, anon-rss:20629004kB, file-rss:0k
while element.firstChild: while element.firstChild:
element.removeChild(element.firstChild) element.removeChild(element.firstChild)
def svg_create_element(self, height, width): def svg_create_element(self, height, width, css_class):
"""Return an empty SVG element""" """Return an empty SVG element"""
svg = document.createElementNS(self.svg_namespace, 'svg') svg = document.createElementNS(self.svg_namespace, 'svg')
svg.setAttribute('version', '1.1') svg.setAttribute('version', '1.1')
svg.setAttribute('height', height) svg.setAttribute('height', height)
svg.setAttribute('width', width) svg.setAttribute('width', width)
svg.setAttribute('viewBox', '0 0 {} {}'.format(width, height)) svg.setAttribute('viewBox', '0 0 {} {}'.format(width, height))
svg.setAttribute('class', css_class)
return svg return svg
def svg_create_rect(self, x=0, y=0, width=0, height=0, colour=None): def svg_create_rect(self, x=0, y=0, width=0, height=0, colour=None):
@ -1115,15 +1116,16 @@ Killed process 6576 (java) total-vm:33914892kB, anon-rss:20629004kB, file-rss:0k
rect.setAttribute('fill', colour) rect.setAttribute('fill', colour)
return rect return rect
def svg_generate_bar_chart(self, *elements): def svg_generate_bar_chart(self, css_class, *elements):
"""Generate a SVG bar chart""" """Generate a SVG bar chart"""
bar_height = 100 bar_height = 100
label_height = 80 label_height = 80
length_factor = 4 length_factor = 4
overall_height = bar_height + label_height overall_height = bar_height + label_height
overall_width = 100 * length_factor overall_width = 100 * length_factor
css_class = 'mem-usage__svg'
svg = self.svg_create_element(overall_height, overall_width) svg = self.svg_create_element(overall_height, overall_width, css_class)
sum_all_elements = sum([length for unused, length in elements]) sum_all_elements = sum([length for unused, length in elements])