Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: show rate expression instead of rate name #1756

Merged
merged 15 commits into from
Sep 8, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const emit = defineEmits([

const equationType = computed(() => props.equationType ?? 'equation');
const isEditingStyle = computed(() => (props.isEditing ? 'is-editing' : ''));
const mathContainerStyle = computed(() => (props.isEditable ? '-1rem' : '0rem'));
</script>

<style scoped>
Expand Down Expand Up @@ -97,6 +98,6 @@ main.is-editing {
border: 4px solid transparent;
border-radius: var(--border-radius);
position: relative;
top: -1rem;
top: v-bind('mathContainerStyle');
}
</style>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<tera-equation-container
:is-editing="isEditing"
:is-editable="isEditable"
:is-editable="isEditable && canEditEquations"
@cancel-edit="cancelEdit"
@add-equation="addEquation"
@start-editing="isEditing = true"
Expand Down Expand Up @@ -47,6 +47,7 @@ const equationsRef = ref<any[]>([]);
const equations = ref<string[]>([]);
const orginalEquations = ref<string[]>([]);
const isEditing = ref(false);
const canEditEquations = ref(true);

const setNewEquation = (index: number, latexEq: string) => {
equations.value[index] = latexEq;
Expand Down Expand Up @@ -80,13 +81,24 @@ const updateModelFromEquations = async () => {
}
};

function modelIsEmpty(targetModel: Model): boolean {
// model does not have any states or transitions
if (targetModel.model?.states?.length === 0 && targetModel.model?.transitions?.length === 0) {
return true;
}

return false;
}

watch(
() => props.model,
async () => {
const latexFormula = await petriToLatex(convertAMRToACSet(props.model));
if (latexFormula) {
updateLatexFormula(cleanLatexEquations(latexFormula.split(' \\\\')));
}

canEditEquations.value = (props.model && modelIsEmpty(props.model)) as boolean;
},
{ deep: true, immediate: true }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ export const convertAMRToACSet = (amr: Model) => {
});
});

// post processing to use expressions rather than ids
result.T = result.T.map((transition) => {
const foundRate = amr.semantics?.ode.rates.find((rate) => rate.target === transition.tname);

// default to the id if there is a case where there is no expression
return { tname: foundRate ? `(${foundRate!.expression})` : transition.tname };
});

return result;
};

Expand Down
2 changes: 2 additions & 0 deletions packages/client/hmi-client/src/utils/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ export const cleanLatexEquations = (equations: Array<string>): Array<string> =>
.replaceAll('\\left', '')
.replaceAll('{align}', '')
.replaceAll('=&', '=')
// scientific variables such as \beta and \gamma are not parsed when there is a '*' (with no space) placed after them - other math operaters do work though
.replaceAll('*', ' *')
.trim()
);

Expand Down