[gi-docgen/nielsdg/class-hierarchy-tooltips] Add tooltips to class hierarchy edges




commit 96104c31d16d8073795dfc7bb00ce80f167190b4
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Fri Jan 21 22:42:47 2022 +0100

    Add tooltips to class hierarchy edges
    
    Currently, when hovering over an edge between a class and its ancestor,
    it gives a tooltip similar to `this--ancestor_0`.
    
    This is not really informative and is probably even worse for people
    with screen readers, as they can't see the diagram and can only get
    confused by it.
    
    Replace it with `$TYPE extends $TYPE` or `$TYPE implements $TYPE`.

 gidocgen/gdgenerate.py | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
---
diff --git a/gidocgen/gdgenerate.py b/gidocgen/gdgenerate.py
index 25b1abc..b9398f2 100644
--- a/gidocgen/gdgenerate.py
+++ b/gidocgen/gdgenerate.py
@@ -1521,7 +1521,6 @@ class TemplateClass:
             else:
                 attrs['tooltip'] = other['fqtn']
 
-        ancestors = []
         implements = []
         res = ["graph hierarchy {"]
         res.append("  bgcolor=\"transparent\";")
@@ -1536,6 +1535,8 @@ class TemplateClass:
         }
         this_attrs.update(node_attrs)
         res.append(f"  this [{fmt_attrs(this_attrs)}];")
+
+        # The ancestor classes
         for idx, ancestor in enumerate(self.ancestors):
             node_id = f"ancestor_{idx}"
             ancestor_attrs = {
@@ -1544,8 +1545,16 @@ class TemplateClass:
             ancestor_attrs.update(node_attrs)
             add_link(ancestor_attrs, ancestor, 'class')
             res.append(f"  {node_id} [{fmt_attrs(ancestor_attrs)}];")
-            ancestors.append(node_id)
-        ancestors.reverse()
+        if len(self.ancestors) > 0:
+            ancestors = self.ancestors.copy()
+            ancestors.reverse()
+            for idx, ancestor in enumerate(ancestors[:-1]):
+                 tooltip = f"{self.type_cname} extends {ancestor['type_cname']}"
+                 res.append(f"  ancestor_{idx} -- this [tooltip=\"{tooltip}\"];")
+            tooltip = f"{self.type_cname} extends {ancestors[-1]['type_cname']}"
+            res.append(f"  ancestor_0 -- this [tooltip=\"{tooltip}\"];")
+
+        # The implemented interfaces
         for idx, iface in enumerate(getattr(self, "interfaces", [])):
             node_id = f"implements_{idx}"
             iface_attrs = {
@@ -1556,10 +1565,9 @@ class TemplateClass:
             add_link(iface_attrs, iface, 'iface')
             res.append(f"  {node_id} [{fmt_attrs(iface_attrs)}];")
             implements.append(node_id)
-        if len(ancestors) > 0:
-            res.append("  " + " -- ".join(ancestors) + " -- this;")
         for node in implements:
-            res.append(f"  this -- {node} [style=dotted];")
+            tooltip = f"{self.type_cname} implements {iface['type_cname']}"
+            res.append(f"  this -- {node} [tooltip=\"{tooltip}\" style=dotted];")
         res.append("}")
         return "\n".join(res)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]