use std::collections::HashMap;
pub fn stripe_tracks_by_id(staff_map: &HashMap<String, u32>, palette: &[&str]) -> String {
if palette.is_empty() || staff_map.is_empty() {
return String::new();
}
let mut out = String::new();
let mut entries: Vec<(&String, &u32)> = staff_map.iter().collect();
entries.sort_by(|a, b| a.0.cmp(b.0));
for (id, staff) in entries {
let color = palette[((staff.saturating_sub(1)) as usize) % palette.len()];
let safe_id = id.replace('"', "\\\"");
out.push_str(&format!(r#"g[id="{safe_id}"] {{ fill: {color}; }} "#));
}
out
}
pub fn fade_others(keep_ids: &[String], fade_color: &str) -> String {
if keep_ids.is_empty() {
return String::new();
}
let mut out = String::new();
out.push_str(&format!(
"g.note, g.rest, g.chord {{ fill: {fade_color}; opacity: 0.3; }} "
));
for id in keep_ids {
let safe_id = id.replace('"', "\\\"");
out.push_str(&format!(
r#"g[id="{safe_id}"] {{ fill: currentColor; opacity: 1.0; }} "#
));
}
out
}