chore: clippy & fmt

This commit is contained in:
Emilia Allison 2023-06-15 22:23:12 -04:00
parent 28c1716f17
commit 6aee3ded2c
Signed by: emilia
GPG Key ID: 7A3F8997BFE894E0
5 changed files with 46 additions and 46 deletions

View File

@ -64,7 +64,7 @@ pub fn DestinationPlate(props: &DestinationPlateProps) -> Html {
.transfers .transfers
.iter() .iter()
.filter(|t| t.dest_id == props.destination_plate.get_uuid()); .filter(|t| t.dest_id == props.destination_plate.get_uuid());
let mut tooltip_map: HashMap<(u8,u8), Vec<&Transfer>> = HashMap::new(); let mut tooltip_map: HashMap<(u8, u8), Vec<&Transfer>> = HashMap::new();
for t in ts { for t in ts {
let dws = t.transfer_region.get_destination_wells(); let dws = t.transfer_region.get_destination_wells();
for dw in dws { for dw in dws {
@ -120,10 +120,8 @@ pub fn DestinationPlate(props: &DestinationPlateProps) -> Html {
.map(|t| PALETTE.get_uuid(t.get_uuid())) .map(|t| PALETTE.get_uuid(t.get_uuid()))
} }
cell_height={props.cell_height} cell_height={props.cell_height}
title={if let Some(transfers) = transfer_map.get(&(i,j)) { title={transfer_map.get(&(i,j)).map(|transfers| format!("Used by: {}", transfers.iter().map(|t| t.name.clone())
Some(format!("Used by: {}", transfers.iter().map(|t| t.name.clone()) .collect::<Vec<_>>().join(", ")))}
.collect::<Vec<_>>().join(", ")))
} else { None }}
/> />
} }
}).collect::<Html>(); }).collect::<Html>();
@ -136,7 +134,7 @@ pub fn DestinationPlate(props: &DestinationPlateProps) -> Html {
.collect::<Html>(); .collect::<Html>();
html! { html! {
<div class={classes!{"dest_plate", <div class={classes!{"dest_plate",
"W".to_owned()+&props.source_plate.plate.plate_format.to_string()}}> "W".to_owned()+&props.source_plate.plate.plate_format.to_string()}}>
<table <table
onmouseup={move |e| { onmouseup={move |e| {
@ -179,10 +177,7 @@ fn DestPlateCell(props: &DestPlateCellProps) -> Html {
Some(true) => Some("in_transfer"), Some(true) => Some("in_transfer"),
_ => None, _ => None,
}; };
let color = match props.color { let color = props.color.unwrap_or([255.0, 255.0, 255.0]);
Some(num) => num,
None => [255.0, 255.0, 255.0],
};
let mouse = Callback::clone(&props.mouse); let mouse = Callback::clone(&props.mouse);
let mouse2 = Callback::clone(&props.mouse); let mouse2 = Callback::clone(&props.mouse);
let (i, j) = (props.i, props.j); let (i, j) = (props.i, props.j);

View File

@ -1,6 +1,6 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
use wasm_bindgen::JsCast;
use wasm_bindgen::prelude::Closure; use wasm_bindgen::prelude::Closure;
use wasm_bindgen::JsCast;
use yew::prelude::*; use yew::prelude::*;
use crate::data::plate_instances::PlateInstance; use crate::data::plate_instances::PlateInstance;
@ -16,26 +16,36 @@ pub struct PlateContainerProps {
#[function_component] #[function_component]
pub fn PlateContainer(props: &PlateContainerProps) -> Html { pub fn PlateContainer(props: &PlateContainerProps) -> Html {
let cell_height = { let cell_height = {
let height = web_sys::window().unwrap().inner_height().unwrap().as_f64().unwrap(); let height = web_sys::window()
let width = web_sys::window().unwrap().inner_width().unwrap().as_f64().unwrap(); .unwrap()
if let (Some(src_d), Some(dest_d)) = (&props.source_dims, &props.destination_dims) { .inner_height()
let h = .unwrap()
(0.78*height)/(src_d.plate.size().0 + dest_d.plate.size().0) as f64; .as_f64()
let w = .unwrap();
(0.90*width)/(src_d.plate.size().1 + dest_d.plate.size().1) as f64; let width = web_sys::window()
f64::min(w,h) .unwrap()
} else { .inner_width()
1f64 .unwrap()
} .as_f64()
}; .unwrap();
if let (Some(src_d), Some(dest_d)) = (&props.source_dims, &props.destination_dims) {
let h = (0.78 * height) / (src_d.plate.size().0 + dest_d.plate.size().0) as f64;
let w = (0.90 * width) / (src_d.plate.size().1 + dest_d.plate.size().1) as f64;
f64::min(w, h)
} else {
1f64
}
};
let resize_trigger = use_force_update(); let resize_trigger = use_force_update();
let onresize = Closure::<dyn FnMut(_)>::new(move |_: Event| { let onresize = Closure::<dyn FnMut(_)>::new(move |_: Event| {
resize_trigger.force_update(); resize_trigger.force_update();
}); });
web_sys::window().unwrap().set_onresize(Some(onresize.as_ref().unchecked_ref())); web_sys::window()
onresize.forget(); // Magic! .unwrap()
.set_onresize(Some(onresize.as_ref().unchecked_ref()));
onresize.forget(); // Magic!
html! { html! {
<div class="plate_container"> <div class="plate_container">

View File

@ -44,7 +44,7 @@ pub fn SourcePlate(props: &SourcePlateProps) -> Html {
.transfers .transfers
.iter() .iter()
.filter(|t| t.source_id == props.source_plate.get_uuid()); .filter(|t| t.source_id == props.source_plate.get_uuid());
let mut tooltip_map: HashMap<(u8,u8), Vec<&Transfer>> = HashMap::new(); let mut tooltip_map: HashMap<(u8, u8), Vec<&Transfer>> = HashMap::new();
for t in ts { for t in ts {
let sws = t.transfer_region.get_source_wells(); let sws = t.transfer_region.get_source_wells();
for sw in sws { for sw in sws {
@ -103,8 +103,8 @@ pub fn SourcePlate(props: &SourcePlateProps) -> Html {
let headers = (1..=props.source_plate.plate.size().1) let headers = (1..=props.source_plate.plate.size().1)
.map(|j| { .map(|j| {
html! {<th> html! {<th>
{format!("{:0>2}", j)} {format!("{:0>2}", j)}
</th>} </th>}
}) })
.collect::<Html>(); .collect::<Html>();
html! {<tr><th />{ headers }</tr>} html! {<tr><th />{ headers }</tr>}
@ -124,10 +124,8 @@ pub fn SourcePlate(props: &SourcePlateProps) -> Html {
.map(|t| PALETTE.get_uuid(t.get_uuid())) .map(|t| PALETTE.get_uuid(t.get_uuid()))
} }
cell_height={props.cell_height} cell_height={props.cell_height}
title={if let Some(transfers) = transfer_map.get(&(i,j)) { title={transfer_map.get(&(i,j)).map(|transfers| format!("Used by: {}", transfers.iter().map(|t| t.name.clone())
Some(format!("Used by: {}", transfers.iter().map(|t| t.name.clone()) .collect::<Vec<_>>().join(", ")))}
.collect::<Vec<_>>().join(", ")))
} else { None }}
/> />
} }
}) })
@ -184,10 +182,7 @@ fn SourcePlateCell(props: &SourcePlateCellProps) -> Html {
Some(true) => Some("in_transfer"), Some(true) => Some("in_transfer"),
_ => None, _ => None,
}; };
let color = match props.color { let color = props.color.unwrap_or([255.0, 255.0, 255.0]);
Some(num) => num,
None => [255.0, 255.0, 255.0],
};
let mouse = Callback::clone(&props.mouse); let mouse = Callback::clone(&props.mouse);
let mouse2 = Callback::clone(&props.mouse); let mouse2 = Callback::clone(&props.mouse);
let (i, j) = (props.i, props.j); let (i, j) = (props.i, props.j);
@ -279,7 +274,7 @@ mod tests {
let c2 = (10, 10); let c2 = (10, 10);
let pt1 = (0, 0); let pt1 = (0, 0);
let pt2 = (15, 15); let pt2 = (15, 15);
assert_eq!(false, in_rect(Some(c1), Some(c2), pt1)); assert!(!in_rect(Some(c1), Some(c2), pt1));
assert_eq!(false, in_rect(Some(c1), Some(c2), pt2)); assert!(!in_rect(Some(c1), Some(c2), pt2));
} }
} }

View File

@ -26,9 +26,9 @@ impl ColorPalette {
] ]
} }
pub fn get_u8(&self, t: u8) -> [f64; 3] { pub fn _get_u8(&self, t: u8) -> [f64; 3] {
assert!(t > 0, "t must be greater than zero!"); assert!(t > 0, "t must be greater than zero!");
self.get((2f64.powi(-1*t.ilog2() as i32)) as f64 * (t as f64 + 0.5f64)-1.0f64) self.get((2f64.powi(-(t.ilog2() as i32))) * (t as f64 + 0.5f64) - 1.0f64)
} }
pub fn get_uuid(&self, t: uuid::Uuid) -> [f64; 3] { pub fn get_uuid(&self, t: uuid::Uuid) -> [f64; 3] {

View File

@ -454,7 +454,7 @@ mod tests {
Some("BJ".to_string()) Some("BJ".to_string())
); );
for i in 1..=255 { for i in 1..=255 {
assert_eq!(letters_to_num(&num_to_letters(i as u8).unwrap()), Some(i)); assert_eq!(letters_to_num(&num_to_letters(i).unwrap()), Some(i));
} }
} }