Make colors consistent regardless of # transfers

This commit is contained in:
Emilia Allison 2023-06-13 11:05:40 -04:00
parent c88a34595e
commit dd479868cc
Signed by: emilia
GPG Key ID: 7A3F8997BFE894E0
3 changed files with 8 additions and 12 deletions

View File

@ -111,7 +111,7 @@ pub fn DestinationPlate(props: &DestinationPlateProps) -> Html {
selected={super::source_plate::in_rect(*m_start_handle.clone(), *m_end_handle.clone(), (i,j))} selected={super::source_plate::in_rect(*m_start_handle.clone(), *m_end_handle.clone(), (i,j))}
mouse={mouse_callback.clone()} mouse={mouse_callback.clone()}
in_transfer={destination_wells.contains(&(i,j))} in_transfer={destination_wells.contains(&(i,j))}
color={color_map.get(&(i,j)).copied().map(|y| (y,color_counter))} color={color_map.get(&(i,j)).copied()}
/> />
} }
}).collect::<Html>(); }).collect::<Html>();
@ -151,7 +151,7 @@ pub struct DestPlateCellProps {
pub selected: bool, pub selected: bool,
pub mouse: Callback<(u8, u8, MouseEventType)>, pub mouse: Callback<(u8, u8, MouseEventType)>,
pub in_transfer: Option<bool>, pub in_transfer: Option<bool>,
color: Option<(u8, u8)>, color: Option<u8>,
} }
#[function_component] #[function_component]
@ -165,7 +165,7 @@ fn DestPlateCell(props: &DestPlateCellProps) -> Html {
_ => None, _ => None,
}; };
let color = match props.color { let color = match props.color {
Some(num) => PALETTE.get_u8(num.0, num.1), Some(num) => PALETTE.get_u8(num),
None => [255.0, 255.0, 255.0], None => [255.0, 255.0, 255.0],
}; };
let mouse = Callback::clone(&props.mouse); let mouse = Callback::clone(&props.mouse);

View File

@ -113,7 +113,7 @@ pub fn SourcePlate(props: &SourcePlateProps) -> Html {
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={source_wells.contains(&(i,j))} in_transfer={source_wells.contains(&(i,j))}
color={color_map.get(&(i,j)).copied().map(|y| (y,color_counter))} color={color_map.get(&(i,j)).copied()}
/> />
} }
}) })
@ -149,7 +149,7 @@ pub struct SourcePlateCellProps {
selected: bool, selected: bool,
mouse: Callback<(u8, u8, MouseEventType)>, mouse: Callback<(u8, u8, MouseEventType)>,
in_transfer: Option<bool>, in_transfer: Option<bool>,
color: Option<(u8, u8)>, color: Option<u8>,
} }
#[derive(Debug)] #[derive(Debug)]
pub enum MouseEventType { pub enum MouseEventType {
@ -168,7 +168,7 @@ fn SourcePlateCell(props: &SourcePlateCellProps) -> Html {
_ => None, _ => None,
}; };
let color = match props.color { let color = match props.color {
Some(num) => PALETTE.get_u8(num.0, num.1), Some(num) => PALETTE.get_u8(num),
None => [255.0, 255.0, 255.0], None => [255.0, 255.0, 255.0],
}; };
let mouse = Callback::clone(&props.mouse); let mouse = Callback::clone(&props.mouse);

View File

@ -26,13 +26,9 @@ impl ColorPalette {
] ]
} }
pub fn get_u8(&self, t: u8, n: 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!");
assert!(n > 0, "There cannot be zero points!"); self.get((2f64.powi(-1*t.ilog2() as i32)) as f64 * (t as f64 + 0.5f64)-1.0f64)
if n == 1 {
return self.get(0.5f64);
}
self.get((t - 1) as f64 / (n - 1) as f64)
} }
} }