Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export graph data #61

Open
rotten opened this issue Feb 17, 2023 · 2 comments
Open

Export graph data #61

rotten opened this issue Feb 17, 2023 · 2 comments

Comments

@rotten
Copy link

rotten commented Feb 17, 2023

Gephi [ https://gephi.org ] is a handy graph visualization tool, as is Graphviz [ https://graphviz.org ]. It would be cool if it were easy to just export the raw graph data here, and then import it a popular graph visualization tool of choice to run graph algorithms on it and study it further.

@rotten
Copy link
Author

rotten commented Feb 17, 2023

FWIW, I was able to grab the raw graph data this tool generates by using the wget command found in issue #49: #49 (comment) and then editing the index.html, and then post-processing it to a format gephi could use. It was more manual work than I had planned, which is why I thought it might make a nice feature.

@meshy
Copy link
Owner

meshy commented Oct 10, 2023

It should be possible to create a view that returns the data in a format you like by taking inspiration from the existing view:

def get_context_data(self, **kwargs):
schema = get_schema()
json_converter = make_json_converter()
kwargs["schema"] = json_converter.dumps(schema)
return super().get_context_data(**kwargs)

In your case, I think you'll want something like:

from cattrs.preconf.json import make_converter as make_json_converter
from django.http import HttpResponse

from schema_graph.schema import get_schema


def schema_json(request):
     schema = get_schema()
     json_converter = make_json_converter()
     schema_json = json_converter.dumps(schema)
     return HttpResponse(schema_json, content_type="application/json")

This example returns the graph data as JSON, but if you want another format you should be able to do that in the view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants