Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions src/WrapperApp/components/Results/EstimatorTab/EstimatorTab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { Box, Card, CardContent, CircularProgress } from '@mui/material';

import { generateGraphs } from '../../../../JsRoot/GraphData';
import { FullSimulationData } from '../../../../services/ShSimulatorService';
import { TabPanel } from '../../Panels/TabPanel';
import { EstimatorResults } from '../ResultsPanel';
import TablePage0D from '../ResultsTable';

interface EstimatorTabProps {
estimator: EstimatorResults;
tabsValue: number;
resultsGeneratedFromProjectFile: boolean;
groupQuantities: boolean;
simulation: FullSimulationData;
}

const EstimatorTab = ({
estimator,
tabsValue,
resultsGeneratedFromProjectFile,
groupQuantities,
simulation
}: EstimatorTabProps) => {
return (
<Card
variant='outlined'
sx={{
'flexGrow': 1,
'margin': '0.5rem',
'bgcolor': theme =>
theme.palette.mode === 'dark' ? 'text.disabled' : 'background.paper',
'& .MuiCardContent-root div': {
bgcolor: 'transparent',
backgroundImage: 'none',
color: 'black'
}
}}>
{!estimator ? (
<Box
sx={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: '100vh'
}}>
<CircularProgress />
</Box>
) : (
<CardContent>
<TabPanel
key={`tab_panel_${estimator.name}_${tabsValue}`}
value={tabsValue}
index={tabsValue}
persistentIfVisited>
<Box
style={{
width: '100%',
display: 'flex',
flexDirection: 'column'
}}>
{estimator.tablePages.length > 0 && (
<TablePage0D estimator={estimator}></TablePage0D>
)}
{generateGraphs(
estimator,
resultsGeneratedFromProjectFile && groupQuantities,
simulation?.jobId
)}
</Box>
</TabPanel>
</CardContent>
)}
</Card>
);
};

export default EstimatorTab;
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { Card, CardContent, Tab, Tabs } from '@mui/material';
import { SyntheticEvent, useCallback, useState } from 'react';

import { FullSimulationData, useShSimulation } from '../../../../services/ShSimulatorService';

interface EstimatorsTabProps {
tabsValue: number;
setTabsValue: (value: number) => void;
simulation: FullSimulationData;
setResultsSimulationData: React.Dispatch<React.SetStateAction<FullSimulationData | undefined>>;
estimatorsTabData: string[];
}

const EstimatorsSelect = ({
tabsValue,
setTabsValue,
simulation,
setResultsSimulationData,
estimatorsTabData
}: EstimatorsTabProps) => {
const [controller] = useState(new AbortController());

const { getJobResult } = useShSimulation();

const handleEstimatorTabChange = useCallback(
async (id: number) => {
const currentEstimatorData = simulation.estimators;
const estimatorExists = currentEstimatorData.some(
estimator => estimator.name === estimatorsTabData[id]
);

if (!estimatorExists) {
const simulationJobId = simulation.jobId;

const estimatorData = await getJobResult(
{
jobId: simulationJobId,
estimatorName: estimatorsTabData[id] + '_'
},
controller.signal,
true
);

const newEstimatorData = estimatorData?.estimators;

if (newEstimatorData) {
const newSimulation = {
...simulation,
estimators: [...currentEstimatorData, ...newEstimatorData]
};
setResultsSimulationData(newSimulation);
}
}
},
[controller.signal, estimatorsTabData, getJobResult, setResultsSimulationData, simulation]
);

const handleChange = (_event: SyntheticEvent, newValue: number) => {
setTabsValue(newValue);
};

return (
<Card
sx={{
margin: '0.5rem',
height: 'min-content',
overflow: 'unset',
position: 'sticky',
top: '8px',
zIndex: 1
}}>
<CardContent
sx={{
color: theme =>
theme.palette.mode === 'dark' ? 'secondary.contrastText' : 'secondary.dark'
}}>
<Tabs
textColor='inherit'
sx={{
'flexShrink': 0,
'& .MuiTabs-indicator': {
backgroundColor: theme =>
theme.palette.mode === 'dark'
? 'secondary.contrastText'
: 'secondary.dark'
},
'& .MuiButtonBase-root': {
fontWeight: 'bold'
}
}}
orientation='vertical'
variant='scrollable'
value={tabsValue}
onChange={handleChange}>
{estimatorsTabData.map((estimatorName, id) => {
return (
<Tab
key={`tab_${estimatorName}`}
label={estimatorName}
value={id}
onClick={() => handleEstimatorTabChange(id)}
/>
);
})}
</Tabs>
</CardContent>
</Card>
);
};

export default EstimatorsSelect;
147 changes: 34 additions & 113 deletions src/WrapperApp/components/Results/ResultsPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,40 @@
import {
Box,
Button,
Card,
CardContent,
FormControlLabel,
Switch,
Tab,
Tabs,
Typography
} from '@mui/material';
import { ChangeEvent, SyntheticEvent, useEffect, useState } from 'react';
import { Box, Button, Card, FormControlLabel, Switch, Typography } from '@mui/material';
import { ChangeEvent, useEffect, useState } from 'react';

