refactor: Well struct in web

This commit is contained in:
Emilia Allison 2024-08-10 00:58:55 -04:00
parent 7e321a78c4
commit 63790c2145
Signed by: emilia
GPG Key ID: 7A3F8997BFE894E0
5 changed files with 24 additions and 15 deletions

View File

@ -38,3 +38,9 @@ impl Into<Well> for (u8, u8) {
}
}
}
impl Into<(u8,u8)> for Well {
fn into(self) -> (u8,u8) {
(self.col, self.row)
}
}

View File

@ -1,5 +1,6 @@
use std::collections::HashSet;
use plate_tool_lib::well::Well;
use wasm_bindgen::{prelude::*, JsCast};
use web_sys::{
FileReader, HtmlButtonElement, HtmlDialogElement, HtmlElement, HtmlFormElement,
@ -238,7 +239,7 @@ pub fn import_transfer_csv_submit_callback(
let from_dest = from_dest.value();
let to_dest = to_dest.value();
let records: Vec<((u8, u8), (u8, u8))> = records
let records: Vec<(Well, Well)> = records
.iter()
.filter(|record| record.source_plate == from_source)
.filter(|record| record.destination_plate == from_dest)

View File

@ -7,6 +7,7 @@ use yewdux::prelude::*;
use crate::components::states::{CurrentTransfer, MainState};
use plate_tool_lib::plate::PlateType;
use plate_tool_lib::transfer::Transfer;
use plate_tool_lib::well::Well;
use plate_tool_lib::transfer_region::Region;
// Color Palette for the Source Plates, can be changed here
@ -32,8 +33,8 @@ pub fn Plate(props: &PlateProps) -> Html {
PlateType::Destination => ct_state.transfer.transfer_region.dest_region.clone(),
};
let (pt1, pt2) = match region {
Region::Point((x, y)) => ((x, y), (x, y)),
Region::Rect(c1, c2) => (c1, c2),
Region::Point(Well {col: x, row: y}) => ((x, y), (x, y)),
Region::Rect(c1, c2) => (c1.into(), c2.into()),
Region::Custom(_) => ((0, 0), (0, 0)),
};
m_start_handle.set(Some(pt1));
@ -57,15 +58,15 @@ pub fn Plate(props: &PlateProps) -> Html {
PlateType::Destination => transfer.transfer_region.get_destination_wells(),
};
for well in wells {
if let Some(val) = tooltip_map_temp.get_mut(&well) {
if let Some(val) = tooltip_map_temp.get_mut(&well.into()) {
val.push(transfer);
} else {
tooltip_map_temp.insert(well, vec![transfer]);
tooltip_map_temp.insert(well.into(), vec![transfer]);
}
if let Some(val) = volume_map_temp.get_mut(&well) {
if let Some(val) = volume_map_temp.get_mut(&well.into()) {
*val += transfer.volume;
} else {
volume_map_temp.insert(well, transfer.volume);
volume_map_temp.insert(well.into(), transfer.volume);
}
volume_max_temp = f32::max(volume_max_temp, transfer.volume);
}
@ -162,7 +163,7 @@ pub fn Plate(props: &PlateProps) -> Html {
<PlateCell i={i} j={j}
selected={in_rect(*m_start_handle.clone(), *m_end_handle.clone(), (i,j))}
mouse={mouse_callback.clone()}
in_transfer={wells.contains(&(i,j)) && main_state.preferences.in_transfer_hashes}
in_transfer={wells.contains(&Well {col: i, row: j}) && main_state.preferences.in_transfer_hashes}
color={ color }
cell_height={props.cell_height}
title={title}

View File

@ -1,6 +1,7 @@
#![allow(non_snake_case)]
use lazy_static::lazy_static;
use plate_tool_lib::well::Well;
use regex::Regex;
use serde::{Deserialize, Serialize};
use yew::prelude::*;
@ -233,10 +234,10 @@ impl TryFrom<&str> for RegionDisplay {
impl From<&Region> for RegionDisplay {
fn from(value: &Region) -> Self {
match *value {
Region::Point((col, row)) => {
Region::Point(Well { col, row }) => {
RegionDisplay::try_from((col, row, col, row)).ok().unwrap()
}
Region::Rect(c1, c2) => RegionDisplay::try_from((c1.0, c1.1, c2.0, c2.1))
Region::Rect(c1, c2) => RegionDisplay::try_from((c1.col, c1.row, c2.col, c2.row))
.ok()
.unwrap(),
Region::Custom(_) => RegionDisplay {
@ -252,11 +253,11 @@ impl From<&Region> for RegionDisplay {
impl From<&RegionDisplay> for Region {
fn from(value: &RegionDisplay) -> Self {
if value.col_start == value.col_end && value.row_start == value.row_end {
Region::Point((value.col_start, value.row_start))
Region::Point((value.col_start, value.row_start).into())
} else {
Region::Rect(
(value.col_start, value.row_start),
(value.col_end, value.row_end),
(value.col_start, value.row_start).into(),
(value.col_end, value.row_end).into(),
)
}
}

View File

@ -25,9 +25,9 @@ pub fn plate_test() {
let transfer = transfer_region::TransferRegion {
source_plate: source,
source_region: transfer_region::Region::Rect((1, 1), (2, 2)),
source_region: transfer_region::Region::Rect((1, 1).into(), (2, 2).into()),
dest_plate: destination,
dest_region: transfer_region::Region::Rect((2, 2), (11, 11)),
dest_region: transfer_region::Region::Rect((2, 2).into(), (11, 11).into()),
interleave_source: (1, 1),
interleave_dest: (3, 3),
};