Skip to content

Commit

Permalink
Fix relation labels
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoobergs committed Sep 28, 2021
1 parent bafcb31 commit 8422ef6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
13 changes: 9 additions & 4 deletions erd/src/erd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ impl ToDot for Relation {
fn to_dot_statements(&self) -> Vec<dot::Statement> {
let relation_name: String = self.name.clone().into();

let relation_label = if let Some(l) = self.label.clone() {
l
} else {
relation_name.clone()
};
let relation_node = dot::Statement::Node(dot::NodeStatement {
node: relation_name.clone(),
attributes: Some(dot::AttributeList {
Expand All @@ -164,7 +169,7 @@ impl ToDot for Relation {
},
dot::AListItem {
key: "label".into(),
value: format!("{}", relation_name.clone(),),
value: format!("\"{}\"", relation_label),
},
]),
tail: Box::new(None),
Expand Down Expand Up @@ -219,13 +224,13 @@ impl ToDot for Relation {
key: "color".into(),
value: match member.optionality {
RelationOptionality::Optional => "black",
RelationOptionality::Required => "\"black:invis:black\"",
RelationOptionality::Required => "\"black:invis:invis:black\"",
}
.into(),
},
dot::AListItem {
key: "label".into(),
value: amount,
value: format!("<<font color=\"blue\">{}</font>>", amount),
},
dot::AListItem {
key: "len".into(),
Expand Down Expand Up @@ -310,7 +315,7 @@ impl ToDot for ERD {
content: dot::AList(vec![
dot::AListItem {
key: "pad".into(),
value: "0.5".to_string(),
value: "2".to_string(),
},
dot::AListItem {
key: "nodesep".into(),
Expand Down
1 change: 1 addition & 0 deletions erd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use parser::ConsumeError;
fn parse_file(path: &std::path::Path) -> Result<Vec<ast::Expr>, ConsumeError> {
println!("{:?}", path.display());
let content = std::fs::read_to_string(path).expect("Valid file");
println!("{}", content);
let pairs =
parser::parse_as_erd(&content).map_err(|e| parser::ConsumeError::ERDParseError(vec![e]))?;
println!("{:?}", pairs);
Expand Down
2 changes: 1 addition & 1 deletion examples/attribute.erd
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
entity Student
attribute Naam
attribute Naam
36 changes: 36 additions & 0 deletions examples/patients.erd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
entity patient

entity division

entity room

entity medicin

entity prescription

entity doctor

relation Houses
one required division
multiple optional room

relation Sleeps(Sleeps in)
one required room
multiple optional patient

relation Weekly(Gets weekly)
one required patient
multiple optional prescription

relation PrescriptionMedicin(Contains)
one optional prescription
multiple required medicin

relation PrescriptionDoctor(Prescribes)
one required doctor
multiple optional prescription

relation PatientDoctor(Has)
multiple optional patient
one required doctor

0 comments on commit 8422ef6

Please sign in to comment.