viewtopic.php?t=332496

For quick prototyping and interaction with the graph I switched to using JavaScript and made tool work in the browser:

"JavaScript graph library, for embedding and drawing planar graphs in 2D and/or sphere surface"

viewtopic.php?t=333342

Here is an example screen recording of embedding and drawing C30 fullerene, and its dual graph:

Later I created tool "rjs" allowing to run the JavaScript graph library on the command line using nodejs. Because the code needs to run in browser as well, nodejs "require" was no option. So "rjs" (run JavaScript) uses C preprocessor #include instead.

Few days ago I learned that Mathplotlib allows for drawing graphs together with networkx library:

https://twitter.com/HermannSW/status/15 ... 2681232386

Especially the zoom in/out feuture impressed me, and I wanted to get Mathplotlib output for my graph library as well.

That was the start of the Python port of my lib. No drawing yet, but graph embedding, is_embedding(), dual_graph() utllizing "planar_face_traversal()" with "planar_face_traversal_visitor" motivated by Boost graph library already work in Python.

I just did initial commit, one function is missing, and cleanup work (pylint) is not completed:

https://github.com/Hermann-SW/planar_gr ... ain/python

Here is initial demo run:

In previous JavaScript posting I showed how to get rid of need for global variables in Python for use of lambda with "planar_face_traversal_visitor". The trick was to pass 1-element list of integer instead of integer, because that gets passed as reference. The needed increment of integer variable was not only needed in "is_embedding()" described in that posting. So this functions gets used several times now:

https://github.com/Hermann-SW/planar_gr ... py#L12-L13

Code: Select all

```
def incr(arr, i=0):
arr[i] += 1
```

Here is example use in "dual_graph()":

https://github.com/Hermann-SW/planar_gr ... #L206-L216

Code: Select all

```
def dual_graph(G):
last_face = [-1]
D = new_graph(n_faces_planar(G), n_edges(G))
pftv = planar_face_traversal_visitor()
pftv.begin_face = lambda: incr(last_face)
pftv.next_edge = lambda e: new_edge_vertex(D, last_face[0], e)
planar_face_traversal(G, pftv)
return D
```

The design goal of Python lib was to be as similar as possible to JavaScript lib, therefore no camelCase.

Tool rpylint allows for pylint with C includes, and turns off warnings like camelCase that are intentlionally accepted:

https://github.com/Hermann-SW/planar_gr ... on/rpylint

Next, after more cleanup and adding missing "is_same_embedding()" function will be to integrate with Mathplotlib.

networkx graph representation has no representation for edges, that was the reason I ported to "undirected_graph.py".

Initially networkx will be used just to draw graph with ".draw()", with coordinates determined by already implemented in JavaScript code "convex face planar straight line drawing". Later networkx will not be used anymore.

P.S:

Besides drawing with Mathplotlib, output to PostScript directly will be possible as well (the needed code just needs to be ported from JavaScript).