/
form.html
306 lines (277 loc) · 12.4 KB
/
form.html
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
{% extends "faustedition.html" %}
{% block head %}
<style>
main {
display: flex;
justify-items: center;
flex-direction: column;
width: 100%;
height: calc(100vh - 3.4em);
}
main.vertical {
flex-direction: row;
}
#subgraph-form {
flex-grow: 0;
min-width: 24em;
}
.flex-form {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.vertical > .flex-form {
flex-direction: column;
}
.flex-form fieldset, .flex-form section {
padding: 0 1em;
flex-grow: 1;
}
#refgraph {
text-align: center;
flex-grow: 1;
overflow: auto;
}
button, input, select, textarea {
vertical-align: middle;
}
footer { display: none; }
#header-status {
padding: 5px;
margin-bottom: 0;
}
#subgraph-form p {
margin: 0.5em 0;
}
</style>
{% endblock %}
{% block d3script %}
<script type="application/javascript">
async function updateURLs(query) {
const params = new URLSearchParams(query),
searchString = '?' + params.toString(),
location = new URL(window.location);
if (location.search !== searchString) {
location.search = searchString;
history.replaceState(null, '', location)
try {
const downloadTemplateEl = document.getElementById('download');
const parseContainer = document.createElement('div');
parseContainer.innerHTML = downloadTemplateEl.innerHTML;
const graphDownloadArea = parseContainer.querySelector('#download-graph');
for (const a of graphDownloadArea.getElementsByTagName("a")) {
a.search = searchString;
}
downloadTemplateEl.innerHTML = parseContainer.innerHTML;
} catch (e) {
console.warn(e);
}
}
const breadcrumbElement = document.getElementById('current');
current.innerText = 'Teilgraph: ' + params.get('nodes');
}
function message(msg, severity, long) {
const headerElement = document.getElementById('header-status'),
longMessage = document.getElementById('long-message'),
updating = long? longMessage: headerElement,
other = long? headerElement: longMessage;
if (msg) {
if (!severity)
severity = "info";
updating.innerHTML = msg;
updating.className = "pure-alert pure-alert-" + severity
updating.style.visibility = "visible";
other.style.visibility = "hidden";
} else {
updating.style.visibility = "hidden";
other.style.visibility = "hidden";
}
}
function getFormData() {
const form = document.getElementById('subgraph-form');
return new FormData(form);
}
function setFormData(form, data) {
if (!form) form = document.getElementById('subgraph-form');
if (!data) data = document.location.search;
const entries = (new URLSearchParams(data)).entries();
console.log(form, data, entries);
form.reset();
for (const [key, val] of entries) {
const input = form.elements[key];
if (input) {
if (input.type === 'checkbox')
input.checked = !!val;
else
input.value = val;
}
console.log(form, key, val)
}
}
async function getDotStr(formdata) {
const response = await fetch('subgraph/dot', {method: "POST", body: formdata});
if (response.status === 200)
return await response.text();
else
throw await response.text();
}
const graphviz = d3.select('#refgraph').graphviz({fit: false}),
statusMessages = {
start: "Parse Graphdatei …",
layoutStart: "Berechne Graphlayout …",
renderStart: "Rendere …",
transitionStart: "Überblende neuen Graph …",
end: ""
};
for (const eventType in statusMessages) {
graphviz.on(eventType, () => message(statusMessages[eventType], 'info'));
}
const transitionFactory = () => d3.transition().duration(750);
const updateGraph = function updateGraph() {
const formdata = getFormData(),
main = document.getElementsByTagName('main')[0];
message("Lade aktualisierten Graphen …")
getDotStr(formdata).then(dot => {message("Berechne neues Layout …"); return dot;})
.then(dot => {
graphviz.transition(transitionFactory).renderDot(dot);
})
//.then(() => message())
.catch(reason => {
message(reason, "danger", true)
console.error(reason)
});
updateURLs(formdata);
if (formdata.get('dir').includes('B')) { // vertical layout
main.classList.add('vertical');
} else {
main.classList.remove('vertical');
}
}
const fixNodesField = function fixNodesField(element) {
const origValue = element.value,
query = new URLSearchParams([['nodes', origValue]]).toString();
fetch('subgraph/check-nodes?' + query)
.then(response => response.json())
.then(checkedNodes => {
if (element.value === origValue) { // no change from user in the meantime
element.value = checkedNodes.normalized;
if (checkedNodes.not_found) {
message(checkedNodes.error_msg, 'error');
element.valid = false;
element.title = checkedNodes.error_msg;
} else {
element.valid = true;
element.title = checkedNodes.error_msg;
}
}
})
}
d3.selectAll('#subgraph-form input[type=checkbox], #subgraph-form input[type=radio]').on("click", updateGraph);
d3.selectAll('#subgraph-form select').on("input", updateGraph);
d3.selectAll('#subgraph-form input[type=text]').on("blur", function() {
updateGraph();
fixNodesField(this);
});
document.addEventListener("keypress", function (event) {
if (event.key === "Enter") {
updateGraph();
fixNodesField(this);
}
});
setFormData();
updateGraph();
function contentRequired(formSelector, nonEmptyFieldName) {
const form = document.querySelector(formSelector),
nonEmptyField = form.elements[nonEmptyFieldName],
submitButton = form.querySelector('input[type=submit]'),
checkInput = function() {
if (submitButton)
submitButton.disabled = !nonEmptyField.value; /* ← äußere Variablen */
};
nonEmptyField.addEventListener("input", checkInput);
checkInput();
}
contentRequired('#subgraph-form', 'nodes');
</script>
{% endblock %}
{% block content %}
<p class="pure-alert pure-alert-warning pure-invisible" id="long-message">
Berechne aktualisierten Graphen …
</p>
<div id="refgraph"></div>
<form id="subgraph-form" method="get" class="flex-form pure-form">
<fieldset>
<legend>Zentrale Knoten
<small class="pull-right"><label><input type="checkbox" name="nohl" id="nohl" > nicht hervorheben</label></small>
</legend>
<p><input type="text" name="nodes" id="nodes" value="" style="width: 100%;" placeholder="2 V H.13">
</p>
<p>Pfade dazwischen:
<input type="radio" name="central_paths" value="no" id="ce_no"> <label for="ce_no">keine</label>
<input type="radio" name="central_paths" value="dag" id="ce_dag"> <label for="ce_dag">nur positive</label>
<input type="radio" name="central_paths" value="all" id="ce_all" checked> <label for="ce_all">alle</label>
</p>
<p><input type="checkbox" name="context" id="context" > <label for="context">Nachbarknoten</label></p>
<p><input type="checkbox" name="inscriptions" id="inscriptions" >
<label for="inscriptions">Inskriptionen ↔ Zeugen</label> </p>
<p><input type="checkbox" name="syn" id="syn" > <label for="syn">ungefähr gleichzeitige Knoten</label> </p>
</fieldset>
<fieldset>
<legend>Zusätzliche Pfade</legend>
<p><input type="checkbox" name="abs_dates" id="abs_dates" > <label for="abs_dates">absolute Datierungen rechtfertigen</label></p>
<p><label for="extra">Pfade von/zu (falls verfügbar): </label><br/>
<input type="text" name="extra" id="extra" value="" list="interesting-nodes" placeholder="A, 2 H" style="width: 100%"><br />
<input type="checkbox" name="paths_wo_timeline" id="paths_wo_timeline" > <label for="paths_wo_timeline">ohne Timeline</label>
</p>
{% if models|length > 1 %}
<p>
<label for="model">Modell: </label>
<select id="model" name="model" value="">
{% for model_name in models %}
<option value="{{ model_name }}">{{ model_name }}</option>
{% endfor %}
</select>
</p>
{% endif %}
</fieldset>
<fieldset>
<legend>Kantenauswahl</legend>
<p><input type="checkbox" name="assertions" id="assertions" > <label for="assertions">unmittelbare Aussagen über Kernknoten</label> </p>
<p><input type="checkbox" name="induced_edges" id="induced_edges" > <label for="induced_edges">alle induzierten Kanten</label></p>
<p><input type="checkbox" name="ignored_edges" id="ignored_edges" > <label for="ignored_edges">ignorierte (graue) Kanten</label> </p>
<p><input type="checkbox" name="tred" id="tred" > <label for="tred">Transitive Reduktion</label> </p>
</fieldset>
<fieldset>
<legend>Graphlayout</legend>
<p><input type="checkbox" name="no_edge_labels" id="no_edge_labels" > <label for="no_edge_labels">keine Kantenbeschriftung</label> </p>
<p><input type="checkbox" name="collapse" id="collapse" > <label for="collapse">Parallelkanten zusammenfassen</label> </p>
<p><input type="checkbox" name="order" id="order" > <label for="order">Topologische Sortierung</label></p>
<p style="vertical-align: middle">
Richtung:
<input id="dir-lr" name="dir" type="radio" value="LR" checked> <label for="dir-lr">→</label>
<input id="dir-tb" name="dir" type="radio" value="TB"> <label for="dir-tb">↓</label>
<input id="dir-rl" name="dir" type="radio" value="RL"> <label for="dir-rl">←</label>
<input id="dir-bt" name="dir" type="radio" value="BT"> <label for="dir-bt">↑</label>
</p>
</fieldset>
</form>
<datalist id="interesting-nodes">
<option value="A, 2 H"></option>
<option value="1 H.5, J.1, S, 2 III H.1, H P1, A, H P63, 2 V H.2, C.1 4, C.1 12, 2 H"></option>
</datalist>
{% endblock %}
{%- block title -%}
· Makrogenese-Teilgraph: {{ nodes }}
{%- endblock -%}
{% block download_current %}
<div id="download-graph" class="pure-u-1-3 pure-gap">
<a>aktueller Graph</a>
<a href="subgraph/pdf?{{ query }}"><i class="fa fa-file-pdf"></i> als PDF</a>
<a href="subgraph/dot?{{ query }}"><i class="fa fa-doc-text"></i> als GraphViz .dot</a>
<a href="subgraph/svg?{{ query }}"><i class="fa fa-file-image"></i> als SVG</a>
</div>
{% endblock %}
{% block helpurl %}subgraph/help{% endblock %}
{%- block breadcrumbs -%}
[{caption: 'Makrogenese', link: '/macrogenesis'}, {caption: 'Teilgraph: {{ nodes }}'}]
{%- endblock -%}