pub use crate::diagrams::util::fmt;
pub fn escape_text(s: &str) -> String {
s.replace('&', "&")
.replace('<', "<")
.replace('>', ">")
}
pub fn escape_attr(s: &str) -> String {
s.replace('&', "&")
.replace('"', """)
.replace('<', "<")
.replace('>', ">")
}
pub fn svg_root(id: &str, width: i64, height: i64) -> String {
format!(
r##"<svg id="{id}" width="100%" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" font-family="Arial, sans-serif" style="max-width: {w}px;" viewBox="0 0 {w} {h}" role="graphics-document document" aria-roledescription="xychart">"##,
id = id,
w = width,
h = height,
)
}
pub fn main_group_with_bg(width: i64, height: i64, bg_color: &str) -> String {
format!(
r##"<g class="main"><rect width="{}" height="{}" class="background" fill="{}"></rect>"##,
width, height, bg_color,
)
}
pub fn chart_rect(
x: &str,
y: &str,
w: &str,
h: &str,
fill: &str,
stroke: &str,
stroke_w: &str,
) -> String {
format!(
r##"<rect x="{}" y="{}" width="{}" height="{}" fill="{}" stroke="{}" stroke-width="{}"></rect>"##,
x, y, w, h, fill, stroke, stroke_w,
)
}
pub fn chart_text(
fill: &str,
font_size: &str,
dominant_baseline: &str,
text_anchor: &str,
transform: &str,
text: &str,
) -> String {
format!(
r##"<text x="0" y="0" fill="{}" font-size="{}" dominant-baseline="{}" text-anchor="{}" transform="{}">{}</text>"##,
fill, font_size, dominant_baseline, text_anchor, transform, text,
)
}
pub fn chart_path(path_d: &str, fill: &str, stroke: &str, stroke_w: &str) -> String {
format!(
r##"<path d="{}" fill="{}" stroke="{}" stroke-width="{}"></path>"##,
path_d, fill, stroke, stroke_w,
)
}
pub fn group_open(class: &str) -> String {
format!(r##"<g class="{}">"##, class)
}