modelmat / sphinxcontrib-drawio

Sphinx extension for including draw.io files.
MIT License
39 stars 17 forks source link

Add the border parameter in the image definition #101

Open maximeflya opened 4 months ago

maximeflya commented 4 months ago

Is your feature request related to a problem? Please describe. When building my documentation, the distance between my figures and the following line is very small and it doesn't look good.

From the image below, you can see by selecting the image, that the image border is basically the same as the border of the elements

image

Describe the solution you'd like It would be nice to implement the border parameter from drawio in the figure or image definition so that we could write the following code:

.. drawio-figure:: diagrams/program_flow.drawio
    :page-name: action_manager
    :border: 10
    :width: 100%
    :align: center

It should not be too much work as it is already available in the drawio cli:

Usage: drawio [options] [input file/folder]

Options:
  -V, --version                      output the version number
  -c, --create                       creates a new empty file if no file is passed
 [...]
  -b, --border <border>              sets the border width around the diagram (default: 0)
 [...]

Describe alternatives you've considered I briefly tried to change my css config file with the border property similar to what you have here but it did nothing

https://github.com/modelmat/sphinxcontrib-drawio/blob/f962049de5a115042e4352316cb9cc3b82408a56/sphinxcontrib/drawio/drawio.css#L1-L4

If you know how to make this parameter work, that would also be a solution that I am satisfied with. The advantage with the border parameter in the figure definition is that it can be used on a per image basis.

Note When hacking the module's code to add the border parameter, https://github.com/modelmat/sphinxcontrib-drawio/blob/f962049de5a115042e4352316cb9cc3b82408a56/sphinxcontrib/drawio/__init__.py#L305

        drawio_args = [
            binary_path,
            "--export",
            "--crop",
            "--border",
            "20",
            "--page-index",
            page_index,
            *scale_args,
            *extra_args,
            "--format",
            output_format,
            "--output",
            str(export_abspath),
            str(input_abspath),
        ]

I get the desired layout. Interestingly, the border is not applied around the whole image like I would expect. (In my case it is even better this way, but is this a bug from drawio cli?) image

jdillard commented 3 months ago

Nice! Since you've done a little hacking you should try making a PR!

If you know how to make this parameter work, that would also be a solution that I am satisfied with. The advantage with the border parameter in the figure definition is that it can be used on a per image basis.

It would probably be best to add an optional default border config value, and have the parameter override if provided.