From cd832461b6a1c7a37a8772e02d18a0da470dd698 Mon Sep 17 00:00:00 2001 From: Carsten Grohmann Date: Sun, 25 Jul 2021 08:41:57 +0200 Subject: [PATCH] Add tooltips to memory SVGs --- OOMAnalyser.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/OOMAnalyser.py b/OOMAnalyser.py index 99f66c2..87348e1 100644 --- a/OOMAnalyser.py +++ b/OOMAnalyser.py @@ -33,6 +33,9 @@ class document(): def getElementById(self, *arg, **kwargs): return element() + def createElementNS(self, *arg, **kwargs): + return element() + class element(): @@ -1161,7 +1164,8 @@ Killed process 6576 (mysqld) total-vm:33914892kB, anon-rss:20629004kB, file-rss: svg.setAttribute('class', css_class) 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, title=None): + g = document.createElementNS(self.svg_namespace, 'g') rect = document.createElementNS(self.svg_namespace, 'rect') if x: rect.setAttribute('x', x) @@ -1173,7 +1177,12 @@ Killed process 6576 (mysqld) total-vm:33914892kB, anon-rss:20629004kB, file-rss: rect.setAttribute('height', height) if colour: rect.setAttribute('fill', colour) - return rect + if title: + t = document.createElementNS(self.svg_namespace, 'title') + t.textContent = title + g.appendChild(t) + g.appendChild(rect) + return g def svg_generate_bar_chart(self, css_class, *elements): """Generate a SVG bar chart""" @@ -1207,7 +1216,7 @@ Killed process 6576 (mysqld) total-vm:33914892kB, anon-rss:20629004kB, file-rss: colour = self.svg_colours[nr_processed_elements % len(self.svg_colours)] - rect = self.svg_create_rect(current_pos, 0, rect_len, bar_height, colour) + rect = self.svg_create_rect(current_pos, 0, rect_len, bar_height, colour, title) bar_group.appendChild(rect) label_group = document.createElementNS(self.svg_namespace, 'g')