Skip to content

Commit

Permalink
add graph
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Jun 11, 2024
1 parent 4f1fc99 commit 2bd521e
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 27 deletions.
13 changes: 11 additions & 2 deletions app/static/src/app/components/code/CodeTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
<error-info :error="error"></error-info>
<div class="mt-3">
<vertical-collapse v-if="showSelectedVariables" title="Select variables" collapse-id="select-variables">
<selected-variables></selected-variables>
<div class="ms-2">Click to toggle variables to include in graphs.</div>
<selected-variables v-for="graphKey in graphKeys" :graph-key="graphKey"></selected-variables>
<button class="btn btn-primary mt-2" id="add-graph-btn" @click="addGraph">Add Graph</button>
</vertical-collapse>
</div>
</div>
Expand Down Expand Up @@ -60,6 +62,11 @@ export default defineComponent({
const appIsConfigured = computed(() => store.state.configured);
const compile = () => store.dispatch(`model/${ModelAction.CompileModel}`);
const loadingMessage = userMessages.code.isValidating;
const graphKeys = computed(() => Object.keys(store.state.model.graphs));
const addGraph = () => {
const newGraphKey = `Graph ${Object.keys(store.state.model.graphs).length + 1}`;
store.dispatch(`model/${ModelAction.UpdateSelectedVariables}`, { key: newGraphKey, selectedVariables: [] });
};
return {
appIsConfigured,
Expand All @@ -72,7 +79,9 @@ export default defineComponent({
showSelectedVariables,
codeHelp,
codeValidating,
loadingMessage
loadingMessage,
graphKeys,
addGraph
};
}
});
Expand Down
14 changes: 10 additions & 4 deletions app/static/src/app/components/code/SelectedVariables.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="ms-2">Click to toggle variables to include in graphs.</div>
<div class="selected-variables-panel m-2">
<h5>{{ graphKey }}</h5>
<span
v-for="variable in allVariables"
class="badge variable me-2 mb-2"
Expand All @@ -23,10 +23,16 @@ import { ModelAction } from "../../store/model/actions";
export default defineComponent({
name: "SelectedVariables",
setup() {
props: {
graphKey: {
type: String,
required: true
}
},
setup(props) {
const store = useStore();
const allVariables = computed<string[]>(() => store.state.model.odinModelResponse?.metadata?.variables || []);
const selectedVariables = computed<string[]>(() => store.state.model.graphs["graph1"].selectedVariables);
const selectedVariables = computed<string[]>(() => store.state.model.graphs[props.graphKey].selectedVariables);
const palette = computed(() => store.state.model.paletteModel!);
const getStyle = (variable: string) => {
Expand All @@ -39,7 +45,7 @@ export default defineComponent({
const updateSelectedVariables = (newVariables: string[]) => {
store.dispatch(`model/${ModelAction.UpdateSelectedVariables}`, {
key: "graph1",
key: props.graphKey,
selectedVariables: newVariables
});
};
Expand Down
2 changes: 1 addition & 1 deletion app/static/src/app/components/mixins/baseSensitivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default (store: Store<AppState>, multiSensitivity: boolean): BaseSensitiv
}

// TODO: will need to tweak this to use combined set
if (!store.state.model.graphs["graph1"].selectedVariables.length) {
if (!store.state.model.graphs["Graph 1"].selectedVariables.length) {
return userMessages.model.selectAVariable;
}

Expand Down
2 changes: 1 addition & 1 deletion app/static/src/app/components/options/LinkData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default defineComponent({
const dataColumns = computed(() => store.getters[`${namespace}/${FitDataGetter.nonTimeColumns}`]);
const modelSuccess = computed(() => store.state.model.odinModelResponse?.valid);
// TODO: will need to tweak this to use combined set
const selectedVariables = computed(() => store.state.model.graphs["graph1"].selectedVariables);
const selectedVariables = computed(() => store.state.model.graphs["Graph 1"].selectedVariables);
const linkedVariables = computed(() => store.state.fitData.linkedVariables);
const linkPrerequisitesMessage = computed(() => {
const messages = [];
Expand Down
12 changes: 8 additions & 4 deletions app/static/src/app/components/run/RunPlot.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<template>
<h5>{{ graphKey }}</h5>
<wodin-plot
:fade-plot="fadePlot"
:placeholder-message="placeholderMessage"
Expand Down Expand Up @@ -26,12 +27,16 @@ import { ParameterSet } from "../../store/run/state";
export default defineComponent({
name: "RunPlot",
props: {
fadePlot: Boolean
fadePlot: Boolean,
graphKey: {
type: String,
default: "Graph 1"
}
},
components: {
WodinPlot
},
setup() {
setup(props) {
const store = useStore();
const solution = computed(() => store.state.run.resultOde?.solution);
Expand All @@ -58,8 +63,7 @@ export default defineComponent({
const allFitData = computed(() => store.getters[`fitData/${FitDataGetter.allData}`]);
// TODO: tweak for multiple plots
const selectedVariables = computed(() => store.state.model.graphs["graph1"].selectedVariables);
const selectedVariables = computed(() => store.state.model.graphs[props.graphKey].selectedVariables);
const placeholderMessage = computed(() => runPlaceholderMessage(selectedVariables.value, false));
const allPlotData = (start: number, end: number, points: number): WodinPlotData => {
Expand Down
2 changes: 1 addition & 1 deletion app/static/src/app/components/run/RunStochasticPlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default defineComponent({
const store = useStore();
// TODO: tweak for multiple graphs
const selectedVariables = computed(() => store.state.model.graphs["graph1"].selectedVariables);
const selectedVariables = computed(() => store.state.model.graphs["Graph 1"].selectedVariables);
const placeholderMessage = computed(() => runPlaceholderMessage(selectedVariables.value, false));
const solution = computed(() => store.state.run.resultDiscrete?.solution);
Expand Down
15 changes: 12 additions & 3 deletions app/static/src/app/components/run/RunTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
</div>
<action-required-message :message="updateMsg"></action-required-message>
<run-stochastic-plot v-if="isStochastic" :fade-plot="!!updateMsg"></run-stochastic-plot>
<run-plot v-else :fade-plot="!!updateMsg" :model-fit="false">
<run-plot
v-for="graphKey in graphKeys"
v-else
:fade-plot="!!updateMsg"
:model-fit="false"
:graph-key="graphKey"
>
<div v-if="sumOfSquares">
<span>Sum of squares: {{ sumOfSquares }}</span>
</div>
Expand Down Expand Up @@ -100,7 +106,7 @@ export default defineComponent({
return userMessages.run.compileRequired;
}
// TODO: tweak for multiple graphs
if (!store.state.model.graphs["graph1"].selectedVariables.length) {
if (!store.state.model.graphs["Graph 1"].selectedVariables.length) {
return userMessages.model.selectAVariable;
}
// TODO: eventually make runRequired to runUpdateRequired I think?
Expand All @@ -119,6 +125,8 @@ export default defineComponent({
const download = (payload: { fileName: string; points: number }) =>
store.dispatch(`run/${RunAction.DownloadOutput}`, payload);
const graphKeys = computed(() => Object.keys(store.state.model.graphs));
return {
canRunModel,
isStochastic,
Expand All @@ -131,7 +139,8 @@ export default defineComponent({
canDownloadOutput,
downloadUserFileName,
toggleShowDownloadOutput,
download
download,
graphKeys
};
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default defineComponent({
const batch = computed(() => store.state.sensitivity.result?.batch);
const plotSettings = computed(() => store.state.sensitivity.plotSettings);
const palette = computed(() => store.state.model.paletteModel);
const selectedVariables = computed(() => store.state.model.graphs["graph1"].selectedVariables);
const selectedVariables = computed(() => store.state.model.graphs["Graph 1"].selectedVariables);
const placeholderMessage = computed(() => runPlaceholderMessage(selectedVariables.value, true));
const xAxisSettings = computed(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default defineComponent({
const palette = computed(() => store.state.model.paletteModel);
// TODO: tweak for multiple graphs
const selectedVariables = computed(() => store.state.model.graphs["graph1"].selectedVariables);
const selectedVariables = computed(() => store.state.model.graphs["Graph 1"].selectedVariables);
const placeholderMessage = computed(() => runPlaceholderMessage(selectedVariables.value, true));
Expand Down
4 changes: 2 additions & 2 deletions app/static/src/app/excel/wodinModelOutputDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class WodinModelOutputDownload extends WodinExcelDownload {
nPoints: this._points
});
// TODO: tweak for multiple graphs
const { selectedVariables } = this._state.model.graphs["graph1"];
const { selectedVariables } = this._state.model.graphs["Graph 1"];

const worksheet = WodinModelOutputDownload._generateModelledOutput(
selectedVariables,
Expand All @@ -69,7 +69,7 @@ export class WodinModelOutputDownload extends WodinExcelDownload {
const times = fitData.map((row: Dict<number>) => row[timeVariable]);
const solutionOutput = solution({ mode: "given", times });
// TODO: Tweak for multiple graphs
const { selectedVariables } = this._state.model.graphs["graph1"];
const { selectedVariables } = this._state.model.graphs["Graph 1"];

const worksheet = WodinModelOutputDownload._generateModelledOutput(
selectedVariables,
Expand Down
6 changes: 3 additions & 3 deletions app/static/src/app/serialise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ export const deserialiseState = (targetState: AppState, serialised: SerialisedAp
// TODO: tweak for multiple graphs
if (
model.odinModelResponse?.metadata?.variables &&
!model.graphs["graph1"].selectedVariables.length &&
!model.graphs["graph1"].unselectedVariables?.length
!model.graphs["Graph 1"].selectedVariables.length &&
!model.graphs["Graph 1"].unselectedVariables?.length
) {
/* eslint-disable no-param-reassign */
const selectedVariables = [...(model.odinModelResponse?.metadata?.variables || [])];
const unselectedVariables: string[] = [];

targetState.model.graphs = {
graph1: {
"Graph 1": {
selectedVariables,
unselectedVariables
}
Expand Down
2 changes: 1 addition & 1 deletion app/static/src/app/store/fitData/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const updateLinkedVariables = (context: ActionContext<FitDataState, FitState>) =
const { commit, state, rootState, getters } = context;
const modelResponse = rootState.model.odinModelResponse;
// TODO: tweak for multiple graphs
const modelVariables = modelResponse?.valid ? rootState.model.graphs["graph1"].selectedVariables : [];
const modelVariables = modelResponse?.valid ? rootState.model.graphs["Graph 1"].selectedVariables : [];
const dataColumns = getters.nonTimeColumns;
let newLinks = {};
if (dataColumns) {
Expand Down
4 changes: 2 additions & 2 deletions app/static/src/app/store/model/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ const compileModelAndUpdateStore = (context: ActionContext<ModelState, AppState>

// Retain variable selections. Newly added variables will be selected by default
// TODO: tweak for multiple graphs
const select = variables.filter((s) => !state.graphs["graph1"].unselectedVariables.includes(s));
commit(ModelMutation.SetSelectedVariables, { key: "graph1", selectedVariables: select });
const select = variables.filter((s) => !state.graphs["Graph 1"].unselectedVariables.includes(s));
commit(ModelMutation.SetSelectedVariables, { key: "Graph 1", selectedVariables: select });

if (state.compileRequired) {
commit(ModelMutation.SetCompileRequired, false);
Expand Down
2 changes: 1 addition & 1 deletion app/static/src/app/store/model/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const defaultState: ModelState = {
//selectedVariables: [],
//unselectedVariables: []
graphs: {
graph1: {
"Graph 1": {
selectedVariables: [],
unselectedVariables: []
}
Expand Down
6 changes: 6 additions & 0 deletions app/static/src/app/store/model/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export const mutations: MutationTree<ModelState> = {
},

[ModelMutation.SetSelectedVariables](state: ModelState, payload: { key: string; selectedVariables: string[] }) {
if (!Object.keys(state.graphs).includes(payload.key)) {
state.graphs[payload.key] = {
selectedVariables: [],
unselectedVariables: []
};
}
state.graphs[payload.key].selectedVariables = payload.selectedVariables;
// Maintain unselected variables too, so we know which variables had been explicitly unselected when model
// updates
Expand Down

0 comments on commit 2bd521e

Please sign in to comment.