Commit 47b1476d authored by Jérome Perrin's avatar Jérome Perrin

Use pydot to layout the graph

parent 0d5d6bd7
import json
import traceback
import multiprocessing
import pydot
from flask import Flask, jsonify, redirect, url_for
from flask import request
......@@ -16,6 +17,39 @@ def front_page():
return redirect(url_for('static', filename='index.html'))
@app.route("/positionGraph", methods=["POST", "OPTIONS"])
def positionGraph():
"""Uses graphviz to position nodes of the graph.
"""
graph = pydot.Dot()
for node in request.json['element'].itervalues():
graph.add_node(pydot.Node(node['id']))
for successor in node.get('successorList', []):
graph.add_edge(pydot.Edge(node['id'], successor))
new_graph = pydot.graph_from_dot_data(graph.create_dot())
# calulate the ratio from the size of the bounding box
ratio = new_graph.get_bb()
origin_left, origin_top, max_left, max_top = [float(p) for p in
new_graph.get_bb()[1:-1].split(',')]
ratio_top = max_top - origin_top
ratio_left = max_left - origin_left
preference_dict = dict()
for node in new_graph.get_nodes():
# skip technical nodes
if node.get_name() in ('graph', 'node', 'edge'):
continue
left, top = [float(p) for p in node.get_pos()[1:-1].split(",")]
preference_dict[node.get_name()[1:-1]] = dict(
top=1-(top/ratio_top),
left=1-(left/ratio_left),)
return jsonify(preference_dict)
@app.route("/runSimulation", methods=["POST", "OPTIONS"])
def runSimulation():
parameter_dict = request.json['json']
......
......@@ -12,6 +12,8 @@ setup(
'SimPy>=2,<3',
'xlrd',
'xlwt',
'pyparsing==1.5.7',
'pydot',
],
entry_points=("""
[console_scripts]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment