Skip to content

Commit

Permalink
- fix typescript issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed Jan 19, 2024
1 parent 0992604 commit 7ad47d7
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@
/dist-web/
/em-build/

.DS_Store
.DS_Store
1 change: 1 addition & 0 deletions examples/vue-copasi-ts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ coverage

src/copasijs.js
src/copasi.js
src/copasi.d.ts
src/copasijs.wasm
src/copasijs.data
8 changes: 8 additions & 0 deletions examples/vue-copasi-ts/src/copasi-plugin-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type COPASI from "./copasi";

export interface CopasiPlugin {
state: string;
module: any;
instance: COPASI|undefined;
version: string;
}
8 changes: 5 additions & 3 deletions examples/vue-copasi-ts/src/copasi-plugin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { COPASI } from './copasi.js'
import { createCpsModule } from './copasijs.js'
import { reactive } from 'vue'

/**
* Install function for installing plugin into Vue 3 application.
*
Expand All @@ -12,15 +11,18 @@ function install(app) {
const copasi = reactive({
state: 'loading',
module: undefined,
instance: {version: 'loading'},
instance: undefined,
version: 'loading'
})

app.provide('$copasi', copasi)

createCpsModule().then((module) => {
const c = new COPASI(module)
copasi.state = 'ready'
copasi.module = module
copasi.instance = new COPASI(module)
copasi.instance = c
copasi.version = c.version
// console.log('initialized COPASI', copasi.instance.version)
})
}
Expand Down
16 changes: 12 additions & 4 deletions examples/vue-copasi-ts/src/views/HomeView.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
<script setup lang="ts">
import { ref, onMounted, inject } from 'vue'
import {type COPASI } from '../copasi'
import {type CopasiPlugin } from '../copasi-plugin-type'
// inject the COPASI object from the main app
const copasi : any = inject('$copasi')
const copasi : CopasiPlugin|undefined = inject('$copasi')
const data: any = ref(null);
const simData: any = ref(null);
const model : string = ref('');
const info = ref(null);
const model : any = ref('');
const info : any = ref(null);
onMounted(async () => {
if (!copasi?.instance || copasi?.state == 'loading'){
// load the copasi object
return;
}
if (!model.value){
// download `brusselator.cps` model copied to
// /public folder
Expand Down Expand Up @@ -52,7 +60,7 @@ onMounted(async () => {
<VuePlotly :data="data" :layout="layout" :display-mode-bar="false"></VuePlotly>
<div>
<p>Model: {{ info?.model.name }}</p>
<p >COPASI Version: {{copasi.instance.version}}</p>
<p >COPASI Version: {{copasi?.version}}</p>
</div>
</main>
</template>
Expand Down
2 changes: 1 addition & 1 deletion examples/vue-copasi-ts/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"include": [
"vite.config.*",
"vite.config.ts",
"vitest.config.*",
"cypress.config.*",
"nightwatch.conf.*",
Expand Down
94 changes: 94 additions & 0 deletions js/copasi.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import type exp from "constants";

export interface SimResult {
num_variables: number;
recorded_steps: number;
titles: string[];
columns: string[];
}

export interface SpeciesInfo {
compartment: string;
concentration: number;
id: string;
name: string;
initial_concentration: number;
initial_particle_number: number;
particle_number: number;
type: string;
}

export interface CompartmentInfo {
id: string;
name: string;
size: number;
type: string;
}
export interface LocalParamterInfo {
name: string;
value: number;
}

export interface ReactionInfo {
id: string;
name: string;
reversible: boolean;
scheme: string;
local_paramters: LocalParamterInfo[];
}

export interface ModelName
{
name: string;
notes: string;
}

export interface GlobalParamterInfo {
name: string;
value: number;
initial_value: number;
id: string;
type: string;
}

export interface ModelInfo {
species: SpeciesInfo[];
compartments: CompartmentInfo[];
reactions: ReactionInfo[];
global_parameters: GlobalParamterInfo[];
model : ModelName;
time: number;
status: string;
messages: string;
}

export default class COPASI {
constructor(module: any);
reset(): void;
readonly version: string;
_vectorToArray(v: any): any[];
loadExample(path: string) : ModelInfo;
loadModel(modelCode: string): ModelInfo;
simulate() : object;
simulate2D() : number[][];
simulateEx(startTime : number, endTime : number, numPoints : number) : SimResult;
simulateEx2D(startTime : number, endTime : number, numPoints : number) : number[][];
simulateYaml(yamlProcessingOptions : string|object) : SimResult;
simulateYaml2D(yamlProcessingOptions : string|object) : SimResult;
readonly floatingSpeciesConcentrations : number[];
readonly ratesOfChange : number[];
readonly floatingSpeciesNames : string[];
readonly boundarySpeciesConcentrations : number[];
readonly boundarySpeciesNames : string[];
readonly reactionNames : string[];
readonly reactionRates : number[];
readonly compartmentNames : string[];
readonly compartmentSizes : number[];
readonly globalParameterNames : string[];
readonly globalParameterValues : number[];
readonly localParameterNames : string[];
readonly localParameterValues : number[];
}

export {COPASI};
export default COPASI;

0 comments on commit 7ad47d7

Please sign in to comment.