Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A very very rudimentary interactive graph visualization app.
This loads a graph from a zip file and can produce subgraphs via webform
- Loading branch information
Showing
4 changed files
with
95 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import subprocess | ||
|
||
import networkx as nx | ||
from flask import Flask, render_template, request, flash | ||
from markupsafe import Markup | ||
|
||
from macrogen import MacrogenesisInfo, write_dot | ||
from macrogen.graphutils import remove_edges, simplify_timeline | ||
|
||
app = Flask(__name__) | ||
from pathlib import Path | ||
|
||
info = MacrogenesisInfo('target/macrogenesis/macrogen-info.zip') | ||
|
||
@app.route('/') | ||
def hello_world(): | ||
node_str = request.args.get('nodes') | ||
nodes = parse_nodes(node_str) | ||
context = request.args.get('context', False) | ||
abs_dates = request.args.get('abs_dates', False) | ||
extra = parse_nodes(request.args.get('extra', '')) | ||
induced_edges = request.args.get('induced_edges', False) | ||
ignored_edges = request.args.get('ignored_edges', False) | ||
tred = request.args.get('tred', False) | ||
if nodes: | ||
g = info.subgraph(*nodes, context=context, abs_dates=abs_dates, pathes=extra, keep_timeline=True) | ||
if induced_edges: | ||
g = info.base.subgraph(g.nodes).copy() | ||
if not ignored_edges or tred: | ||
g = remove_edges(g, lambda u,v,attr: attr.get('ignore', False)) | ||
if tred: | ||
g = remove_edges(g, lambda u, v, attr: attr.get('delete', False)) | ||
g = simplify_timeline(g) | ||
agraph = write_dot(g, target=None, highlight=nodes[0]) | ||
p = subprocess.run(['dot', '-T', 'svg'], input=agraph.to_string(), capture_output=True, timeout=30, encoding='UTF-8') | ||
svg = Markup(p.stdout) | ||
else: | ||
svg = ':( Keine Knoten' | ||
|
||
|
||
|
||
return render_template('form.html', svg=svg, **request.args) | ||
|
||
|
||
def parse_nodes(node_str): | ||
nodes = [] | ||
if node_str: | ||
for node_spec in node_str.split(','): | ||
try: | ||
nodes.append(info.node(node_spec.strip())) | ||
except KeyError: | ||
... # flash("Knoten »%s« nicht gefunden", node_spec.strip()) | ||
return nodes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="de"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Kontextgraph</title> | ||
</head> | ||
<body> | ||
|
||
{{ svg }} | ||
|
||
<form method="get"> | ||
<p><label for="nodes">Zentrale(r) Knoten: </label><input type="text" name="nodes" id="nodes" value="{{ nodes }}"></p> | ||
<h3>Kontextknoten:</h3> | ||
<p><input type="checkbox" name="context" id="context" {% if context %}checked{% endif %}> <label for="context">Nachbarknoten</label></p> | ||
<p><input type="checkbox" name="abs_dates" id="abs_dates" {% if abs_dates %}checked{% endif %}> <label for="abs_dates">absolute Datierungen rechtfertigen</label></p> | ||
<p><label for="extra">Pfade von/zu (falls verfügbar): </label><input type="text" name="extra" id="extra" value="{{ extra }}"></p> | ||
<h3>Kantenauswahl und -Gestaltung:</h3> | ||
<p><input type="checkbox" name="induced_edges" id="induced_edges" {% if induced_edges %}checked{% endif %}> <label for="induced_edges">alle induzierten Kanten</label></p> | ||
<p><input type="checkbox" name="ignored_edges" id="ignored_edges" {% if ignored_edges %}checked{% endif %}> <label for="ignored_edges">ignorierte (graue) Kanten</label> </p> | ||
<p><input type="checkbox" name="tred" id="tred" {% if tred %}checked{% endif %}> <label for="tred">Transitive Hülle</label> </p> | ||
<p><input type="submit"></p> | ||
</form> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters