forked from ParticipioLabs/graph-ryder-api
/
tulip_layout.py
33 lines (25 loc) · 1.08 KB
/
tulip_layout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import configparser
import os
import tempfile
from flask_restful import Resource, reqparse
from routes.utils import makeResponse
from tulip import *
config = configparser.ConfigParser()
config.read("config.ini")
parser = reqparse.RequestParser()
class GetLayoutAlgorithm(Resource):
def get(self):
return makeResponse(tlp.getLayoutAlgorithmPluginsList(), 200)
class DrawGraph(Resource):
def __init__(self, **kwargs):
self.gid_stack = kwargs['gid_stack']
def get(self, public_gid, layout):
private_gid = self.gid_stack[public_gid]
if not os.path.isfile("%s%s.tlp" % (config['exporter']['tlp_path'], private_gid)):
return makeResponse("Unknow graph id : %s" % public_gid)
tulip_graph = tlp.loadGraph("%s%s.tlp" % (config['exporter']['tlp_path'], private_gid))
tulip_graph.applyLayoutAlgorithm(layout)
path = tempfile.mkstemp()
ds = tlp.getDefaultPluginParameters("SIGMA JSON Export", tulip_graph)
tlp.exportGraph("SIGMA JSON Export", tulip_graph, path[1], ds)
return makeResponse(path[1], 200, True)