import { Estimator, generateGraphs, isPage0d, Page, Page0D } from '../../../JsRoot/GraphData';
import { Estimator, isPage0d, Page, Page0D } from '../../../JsRoot/GraphData';
import { useDialog } from '../../../services/DialogService';
import { useStore } from '../../../services/StoreService';
import { InfoTooltip } from '../../../shared/components/tooltip/InfoTooltip';
import { titleToKebabCase } from '../../../ThreeEditor/components/Dialog/CustomDialog';
import { TabPanel } from '../Panels/TabPanel';
import TablePage0D from './ResultsTable';
import EstimatorsSelect from './EstimatorsSelect/EstimatorsSelect';
import EstimatorTab from './EstimatorTab/EstimatorTab';

export interface EstimatorResults extends Estimator {
tablePages: Page0D[];
gridPages: Page[];
}

const estimatorsTabData: string[] = ['z_profile', 'yz_profile', 'entrance', 'peak'];

function ResultsPanel() {
const { open: openSaveFileDialog } = useDialog('saveFile');
const { yaptideEditor, resultsSimulationData: simulation } = useStore();
const {
yaptideEditor,
resultsSimulationData: simulation,
setResultsSimulationData
} = useStore();

const [tabsValue, setTabsValue] = useState(0);
const [estimatorsResults, setEstimatorsResults] = useState<EstimatorResults[]>([]);
const [groupQuantities, setGroupQuantities] = useState(false);

useEffect(() => {
setTabsValue(0);
setEstimatorsResults(parseEstimators(simulation?.estimators ?? []));
}, [simulation]);

const handleChange = (_event: SyntheticEvent, newValue: number) => {
setTabsValue(newValue);
};
if (simulation?.estimators.length === 1) {
setTabsValue(0);
}
}, [simulation]);

const onClickSaveToFile = () => {
if (yaptideEditor)
Expand All @@ -64,6 +59,9 @@ function ResultsPanel() {
};

const resultsGeneratedFromProjectFile = !!simulation?.input.inputJson;
const chosenEstimator = estimatorsResults.filter(
estimator => estimator.name === estimatorsTabData[tabsValue]
)[0];

return (
<Box
Expand Down Expand Up @@ -143,99 +141,22 @@ function ResultsPanel() {
maxWidth: '100vw',
width: '100%'
}}>
{estimatorsResults.length > 0 && (
{estimatorsResults.length > 0 && simulation && (
<>
<Card
sx={{
margin: '0.5rem',
height: 'min-content',
overflow: 'unset',
position: 'sticky',
top: '8px',
zIndex: 1
}}>
<CardContent
sx={{
color: theme =>
theme.palette.mode === 'dark'
? 'secondary.contrastText'
: 'secondary.dark'
}}>
<Tabs
textColor='inherit'
sx={{
'flexShrink': 0,
'& .MuiTabs-indicator': {
backgroundColor: theme =>
theme.palette.mode === 'dark'
? 'secondary.contrastText'
: 'secondary.dark'
},
'& .MuiButtonBase-root': {
fontWeight: 'bold'
}
}}
orientation='vertical'
variant='scrollable'
value={tabsValue}
onChange={handleChange}>
{estimatorsResults.map((estimator, idx) => {
return (
<Tab
key={`tab_${estimator.name}`}
label={estimator.name}
value={idx}
/>
);
})}
</Tabs>
</CardContent>
</Card>
<Card
variant='outlined'
sx={{
'flexGrow': 1,
'margin': '0.5rem',
'bgcolor': theme =>
theme.palette.mode === 'dark'
? 'text.disabled'
: 'background.paper',
'& .MuiCardContent-root div': {
bgcolor: 'transparent',
backgroundImage: 'none',
color: 'black'
}
}}>
<CardContent>
{estimatorsResults.map((estimator, idx) => {
return (
<TabPanel
key={`tab_panel_${estimator.name}_${idx}`}
value={tabsValue}
index={idx}
persistentIfVisited>
<Box
style={{
width: '100%',
display: 'flex',
flexDirection: 'column'
}}>
{estimator.tablePages.length > 0 && (
<TablePage0D
estimator={estimator}></TablePage0D>
)}
{generateGraphs(
estimator,
resultsGeneratedFromProjectFile &&
groupQuantities,
simulation?.jobId
)}
</Box>
</TabPanel>
);
})}
</CardContent>
</Card>
<EstimatorsSelect
tabsValue={tabsValue}
setTabsValue={setTabsValue}
simulation={simulation}
setResultsSimulationData={setResultsSimulationData}
estimatorsTabData={estimatorsTabData}
/>
<EstimatorTab
estimator={chosenEstimator}
tabsValue={tabsValue}
resultsGeneratedFromProjectFile={resultsGeneratedFromProjectFile}
groupQuantities={groupQuantities}
simulation={simulation}
/>
</>
)}
</Box>
Expand Down
Loading