mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-04-24 22:57:12 -04:00
fix: avoid overlapping option colors (#1318)
This commit is contained in:
parent
58ad9a260c
commit
10229ca8b5
1 changed files with 15 additions and 3 deletions
|
@ -101,7 +101,7 @@ pub trait SelectTypeOptionSharedAction: TypeOptionDataSerializer + Send + Sync {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_option(&self, name: &str) -> SelectOptionPB {
|
fn create_option(&self, name: &str) -> SelectOptionPB {
|
||||||
let color = select_option_color_from_index(self.options().len());
|
let color = new_select_option_color(self.options());
|
||||||
SelectOptionPB::with_color(name, color)
|
SelectOptionPB::with_color(name, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,8 +215,20 @@ pub fn select_type_option_from_field_rev(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_option_color_from_index(index: usize) -> SelectOptionColorPB {
|
pub fn new_select_option_color(options: &Vec<SelectOptionPB>) -> SelectOptionColorPB {
|
||||||
match index % 8 {
|
let mut freq: Vec<usize> = vec![0; 9];
|
||||||
|
|
||||||
|
for option in options {
|
||||||
|
freq[option.color.to_owned() as usize] += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
match freq
|
||||||
|
.into_iter()
|
||||||
|
.enumerate()
|
||||||
|
.min_by_key(|(_, v)| *v)
|
||||||
|
.map(|(idx, _val)| idx)
|
||||||
|
.unwrap()
|
||||||
|
{
|
||||||
0 => SelectOptionColorPB::Purple,
|
0 => SelectOptionColorPB::Purple,
|
||||||
1 => SelectOptionColorPB::Pink,
|
1 => SelectOptionColorPB::Pink,
|
||||||
2 => SelectOptionColorPB::LightPink,
|
2 => SelectOptionColorPB::LightPink,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue