From 6a7259c4d53fb45fe67eef19515025a2299b31d2 Mon Sep 17 00:00:00 2001
From: fmk17 <fmk17@inf.ufpr.br>
Date: Wed, 23 Nov 2022 16:30:08 -0300
Subject: [PATCH] =?UTF-8?q?Usa=20requestAnimationFrame=20ao=20inv=C3=A9s?=
 =?UTF-8?q?=20de=20setInterval?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 html/assets/js/script.js | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/html/assets/js/script.js b/html/assets/js/script.js
index 0545a8c..1452bee 100644
--- a/html/assets/js/script.js
+++ b/html/assets/js/script.js
@@ -15,28 +15,16 @@ window.addEventListener("load", function () {
       initInputHandlers(graph);
       let svg = document.querySelector("header svg");
       graph.setOutput(svg).initSvgGraph();
-      // Periodically update graph to create animation
-      const frameIntervalMs = 20;
       window.addEventListener('resize', function() { graph.setOutput(svg); });
-      setInterval(() => {
+      function stepGraph() {
         graph.stepFrame();
         graph.redrawOutput();
-      }, frameIntervalMs);
+        window.requestAnimationFrame(stepGraph);
+      }
+      window.requestAnimationFrame(stepGraph);
     }
     // Sets event handlers for form input elements, and sets configuration variables.
     function initInputHandlers(graph) {
-      function setAndCall(elemId, func) {
-        let handler;
-        let elem = document.getElementById(elemId);
-        if (elem instanceof HTMLInputElement) {
-          handler = () => func(parseFloat(elem.value));
-          elem.oninput = handler;
-        } else if (elem instanceof HTMLSelectElement) {
-          handler = () => func(parseFloat(elem.value));
-          elem.onchange = handler;
-        } else throw new Error("Assertion error");
-        handler();
-      }
       graph.idealNumNodes = 40;
       graph.extraEdgeProportion = 40 / 100;
       graph.radiiWeightPower = 0.8;
-- 
GitLab