Skip to content

Commit

Permalink
reorganize tabs for analysis scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
magland committed Jul 3, 2024
1 parent 9d2b45d commit e1883a7
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 65 deletions.
3 changes: 2 additions & 1 deletion gui/src/app/SamplerOutputView/SamplerOutputView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import TracePlotsView from "./TracePlotsView";
type SamplerOutputViewProps = {
width: number;
height: number;
sampler: StanSampler;
sampler: StanSampler | undefined;
};

const SamplerOutputView: FunctionComponent<SamplerOutputViewProps> = ({
Expand All @@ -25,6 +25,7 @@ const SamplerOutputView: FunctionComponent<SamplerOutputViewProps> = ({
useSamplerOutput(sampler);

if (!draws || !paramNames || !numChains) return <span />;
if (!sampler) return <span>No sampler</span>;
return (
<DrawsDisplay
width={width}
Expand Down
15 changes: 9 additions & 6 deletions gui/src/app/pages/HomePage/AnalysisPyWindow/AnalysisPyWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,16 @@ const RightPane: FunctionComponent<RightPaneProps> = ({

const getScriptHeaderForEmptyDraws = () => {
return `
class _SPSampling:
def __init__(self):
self.draws = []
self.parameter_names = []
self.num_chains = 0
sp_sampling = _SPSampling()
raise Exception("You must run the sampler before executing the analysis script.")
`;
// return `
// class _SPSampling:
// def __init__(self):
// self.draws = []
// self.parameter_names = []
// self.num_chains = 0
// sp_sampling = _SPSampling()
// `;
};

const getScriptHeaderForNonemptyDraws = () => {
Expand Down
47 changes: 3 additions & 44 deletions gui/src/app/pages/HomePage/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import {
import LeftPanel from "./LeftPanel";
import SamplingWindow from "./SamplingWindow/SamplingWindow";
import TopBar from "./TopBar";
import TabWidget from "../../TabWidget/TabWidget";
import AnalysisPyWindow from "./AnalysisPyWindow/AnalysisPyWindow";
import StanSampler from "../../StanSampler/StanSampler";

type Props = {
width: number;
Expand Down Expand Up @@ -143,55 +140,17 @@ type RightViewProps = {
compiledMainJsUrl: string;
};

const tabs = [
{
id: "sampling",
label: "Sampling",
title: "Run sampling and view draws",
closeable: false,
},
{
id: "analysis.py",
label: "Analysis (Py)",
title: "Python analysis",
closeable: false,
},
{
id: "analysis.r",
label: "Analysis (R)",
title: "R analysis",
closeable: false,
},
];

const RightView: FunctionComponent<RightViewProps> = ({
width,
height,
compiledMainJsUrl,
}) => {
const [currentTabId, setCurrentTabId] = useState("sampling");
const [stanSampler, setStanSampler] = useState<StanSampler | null>(null);
return (
<TabWidget
<SamplingWindow
width={width}
height={height}
tabs={tabs}
currentTabId={currentTabId}
setCurrentTabId={setCurrentTabId}
>
<SamplingWindow
width={width}
height={height}
compiledMainJsUrl={compiledMainJsUrl}
onStanSampler={setStanSampler} // todo: lift the state rather than having to use this callback
/>
<AnalysisPyWindow
width={width}
height={height}
stanSampler={stanSampler}
/>
<div>R Analysis not yet implemented</div>
</TabWidget>
compiledMainJsUrl={compiledMainJsUrl}
/>
);
};

Expand Down
74 changes: 60 additions & 14 deletions gui/src/app/pages/HomePage/SamplingWindow/SamplingWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@ import {
useContext,
useEffect,
useMemo,
useState,
} from "react";
import { ProjectContext } from "../../../Project/ProjectContextProvider";
import { modelHasUnsavedDataFileChanges } from "../../../Project/ProjectDataModel";
import RunPanel from "../../../RunPanel/RunPanel";
import { SamplingOpts } from "../../../StanSampler/StanSampler";
import StanSampler, { SamplingOpts } from "../../../StanSampler/StanSampler";
import useStanSampler, {
useSamplerStatus,
} from "../../../StanSampler/useStanSampler";
import SamplerOutputView from "../../../SamplerOutputView/SamplerOutputView";
import SamplingOptsPanel from "../../../SamplingOptsPanel/SamplingOptsPanel";
import TabWidget from "../../../TabWidget/TabWidget";
import AnalysisPyWindow from "../AnalysisPyWindow/AnalysisPyWindow";

type SamplingWindowProps = {
width: number;
height: number;
compiledMainJsUrl?: string;
onStanSampler: (sampler: any) => void; // todo: lift the state rather than having to use this callback
};

const SamplingWindow: FunctionComponent<SamplingWindowProps> = ({
width,
height,
compiledMainJsUrl,
onStanSampler,
compiledMainJsUrl
}) => {
const { data, update } = useContext(ProjectContext);
const parsedData = useMemo(() => {
Expand All @@ -47,9 +48,6 @@ const SamplingWindow: FunctionComponent<SamplingWindowProps> = ({
);

const { sampler } = useStanSampler(compiledMainJsUrl);
useEffect(() => {
onStanSampler(sampler);
}, [sampler, onStanSampler]);
const { status: samplerStatus } = useSamplerStatus(sampler);
const isSampling = samplerStatus === "sampling";
return (
Expand Down Expand Up @@ -92,16 +90,64 @@ const SamplingWindow: FunctionComponent<SamplingWindowProps> = ({
height: height - samplingOptsPanelHeight,
}}
>
{sampler && (
<SamplerOutputView
width={width}
height={height - samplingOptsPanelHeight}
sampler={sampler}
/>
)}
<SamplingResultsArea
width={width}
height={height - samplingOptsPanelHeight}
sampler={sampler}
/>
</div>
</div>
);
};

const samplingResultsTabs = [
{
id: "output",
label: "Output",
title: "View the output of the sampler",
closeable: false,
},
{
id: "analysis.py",
label: "Analysis (Py)",
title: "Python analysis",
closeable: false,
},
{
id: "analysis.r",
label: "Analysis (R)",
title: "R analysis",
closeable: false,
}
];

type SamplingResultsAreaProps = {
width: number;
height: number;
sampler: StanSampler | undefined;
};

const SamplingResultsArea: FunctionComponent<SamplingResultsAreaProps> = ({
width,
height,
sampler,
}) => {
const [currentTabId, setCurrentTabId] = useState("output");
return (
<TabWidget
width={width}
height={height}
tabs={samplingResultsTabs}
currentTabId={currentTabId}
setCurrentTabId={setCurrentTabId}
>
<SamplerOutputView width={width} height={height} sampler={sampler} />
<AnalysisPyWindow width={width} height={height} stanSampler={sampler || null} />
<div>
<div style={{ padding: 5 }}>R analysis not yet implemented</div>
</div>
</TabWidget>
);
};

export default SamplingWindow;

0 comments on commit e1883a7

Please sign in to comment.