Skip to content

Reconfigure Adigraph interface from NetworkX to Latex#5702

Closed
dschult wants to merge 31 commits intonetworkx:mainfrom
dschult:split_adigraph
Closed

Reconfigure Adigraph interface from NetworkX to Latex#5702
dschult wants to merge 31 commits intonetworkx:mainfrom
dschult:split_adigraph

Conversation

@dschult
Copy link
Copy Markdown
Member

@dschult dschult commented Jun 8, 2022

This builds on PR #5639 and proposes a new interface focusing on

  • to_latex(G, caption, latex_label, as_document=False)
  • write_latex(G, "just_a_figure.tex", caption, latex_label, as_document=False)

I have put it in a separate PR because I want feedback on the interface. I like the functions here, but handling the options for node_color/edge_width/etc feels kludgy.
With two PRs we can more easily compare the two interfaces.

Suggestions?

The Adigraph interface is split into two classes:

  • Adigraph handles a single graph and it's options.
    • ADIG.to_latex_raw()
    • ADIG.to_latex_figure()
    • ADIG.to_latex_document()
  • AdigraphCollection handles multiple graphs to be put into subfigures within a figure.
    • ADIGcoll.to_latex_figure()
    • ADIGcoll.to_latex_document()

LucaCappelletti94 and others added 23 commits September 16, 2019 11:22
vertex -> node,  vertices -> nodes
PEP8 spacing and tabs
pytest function instead of class (class not needed here -- no imports)
Moved author info to CONTRIBUTORS.rst as our new standard
converted list comprehension done for side-effects to for-loop.
switch to f-strings from string-format calls
update setup.py to remove conflicts
Check not multigraph.
Add example
Change variable name `file` to `latex_code`
inline if/else for __init__ setup
Copy link
Copy Markdown
Contributor

@rossbar rossbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only taken a high-level look so far, focusing mostly on the interface options. I definitely like the functional interface with to_latex and write_latex and prefer it to the OO interface of the Adigraph class. In fact, I'd advocate to keep the Adigraph and AdigraphCollection classes private, at least initially. IMO it makes more sense for the user to be able to set the node/edge attributes on the networkx graph objects then use the functions to convert to the LaTeX output rather than introduce new classes with more interfaces for users to learn.

@dschult
Copy link
Copy Markdown
Member Author

dschult commented Jun 10, 2022

I have taken the functional approach for to_latex and write_latex by collapsing the features provided by the Adigraph class into two main functions: to_latex_raw and to_latex. Then adding write_latex to write the results of to_latex into a file provides the entire codebase. The class Adigraph is no longer needed. The features previously provided by the class are split into

  1. to_latex_raw for constructing the latex code to draw the graph using the adigraph latex style file
  2. to_latex which handles multiple graphs in subfigures if needed, and wrapping the results in a figure and possibly document environment.

I think the result is much easier to read and perhaps to understand, though the docs are not checked yet and I'd like to add tests for the many corner cases. Thoughts?

@dschult dschult marked this pull request as ready for review June 15, 2022 13:27
@dschult
Copy link
Copy Markdown
Member Author

dschult commented Jun 20, 2022

I've cleaned up the docs and added more tests. I think this is ready to merge
It's not a full implementation of TikZ graph drawing, but it gives a pretty good framework for most basic stuff and options for some more advanced stuff.

I'm torn between to_latex and generate_latex. Also whether this belongs in the drawing subpackage or the readwrite subpackage.

@dschult
Copy link
Copy Markdown
Member Author

dschult commented Jun 28, 2022

I've updated the LaTeX interface to allow either Adigraph output, or TikZ output.
The default is currently set to TikZ because that doesn't restrict you to only color, width and label attributes.

TikZ allows any valid tikz options, with inputs for

  • options for the tikzpicture environment itself: e.g. [scale=2]
  • options for the \draw command that draws nodes: e.g. [shape=rectangle]
  • options for the scope environment within which the edges are drawn: e.g. [blue,>->,line width=3]
  • options for each node (can override the default values above)
  • options for each edge (can override the default values above)
  • label text for nodes
  • label text for edges
  • options for the style of each edge text label.

I'd like feedback on whether to include both of these, or only the TikZ version. The only advantage I can think of for the adigraph interface is that you can store the values in different attributes on each node or edge. You only get 2 style features: color, width. But you can store them as "blue" and 3 rather than having to store them as a combined single attribute for options: "blue,line width=3".

Also, if anyone has suggestions for TikZ features to add/test that would be cool too.
I'm putting off an implementation that uses the TikZ Graph Library which includes layout routines and is a competitor of GraphViz I guess.

@dschult
Copy link
Copy Markdown
Member Author

dschult commented Dec 6, 2022

I'm going to close this with a redirection to #6238
We can reopen if adigraph is desired/

@dschult dschult closed this Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants