Skip to content

Commit

Permalink
added warning if image larger than target
Browse files Browse the repository at this point in the history
  • Loading branch information
rmdocherty committed Jul 8, 2024
1 parent 4513bd6 commit 6522e2d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ const App = () => {
})

if (obj["cls"] > IR_LIMIT_PX) { setShowWarning("cls") }
const minSide = Math.min(imageInfo?.width!, imageInfo?.height!)
if (obj["l"] < minSide) { setShowWarning("over") }

setTargetL(obj["l"]);
} catch (e) {
Expand Down
19 changes: 12 additions & 7 deletions frontend/src/components/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,28 +159,33 @@ const PreviewCanvas = () => {
if (targetL === null) { return; }
const canvas = canvasRef.current!;

const sf = (targetL / imageInfo?.width!); // TODO: FIX WHEN DATA IS REAL
const shortestSide = Math.min(imageInfo?.width!, imageInfo?.height!);
const maxSF = (targetL / shortestSide);

const newCanvL = Math.min(canvDims.h, canvDims.w)

const image = previewImg!
const [ih, iw, ch, cw] = [image.naturalHeight, image.naturalWidth, canvDims.h, canvDims.w];
const correctDims = getAspectCorrectedDims(ih, iw, ch, cw, 0, 0, ADDITIONAL_SF);
// centred-adjusted shift
const dx = (correctDims.w / 2) - (canvDims.w / (2 * sf));
const dy = (correctDims.h / 2) - (canvDims.h / (2 * sf));
const dx = (correctDims.w / 2) - (newCanvL / (2 * maxSF));
const dy = (correctDims.h / 2) - (newCanvL / (2 * maxSF));
// image drawn centred on canvas, need to correct to shift top left of image to top left of div.
const shiftX = -(dx * sf + correctDims.ox);
const shiftY = -(dy * sf + correctDims.oy);
const shiftX = -(dx * maxSF + correctDims.ox);
const shiftY = -(dy * maxSF + correctDims.oy);


console.log(correctDims, dx, dy)
const canvAnim = canvas.animate([
{ transform: `scale(${1 / sf}) translate(${shiftX}px, ${shiftY}px)` },
{ transform: `scale(${1 / maxSF}) translate(${0}px, ${0}px)` },
], {
duration: 1600, //1.6s
iterations: 1, // one shot
fill: 'forwards', // no reset
easing: 'ease-in-out'
})
canvAnim.onfinish = (e) => {
animateDiv(frontDivRef.current!, correctDims.w, correctDims.h)
animateDiv(frontDivRef.current!, newCanvL, newCanvL)
}

}, [targetL])
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/Popups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,21 @@ export const ErrorMessage = () => {
export const CLSModal = () => {
const {
analysisInfo: [analysisInfo,],
errVF: [errVF,],
showWarning: [showWarning, setShowWarning],
} = useContext(AppContext)!;

const hide = () => {
setShowWarning("");
}

const getText = (state: "" | "cls" | "size") => {
const getText = (state: "" | "cls" | "size" | "over") => {
if (state == "cls") {
return `Integral Range/feature size of ${analysisInfo?.integralRange.toFixed(2)} exceeds tested limit of ${IR_LIMIT_PX}px, results may be inaccurate.`
} else if (state == "size") {
return `Image size < 200 px in at least one dimension. Results may be unstable.`
} else if (state == "over") {
return `Image phase fraction uncertainty ${analysisInfo?.percentageErr.toFixed(2)}% already less than target uncertainty ${errVF.toFixed(2)}%`
} else {
return ""
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const AppContextProvider = (props: {
// control flow
const [menuState, setMenuState] = useState<MenuState>('hidden');
const [errorState, setErrorState] = useState<ErrorMessage>({ msg: "", stackTrace: "" });
const [showWarning, setShowWarning] = useState<"" | "cls" | "size">("");
const [showWarning, setShowWarning] = useState<"" | "cls" | "size" | "over">("");
const [showInfo, setShowInfo] = useState<boolean>(false);


Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/interfaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ interface contextProps {
setErrorState: (e: ErrorMessage) => void
];
showWarning: [
showWarning: "" | "cls" | "size",
setShowWarning: (e: "" | "cls" | "size") => void
showWarning: "" | "cls" | "size" | "over",
setShowWarning: (e: "" | "cls" | "size" | "over") => void
]
showInfo: [
showInfo: boolean,
Expand Down

0 comments on commit 6522e2d

Please sign in to comment.