Skip to content

Commit

Permalink
automatically scale the plot so that it fits the container
Browse files Browse the repository at this point in the history
  • Loading branch information
tuner committed Jan 10, 2025
1 parent e64f4c6 commit c30e7d3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/gui/gui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export function setupGui(
".jellyfish-plot-container"
) as HTMLElement;

const querySvg = () =>
jellyfishGui.querySelector(".jellyfish-plot svg") as SVGElement;

const { generalProps, layoutProps, costWeights } =
getSavedOrDefaultSettings();

Expand All @@ -60,6 +63,7 @@ export function setupGui(
if (controllerStatus === "closed") {
gui.close();
} else if (controllerStatus === "hidden") {
gui.close();
gui.hide();
}

Expand All @@ -81,12 +85,24 @@ export function setupGui(
costWeights
);

generalProps.zoom = 1;
translateX = 0;
translateY = 0;

patientNameElement.textContent = generalProps.patient;

const svg = querySvg();
const containerRect = jellyfishPlotContainer.getBoundingClientRect();

const sufficientZoom = Math.min(
containerRect.width / +svg.getAttribute("width"),
containerRect.height / +svg.getAttribute("height")
);

generalProps.zoom = Math.min(generalProps.zoom, sufficientZoom);

onZoomOrPan();
zoomController.updateDisplay();
};

let patientController: Controller;
Expand Down Expand Up @@ -137,9 +153,6 @@ export function setupGui(
weightsFolder.onChange(onPatientChange);
weightsFolder.close();

const querySvg = () =>
jellyfishGui.querySelector(".jellyfish-plot svg") as SVGElement;

const toolsFolder = gui.addFolder("Tools");
const tools = {
downloadSvg: () =>
Expand Down

0 comments on commit c30e7d3

Please sign in to comment.