use crate::syntax::ast::{Child, Decl, Node, TextNode, Value, Wire};
pub(super) fn label_child_for(node: &Node, is_icon: bool, is_container: bool) -> Option<Child> {
if is_icon || is_container {
return None;
}
node.id.as_ref().map(|id| {
Child::Text(TextNode {
text: id.clone(),
span: node.span,
})
})
}
pub(super) fn auto_along(w: &Wire) -> Wire {
let n = w.labels.len();
let has_along = w.style.iter().any(|d| d.name == "along");
if n == 0 || has_along {
return w.clone();
}
let fractions: Vec<Value> = (0..n)
.map(|i| {
let f = (i as f64 + 1.0) / (n as f64 + 1.0);
Value::Number((f * 100.0).round() / 100.0)
})
.collect();
let mut style = w.style.clone();
style.insert(
0,
Decl {
name: "along".to_string(),
groups: vec![fractions],
span: w.span,
},
);
Wire {
chain: w.chain.clone(),
op: w.op,
classes: w.classes.clone(),
style,
style_span: w.style_span,
labels: w.labels.clone(),
span: w.span,
}
}