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
|
# Copyright 2012, 2013 Marco Ceppi, Canonical Ltd. This software is
# licensed under the GNU Affero General Public License version 3 (see
# the file LICENSE).
"""
Charm/Interface Graph Visualization.
Using thejit.org canvas graphing.
http://thejit.org/static/v20/Docs/files/Loader/Loader-js.html
"""
def graph_by_charms(charms, interfaces):
"""Force directed graph
Per thejit loader format for graphs.
charms with edges to required interfaces.
interfaces with edges to provider charms.
"""
nodes = []
for charm in charms:
data = {
"summary": charm.summary,
#"series": charm['series'],
"i_requires": charm.i_requires,
"i_provides": charm.i_provides,
'label': charm.label,
'url': charm.short_url,
}
node = {
'id': charm.label,
'adjacencies': charm.i_requires,
'data': data}
nodes.append(node)
for interface in interfaces:
node = {
'id': interface['name'],
#'data': dict(interface), # Use a copy
'adjacencies': list(
[i.label for i in interface['provided_by']])
}
nodes.append(node)
return nodes
def graph_by_interface(interfaces):
"""Hypertree data set, artifical root to interfaces to providers.
"""
nodes = []
for i in interfaces:
node = {'id': i['name']}
node['adjacencies'] = list(i['i_requires'])
nodes.append(node)
return nodes
|