Skip to content

Commit 71d6626

Browse files
author
rmdocherty
committed
added rounding to 1 s.f of abs pf uncertainty and copy text button
1 parent 7fb4cd5 commit 71d6626

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

frontend/src/components/Menu.tsx

+20-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import Table from "react-bootstrap/Table";
1414
import Accordion from 'react-bootstrap/Accordion';
1515
import { getPhaseFraction } from "./imageLogic";
1616

17-
1817
const centreStyle = { display: 'flex', justifyContent: 'space-evenly', alignItems: 'center', marginTop: '1em' }
1918

2019
const _getCSSColour = (currentStateVal: any, targetStateVal: any, successPrefix: string, colourIdx: number): string => {
@@ -168,7 +167,6 @@ const Result = () => {
168167
);
169168

170169
const perErr = analysisInfo?.percentageErr;
171-
const [LB, UB] = [Math.max((1 - perErr! / 100) * phaseFrac, 0), Math.min((1 + perErr! / 100) * phaseFrac, 1)];
172170

173171
const l = analysisInfo?.lForDefaultErr;
174172
const lStr = l?.toFixed(0);
@@ -187,6 +185,15 @@ const Result = () => {
187185
setMenuState('processing');
188186
}
189187

188+
const getDPofSigFig = (decimal: number) => {
189+
const rounded = parseFloat(decimal.toPrecision(1));
190+
const loc = Math.ceil(Math.abs(Math.log10(rounded)));
191+
return loc
192+
}
193+
194+
const absErr = analysisInfo?.absError!
195+
const roundTo = getDPofSigFig(absErr);
196+
190197
const c = colours[selectedPhase];
191198
const headerHex = rgbaToHex(c[0], c[1], c[2], c[3]);
192199

@@ -213,6 +220,11 @@ const Result = () => {
213220
refs.map((r, i) => restyleAccordionHeaders(r, (i == 0)));
214221
}, [selectedPhase])
215222

223+
const beforeBoldText = `The phase fraction in the segmented image is ${phaseFrac.toFixed(3)}. Assuming perfect segmentation, the model proposed by Dahari et al. suggests that `
224+
const boldText = `we can be ${selectedConf}% confident of the true phase fraction being within ${perErr?.toFixed(1)}% of this value (i.e. ${phaseFrac.toFixed(roundTo)}±${(absErr).toFixed(roundTo)})`
225+
const copyText = beforeBoldText + boldText
226+
227+
const copyBtn = () => { navigator.clipboard.writeText(copyText) }
216228

217229
return (
218230
<>
@@ -221,9 +233,12 @@ const Result = () => {
221233
<Accordion.Header ref={pfResultRef}>Phase Fraction Uncertainty</Accordion.Header>
222234
{/*Need to manually overwrite the style here because of werid bug*/}
223235
<Accordion.Body style={{ visibility: "visible" }}>
224-
The <b>bulk phase fraction ϕ is within {perErr?.toFixed(3)}% of your image phase
225-
fraction Φ ({phaseFrac.toFixed(3)}) </b> with {selectedConf}% confidence.
226-
{/*<p><b><i>i.e,</i> {LB.toFixed(3)} ≤ ϕ ≤ {UB.toFixed(3)} with {selectedConf}% confidence.</b></p>*/}
236+
{beforeBoldText}<b>{boldText}</b>
237+
<InputGroup style={{ justifyContent: 'center', marginTop: '1em' }}>
238+
<InputGroup.Text id="btnGroupAddon">Copy:</InputGroup.Text>
239+
<Button variant="outline-secondary" onClick={copyBtn}>text</Button>
240+
<Button variant="outline-secondary">citation</Button>
241+
</InputGroup>
227242
</Accordion.Body>
228243
</Accordion.Item>
229244
<Accordion.Item eventKey="1" >

0 commit comments

Comments
 (0)