KeRNeLith / QuikGraph

Generic Graph Data Structures and Algorithms for .NET
https://kernelith.github.io/QuikGraph/
Microsoft Public License
467 stars 69 forks source link

[BUG] graph.ToSvg() not working. (rise4fun is down) #48

Open samvanlier opened 2 years ago

samvanlier commented 2 years ago

I'm trying to use the ToSvg() method to render a graph but it seems that it uses rise4fun.com in the background to do this.

After some digging, I found out that this service has been shut down and will probably not recover (source: https://github.com/Z3Prover/z3/issues/5472).

Is there a plan to create a solution for this?

And in the meantime, are there alternatives for rendering a graph to svg? I would prefer a local solution because I need to render quite a few.

Thanks in advance

KeRNeLith commented 2 years ago

Hello @samvanlier,

Ah, sad news. I always though that replacing this call to a web service by a proper implementation of svg conversion would have been better. That was the same case when Graphviz website certificate has expirated some API of the library were broken, but for this case I already fixed that.

When reworking the library I already had in mind the fact of doing a web independant version of this conversion for several other reasons BTW. So I guess it quite answers you question about plan about this! But the main problem is that I did not managed to get/find an implementation for this scenario. If you have any suggestion on an algorithm that can be re-used or adapted feel free to propose.

Otherwise a possible solution might be to use the graphviz dot executable that if I'm not wrong has a command line to do so.

Hope it helped a bit.

samvanlier commented 2 years ago

Hello @KeRNeLith ,

I used the command line tool of graphviz to fix this problem but that is not a solution that is usable for the nuget because it requires the tool being installed on the machine.

It is my first time using Graphviz so I cannot recommend any idea to solve this issue without using Graphviz locally.

Anyway, thanks for the reply and good luck finding a solution.

KeRNeLith commented 2 years ago

Yeah it requires the tool to be installed indeed, or an alternative would be to create a package that embeds the tool executable. It possible but not ideal, I would prefer having an implementation in the package itself.

I have to admit that I'm pretty stuck too without having an implementation of what's done in the dot executable. It would be certainly nice to kind of make an equivalent implementation in C#. BTW I don't have the sources of the dot executable. So I'm afraid I don't really have solution for now. Deploying a dot executable may be the best compromise for now. Depending on your need and constraint it's possible by the way. I've already seen usage for graph layout in an application that is calling this executable under the hood.

samvanlier commented 2 years ago

I now just call the dot executable from C# giving the Graphviz string as input to convert a graph to a file. It is a hacky solution but requires some work because of the different platforms .Net core/standard needs to support.

I use Mac and accessing command line tools from within C# wasn't easy.

So a implementation in C# would seem the most useful solution.

eosfor commented 2 years ago

Hello @KeRNeLith,

For simplicity and, kind of, being cross-platform I'd perhaps think of using some wrapper around things like vis.js or d3. Throughout the years I haven't seen any .NET-based visualization libraries for graphs, except, perhaps, MSAGL

KeRNeLith commented 2 years ago

@samvanlier I'm totally agree that a C# implementation will always be better in term of portability, practicality and also resilience. That's why I always wanted to replace this web dependent implementation.

I'm not really aware of those solution @eosfor. Do you have some references on them (vis.js and d3) for the scenario we're facing? There is a bridge to MSAGL through the QuikGraph.MSAGL library. BTW I'm not sure there is any conversion to SVG implemented in it. In my knowledge it's mostly for layout.

eosfor commented 2 years ago

Hello @KeRNeLith , here is the example in MSAGL repo. I tried it here

I wonder what dows QuikGraph.MSAGL do?

KeRNeLith commented 2 years ago

@eosfor the QuikGraph.MSAGL is basically a bridging library. I mean it allows to convert from a QuikGraph representation to an MSAGL one. The main relevant implementation you can have a look around this is here. As a summary QuikGraph provide a customizable convertion by hooking events at some point that gives control to user. Other than that, it's basically almost what your example is showcasing indeed.

KeRNeLith commented 2 years ago

@eosfor The implementation of MSAGL bridge may be improved based on the test implementation you gave earlier. But note that it seems we miss the clustering feature.

The best thing would certainly be to get the code that was running behind the rise4fun AGL API, but seems to not be an easy task BTW.

aviatrix commented 2 years ago

This might be of help as a temporary work around for people that want to implement their own .ToSVG : https://kroki.io/ https://github.com/yuzutech/kroki