Skip to content

Commit 4294617

Browse files
committed
WIP: interface for pausing re-execution of simulations
1 parent 254b1d9 commit 4294617

4 files changed

Lines changed: 77 additions & 6 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { Signal } from "solid-js";
2+
3+
import { Button } from "catcolab-ui-components";
4+
5+
export function ExecuteGuard(props: {
6+
text: string;
7+
triggerText?: string;
8+
canTrigger: Signal<boolean>;
9+
shouldTrigger: Signal<boolean>;
10+
}) {
11+
const [canTrigger, setCanTrigger] = props.canTrigger;
12+
const [_shouldTrigger, setShouldTrigger] = props.shouldTrigger;
13+
14+
return (
15+
<div style="display: flex; align-items: center; justify-content: flex-end; gap: 4px;">
16+
<Button
17+
type="button"
18+
variant="utility"
19+
onClick={() => setShouldTrigger((val) => !val)}
20+
disabled={canTrigger()}
21+
>
22+
{props.text}
23+
</Button>
24+
<Button
25+
type="button"
26+
variant="utility"
27+
onClick={() => setCanTrigger((val) => !val)}
28+
disabled={false}
29+
>
30+
{`Turn ${canTrigger() ? "off" : "on"} ${props.triggerText ?? ""}`}
31+
</Button>
32+
</div>
33+
);
34+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from "./delete_document_dialog";
22
export * from "./document_picker";
3+
export * from "./execute_control";
34
export * from "./id_input";
45
export * from "./json_import";
56
export * from "./rich_text_editor";

packages/frontend/src/stdlib/analyses/mass_action.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createMemo } from "solid-js";
1+
import { createMemo, createSignal, on } from "solid-js";
22

33
import {
44
BlockTitle,
@@ -11,6 +11,7 @@ import {
1111
} from "catcolab-ui-components";
1212
import type { MassActionProblemData, MorType, ObType, QualifiedName } from "catlog-wasm";
1313
import type { ModelAnalysisProps } from "../../analysis";
14+
import { ExecuteGuard } from "../../components";
1415
import { morLabelOrDefault } from "../../model";
1516
import { ODEResultPlot } from "../../visualization";
1617
import { createModelODEPlotWithEquations } from "./model_ode_plot";
@@ -101,12 +102,28 @@ export default function MassAction(
101102
(model) => props.simulate(model, props.content),
102103
);
103104

104-
const plotResult = () => result()?.plotData;
105+
const [autoUpdate, setAutoUpdate] = createSignal(true);
106+
const [shouldUpdate, trigger] = createSignal(false);
107+
const plotResult = createMemo(
108+
on(
109+
() => (autoUpdate() ? result()?.plotData : shouldUpdate()),
110+
() => result()?.plotData,
111+
),
112+
);
105113
const latexEquations = () => result()?.latexEquations ?? [];
106114

115+
const execute = () => (
116+
<ExecuteGuard
117+
text="Execute"
118+
triggerText="auto-simulate"
119+
canTrigger={[autoUpdate, setAutoUpdate]}
120+
shouldTrigger={[shouldUpdate, trigger]}
121+
/>
122+
);
123+
107124
return (
108125
<div class="simulation">
109-
<BlockTitle title={props.title} />
126+
<BlockTitle title={props.title} settingsPane={execute()} />
110127
<Foldable title="Parameters" defaultExpanded>
111128
<div class="parameters">
112129
<FixedTableEditor rows={obGenerators()} schema={obSchema} />

packages/frontend/src/stdlib/analyses/stochastic_mass_action.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createMemo } from "solid-js";
1+
import { createMemo, createSignal, on } from "solid-js";
22

33
import {
44
BlockTitle,
@@ -9,6 +9,7 @@ import {
99
} from "catcolab-ui-components";
1010
import type { DblModel, MassActionProblemData, MorType, ObType, QualifiedName } from "catlog-wasm";
1111
import type { ModelAnalysisProps } from "../../analysis";
12+
import { ExecuteGuard } from "../../components";
1213
import { morLabelOrDefault } from "../../model";
1314
import { ODEResultPlot } from "../../visualization";
1415
import { createModelODEPlot } from "./model_ode_plot";
@@ -92,14 +93,32 @@ export default function StochasticMassAction(
9293
}),
9394
];
9495

95-
const plotResult = createModelODEPlot(
96+
const result = createModelODEPlot(
9697
() => props.liveModel.validatedModel(),
9798
(model: DblModel) => props.simulate(model, props.content),
9899
);
99100

101+
const [autoUpdate, setAutoUpdate] = createSignal(true);
102+
const [shouldUpdate, trigger] = createSignal(false);
103+
const plotResult = createMemo(
104+
on(
105+
() => (autoUpdate() ? result() : shouldUpdate()),
106+
() => result(),
107+
),
108+
);
109+
110+
const execute = () => (
111+
<ExecuteGuard
112+
text="Execute"
113+
triggerText="auto-simulate"
114+
canTrigger={[autoUpdate, setAutoUpdate]}
115+
shouldTrigger={[shouldUpdate, trigger]}
116+
/>
117+
);
118+
100119
return (
101120
<div class="simulation">
102-
<BlockTitle title={props.title} />
121+
<BlockTitle title={props.title} settingsPane={execute()} />
103122
<Foldable title="Parameters" defaultExpanded>
104123
<div class="parameters">
105124
<FixedTableEditor rows={obGenerators()} schema={obSchema} />

0 commit comments

Comments
 (0)