@@ -83,18 +83,21 @@ def is_empty_frame(val):
8383 pass
8484
8585#: A nested dictionary controlling the rendering of graph-plots in Jupyter cells,
86- #:
87- #: as those returned from :meth:`.Plottable.plot()` (currently as SVGs).
86+ #:#: as those returned from :meth:`.Plottable.plot()` (currently as SVGs).
8887#: Either modify it in place, or pass another one in the respective methods.
8988#:
89+ #: Any keys ommitted, are taken from :data:`default_jupyter_render` - pass
90+ #: an empty dict(``{}``) if that is not desirable
91+ #: (eg. to revert to panZoom's library's defaults).
92+ #:
9093#: The following keys are supported.
9194#:
9295#: :param svg_pan_zoom_json:
9396#: arguments controlling the rendering of a zoomable SVG in
9497#: Jupyter notebooks, as defined in https://github.com/bumbu/svg-pan-zoom#how-to-use
95- #: if `None`, defaults to string (also maps supported)::
98+ #: if `None`, defaults to this map (json strings also supported)::
9699#:
97- #: "{ controlIconsEnabled: true, fit: true }"
100+ #: {" controlIconsEnabled": True, " fit": True }"
98101#:
99102#: :param svg_element_styles:
100103#: mostly for sizing the zoomable SVG in Jupyter notebooks.
@@ -107,10 +110,10 @@ def is_empty_frame(val):
107110#: like `svg_element_styles`, if `None`, defaults to empty string (also maps supported).
108111#:
109112#: .. note::
110- #: referred also by :rst:dir:`graphtik`'s :confval:`graphtik_zoomable_options`
113+ #: referred also by :rst:dir:`graphtik`'s :confval:`graphtik_zoomable_options`
111114#: default configuration value.
112115default_jupyter_render = {
113- "svg_pan_zoom_json" : "{ controlIconsEnabled: true, fit: true}" ,
116+ "svg_pan_zoom_json" : { " controlIconsEnabled" : True , " fit" : True } ,
114117 "svg_element_styles" : "width: 100%; height: 300px;" ,
115118 "svg_container_styles" : "" ,
116119}
@@ -122,18 +125,20 @@ def _parse_jupyter_render(dot) -> Tuple[str, str, str]:
122125 jupy_cfg = default_jupyter_render
123126
124127 def parse_value (key : str , parser : Callable ) -> str :
125- if key not in jupy_cfg :
126- return parser (default_jupyter_render .get (key , "" ))
128+ val : Union [Mapping , str ] = jupy_cfg .get (key , default_jupyter_render .get (key ))
127129
128- val : Union [Mapping , str ] = jupy_cfg .get (key )
129130 if not val :
130131 val = ""
131132 elif not isinstance (val , str ):
132133 val = parser (val )
133134 return val
134135
135136 def styles_parser (d : Mapping ) -> str :
136- return "" .join (f"{ key } : { val } ;\n " for key , val in d )
137+ try :
138+ return "" .join (f"{ key } : { val } ;\n " for key , val in d )
139+ except Exception as ex :
140+ breakpoint ()
141+ raise ValueError (f"Failed to parse styles { d !r} due to: { ex } " ) from ex
137142
138143 svg_container_styles = parse_value ("svg_container_styles" , styles_parser )
139144 svg_element_styles = parse_value ("svg_element_styles" , styles_parser )
@@ -1817,13 +1822,21 @@ def render_pydot(self, dot: pydot.Dot, filename=None, jupyter_render: str = None
18171822 :seealso: :attr:`.PlotArgs.filename`
18181823 :param jupyter_render:
18191824 a nested dictionary controlling the rendering of graph-plots in Jupyter cells.
1820- If `None`, defaults to :data:`default_jupyter_render`; you may modify those
1825+ If `None`, defaults to :data:`default_jupyter_render`; values for
1826+ ommitted sub-keys are taken also from the above dict - pass an empty dict(``{}``)
1827+ if that is not desirable (eg. to revert to panZoom's library's defaults).
1828+
1829+ You may modify those
18211830 in place and they will apply for all future calls (see :ref:`jupyter_rendering`).
18221831
18231832 You may increase the height of the SVG cell output with
18241833 something like this::
18251834
1826- plottable.plot(jupyter_render={"svg_element_styles": "height: 600px; width: 100%"})
1835+ from graphtik.plot import default_jupyter_render
1836+ plottable.plot(jupyter_render={
1837+ **default_jupyter_render,
1838+ "svg_element_styles": "height: 600px; width: 100%"
1839+ })
18271840 :return:
18281841 the matplotlib image if ``filename=-1``, or the given `dot` annotated with any
18291842 jupyter-rendering configurations given in `jupyter_render` parameter.
0 commit comments