Skip to content

Commit

Permalink
Clean up analysis.py callback
Browse files Browse the repository at this point in the history
  • Loading branch information
WardBrian committed Jul 26, 2024
1 parent afeec3c commit a91f329
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions gui/src/app/Scripting/Analysis/AnalysisPyWindow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FunctionComponent, useCallback, useMemo } from "react";
import { FunctionComponent, RefObject, useCallback, useMemo } from "react";
import { StanRun } from "@SpStanSampler/useStanSampler";
import { FileNames } from "@SpCore/FileMapping";
import { ProjectKnownFiles } from "@SpCore/ProjectDataModel";
Expand Down Expand Up @@ -40,17 +40,7 @@ const AnalysisPyWindow: FunctionComponent<AnalysisWindowProps> = ({
() => ({
onStdout: (x: string) => writeConsoleOutToDiv(consoleRef, x, "stdout"),
onStderr: (x: string) => writeConsoleOutToDiv(consoleRef, x, "stderr"),
onImage: (b64: string) => {
const imageUrl = `data:image/png;base64,${b64}`;

const img = document.createElement("img");
img.style.width = "100%";
img.src = imageUrl;

const divElement = document.createElement("div");
divElement.appendChild(img);
imagesRef.current?.appendChild(divElement);
},
onImage: (b64: string) => addImageToDiv(imagesRef, b64),
onStatus,
}),
[consoleRef, imagesRef, onStatus],
Expand Down Expand Up @@ -92,4 +82,16 @@ const AnalysisPyWindow: FunctionComponent<AnalysisWindowProps> = ({
);
};

const addImageToDiv = (imagesRef: RefObject<HTMLDivElement>, b64: string) => {
const imageUrl = `data:image/png;base64,${b64}`;

const img = document.createElement("img");
img.style.width = "100%";
img.src = imageUrl;

const divElement = document.createElement("div");
divElement.appendChild(img);
imagesRef.current?.appendChild(divElement);
};

export default AnalysisPyWindow;

0 comments on commit a91f329

Please sign in to comment.