use gpui::{Hsla, SharedString};
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct Node {
pub id: SharedString,
pub label: SharedString,
pub category: SharedString,
pub properties: Vec<(SharedString, SharedString)>,
pub group: Option<SharedString>,
pub color: Option<Hsla>,
pub size: Option<f32>,
}
impl Node {
pub fn new(
id: impl Into<SharedString>,
label: impl Into<SharedString>,
category: impl Into<SharedString>,
) -> Self {
Self {
id: id.into(),
label: label.into(),
category: category.into(),
properties: Vec::new(),
group: None,
color: None,
size: None,
}
}
pub fn property(
mut self,
key: impl Into<SharedString>,
value: impl Into<SharedString>,
) -> Self {
self.properties.push((key.into(), value.into()));
self
}
pub fn group(mut self, group: impl Into<SharedString>) -> Self {
self.group = Some(group.into());
self
}
pub fn color(mut self, color: impl Into<Hsla>) -> Self {
self.color = Some(color.into());
self
}
pub fn size(mut self, radius: f32) -> Self {
self.size = Some(radius);
self
}
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct Edge {
pub source: SharedString,
pub target: SharedString,
pub label: SharedString,
pub properties: Vec<(SharedString, SharedString)>,
}
impl Edge {
pub fn new(
source: impl Into<SharedString>,
target: impl Into<SharedString>,
label: impl Into<SharedString>,
) -> Self {
Self {
source: source.into(),
target: target.into(),
label: label.into(),
properties: Vec::new(),
}
}
pub fn property(
mut self,
key: impl Into<SharedString>,
value: impl Into<SharedString>,
) -> Self {
self.properties.push((key.into(), value.into()));
self
}
}
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct GraphData {
pub nodes: Vec<Node>,
pub edges: Vec<Edge>,
}
impl GraphData {
pub fn new(nodes: Vec<Node>, edges: Vec<Edge>) -> Self {
Self { nodes, edges }
}
}