Skip to content

Commit

Permalink
Fix no padding on results page; Add 'auto' layout when no/all options…
Browse files Browse the repository at this point in the history
… are selected
  • Loading branch information
wniestroj committed Nov 27, 2024
1 parent 833e78d commit 30005e7
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 21 deletions.
2 changes: 1 addition & 1 deletion frontend-v2/src/features/results/ResultsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ const ResultsTab: FC = () => {
})}
</Select>
</FormControl>
<Typography variant="h5">{generateTableHeader()}</Typography>
<Typography sx={{ paddingTop: '.5rem', paddingBottom: '.5rem'}} variant="h5">{generateTableHeader()}</Typography>
<ResultsTable
groupIndex={groupIndex}
variableIndex={variableIndex}
Expand Down
50 changes: 42 additions & 8 deletions frontend-v2/src/features/simulation/SimulationPlotView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,13 @@ interface SimulationPlotProps {
model: CombinedModelRead;
visibleGroups: string[];
shouldShowLegend: boolean;
isVertical: boolean;
isHorizontal: boolean;
layout: string;
dimensions: {
width: number;
}
height: number;
};
}

const SimulationPlotView: FC<SimulationPlotProps> = ({
Expand All @@ -287,6 +290,8 @@ const SimulationPlotView: FC<SimulationPlotProps> = ({
model,
visibleGroups,
shouldShowLegend,
isVertical,
isHorizontal,
dimensions,
}) => {
const projectId = useSelector(
Expand Down Expand Up @@ -463,21 +468,50 @@ const SimulationPlotView: FC<SimulationPlotProps> = ({
ln: { type: "log", dtick: Math.log10(Math.E) },
};

const getPlotWidth = () => {
const getPlotDimensions = () => {
const buffor = 10;
const columnCount = screen.width > 2500 ? 3 : 2;
if (screen.width > 1536) {
return dimensions.width / columnCount - buffor;
const layoutBreakpoint = 900;

if (isVertical && !isHorizontal) {
return dimensions.width > layoutBreakpoint
? {
height: dimensions.height / 2 - buffor,
width: dimensions.width - buffor,
}
: {
height: dimensions.height / 1.5 - buffor,
width: dimensions.width - buffor,
};
}

return dimensions.width - buffor;
};
if (!isVertical && isHorizontal) {
return dimensions.width > layoutBreakpoint
? {
height: dimensions.height - buffor,
width: dimensions.width / columnCount - buffor,
}
: {
height: dimensions.height - buffor,
width: dimensions.width / 1.5 - buffor,
};
}

const plotWidth = getPlotWidth();
return dimensions.width > layoutBreakpoint
? {
height: dimensions.height / 2 - buffor,
width: dimensions.width / columnCount - buffor,
}
: {
height: dimensions.height / 2 - buffor,
width: dimensions.width / columnCount - buffor,
};
};

const plotLayout: Partial<Layout> = {
autosize: false,
width: plotWidth,
width: getPlotDimensions()?.width,
height: getPlotDimensions()?.height,
dragmode: "pan",
showlegend: shouldShowLegend,
shapes: icLines.map((icLine, i) => {
Expand Down
31 changes: 23 additions & 8 deletions frontend-v2/src/features/simulation/Simulations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { getConstVariables } from "../model/resetToSpeciesDefaults";
import useSubjectGroups from "../../hooks/useSubjectGroups";
import useExportSimulation from "./useExportSimulation";
import { SimulationsSidePanel } from "./SimulationsSidePanel";
import { useCollapsibleSidebar } from "../../shared/contexts/CollapsibleSidebarContext";

type SliderValues = { [key: number]: number };

Expand Down Expand Up @@ -219,8 +218,8 @@ const Simulations: FC = () => {
{ value: "vertical", label: "Vertical" },
{ value: "horizontal", label: "Horizontal" },
];
const defaultLayout = layoutOptions[0]?.value;
const [layout, setLayout] = useState<string>(defaultLayout);
const defaultLayout = [layoutOptions[0]?.value, layoutOptions[1]?.value];
const [layout, setLayout] = useState<string[]>(defaultLayout);

// reset form and sliders if simulation changes
useEffect(() => {
Expand Down Expand Up @@ -397,6 +396,7 @@ const Simulations: FC = () => {

const [dimensions, setDimensions] = useState({
width: window.innerWidth,
height: window.innerHeight
});

const containerRef: MutableRefObject<HTMLElement | null> = useRef(null);
Expand All @@ -405,6 +405,7 @@ const Simulations: FC = () => {
const debouncedHandleResize = debounce(function handleResize() {
setDimensions({
width: containerRef?.current?.clientWidth || 0,
height: containerRef?.current?.clientHeight || 0
});
}, 1000);

Expand All @@ -419,6 +420,19 @@ const Simulations: FC = () => {
};
});

const isHorizontal = layout.includes('horizontal') || layout?.length === 0;
const isVertical = layout.includes('vertical') || layout?.length === 0;

const getXlLayout = () => {
if (isVertical && !isHorizontal) {
return 12
}

return screen.width > 2500 ? 4 : 6
}

const tableLayout = getXlLayout();

const loading = [
isProjectLoading,
isSimulationsLoading,
Expand Down Expand Up @@ -474,13 +488,13 @@ const Simulations: FC = () => {
container
columns={{ xl: 12, md: 12, sm: 12 }}
direction="row"
wrap={layout === "horizontal" ? "nowrap" : "wrap"}
wrap={isHorizontal && !isVertical ? "nowrap" : "wrap"}
>
{plots.map((plot, index) => (
<Grid
xl={screen.width > 2500 ? 4 : 6}
md={12}
sm={12}
xl={tableLayout}
md={tableLayout}
sm={tableLayout}
item
key={index}
>
Expand All @@ -499,7 +513,8 @@ const Simulations: FC = () => {
model={model}
visibleGroups={visibleGroups}
shouldShowLegend={shouldShowLegend}
layout={layout}
isVertical={isVertical}
isHorizontal={isHorizontal}
dimensions={dimensions}
/>
) : (
Expand Down
16 changes: 12 additions & 4 deletions frontend-v2/src/features/simulation/SimulationsSidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type SimulationsSidePanelType = {
isSharedWithMe: boolean;
layoutOptions: { value: string; label: string }[];
layout: string;
setLayout: (layout: string) => void;
setLayout: (layout: string[]) => void;
plots: SimulationPlot[];
control: Control<Simulation, any>;
units: UnitRead[];
Expand Down Expand Up @@ -151,7 +151,15 @@ export const SimulationsSidePanel = ({
const [collapseParameters, setCollapseParameters] = useState(false);
const [collapseReference, setCollapseReference] = useState(false);
const [collapseLegend, setCollapseLegend] = useState(false);
const { simulationAnimationClasses } = useCollapsibleSidebar();
const { simulationAnimationClasses } = useCollapsibleSidebar();

const onLayoutChange = (value: string) => {
if (layout.includes(value)) {
setLayout(layout.filter(layoutValue => value !== layoutValue))
} else {
setLayout([...layout, value]);
}
}

if (!portalRoot || selectedPage !== PageName.SIMULATIONS) return null;

Expand Down Expand Up @@ -229,9 +237,9 @@ export const SimulationsSidePanel = ({
key={value}
control={
<Checkbox
checked={layout === value}
checked={layout.includes(value)}
onChange={() => {
setLayout(value);
onLayoutChange(value);
}}
/>
}
Expand Down

0 comments on commit 30005e7

Please sign in to comment.