forked from hnakamur/d3.js-class-diagram-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
99 lines (94 loc) · 2.43 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<head>
<meta charset='utf-8'>
</head>
<body>
<div id='example'></div>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.4.10/d3.min.js"></script>
<script src="multiline-text.js"></script>
<script src="class-diagram.js"></script>
<script>
var svg = d3.select('#example').append('svg')
.attr({
width: 540,
height: 280
});
d3.classDiagram.addMarkers(svg.append('defs'));
var classes = [
{
x: 40, y: 20, width: 260,
classname: 'User',
attributes: [
'microposts: Array[Micropost]',
'relationships: Array[Relationship]',
'followed_users: Array[User]',
'reversed_relationships: Array[Relationship]',
'followers: Array[User]',
]
},
{
x: 360, y: 20, width: 140,
classname: 'Micropost',
attributes: [
'user: User',
'content: string'
]
},
{
x: 40, y: 180, width: 160,
classname: 'Relationship',
attributes: [
'follower : User',
'followed : User'
]
}
];
var boxes = d3.classDiagram.createClasses(classes);
svg.selectAll('text').attr('font-family', 'Noto Sans Japanese');
var connectors = [
{
points: [
{x: boxes.User.rightX(), y: boxes.Micropost.midY()},
{x: boxes.Micropost.x, y: boxes.Micropost.midY()}
],
markerEnd: 'filledDiamond'
},
{
points: [
{x: boxes.Relationship.midX() - 20, y: boxes.User.bottomY()},
{x: boxes.Relationship.midX() - 20, y: boxes.Relationship.y}
],
markerEnd: 'filledDiamond'
},
{
points: [
{x: boxes.Relationship.midX() + 20, y: boxes.User.bottomY()},
{x: boxes.Relationship.midX() + 20, y: boxes.Relationship.y}
],
markerEnd: 'filledDiamond'
},
{
points: [
{x: boxes.User.x, y: boxes.User.bottomY() - 20},
{x: boxes.User.x - 20, y: boxes.User.bottomY() - 20},
{x: boxes.User.x - 20, y: boxes.User.bottomY() + 20},
{x: boxes.User.x + 20, y: boxes.User.bottomY() + 20},
{x: boxes.User.x + 20, y: boxes.User.bottomY()}
],
markerEnd: 'diamond'
},
{
points: [
{x: boxes.User.rightX(), y: boxes.User.bottomY() - 20},
{x: boxes.User.rightX() + 20, y: boxes.User.bottomY() - 20},
{x: boxes.User.rightX() + 20, y: boxes.User.bottomY() + 20},
{x: boxes.User.rightX() - 20, y: boxes.User.bottomY() + 20},
{x: boxes.User.rightX() - 20, y: boxes.User.bottomY()}
],
markerEnd: 'diamond'
}
];
d3.classDiagram.createConnectors(connectors);
</script>
</body>
</html>