summaryrefslogtreecommitdiff
path: root/graph/web/legacy.js
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-09-21 21:48:15 -0700
committerCliff Click <cliffc@acm.org>2026-09-21 21:48:15 -0700
commite48d59474230869ba81c1712128c01fd822946f5 (patch)
treedba17d167c2af4b6ca603ee329eb2b3baa8e5617 /graph/web/legacy.js
parente587a11049129866bf3fd6db0a0f72d44ad6b39f (diff)
downloadSimple-e48d59474230869ba81c1712128c01fd822946f5.tar.gz
Simple-e48d59474230869ba81c1712128c01fd822946f5.zip
Switch over to the ELK renderer
Diffstat (limited to 'graph/web/legacy.js')
-rw-r--r--graph/web/legacy.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/graph/web/legacy.js b/graph/web/legacy.js
new file mode 100644
index 00000000..4c1b7ef8
--- /dev/null
+++ b/graph/web/legacy.js
@@ -0,0 +1,25 @@
+// Only earlier chapters need Graphviz. Load it on the first bare-DOT frame.
+let dotView;
+async function drawDot(dot) {
+ if (!dotView) {
+ dotView = (async () => {
+ for (const src of ["vendor/graphviz.umd.js", "vendor/d3-graphviz.js"]) {
+ await new Promise((resolve, reject) => {
+ const script = document.createElement("script");
+ script.src = src; script.onload = resolve;
+ script.onerror = () => reject(new Error("Cannot load " + src));
+ document.head.append(script);
+ });
+ }
+ return new Promise((resolve, reject) => {
+ const view = d3.select("#dot").graphviz({useWorker: false, fit: true})
+ .onerror(reject).on("initEnd", () => resolve(view))
+ .transition(() => d3.transition("main").ease(d3.easeLinear).duration(500));
+ });
+ })();
+ }
+ const view = await dotView;
+ const host = document.getElementById("dot");
+ view.width(host.clientWidth).height(host.clientHeight);
+ await new Promise((resolve, reject) => view.onerror(reject).renderDot(dot, resolve));
+}