mirror of
https://github.com/Leaflet/Leafdoc.git
synced 2025-07-20 18:27:28 +00:00
Working UML relationships in the graphviz-class-diagram templates
This commit is contained in:
@ -184,7 +184,7 @@ The syntax is:
|
||||
🍂relationship type namespace [ ,cardinalityFrom [ ,cardinalityTo [ ,label ]]]
|
||||
```
|
||||
|
||||
The following relationship `type`s are implemented:
|
||||
The following relationship `type`s are implemented for display in the `graphviz-class-diagram` templates:
|
||||
- `associated`
|
||||
- `implements`
|
||||
- `dependsOn`
|
||||
|
32
spec/e2e/uml-class-relationships/basic-classes.leafdoc
Normal file
32
spec/e2e/uml-class-relationships/basic-classes.leafdoc
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
@class ChildClass
|
||||
@inherits ParentClass
|
||||
|
||||
@method childMethod(foo: String): this
|
||||
|
||||
|
||||
@class ParentClass
|
||||
|
||||
@method parentMethod(bar: Boolean): this
|
||||
|
||||
|
||||
@class ConcreteClass
|
||||
@relationship implements AbstractClass
|
||||
|
||||
@class AbstractClass
|
||||
|
||||
|
||||
@namespace Student
|
||||
@relationship associated ConcreteClass ,, Meaningless connection to
|
||||
|
||||
|
||||
@namespace Teacher
|
||||
|
||||
@namespace Classroom
|
||||
@relationship aggregationOf Student, 0..n, 1..n
|
||||
@relationship aggregationOf Teacher, 1 , 0..n
|
||||
|
||||
|
||||
|
||||
|
||||
|
6
spec/e2e/uml-class-relationships/leafdoc-options.json
Normal file
6
spec/e2e/uml-class-relationships/leafdoc-options.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"templateDir": "./templates/graphviz-class-diagram",
|
||||
"showInheritancesWhenEmpty": true,
|
||||
"leadingCharacter": "@",
|
||||
"outputExtension": "dot"
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
digraph ClassDiagram {
|
||||
node [shape=plaintext]
|
||||
edge [arrowhead=empty];
|
||||
|
||||
"ChildClass" [ label = <<TABLE CELLSPACING="0">
|
||||
<TR><TD><B>ChildClass</B></TD></TR>
|
||||
<TR><TD><I>Methods</I><BR/>
|
||||
childMethod(<String> foo):this
|
||||
<BR align="left" />
|
||||
|
||||
</TD></TR>
|
||||
|
||||
|
||||
</TABLE>>]
|
||||
|
||||
"ChildClass" -> "ParentClass"
|
||||
|
||||
"ParentClass" [ label = <<TABLE CELLSPACING="0">
|
||||
<TR><TD><B>ParentClass</B></TD></TR>
|
||||
<TR><TD><I>Methods</I><BR/>
|
||||
parentMethod(<Boolean> bar):this
|
||||
<BR align="left" />
|
||||
|
||||
</TD></TR>
|
||||
|
||||
|
||||
</TABLE>>]
|
||||
|
||||
|
||||
"ConcreteClass" [ label = <<TABLE CELLSPACING="0">
|
||||
<TR><TD><B>ConcreteClass</B></TD></TR>
|
||||
|
||||
</TABLE>>]
|
||||
|
||||
|
||||
"ConcreteClass" -> "AbstractClass" [
|
||||
arrowhead=empty, style=dashed
|
||||
|
||||
|
||||
|
||||
]
|
||||
"AbstractClass" [ label = <<TABLE CELLSPACING="0">
|
||||
<TR><TD><B>AbstractClass</B></TD></TR>
|
||||
|
||||
</TABLE>>]
|
||||
|
||||
|
||||
"Student" [ label = <<TABLE CELLSPACING="0">
|
||||
<TR><TD><B>Student</B></TD></TR>
|
||||
|
||||
</TABLE>>]
|
||||
|
||||
|
||||
"Student" -> "ConcreteClass" [
|
||||
arrowhead = open
|
||||
|
||||
|
||||
, label="Meaningless connection to"
|
||||
]
|
||||
"Teacher" [ label = <<TABLE CELLSPACING="0">
|
||||
<TR><TD><B>Teacher</B></TD></TR>
|
||||
|
||||
</TABLE>>]
|
||||
|
||||
|
||||
"Classroom" [ label = <<TABLE CELLSPACING="0">
|
||||
<TR><TD><B>Classroom</B></TD></TR>
|
||||
|
||||
</TABLE>>]
|
||||
|
||||
|
||||
"Classroom" -> "Student" [
|
||||
arrowhead=odiamond
|
||||
, headlabel="0..n"
|
||||
, taillabel="1..n"
|
||||
|
||||
]
|
||||
"Classroom" -> "Teacher" [
|
||||
arrowhead=odiamond
|
||||
, headlabel="1"
|
||||
, taillabel="0..n"
|
||||
|
||||
]
|
||||
|
||||
|
||||
}
|
@ -0,0 +1 @@
|
||||
{}
|
@ -335,11 +335,11 @@ export default class Leafdoc {
|
||||
if (directive === 'relationship') {
|
||||
var split = regexps.relationshipDefinition.exec(content);
|
||||
currentNamespace.relationships.push({
|
||||
type: parts[1],
|
||||
namespace: parts[2],
|
||||
cardinalityFrom: parts[3],
|
||||
cardinalityTo: parts[4],
|
||||
label: parts[5],
|
||||
type: split[1],
|
||||
namespace: split[2],
|
||||
cardinalityFrom: split[3],
|
||||
cardinalityTo: split[4],
|
||||
label: split[5],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -71,10 +71,10 @@ export const miniclassDefinition = xRegExp('^ (?<miniclass> .+ ) \\s* \\( (?<rea
|
||||
// Parses a UML-like relationship definition
|
||||
export const relationshipDefinition = xRegExp(`^
|
||||
(?<type> \\S+ ) \\s*
|
||||
(?<namespace> \\S+ ) \\s*
|
||||
(?<cardinalityFrom> [^,\\s]* )? \\s*
|
||||
(, \\s* (?<cardinalityTo> [^,\\s]* )? \\s*
|
||||
(, \\s* (?<label> .+ )? )?
|
||||
)? \\s* $`, 'nx');
|
||||
(?<namespace> [^,\\s]+ ) \\s*
|
||||
(, \\s* (?<cardinalityFrom> [^,\\s]*) )? \\s*
|
||||
(, \\s* (?<cardinalityTo> [^,\\s]*) )? \\s*
|
||||
(, \\s* (?<label> .+ )? )?
|
||||
\\s* $`, 'nx');
|
||||
|
||||
|
||||
|
@ -93,3 +93,9 @@ Handlebars.registerHelper('json', function jsonHelper(obj) {
|
||||
});
|
||||
|
||||
|
||||
// Comparison helper. Inspired from https://github.com/helpers/handlebars-helpers
|
||||
Handlebars.registerHelper('equals', function equalityHelper(a, b) {
|
||||
return a == b;
|
||||
});
|
||||
|
||||
|
||||
|
@ -8,6 +8,26 @@
|
||||
"{{../name}}" -> "{{this}}"
|
||||
{{/each}}
|
||||
|
||||
{{#each relationships}}
|
||||
"{{../name}}" -> "{{namespace}}" [
|
||||
{{#if (equals type "associated")}}
|
||||
arrowhead = open
|
||||
{{else if (equals type "implements")}}
|
||||
arrowhead=empty, style=dashed
|
||||
{{else if (equals type "dependsOn")}}
|
||||
arrowhead=open, style=dashed
|
||||
{{else if (equals type "aggregationOf")}}
|
||||
arrowhead=odiamond
|
||||
{{else if (equals type "compositionOf")}}
|
||||
arrowhead=diamond
|
||||
{{else}}
|
||||
{{! Miniclasses don't have a name, skip them }}
|
||||
arrowhead=normal
|
||||
{{/if}}
|
||||
{{#if cardinalityFrom}}, headlabel="{{cardinalityFrom}}"{{/if}}
|
||||
{{#if cardinalityTo}}, taillabel="{{cardinalityTo}}"{{/if}}
|
||||
{{#if label}}, label="{{label}}"{{/if}}
|
||||
]
|
||||
{{/each}}
|
||||
{{else}}
|
||||
{{! Miniclasses don't have a name per se, skip them }}
|
||||
{{/if}}
|
||||
|
Reference in New Issue
Block a user