Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed Sep 23, 2024
1 parent 1bd0674 commit 0307859
Show file tree
Hide file tree
Showing 21 changed files with 301 additions and 104 deletions.
9 changes: 6 additions & 3 deletions src-tauri/src/actions/measurements.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use std::hash::Hash;
use std::sync::Arc;

use enzymeml::prelude::{Measurement, MeasurementBuilder, MeasurementDataBuilder};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use tauri::{AppHandle, Manager, State};

use crate::{create_object, delete_object, get_object, update_event, update_object};
use crate::actions::enzmldoc::get_species_name;
use crate::actions::utils::generate_id;
use crate::states::EnzymeMLState;
use crate::{create_object, delete_object, get_object, update_event, update_object};

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct VisData {
Expand Down Expand Up @@ -127,7 +130,7 @@ pub fn get_datapoints(state: State<Arc<EnzymeMLState>>, id: &str) -> Result<Vec<
}

let vis_data = VisData {
id: species_data.species_id.clone(),
id: get_species_name(state.clone(), &species_data.species_id)?,
data: data_points,
};

Expand Down
37 changes: 15 additions & 22 deletions src-tauri/src/actions/parameters.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,32 @@
use enzymeml::prelude::{Parameter, ParameterBuilder};
use std::sync::Arc;

use enzymeml::prelude::{Parameter, ParameterBuilder};
use tauri::{AppHandle, Manager, State};

use crate::{create_object, delete_object, get_object, update_event, update_object};
use crate::actions::utils::generate_id;
use crate::states::EnzymeMLState;
use crate::{delete_object, get_object, update_event, update_object};

