use std::fmt;
use crate::{ArrowDirection, ArrowType, Color, EdgeStyle};
#[derive(Debug, Clone, PartialEq)]
pub struct EdgeAttributes {
pub label: Option<String>,
pub color: Option<Color>,
pub style: Option<EdgeStyle>,
pub shape: Option<String>,
pub arrow_direction: Option<ArrowDirection>,
pub arrow_head: Option<ArrowType>,
pub arrow_tail: Option<ArrowType>,
}
impl EdgeAttributes {
pub fn new(
label: Option<String>,
color: Option<Color>,
style: Option<EdgeStyle>,
shape: Option<String>,
arrow_direction: Option<ArrowDirection>,
arrow_head: Option<ArrowType>,
arrow_tail: Option<ArrowType>,
) -> Self {
Self {
label,
color,
style,
shape,
arrow_direction,
arrow_head,
arrow_tail,
}
}
pub fn attributes(&self) -> Option<String> {
crate::details::encode::encode_attributes(
&[
("label", self.label.as_ref().map(|s| s as &dyn ToString)),
("color", self.color.as_ref().map(|c| c as &dyn ToString)),
("style", self.style.as_ref().map(|s| s as &dyn ToString)),
("shape", self.shape.as_ref().map(|s| s as &dyn ToString)),
("dir", self.arrow_direction.as_ref().map(|s| s as &dyn ToString)),
("arrowhead", self.arrow_head.as_ref().map(|s| s as &dyn ToString)),
("arrowtail", self.arrow_tail.as_ref().map(|s| s as &dyn ToString)),
],
true,
)
}
}
impl Default for EdgeAttributes {
fn default() -> Self {
Self::new(None, None, None, None, None, None, None)
}
}
impl fmt::Display for EdgeAttributes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(encoded) = self.attributes() {
write!(f, "{}", encoded)
} else {
Ok(())
}
}
}