Skip to content

Commit

Permalink
Reset zoom on draw to make the widest element visible
Browse files Browse the repository at this point in the history
  • Loading branch information
FeniXb3 committed Jul 29, 2023
1 parent ead342b commit 3feb38c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions public/Alakazam.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,23 @@ export class Alakazam {
}
this.ws.send(JSON.stringify(broadcastData));
}

document.querySelector("#theGraph").setAttribute("width", this.zoomSlider.value);
const nodeElements = document.querySelectorAll(`.node`);
let maximumWidth = 0;
nodeElements.forEach((element) => {
const width = element.getBoundingClientRect().width;
if (width > maximumWidth) {
maximumWidth = width;
}
});

const graphWidth = document.querySelector('#theGraph').getAttribute('width');
const outputContainerWidth = document.querySelector("#output-container").clientWidth ;
const desiredElementhWidth = outputContainerWidth * 0.9;

const desiredGraphWidth = (desiredElementhWidth / maximumWidth) * graphWidth;
this.zoomSlider.value = desiredGraphWidth;

document.querySelector("#theGraph").setAttribute("width", this.zoomSlider.value);
this.startingViewBoxData = document.querySelector('#theGraph').getAttribute('viewBox');
Expand Down

0 comments on commit 3feb38c

Please sign in to comment.