powsybl / pypowsybl

A PowSyBl and Python integration based on GraalVM native image
Mozilla Public License 2.0
59 stars 12 forks source link

Ability to display single line diagrams in notebook environment #140

Closed sylvlecl closed 2 years ago

sylvlecl commented 3 years ago

Feature

Single line diagrams can only be exported as SVG files to disk in the python API.

It would be great to be able to visualize the single line diagram, in a jupyter notebook environment, without going through a file on disk.

In order to achieve this, we can :

For the second part, it would be great to be able to zoom in/out, and to drag around the image. We need to investigate if for example plotly or ipywidgets allow to do this with an SVG. jupyter-dash might actually be the most powerful option here, although it brings in a lot of dependencies.

Network inspection in an interactive environment.

geofjamg commented 3 years ago

https://github.com/powsybl/powsybl-single-line-diagram/pull/270 has to be solved before otherwise (I tested!), SVG does not fit correctly in the notebook.

sylvlecl commented 3 years ago

Indeed I've tested too, you need to change the viewbox of the svg element to make it work :( Thanks for the link, good to know that the issue was already logged :)

geofjamg commented 3 years ago

Also an interesting feature, according to https://graphviz.readthedocs.io/en/stable/manual.html#jupyter-notebooks if we return an object that implement _repr_svg_() the notebook automatically display the SVG. So we should return a SvgSingleLineDiagram object in Python from n.get_single_line_diagram('vl1') implementing this method. So we could just write:

sld = n.get_single_line_diagram('vl1')
sld
sylvlecl commented 3 years ago

Then as soon as you want to be able to zoom/drag, some javascript needs to be involved. It looks feasible but needs to write a notebook extension ... Maybe we could try to write a small extension to do this using svg.panzoom.js like in gridsuite, to give this approach a try. Note that this would not be powsybl specific at all!

geofjamg commented 3 years ago

The first part (static image) is ok since #229

sylvlecl commented 2 years ago

Closing the issue since the main feature has been implemented.

We'll create more issues in the future for more dynamic integrations, if there is some demand.