-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
357 lines (311 loc) · 17.4 KB
/
index.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Knottingham</title>
<link rel="icon" href="https://fi-le.net/images/favicon.png">
<meta author content="fi-le">
<meta name="keywords" content="Knot Theory, Knottingham, Knots">
<script type="text/javascript" src="lib/paper.js"></script>
<script type="text/javascript" src="lib/BigInteger.min.js"></script>
<script type="text/javascript" src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script type="text/javascript" src="https://sagecell.sagemath.org/static/embedded_sagecell.js"></script>
<script type="text/javascript" src="js/polynomials.js"></script>
<script type="text/javascript" src="js/knotTools.js"></script>
<script type="text/paperscript" canvas="canvas" src="js/canvas.js"></script>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<div style="text-align:center;">
<div style="margin:0px; padding:0px;">
<canvas id="canvas" width="1000px;" height="450px;"></canvas>
<p style="font-family: monospace;" id="log"></p>
</div>
<div style="margin:1%;">
<div style="display: grid;grid-template-columns: 1.5fr 1fr;align-items: center;">
<p><b>Alexander Polynomial:</b> <span id="alexanderPolynomial"></span></p>
<p style="display:none;" id="jonesContainer"><b>Jones Polynomial:</b> <span id="jonesPolynomial"></span></p>
<p style="display:none;" id="homflyContainer"><b>HOMFLY Polynomial:</b> <span id="homflyPolynomial" style="font-family:monospace;"></span></p>
<p><b>Gauss</b>: <span id="gauss" style="font-family: monospace;"></span> <br> <b>Dowker-Thislethwaite</b>: <span id="dt" style="font-family: monospace;"></span></p>
<p id="candidates-p"><b><!--Candidates with \(<10\) Crossings:--></b> <span id="candidates"></span></p>
</div>
<hr>
<p>
<button type="button" onclick="window.globals.draw(); isomorphy.checked = false; smoothing.checked = false; window.globals.switchIsomorphy(); window.globals.isomorphy = false;"><b>Draw from Scratch</b></button>
<button type="button" onclick="window.globals.select()">Show / Hide Bezier Handles</button>
<button type="button" onclick="window.globals.undo()">Undo</button>
</p>
<p>Force Smoothness: <input id="smoothing" type="checkbox" checked="true" onchange="window.globals.smooth = this.checked;">
| <button type="button" onclick="straighten()">Straighten</button>
<!-- <button type="button" onclick="flatten()">Flatten</button> -->
<button type="button" onclick="window.globals.simplify()">Simplify</button>
<button type="button" onclick="orthogonalise(this, dt.innerHTML, 'DT', 'Orthogonalize', 'Error')" id="orthButton">Orthogonalize (slow)</button> <br>
</p>
<p>Drag Neighboring Points: <input id="dragging" type="checkbox" checked="false" onchange="window.globals.neighbors = this.checked ? 2 : 0;"> | <b>Try reverting Non-Reidemeister moves:</b> <input type="checkbox" id="isomorphy" checked="true", onchange="window.globals.isomorphy = this.checked; window.globals.switchIsomorphy();"></p>
<p>
Additional Invariants, calculated once: <button type="button" onclick="getJones()" id="jonesButton">Jones Polynomial</button>
<button type="button" onclick="getHomfly()" id="homflyButton">HOMFLY Polynomial</button>
</p>
<p><b>Styling:</b><br>
Gap Width: <input type="range" min="2" max="5" value="2" step="0.1" class="slider" onchange="window.globals.gapWidth = this.value; window.globals.updateStyle();"><br>
Stroke Width: <input type="range" min="1" max="10" value="3" step="0.1" class="slider" onchange="window.globals.strokeWidth = this.value; window.globals.updateStyle();"><br>
Show Intersections: <input type="checkbox" id="showIntersections" onchange="window.globals.showIntersections = this.checked;">
Drag Handles Independently: <input type="checkbox" id="dragIndependently" onchange="window.globals.independentHandles = this.checked;">
</p>
<hr>
<p><b>Exporting:</b>
<button type="button" onclick="toSVG();">To SVG</button>
<button type="button" onclick="toJSON();">To JSON</button>
<button type="button" onclick="toTikz(); this.innerHTML='Export to TikZ (Copied to Clipboard!);'">To TikZ</button> <br>
<b>Importing:</b>
<button onclick="orthogonalise(this, dtInput.value, 'DT', 'From DT code:', 'Error: Try again in the format `x y z ...`');">From DT code:</button> <input type="text" id="dtInput" placeholder="4 6 2">
<button onclick="orthogonalise(this, rolfsenInput.value, 'Rolfsen', 'From Rolfsen Table:', 'Error: Try again in the format x_y');">From Rolfsen Table:</button> <input type="text" id="rolfsenInput" placeholder="10_161">
<p>From Knottingham JSON: </p><input type="file" id="file" accept=".JSON,.json,.knottingham"name="Load a Knottingham JSON file" oninput="readJSON(this.files[0])">
</p>
</div>
</div>
<div style="margin:5%;">
<h3>Manual</h3>
<p><b>Knottingham</b> is a tool that lets you draw and manipulate knot diagrams, sporting a clean yet somewhat hand-drawn look. To start knotting away, you may want to follow these steps:</p>
<ul>
<li>Create a knot by:</li>
<ul>
<li>Clicking on segments to add new nodes</li>
<li>Clicking and dragging nodes to move them (you can use 'Drag Neighbors' to rescue nodes from below crossings)</li>
<li>and finally <b>clicking on the (red) crossings to switch them</b> (with "try reverting Non-Reidemeister moves" turned off)</li>
<li>or importing JSON</li>
<li><b>or clicking on 'Drawing' to draw a new knot from scratch</b>!</li>
</ul>
<li>Adjust the knot by:</li>
<ul>
<li>Removing nodes with <b>Shift+Click</b></li>
<li>Smoothing segments with <b>Control+Click</b></li>
<li>Moving, rotating and mirroring the knot with the <b>WASD+EQ+M</b> keys</li>
<li>Undoing with the <b>Z</b> key</li>
<li>Selecting it through the select button and adjust Bezier handles</li>
<li>Creating a <b>minimal-bend diagram</b> on the integer grid with the button "Orthogonalize". You can follow up with:</li>
<li>Forcing smoothness (twice continuous differentiability, to be precise)</li>
<li>Adjusting the style with the sliders</li>
</ul>
<li> Show the knot to your friends by:
<ul>
<li>Exporting it to SVG!</li>
<li>Exporting it to JSON, to be imported back into Knottingham!</li>
<li>Exporting it to TikZ! (Fully customizable, but without crossing Info)</li>
</ul>
</li>
</ul>
Knottingham can also try <b>detecting non-Reidemeister moves</b>! Check the corresponding box and start thinking through knot equivalences. Discontious operations like smoothing or deleting segments might lead to breaking the equivalence.
<h3>How does it work?</h3>
<p>You can read all about that in our preprint about Knottingham <a href="https://arxiv.org/abs/2309.00445">here</a> or the finished paper in the <a href="https://ieeexplore.ieee.org/document/10538424"><i>IEEE Transactions on Visualization and Computer Graphics</i></a>.
If Knottingham helped you with your research or teaching, we are very happy to be cited as
<div style="border: 1px solid; border-radius:15px; background-color: #411; color: rgb(218, 208, 213);">
<code ><pre>
@article{finke2024,
author={Finke, Lennart and Weitz, Edmund},
journal={IEEE Transactions on Visualization and Computer Graphics},
title={A Phenomenological Approach to Interactive Knot Diagrams},
year={2024},
volume={30},
number={8},
pages={5901-5907},
doi={10.1109/TVCG.2024.3405369}}</pre></code>
</div>
</p>
The Jones and HOMFLY polynomial are calculated with <a href="https://sagecell.sagemath.org/">SageCellMath</a>. To help them cover server costs incurred through websites like this, they accept contributions and donations <a href="https://github.com/sponsors/sagemath">here</a>.
<br>
<!--
These features could arrive in a future version:
<ul>
<li>Proven Non-Reidemeister Move-Detection</li>
<li>Some more styling options</li>
<li>Redoing</li>
</ul>
-->
<p>Any and all feedback is appreciated! You can mail to <a href="mailto:developer/at/fi-le.net">developer/at/fi-le.net</a>. <br> Knottingham is open source - you can read and contribute to the code over <a href="https://github.com/file-acomplaint/knottingham">here</a>.</p>
</div>
<script type="text/javascript">
window.globals = {neighbors:0, strokeWidth:5, gapWidth:2, strokeColor:'black', showIntersections:true, independentHandles: false, smooth:false, isomorphy:true};
var polynomial = document.getElementById('alexanderPolynomial');
var jonesPolynomial = document.getElementById('jonesPolynomial');
var candidates = document.getElementById('candidates');
var candidates_p = document.getElementById('candidates-p');
var smoothing = document.getElementById('smoothing');
var dragging = document.getElementById('dragging');
var isomorphy = document.getElementById('isomorphy');
var showIntersections = document.getElementById('showIntersections');
var dragIndependently = document.getElementById('dragIndependently');
var dt = document.getElementById('dt');
var log = document.getElementById('log');
var gauss = document.getElementById('gauss');
var orthButton = document.getElementById('orthButton');
var jonesButton = document.getElementById('jonesButton');
var homflyButton = document.getElementById('homflyButton');
var dtInput = document.getElementById('dtInput');
var rolfsenInput = document.getElementById('rolfsenInput');
isomorphy.checked = smoothing.checked = showIntersections.checked = true;
dragging.checked = dragIndependently.checked = false;
function flatten() {
smoothing.checked = false;
window.globals.flatten();
}
function straighten() {
smoothing.checked = false;
window.globals.straighten();
}
function toTikz() {
var string = window.globals.toTikz();
navigator.clipboard.writeText(string);
}
function readJSON(file) {
const reader = new FileReader();
reader.onload = (e) => {
window.globals.fromJSON(e.target.result);
};
reader.readAsText(file);
}
function toSVG() {
// Kindly provided by users senz, Dave and defghi 1977
// https://stackoverflow.com/questions/23218174/how-do-i-save-export-an-svg-file-after-creating-an-svg-with-d3-js-ie-safari-an
var svg = window.globals.toSVG();
svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
var svgData = svg.outerHTML;
var preface = '<?xml version="1.0" standalone="no"?>\r\n';
var svgBlob = new Blob([preface, svgData], {type:"image/svg+xml;charset=utf-8"});
var svgUrl = URL.createObjectURL(svgBlob);
var downloadLink = document.createElement("a");
downloadLink.href = svgUrl;
downloadLink.download = "knottingham";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}
function toJSON() {
// Many thanks to users bformet and volzoran
// https://stackoverflow.com/questions/19721439/download-json-object-as-a-file-from-browser
var jsonString = window.globals.toJSON();
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(jsonString);
var dl = document.createElement("a");
dl.setAttribute("href", dataStr);
dl.setAttribute("download", "knot.knottingham");
dl.click();
document.body.removeChild(dl);
}
var pyodide = null;
async function getPyodide(display) {
if (pyodide == null) {
display.innerHTML = "loading... [1/7]";
pyodide = await loadPyodide();
display.innerHTML = "loading... [2/7]";
await pyodide.loadPackage("micropip");
display.innerHTML = "loading... [3/7]";
const micropip = pyodide.pyimport("micropip");
await micropip.install("sqlite3");
display.innerHTML = "loading... [4/7]";
await micropip.install('knot_floer_homology-1.2-cp311-cp311-emscripten_3_1_45_wasm32.whl');
display.innerHTML = "loading... [5/7]";
await micropip.install('snappy_manifolds-1.2-py3-none-any.whl');
display.innerHTML = "loading... [6/7]";
await micropip.install('spherogram-2.2.1-cp311-cp311-emscripten_3_1_45_wasm32.whl');
}
}
async function orthogonalise(button, code, codeType, successString, errorString) {
if (window.globals.getNumIntersections() < 3) {
button.innerHTML = ">2 crossings needed.";
return;
}
smoothing.checked = false;
await getPyodide(button);
if (codeType == "DT") {
if (code == "") {
code = "4 6 2";
}
linkString = "DT:[("+code.replaceAll(" ", ", ")+")]";
} else if (codeType == "Rolfsen") {
if (code == "") {
code = "10_161";
}
linkString = code;
}
try {
let geometry = pyodide.runPython(`
from spherogram.links import Link
from spherogram.links.orthogonal import OrthogonalLinkDiagram
from pyodide.ffi import to_js
l = Link("` + linkString + `")
o = OrthogonalLinkDiagram(l)
to_js(o.plink_data())`);
window.globals.fromSnappy(geometry);
button.innerHTML = successString;
} catch(err) {
console.error(err);
button.innerHTML = errorString;
}
}
function runSage(code, callback, display) {
// Using SageMathCell API adapted from
// https://github.com/sagemath/sagecell/blob/master/contrib/sagecell-client/sagecell-service.py
// The right thing to do here would be using
// https://github.com/sagemath/sagecell/blob/master/contrib/sagecell-client/sagecell-client.py
// However, the Javascript Websocket API doesn't allow headers when creating a connection, so the Jupyter-Kernel-ID cannot be sent as intended, resulting in a 403.
retries = 3;
display.innerHTML = "Loading SageCell";
async function executeRequest() {
const url = 'https://sagecell.sagemath.org/service';
const requestBody = {
code: code,
accepted_tos: "true"
};
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams(requestBody)
})
.then(response => response.json())
.then(reply => {
if (reply['success'] && 'stdout' in reply) {
callback(reply['stdout'], display);
} else {
console.log(reply);
if (retries > 0) {
setTimeout(executeRequest, 500);
} else {
display.innerHTML = "Connection to SageCell failed.";
}
}
})
.catch(error => {
console.error(error);
if (retries > 0) {
setTimeout(executeRequest, 500);
} else {
display.innerHTML = "Connection to SageCell failed.";
}
});
}
executeRequest();
}
function getJones() {
const code = 'K = Knots().from_dowker_code([' + dt.innerHTML +'])\nprint(K.jones_polynomial())';
runSage(code,function(result, jonesButton) {
jonesPolynomial.innerHTML = "\\(" + "p_J(t)=" + result.replaceAll("*", "") + "\\)";
if (window.MathJax) {MathJax.typeset();}
document.getElementById('jonesContainer').style.display = "block";
jonesButton.innerHTML = "Refresh Jones Polynomial"
},jonesButton);
}
function getHomfly() {
const code = 'K = Knots().from_dowker_code([' + dt.innerHTML +"])\nprint(K.homfly_polynomial())";
runSage(code,function(result, homflyButton) {
document.getElementById('homflyContainer').style.display = "block";
homflyPolynomial.innerHTML = "p_HOM(M,L)=" + result;
homflyButton.innerHTML = "Refresh HOMFLY Polynomial";
},homflyButton);
}
</script>
<script src="https://cdn.jsdelivr.net/pyodide/v0.24.1/full/pyodide.js"></script>
</body>
</html>