#[tauri::command]
pub fn list_parameters(state: State<Arc<EnzymeMLState>>) -> Vec<String> {
pub fn list_parameters(state: State<Arc<EnzymeMLState>>) -> Vec<(String, String)> {
// Extract the guarded state values
let state_doc = state.doc.lock().unwrap();

state_doc.parameters.iter().map(|s| s.id.clone()).collect()
state_doc.parameters.iter().map(|s| (s.id.clone(), s.name.clone())).collect()
}

#[tauri::command]
pub fn create_parameter(state: State<Arc<EnzymeMLState>>, name: String, app_handle: AppHandle) {
let mut doc = state.doc.lock().unwrap();

// Check if there is already a parameter with the same name
if doc.parameters.iter().any(|p| p.id == name) {
return;
}

// Create the parameter
let parameter = ParameterBuilder::default()
.name(name.clone())
.id(name.clone())
.symbol(name.clone())
.build()
.expect("Failed to build parameter");

// Add the parameter to the document
doc.parameters.push(parameter);
pub fn create_parameter(
state: State<Arc<EnzymeMLState>>,
app_handle: AppHandle,
) -> Result<String, String> {
let id = create_object!(state.doc, parameters, ParameterBuilder, "q", id);

// Notify the frontend
update_event!(app_handle, "update_document");
update_event!(app_handle, "update_parameters");

Ok(id)
}

#[tauri::command]
Expand All @@ -49,6 +40,8 @@ pub fn update_parameter(
data: Parameter,
app_handle: AppHandle,
) -> Result<(), String> {

// Check if the parameter exists
let id: String = update_object!(state.doc, parameters, data, id);

update_event!(app_handle, "update_parameters");
Expand Down
38 changes: 9 additions & 29 deletions src-tauri/src/actions/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,6 @@ use tauri::{Manager, State};

use crate::states::EnzymeMLState;

#[tauri::command]
pub async fn open_simulator(app: tauri::AppHandle) {
let file_path = "index_simulation.html";
let _settings_window = tauri::WindowBuilder::new(
&app,
"Simulation", /* the unique window label */
tauri::WindowUrl::App(file_path.into()),
)
.title("Settings")
.build()
.unwrap();
// #[cfg(debug_assertions)] // only include this code on debug builds
// {
// let window = app.get_window("Simulation").unwrap();
// window.open_devtools();
// window.close_devtools();
// }
}

#[tauri::command]
pub fn open_visualisation(
state: State<Arc<EnzymeMLState>>,
Expand All @@ -34,23 +15,22 @@ pub fn open_visualisation(
return Err("No measurements found".to_string());
}

let file_path = "index_visualisation.html";
let file_path = "viswindow/index.html";
let _settings_window = tauri::WindowBuilder::new(
&app,
"Visualisation", /* the unique window label */
"visualisation", /* the unique window label */
tauri::WindowUrl::App(file_path.into()),
)
.title("Visualisation")
.decorations(false)
.transparent(true)
.resizable(true)
.inner_size(1000_f64, 600_f64)
.build()
.unwrap();
.title("Visualisation")
.decorations(false)
.transparent(true)
.resizable(true)
.inner_size(1000_f64, 600_f64)
.build().map_err(|e| e.to_string())?;

#[cfg(debug_assertions)] // only include this code on debug builds
{
let window = app.get_window("Visualisation").unwrap();
let window = app.get_window("visualisation").unwrap();
window.open_devtools();
window.close_devtools();
}
Expand Down
25 changes: 25 additions & 0 deletions src-tauri/src/dataio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ pub async fn export_to_json(state: State<'_, Arc<EnzymeMLState>>) -> Result<Path
}
}

#[tauri::command]
pub async fn load_json(
state: State<'_, Arc<EnzymeMLState>>,
app_handle: AppHandle,
) -> Result<(), String> {
let dialog_result = FileDialogBuilder::new()
.set_title("Open File")
.add_filter("JSON Files", &["json"])
.pick_file();

match dialog_result {
Some(path) => {
let mut state_doc = state.doc.lock().unwrap();
let json = std::fs::read_to_string(path).map_err(|err| err.to_string())?;
let doc = deserialize_doc(json.as_str()).map_err(|err| err.to_string())?;
*state_doc = doc;

update_event!(app_handle, "update_document");

Ok(())
}
None => Err("No file selected".to_string()),
}
}

#[tauri::command]
pub fn new_document(state: State<Arc<EnzymeMLState>>, app_handle: AppHandle) {
// Extract the guarded state values
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ async fn main() {
dataio::get_state,
dataio::export_measurements,
dataio::import_excel_meas,
dataio::load_json,
// EnzymeML Document
enzmldoc::get_all_species_ids,
enzmldoc::get_all_non_constant_species_ids,
Expand Down Expand Up @@ -142,7 +143,6 @@ async fn main() {
measurements::delete_measurement,
measurements::list_measurements,
// Windows
windows::open_simulator,
windows::open_visualisation,
])
.run(tauri::generate_context!())
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"package": {
"productName": "EnzymeML Suite",
"version": "0.0.0"
"version": "0.0.1"
},
"tauri": {
"macOSPrivateApi": true,
Expand Down
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import SmallMolecules from "./smallmols/SmallMolecules.tsx";
import Home from "./home/Home.tsx";
import Measurements from "./measurements/Measurements.tsx";
import Vessels from "./vessels/Vessels.tsx";
import Equations from "./models/Equations.tsx";
import Proteins from "./proteins/Proteins.tsx";
import Reactions from "./reactions/Reactions.tsx";
import useAppStore, {AvailablePaths} from "./stores/appstore.ts";
import WindowFrame from "./components/WindowFrame.tsx";
import MainMenu from "./components/MainMenu.tsx";
import CollectionNav from "./components/CollectionNav.tsx";
import SubMenu from "./components/SubMenu.tsx";
import Model from "./models/Model.tsx";

interface AppContext {
selectedId: string | null;
Expand Down Expand Up @@ -93,7 +93,7 @@ function App() {
<Route path="/proteins" element={<Proteins/>}/>
<Route path="/reactions" element={<Reactions/>}/>
<Route path="/measurements" element={<Measurements/>}/>
<Route path="/models" element={<Equations/>}/>
<Route path="/models" element={<Model/>}/>
</Routes>
</AppContext.Provider>
</div>
Expand Down
9 changes: 9 additions & 0 deletions src/commands/dataio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ export async function exportToJSON(): Promise<string> {
}
}

export async function loadJSON(): Promise<void> {
try {
await invoke('load_json', {});
} catch (error) {
throw new Error('Error invoking command: ' + error);
}

}

export async function getState(): Promise<EnzymeMLState> {
try {
return await invoke<EnzymeMLState>('get_state');
Expand Down
13 changes: 12 additions & 1 deletion src/commands/measurements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,18 @@ export async function getMeasurement(id: string): Promise<Measurement> {
}

export async function updateMeasurement(id: string, data: Measurement): Promise<void> {
console.log('Updating measurement:', id, data)

// If the data unit of species data is a json string then parse it
data.species_data?.map((species) => {
if (typeof species.data_unit === 'string') {
species.data_unit = JSON.parse(species.data_unit);
}

return species;
})

console.log('data', data)

try {
await invoke('update_measurement', {id: id, data: data});
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {invoke} from "@tauri-apps/api/tauri";
import {Parameter} from "enzymeml/src";

export async function listAllParametersIds(): Promise<string[]> {
export async function listAllParametersIds(): Promise<[string, string][]> {
try {
return await invoke('list_parameters');
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/CollectionNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default function CollectionNav() {

return (
<Grow>
<List className={"h-auto py-2 shadow-sm 2-full"}
<List className={"max-h-64 py-2 shadow-sm 2-full overflow-auto scrollbar-hide"}
style={{
background: token.colorBgContainer,
borderRadius: token.borderRadiusLG,
Expand Down
22 changes: 17 additions & 5 deletions src/components/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,25 @@ export default function LineChart(

if (true === true) {
const newChartTheme: LineProps["theme"] = {
crosshair: {
line: {
stroke: token.colorText,
strokeWidth: 1,
strokeDasharray: "2 2"
}
},
legends: {
text: {
fill: token.colorTextLabel,
fontSize: 18,
fontSize: 12,
},
},
tooltip: {
container: {
background: token.colorBgContainer,
color: token.colorText,
}
},
grid: {
line: {
stroke: token.colorBorder,
Expand Down Expand Up @@ -115,19 +128,18 @@ export default function LineChart(
// @ts-ignore
data={data}
theme={chartTheme}
lineWidth={useLines ? 2 : 0}
lineWidth={useLines ? 1 : 0}
animate={false}
margin={{top: 30, right: 140, bottom: 110, left: 80}}
xScale={{type: 'point'}}
yScale={{
type: 'linear',
min: 'auto',
max: 'auto',
stacked: true,
reverse: false
}}
yFormat=" >-.2f"
curve="natural"
curve="cardinal"
axisTop={null}
axisRight={null}
axisBottom={{
Expand All @@ -149,7 +161,7 @@ export default function LineChart(
enableGridX={true}
colors={{scheme: 'nivo'}}
enablePoints={true}
pointSize={usePoints ? 6 : 0}
pointSize={usePoints ? 4 : 0}
pointColor={{from: 'color', modifiers: []}}
pointBorderWidth={2}
pointBorderColor={{from: 'color', modifiers: []}}
Expand Down
Loading

0 comments on commit 0307859

Please sign in to comment.