Skip to content

Commit

Permalink
working requested min and max
Browse files Browse the repository at this point in the history
  • Loading branch information
tizayi committed Oct 5, 2023
1 parent f6ab2e0 commit fc88d2d
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 67 deletions.
6 changes: 0 additions & 6 deletions src/plot/plotStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ export enum PlotAxes {
pixel = "pixel",
reciprocal = "reciprocal",
}
export enum ScatteringOptions {
q = "q",
s = "s",
d = "d",
twoTheta = `2${'\u03B8'}`
}

export interface PlotConfig {
detector: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/results/rangeDiagram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default function RangeDiagram(props: {
<svg
style={{
display: "grid",
height: "100",
width: "100",
height: "50",
width: "90%",
border: "solid black",
}}
>
Expand Down
262 changes: 208 additions & 54 deletions src/results/resultsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,75 @@ import {
CardContent,
Divider,
FormControl,
Grid,
FormControlLabel,
FormLabel,
InputLabel,
MenuItem,
Paper,
Select,
Stack,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
TextField,
Typography,
} from "@mui/material";
import NumericRange from "../calculations/numericRange";
import { useResultStore } from "./resultsStore";
import { ScatteringOptions, useResultStore } from "./resultsStore";
import { AngleUnits, ReciprocalWavelengthUnits, WavelengthUnits } from "../utils/units";
import { useBeamlineConfigStore } from "../data-entry/beamlineconfigStore";
import RangeDiagram from "./rangeDiagram";
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';



export default function ResultsBar(props: {
visableQRange: NumericRange;
fullQrange: NumericRange;
}): JSX.Element {
const quantityQ = useResultStore(state => state.q);
const quantityS = useResultStore(state => state.s);
const quantityD = useResultStore(state => state.d);
const quantityTheta = useResultStore(state => state.twoTheta);
const resultStore = useResultStore()
const updateQUnits = useResultStore(state => state.updateQUnits);
const updateSUnits = useResultStore(state => state.updateSUnits);
const updateDUnits = useResultStore(state => state.updateDUnits);
const updateThetaUnits = useResultStore(state => state.updateThetaUnits);
const wavelength = useBeamlineConfigStore(state => state.wavelength);

const qRange = new NumericRange(resultStore.q.fromQ(props.visableQRange.min), resultStore.q.fromQ(props.visableQRange.max));
const sRange = new NumericRange(resultStore.s.fromQ(props.visableQRange.min), resultStore.s.fromQ(props.visableQRange.max));
const dRange = new NumericRange(resultStore.d.fromQ(props.visableQRange.min), resultStore.d.fromQ(props.visableQRange.max));
const thetaRange = new NumericRange(resultStore.twoTheta.fromQ(props.visableQRange.min), resultStore.twoTheta.fromQ(props.visableQRange.max));

let ajustedVisibleRange: NumericRange;
let ajustedFullRange: NumericRange;
let ajustedRequestedRange: NumericRange;

switch (resultStore.requested) {
case ScatteringOptions.s:
ajustedVisibleRange = sRange;
ajustedFullRange = new NumericRange(resultStore.s.fromQ(props.fullQrange.min), resultStore.s.fromQ(props.fullQrange.max));
ajustedRequestedRange = new NumericRange(resultStore.s.fromQ(resultStore.requestedRange.min), resultStore.s.fromQ(resultStore.requestedRange.max));
break;
case ScatteringOptions.d:
ajustedVisibleRange = dRange;
ajustedFullRange = new NumericRange(resultStore.d.fromQ(props.fullQrange.min), resultStore.d.fromQ(props.fullQrange.max));
ajustedRequestedRange = new NumericRange(resultStore.d.fromQ(resultStore.requestedRange.min), resultStore.d.fromQ(resultStore.requestedRange.max));
break;
case ScatteringOptions.twoTheta:
ajustedVisibleRange = thetaRange;
ajustedFullRange = new NumericRange(resultStore.twoTheta.fromQ(props.fullQrange.min), resultStore.twoTheta.fromQ(props.fullQrange.max));
ajustedRequestedRange = new NumericRange(resultStore.twoTheta.fromQ(resultStore.requestedRange.min), resultStore.twoTheta.fromQ(resultStore.requestedRange.max));
break;
default:
ajustedVisibleRange = qRange;
ajustedFullRange = new NumericRange(resultStore.q.fromQ(props.fullQrange.min), resultStore.q.fromQ(props.fullQrange.max));
ajustedRequestedRange = new NumericRange(resultStore.q.fromQ(resultStore.requestedRange.min), resultStore.q.fromQ(resultStore.requestedRange.max));
break;
}


return (
<Box sx={{ flexGrow: 2 }}>
Expand All @@ -33,57 +83,161 @@ export default function ResultsBar(props: {
<Divider />
<Stack direction={"row"} spacing={3}>
<Box flexGrow={1}>
<Grid container spacing={0} columns={8}>
<Grid xs={2}>
<Typography>Values</Typography>
<Divider />
<Typography>q</Typography>
<Divider />
<Typography>s</Typography>
<Divider />
<Typography>d</Typography>
<Divider />
<Typography>twoTheta</Typography>
</Grid>
<Grid xs={2}>
<Typography>Min</Typography>
<Divider />
<Typography>{quantityQ.fromQ(props.visableQRange.min).toFixed(4)}</Typography>
<Divider />
<Typography>{quantityS.fromQ(props.visableQRange.min).toFixed(4)}</Typography>
<Divider />
<Typography>{quantityD.fromQ(props.visableQRange.min).toFixed(4)}</Typography>
<Divider />
<Typography>{quantityTheta.fromQ(props.visableQRange.min).toFixed(4)}</Typography>
</Grid>
<Grid xs={2}>
<Typography>Max</Typography>
<Divider />
<Typography>{quantityQ.fromQ(props.visableQRange.max).toFixed(4)}</Typography>
<Divider />
<Typography>{quantityS.fromQ(props.visableQRange.max).toFixed(4)}</Typography>
<Divider />
<Typography>{quantityD.fromQ(props.visableQRange.max).toFixed(4)}</Typography>
<Divider />
<Typography>{quantityTheta.fromQ(props.visableQRange.max).toFixed(4)}</Typography>
</Grid>
<Grid xs={2}>
<Typography>Units</Typography>
<FormControl>
<InputLabel>q</InputLabel>
<Select
size="small"
label="units"
<TableContainer component={Paper}>
<Table sx={{ minWidth: 50 }} aria-label="simple table" size="small">
<TableHead>
<TableRow>
<TableCell>Values</TableCell>
<TableCell align="right">Min</TableCell>
<TableCell align="right">Max</TableCell>
<TableCell align="right">Units</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow
key={"q"}
>
</Select>
</FormControl>
</Grid>
</Grid>
<TableCell component="th" scope="row">q</TableCell>
<TableCell align="right">{qRange.min.toFixed(4)}</TableCell>
<TableCell align="right">{qRange.max.toFixed(4)}</TableCell>
<TableCell align="right">
<FormControl>
<InputLabel>q</InputLabel>
<Select
size="small"
label="units"
value={resultStore.q.units}
onChange={(event) => updateQUnits(event.target.value as ReciprocalWavelengthUnits)}
>
<MenuItem value={ReciprocalWavelengthUnits.nanmometres}>
{ReciprocalWavelengthUnits.nanmometres}
</MenuItem>
<MenuItem value={ReciprocalWavelengthUnits.angstroms}>
{ReciprocalWavelengthUnits.angstroms}
</MenuItem>
</Select>
</FormControl></TableCell>
</TableRow>
<TableRow
key={"things"}
>
<TableCell component="th" scope="row">s</TableCell>
<TableCell align="right">{sRange.min.toFixed(4)}</TableCell>
<TableCell align="right">{sRange.max.toFixed(4)}</TableCell>
<TableCell align="right">
<FormControl>
<InputLabel>s</InputLabel>
<Select
size="small"
label="units"
value={resultStore.s.units}
onChange={(event) => updateSUnits(event.target.value as ReciprocalWavelengthUnits)}
>
<MenuItem value={ReciprocalWavelengthUnits.nanmometres}>
{ReciprocalWavelengthUnits.nanmometres}
</MenuItem>
<MenuItem value={ReciprocalWavelengthUnits.angstroms}>
{ReciprocalWavelengthUnits.angstroms}
</MenuItem>
</Select>
</FormControl></TableCell>
</TableRow>
<TableRow
key={"things"}
>
<TableCell component="th" scope="row">d</TableCell>
<TableCell align="right">{dRange.min.toFixed(4)}</TableCell>
<TableCell align="right">{dRange.max.toFixed(4)}</TableCell>
<TableCell align="right">
<FormControl>
<InputLabel>d</InputLabel>
<Select
size="small"
label="units"
value={resultStore.d.units}
onChange={(event) => updateDUnits(event.target.value as WavelengthUnits)}
>
<MenuItem value={WavelengthUnits.nanmometres}>
{WavelengthUnits.nanmometres}
</MenuItem>
<MenuItem value={WavelengthUnits.angstroms}>
{WavelengthUnits.angstroms}
</MenuItem>
</Select>
</FormControl></TableCell>
</TableRow>
<TableRow
key={"things"}
>
<TableCell component="th" scope="row">two theta</TableCell>
<TableCell align="right">{thetaRange.min.toFixed(4)}</TableCell>
<TableCell align="right">{thetaRange.max.toFixed(4)}</TableCell>
<TableCell align="right">
<FormControl>
<InputLabel>theta</InputLabel>
<Select
size="small"
label="units"
value={resultStore.twoTheta.units}
onChange={(event) => updateThetaUnits(event.target.value as AngleUnits, wavelength ?? 0)}
>
<MenuItem value={AngleUnits.radians}>
{AngleUnits.radians}
</MenuItem>
<MenuItem value={AngleUnits.degrees}>
{AngleUnits.degrees}
</MenuItem>
</Select>
</FormControl>
</TableCell>
</TableRow>
</TableBody>
</Table>
</TableContainer>
</Box>
<Divider orientation="vertical" />
<Box flexGrow={2}>
<Typography>Other side</Typography>
</Box>
<Stack flexGrow={2}>
<Stack spacing={2}>
<Stack direction={"row"} spacing={3}>
<Stack spacing={2}>
<Typography>Requested min {resultStore.requested} value: </Typography>
<Typography>Requested max {resultStore.requested} value: </Typography>
</Stack>
<Stack spacing={1}>
<TextField
type="number"
size="small"
value={resultStore.requestedRange.min}
onChange={(event) => {
resultStore.updateRequestedRange(new NumericRange(parseFloat(event.target.value) ?? 0, resultStore.requestedRange.max))
}}
/>
<TextField
type="number"
size="small"
value={resultStore.requestedRange.max}
onChange={(event) => {
resultStore.updateRequestedRange(new NumericRange(resultStore.requestedRange.min, parseFloat(event.target.value) ?? 1))
}}
/>
</Stack>
<FormControl>
<FormLabel>Requested Quantiy</FormLabel>
<RadioGroup
row
value={resultStore.requested}
onChange={(event) => resultStore.updateRequested(event.target.value as ScatteringOptions)}
>
<FormControlLabel value={ScatteringOptions.q} control={<Radio />} label={ScatteringOptions.q} />
<FormControlLabel value={ScatteringOptions.s} control={<Radio />} label={ScatteringOptions.s} />
<FormControlLabel value={ScatteringOptions.d} control={<Radio />} label={ScatteringOptions.d} />
<FormControlLabel value={ScatteringOptions.twoTheta} control={<Radio />} label={ScatteringOptions.twoTheta} />
</RadioGroup>
</FormControl>
</Stack>
</Stack>
<RangeDiagram visibleQRange={ajustedVisibleRange} fullQRange={ajustedFullRange} requestedRange={ajustedRequestedRange} />
</Stack>
</Stack>
</Stack>
</CardContent>
Expand Down
21 changes: 16 additions & 5 deletions src/results/resultsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,30 +87,41 @@ export class TwoTheta implements ScatteringQuantity {
}
}

export enum ScatteringOptions {
q = "q",
s = "s",
d = "d",
twoTheta = `2${'\u03B8'}`
}


export interface ResultStore {
requested: ScatteringOptions;
q: ScatteringQuantity;
s: ScatteringQuantity;
d: ScatteringQuantity;
twoTheta: ScatteringQuantity;
requestedRange: NumericRange;
updateRequested: (newRange: NumericRange) => void;
updateRequested: (quantity: ScatteringOptions) => void;
updateRequestedRange: (newRange: NumericRange) => void;
updateQUnits: (newunits: ReciprocalWavelengthUnits) => void;
updateSUnits: (newunits: ReciprocalWavelengthUnits) => void;
updateDUnits: (newunits: WavelengthUnits) => void;
updateThetaUnits: (newunits: AngleUnits, wavelength: number) => void;
}

export const useResultStore = create<ResultStore>((set) => ({
requested: ScatteringOptions.q,
q: new Q(ReciprocalWavelengthUnits.nanmometres),
s: new S(ReciprocalWavelengthUnits.nanmometres),
d: new D(WavelengthUnits.nanmometres),
twoTheta: new TwoTheta(AngleUnits.radians, 0),
requestedRange: new NumericRange(0, 1),
updateRequested: (newRange: NumericRange) => { set({ requestedRange: newRange }) },
updateRequested: (quantity: ScatteringOptions) => { set({ requested: quantity }) },
updateRequestedRange: (newRange: NumericRange) => { set({ requestedRange: newRange }) },
updateQUnits: (newunits: ReciprocalWavelengthUnits) => set({ q: new Q(newunits) }),
updateSUnits: (newunits: ReciprocalWavelengthUnits) => set({ q: new S(newunits) }),
updateDUnits: (newunits: WavelengthUnits) => set({ q: new D(newunits) }),
updateThetaUnits: (newunits: AngleUnits, wavelength: number) => set({ q: new TwoTheta(newunits, wavelength) })
updateSUnits: (newunits: ReciprocalWavelengthUnits) => set({ s: new S(newunits) }),
updateDUnits: (newunits: WavelengthUnits) => set({ d: new D(newunits) }),
updateThetaUnits: (newunits: AngleUnits, wavelength: number) => set({ twoTheta: new TwoTheta(newunits, wavelength) })
}));

0 comments on commit fc88d2d

Please sign in to comment.