forked from ulthiel/Bocses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Draw.i.m
215 lines (175 loc) · 4.69 KB
/
Draw.i.m
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
Bocses - A Magma package for computing with bocses.
By
Julian Külshammer ([email protected])
and
Ulrich Thiel ([email protected])
File: Draw.i.m
*/
//============================================================================
intrinsic Draw(B::BocsType : Dir:="", File:="", Quiet:=false, EdgeLabels:=true)
{}
if Dir eq "" then
Dir := "Output/"*B`Title;
else
Dir := "Output/"*Dir;
end if;
if File eq "" then
File := B`Title;
else
File := File;
end if;
System("mkdir -p "*Replace(Dir, " ", "\\ "));
//code
codestr := "$(function(){ // on dom ready
var cy = cytoscape({
container: document.getElementById('cy'),
style: cytoscape.stylesheet()
.selector('node')
.css({
'content': 'data(id)',
'font-size' : '10',
'background-color': '#61bffc',
'text-valign': 'center'
})
.selector('edge')
.css({
'target-arrow-shape': 'triangle',
'width': 1,
'curve-style': 'bezier',
'font-size' : '10',
'line-style': 'data(myLineStyle)',";
if EdgeLabels then
codestr *:= "
'label': 'data(id)'";
end if;
codestr *:="
}),
elements: {
nodes: [";
for i:=1 to #B`VertexLabels do
v := Sprint(B`VertexLabels[i]);
codestr *:= "\n { data: { id: '" * Sprint(v)*"' } }";
if i lt #B`VertexLabels then
codestr *:= ",";
end if;
end for;
codestr *:= "
],
";
codestr *:= "
edges: [";
for i:=1 to #B`EdgeLabels do
e := B`EdgeLabels[i];
codestr *:= "\n { data: { id: '"*Sprint(e)*"', source: '"*Sprint(B`EdgeSources[e])*"', target: '"*Sprint(B`EdgeTails[e])*"', degree: '"*Sprint(B`EdgeDegrees[e])*"', level: '"*Sprint(B`EdgeLevels[e])*"', differential: '"*Sprint(B`EdgeDifferentials[e])*"'";
if B`EdgeDegrees[B`EdgeLabels[i]] eq 1 then
codestr *:= ", myLineStyle: 'dashed'";
else
codestr *:= ", myLineStyle: 'solid'";
end if;
codestr *:= "} }";
if i lt #B`EdgeLabels then
codestr *:= ",";
end if;
end for;
codestr *:= "
]
},
layout: {
name: 'grid',
directed: true,
roots: '#a',
padding: 50
}
});";
codestr *:= "
cy.edges().qtip({
content: function(){
return '<b>Edge ' + this.data('id') + '</b><br>Source: ' + this.data('source') + '<br>Target: ' + this.data('target') + '<br>Degree: ' + this.data('degree') + '<br>Level: ' + this.data('level') + '<br>Differential: ' + this.data('differential');
},
position: {
my: 'bottom left',
at: 'bottom center'
},
style: {
classes: 'qtip-bootstrap',
tip: {
width: 10,
height: 8
}
}
});
";
codestr *:= "
cy.nodes().qtip({
content: function(){
return '<b>Vertex ' + this.data(id);
},
position: {
my: 'bottom left',
at: 'bottom center'
},
style: {
classes: 'qtip-bootstrap',
tip: {
width: 10,
height: 8
}
}
});
";
codestr *:= "
}); // on dom ready
";
//css file
cssstr := "body {
font: 12px helvetica neue, helvetica, arial, sans-serif;
}
#cy {
height: 100%;
width: 100%;
position: absolute;
left: 0;
top: 0;
}";
htmlstr := "
<!DOCTYPE html>
<html>
<head>
<link href=\"style.css\" rel=\"stylesheet\" />
<meta charset=utf-8 />
<meta name=\"viewport\" content=\"user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0\">
<title>"*B`Title*"</title>
<link rel=\"stylesheet\" type=\"text/css\"
href=\"http://cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.0/jquery.qtip.css\">
<script
src=\"http://code.jquery.com/jquery-2.0.3.min.js\">
</script>
<script
src=\"http://cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.0/jquery.qtip.js\">
</script>
<script
src=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/cytoscape.min.js\">
</script>
<script
src=\"https://cdn.jsdelivr.net/npm/[email protected]/cytoscape-qtip.min.js\">
</script>
<script src=\""*File*".js\"></script>
</head>
<body>
<center><h1>"*B`Title*"</h1></center>
<div id=\"cy\"></div>
</body>
</html>
";
Write(Dir*"/"*File*".html", htmlstr : Overwrite:=true);
Write(Dir*"/style.css", cssstr : Overwrite:=true);
Write(Dir*"/"*File*".js", codestr : Overwrite:=true);
Dir := Replace(Dir, " ", "\\ ");
File := Replace(File, " ", "\\ ");
if not Quiet then
System("open "*Dir*"/"*File*".html");
end if;
end intrinsic;
function QTip()
end function;