Skip to content

Commit

Permalink
feat: patch digraph repr to add text/html mimetype
Browse files Browse the repository at this point in the history
  • Loading branch information
jokasimr committed Oct 16, 2023
1 parent 4e29cfa commit c2ac721
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/sciline/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,26 @@
get_origin,
)

from graphviz import Digraph
import graphviz

from .pipeline import Pipeline, SeriesProvider
from .typing import Graph, Item, Key, get_optional


class Digraph(graphviz.Digraph): # type: ignore[misc]
'''Replace the default `_repr_mimebundle_` implementation from graphviz.Digraph.
The default implementation does not return a 'text/html' mimetype.
The 'image/svg+xml' mimetype renders as an <img> node in Jupyter.
We want graphs to render a <svg> node to enable text selection in the graph.
'''

def _repr_mimebundle_(self, *args, **kwargs): # type: ignore[no-untyped-def]
data = super()._repr_mimebundle_(*args, **kwargs)
if 'image/svg+xml' in data:
data['text/html'] = data['image/svg+xml']
return data


@dataclass
class Node:
name: str
Expand Down

0 comments on commit c2ac721

Please sign in to comment.