From a89df10d92989ebdecc7aac31f65222a83870b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20M=C3=A9ndez?= Date: Fri, 22 Nov 2024 12:34:09 +0100 Subject: [PATCH] highlighting linear plots --- .../public/js/proof/rules/cd/diff/diff.js | 2 +- .../public/js/proof/rules/cd/linear/linear.js | 419 ++++++++++-------- frontend/public/js/proof/rules/rules.js | 9 +- 3 files changed, 251 insertions(+), 179 deletions(-) diff --git a/frontend/public/js/proof/rules/cd/diff/diff.js b/frontend/public/js/proof/rules/cd/diff/diff.js index 98ae602..5e61334 100644 --- a/frontend/public/js/proof/rules/cd/diff/diff.js +++ b/frontend/public/js/proof/rules/cd/diff/diff.js @@ -565,7 +565,7 @@ export class DifferenceCD { cy.nodes().forEach(d => { d.data({v: d.data().og}) }) - animateNegativeCycle(cy, { nid: params.manual.id}) + animateNegativeCycle(cy, { nid: params.manual.id }) } const varInput = document.getElementById('var-input') varInput.value = ""; diff --git a/frontend/public/js/proof/rules/cd/linear/linear.js b/frontend/public/js/proof/rules/cd/linear/linear.js index ec6e9c7..4230cc4 100644 --- a/frontend/public/js/proof/rules/cd/linear/linear.js +++ b/frontend/public/js/proof/rules/cd/linear/linear.js @@ -1,5 +1,6 @@ import { controls, createVisContainer } from "../cd-rules.js"; import { utils } from "../../rules.js"; +import { throttle } from "../../../../utils/throttle.js"; function f(number) { return Fraction(number).toFraction(); @@ -8,16 +9,27 @@ function f(number) { const tip = { xLine: true, yLine: true, - renderer: (_, __, i) => { } + renderer: throttle((x, y) => { + d3.selectAll(".text-eq").classed("hl-text", false); + Object.keys(hl).forEach(d => { + if (hl[d].evaluate({x, y})) { + d3.select(`#eq-${d}`).classed("hl-text", true); + //console.log(`x:${x}, y:${x} intersects with: ${d}`); + } + }) + }, 50) }; const premiseColor = '#80cbc4'; const conclusionColor = '#b89aef'; const plot = 'cd-linear-plot'; -let struct = {}; -let vars = []; -let frees = []; +let struct = {}; // copy of the node/subproof data +let vars = []; // list of variables. The order of this list determines the order of the solutions, which allows us to "target" which variables will be free in case of infinite solutions. +let frees = []; // the indices of this list correspond to the ids of the dropdowns to select free variables +let hl = {}; // correspondence between equation ids from `struct` and the plotter line (svg) that should be altered when highlighting occurs + +// gaussian elimination using Fraction.js function solve(data) { function solveEquations(systemInput, singleInput) { function extractSolutions(matrix, tolerance, solutionType) { @@ -184,8 +196,8 @@ function vis(plot, solution) { container.appendChild(vis); } - vis.innerHTML = ` -
+ vis.innerHTML = + `