Compare commits

..

No commits in common. "8f82c4e224f198759c87750f3e50f576941fa1d7" and "f7f492b70e052d02dd442f503d7ab87d2c1b2a15" have entirely different histories.

6 changed files with 14 additions and 74 deletions

2
Cargo.lock generated
View File

@ -633,7 +633,7 @@ dependencies = [
[[package]] [[package]]
name = "plate-tool-lib" name = "plate-tool-lib"
version = "0.3.1" version = "0.3.0"
dependencies = [ dependencies = [
"csv", "csv",
"getrandom", "getrandom",

View File

@ -43,17 +43,6 @@ pub fn toggle_in_transfer_hashes_callback(
}) })
} }
pub fn toggle_volume_heatmap_callback(
main_dispatch: Dispatch<MainState>,
) -> Callback<web_sys::MouseEvent> {
let main_dispatch = main_dispatch.clone();
Callback::from(move |_| {
main_dispatch.reduce_mut(|state| {
state.preferences.volume_heatmap ^= true;
})
})
}
pub fn new_plate_dialog_callback( pub fn new_plate_dialog_callback(
new_plate_dialog_is_open: UseStateHandle<bool>, new_plate_dialog_is_open: UseStateHandle<bool>,
) -> NoParamsCallback { ) -> NoParamsCallback {

View File

@ -43,11 +43,6 @@ pub fn MainWindow() -> Html {
main_window_callbacks::toggle_in_transfer_hashes_callback(main_dispatch) main_window_callbacks::toggle_in_transfer_hashes_callback(main_dispatch)
}; };
let toggle_volume_heatmap_callback = {
let main_dispatch = main_dispatch.clone();
main_window_callbacks::toggle_volume_heatmap_callback(main_dispatch)
};
let new_plate_dialog_is_open = use_state_eq(|| false); let new_plate_dialog_is_open = use_state_eq(|| false);
let new_plate_dialog_callback = let new_plate_dialog_callback =
main_window_callbacks::new_plate_dialog_callback(new_plate_dialog_is_open.clone()); main_window_callbacks::new_plate_dialog_callback(new_plate_dialog_is_open.clone());
@ -103,7 +98,6 @@ pub fn MainWindow() -> Html {
<button>{"Styles"}</button> <button>{"Styles"}</button>
<div> <div>
<button onclick={toggle_in_transfer_hashes_callback}>{"Toggle transfer hashes"}</button> <button onclick={toggle_in_transfer_hashes_callback}>{"Toggle transfer hashes"}</button>
<button onclick={toggle_volume_heatmap_callback}>{"Toggle volume heatmap"}</button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -40,40 +40,26 @@ pub fn Plate(props: &PlateProps) -> Html {
m_end_handle.set(Some(pt2)); m_end_handle.set(Some(pt2));
} }
let tooltip_map: HashMap<(u8, u8), Vec<&Transfer>>; let tooltip_map = {
let volume_map: HashMap<(u8, u8), f32>;
let volume_max: f32;
{
let transfers = main_state.transfers.iter().filter(|t| match props.ptype { let transfers = main_state.transfers.iter().filter(|t| match props.ptype {
PlateType::Source => t.source_id == props.source_plate.get_uuid(), PlateType::Source => t.source_id == props.source_plate.get_uuid(),
PlateType::Destination => t.dest_id == props.destination_plate.get_uuid(), PlateType::Destination => t.dest_id == props.destination_plate.get_uuid(),
}); });
let mut tooltip_map_temp: HashMap<(u8, u8), Vec<&Transfer>> = HashMap::new(); let mut tooltip_map: HashMap<(u8, u8), Vec<&Transfer>> = HashMap::new();
let mut volume_map_temp: HashMap<(u8,u8), f32> = HashMap::new();
let mut volume_max_temp: f32 = f32::NEG_INFINITY;
for transfer in transfers { for transfer in transfers {
let wells = match props.ptype { let wells = match props.ptype {
PlateType::Source => transfer.transfer_region.get_source_wells(), PlateType::Source => transfer.transfer_region.get_source_wells(),
PlateType::Destination => transfer.transfer_region.get_destination_wells(), PlateType::Destination => transfer.transfer_region.get_destination_wells(),
}; };
for well in wells { for well in wells {
if let Some(val) = tooltip_map_temp.get_mut(&well) { if let Some(val) = tooltip_map.get_mut(&well) {
val.push(transfer); val.push(transfer);
} else { } else {
tooltip_map_temp.insert(well, vec![transfer]); tooltip_map.insert(well, vec![transfer]);
} }
if let Some(val) = volume_map_temp.get_mut(&well) {
*val += transfer.volume;
} else {
log::info!("well: {:?}, vol: {:?}", well, transfer.volume);
volume_map_temp.insert(well, transfer.volume);
}
volume_max_temp = f32::max(volume_max_temp, transfer.volume);
} }
} }
tooltip_map = tooltip_map_temp; tooltip_map
volume_map = volume_map_temp;
volume_max = volume_max_temp;
}; };
let wells = match props.ptype { let wells = match props.ptype {
@ -134,39 +120,18 @@ pub fn Plate(props: &PlateProps) -> Html {
let row_header = html! {<th>{num_to_letters(i)}</th>}; let row_header = html! {<th>{num_to_letters(i)}</th>};
let row = (1..=width) let row = (1..=width)
.map(|j| { .map(|j| {
let color = {
if !main_state.preferences.volume_heatmap {
tooltip_map.get(&(i,j))
.and_then(|t| t.last())
.map(|t| PALETTE.get_ordered(t.get_uuid(), &ordered_ids))
} else {
volume_map.get(&(i,j))
.map(|t| PALETTE.get_linear(*t as f64, volume_max as f64))
}
};
let title = {
let mut out = String::new();
let used_by = tooltip_map.get(&(i,j)).map(|transfers| format!("Used by: {}", transfers.iter().map(|t| t.name.clone())
.collect::<Vec<_>>().join(", ")));
if let Some(val) = used_by {
out += &val;
}
let volume_sum = volume_map.get(&(i,j))
.map(|t| format!("Volume: {}", t));
if let Some(val) = volume_sum {
if !out.is_empty() { out += "\n" }
out += &val;
}
out
};
html! { html! {
<PlateCell i={i} j={j} <PlateCell i={i} j={j}
selected={in_rect(*m_start_handle.clone(), *m_end_handle.clone(), (i,j))} selected={in_rect(*m_start_handle.clone(), *m_end_handle.clone(), (i,j))}
mouse={mouse_callback.clone()} mouse={mouse_callback.clone()}
in_transfer={wells.contains(&(i,j)) && main_state.preferences.in_transfer_hashes} in_transfer={wells.contains(&(i,j)) && main_state.preferences.in_transfer_hashes}
color={ color } color={tooltip_map.get(&(i,j))
.and_then(|t| t.last())
.map(|t| PALETTE.get_ordered(t.get_uuid(), &ordered_ids))
}
cell_height={props.cell_height} cell_height={props.cell_height}
title={title} title={tooltip_map.get(&(i,j)).map(|transfers| format!("Used by: {}", transfers.iter().map(|t| t.name.clone())
.collect::<Vec<_>>().join(", ")))}
/> />
} }
}) })

View File

@ -26,7 +26,7 @@ impl ColorPalette {
] ]
} }
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(-(t.ilog2() as i32))) * (t as f64 + 0.5f64) - 1.0f64) self.get((2f64.powi(-(t.ilog2() as i32))) * (t as f64 + 0.5f64) - 1.0f64)
} }
@ -43,11 +43,6 @@ impl ColorPalette {
self.get(Self::space_evenly(index)) self.get(Self::space_evenly(index))
} }
pub fn get_linear(&self, t: f64, max: f64) -> [f64; 3] {
let scaled = t / max;
self.get(scaled)
}
fn space_evenly(x: usize) -> f64 { fn space_evenly(x: usize) -> f64 {
let e: usize = (x.ilog2() + 1) as usize; let e: usize = (x.ilog2() + 1) as usize;
let d: usize = 2usize.pow(e as u32); let d: usize = 2usize.pow(e as u32);

View File

@ -15,15 +15,12 @@ pub struct CurrentTransfer {
#[derive(PartialEq, Clone, Copy, Serialize, Deserialize)] #[derive(PartialEq, Clone, Copy, Serialize, Deserialize)]
pub struct Preferences { pub struct Preferences {
#[serde(default)]
pub in_transfer_hashes: bool, pub in_transfer_hashes: bool,
#[serde(default)]
pub volume_heatmap: bool,
} }
impl Default for Preferences { impl Default for Preferences {
fn default() -> Self { fn default() -> Self {
Self { in_transfer_hashes: true, volume_heatmap: false } Self { in_transfer_hashes: true }
} }
} }