sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.17k stars 2.02k forks source link

Put graphviz objects into a zoom & pan box. #6991

Open Paebbels opened 4 years ago

Paebbels commented 4 years ago

Feature Description

Diagrams generated with embedded Graphviz code or read dot files may be quite large. Zooming and panning will help to navigate in big diagrams. The sphinx.ext.graphviz extension generates diagrams as SVG graphics. SVG graphics are displayed with an object tag in HTML.

Describe the solution you'd like

Added a zoom and pan functionality is quite simple. E.g. the svg-pan-zoom framework could solve it with a few lines of Javascript code:

<object id="demo-tiger" type="image/svg+xml" data="tiger.svg" style="width: 500px; height: 500px; border:1px solid black; ">Your browser does not support SVG</object>

<script>
document.getElementById('my-embed').addEventListener('load', function(){
  // Will get called after embed element was loaded
  svgPanZoom(document.getElementById('my-embed'));
})
</script>

Describe alternatives you've considered There are other Javascript based frameworks offering such a option.

Additional context

This could also be useful with:


/cc: @eine

tk0miya commented 4 years ago

I think Sphinx already provides enough APIs and hooks. So we can make such extension. So -1 for adding it to core.

Paebbels commented 4 years ago

@tk0miya arn't all extensions in namespace sphinx.ext.* part of Sphinx? Thus it's core, right?

tk0miya commented 4 years ago

Yes. I meant I'd not like to add zoom feature to sphinx package. Please add it as your own extension. I suppose you can do it with app.add_js_file() API.

Paebbels commented 4 years ago

This will add the JS file, but it doesn't edit the HTML template.

I don't think it's good to create so many variations of Sphinx.
To create a modified extension I need to:

Other drawbacks:


Adding zooming to Sphinx code base could mean:

If you prefer users to create hundreds of modified extension versions, you you consider two options:

tk0miya commented 4 years ago

TBH, Sphinx project does not have enough resource to maintain Sphinx core. There are still many issues and PRs. So I'd not like to add more new minor feature to Sphinx. I don't think zooming is important feature for all documents. So it is better to implement this as an extension.

In addition, zooming feature is available only in HTML format, right? One of the concept of Sphinx is "one source, multiple output". So I feel strange to add :zoomable: to SVG images. I also afraid adding it to HTML writer causes their children broken (EPUB, HTMLhelp and so on).

I'm ready to add new APIs and libraries if you feel Sphinx is not extensible. What is shortage to realize zooming?

Paebbels commented 4 years ago

If you want to split and distribute work, would it be good to move Sphinx extensions to separate packages or to sphinxcontrib ?

I'm aware of the shortcomings of zooming being HTML-only. Currently, I have no idea for other format. In LaTeX an inner double-page could be use to have a landscape A3 format ... but this is complicated and very specific too ...

On the other hand, many people document sourcecode and big projects with:

These projects mainly need HTML results.

My use cases for bigger SVG images are:

SVG has the ability to be perfectly zoomable.

Example: The following state machine is only drawn by 20%. image

Paebbels commented 4 years ago

@tk0miya where can I ask further questions regarding the graphviz extension?

Based on Sphinx 2.3.1.

Paebbels commented 4 years ago

@tk0miya I have made a forked version of the graphviz extension (see: https://github.com/buildthedocs/sphinx.graphviz)
More over I also needed to fork inheritance_diagram (see https://github.com/buildthedocs/sphinx.inheritance_diagram)

Can you please assist and answer the questions above or should I report some of them as a bug?