preserve ratio on subsequent renders
This commit is contained in:
parent
421b22c106
commit
1dc45b64a6
1 changed files with 9 additions and 9 deletions
|
|
@ -12,6 +12,7 @@ function init(reconnectDelay) {
|
|||
`ws://${window.location.host}${window.location.pathname}watch`
|
||||
);
|
||||
let isInit = true;
|
||||
let ratio;
|
||||
ws.onopen = () => {
|
||||
reconnectDelay = 1000;
|
||||
console.info("watch websocket opened");
|
||||
|
|
@ -33,11 +34,10 @@ function init(reconnectDelay) {
|
|||
// out the width, height and viewbox out of the top level SVG tag and update those manually.
|
||||
d2SVG.innerHTML = msg.svg;
|
||||
|
||||
if (isInit) {
|
||||
const svgEl = d2SVG.querySelector("svg");
|
||||
let width = parseInt(svgEl.getAttribute("width"), 10);
|
||||
let height = parseInt(svgEl.getAttribute("height"), 10);
|
||||
let ratio;
|
||||
if (isInit) {
|
||||
if (width > height) {
|
||||
if (width > window.innerWidth) {
|
||||
ratio = window.innerWidth / width;
|
||||
|
|
@ -46,13 +46,13 @@ function init(reconnectDelay) {
|
|||
ratio = window.innerHeight / height;
|
||||
}
|
||||
// Scale svg fit to zoom
|
||||
isInit = false;
|
||||
}
|
||||
if (ratio) {
|
||||
// body padding is 8px
|
||||
svgEl.setAttribute("width", width * ratio - 16);
|
||||
svgEl.setAttribute("height", height * ratio - 16);
|
||||
}
|
||||
isInit = false;
|
||||
}
|
||||
|
||||
d2ErrDiv.style.display = "none";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue