pub fn fmt(v: f64) -> String {
if v.fract() == 0.0 && v.abs() < 1e12 {
return format!("{}", v as i64);
}
let s = format!("{:.13}", v);
let s = s.trim_end_matches('0');
let s = s.trim_end_matches('.');
s.to_string()
}
pub fn esc(s: &str) -> String {
s.replace('&', "&")
.replace('<', "<")
.replace('>', ">")
.replace('"', """)
}
#[allow(clippy::too_many_arguments)]
pub fn label_tspan(
cx: f64,
cy: f64,
label: &str,
font_size: f64,
color: &str,
anchor: &str,
extra_text_attrs: &str,
font_family: &str,
) -> String {
let group_y = cy - font_size / 1.882; label_tspan_raw(
cx,
group_y,
label,
font_size,
color,
anchor,
extra_text_attrs,
font_family,
)
}
#[allow(clippy::too_many_arguments)]
pub fn label_tspan_raw(
cx: f64,
gy: f64,
label: &str,
font_size: f64,
color: &str,
anchor: &str,
extra_text_attrs: &str,
font_family: &str,
) -> String {
let text_y = -(font_size * 0.631); format!(
"<g class=\"label\" transform=\"translate({cx},{gy})\"><text text-anchor=\"{anchor}\" y=\"{ty}\" font-family=\"{ff}\" font-size=\"{fs}\" fill=\"{color}\"{extra}><tspan x=\"0\" y=\"-0.1em\" dy=\"1.1em\"><tspan>{label}</tspan></tspan></text></g>",
cx = fmt(cx),
gy = fmt(gy),
ty = fmt(text_y),
anchor = anchor,
ff = font_family,
fs = font_size,
color = color,
extra = extra_text_attrs,
label = label,
)
}