From 326756db695122ee260b3cc758429d6e773b4b9d Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Mon, 16 May 2022 16:47:27 +0200 Subject: [PATCH] fix: add ability to choose trees to comparator too Signed-off-by: Matej Focko --- .pre-commit-config.yaml | 2 +- comparator.html | 141 ++++++++++++++++++++++-------------- comparator_visualization.js | 18 +++++ index.html | 5 -- 4 files changed, 106 insertions(+), 60 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 42fb4b7..4491dac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.2.0 + rev: v4.2.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer diff --git a/comparator.html b/comparator.html index fee8fcd..bf67071 100755 --- a/comparator.html +++ b/comparator.html @@ -2,67 +2,100 @@ - - + + + -
-
- - -
-
- - -
-
+
+
+
+
+
+ +
+
+ +
+
+
- - - - - -
-
-
- -
+
+
+
+ +
+
+ +
+
+
+
- - - - +
+
+
+

Choose left tree:

+
+ + - + + - - - - - + + +
+
+
- - +
+
+

Choose right tree:

+
+ + + + + + + + +
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + diff --git a/comparator_visualization.js b/comparator_visualization.js index c73541d..61fe743 100644 --- a/comparator_visualization.js +++ b/comparator_visualization.js @@ -45,6 +45,24 @@ function deleteCallback() { return false; } +function switchTree(TreeType, side) { + let [lType, rType] = + side == "left" + ? [TreeType, right.constructor] + : [left.constructor, TreeType]; + + left = new lType(); + left.recorder = lRecorder; + + right = new rType(); + right.recorder = rRecorder; + + for (let t of [left, right]) { + t.recorder.clear(); + t.record(); + } +} + async function render() { await Promise.all([ new Promise(() => lRecorder.render()), diff --git a/index.html b/index.html index 9df58c2..2fb3a9f 100755 --- a/index.html +++ b/index.html @@ -2,11 +2,6 @@ - -