-
Notifications
You must be signed in to change notification settings - Fork 2
/
zcreate_centrality.py
55 lines (41 loc) · 1.62 KB
/
zcreate_centrality.py
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
def createhtml(data):
with open("./centrality.html",'w') as f:
INSERT = data.to_json()
print INSERT
contents = '''
<script src="https://cdnjs.cloudflare.com/ajax/libs/rough.js/3.0.0/rough-async.es5.js"></script>
<canvas id="myCanvas"></canvas>
<script>
width = window.innerWidth
height = window.innerHeight
document.getElementById("myCanvas").width=width
document.getElementById("myCanvas").height = height
var rough = new rough.canvas(document.getElementById("myCanvas"), width, height);
rough.strokeWidth = 2;
rough.fill = "rgba(255,0,0,0.2)";
function draw(data){
var keys = Object.keys(data)
var dh = height / (keys.length+1)
margin = width*.25
var dw = (width-margin)/(Object.values(data[keys[1]]).length + 1)
keys.forEach((d,i)=>{
var x = 0
Object.values(data[d]).forEach((c,j)=>{
var e = rough.circle(margin + dw*j, i*dh, dw*c);
e.roughness = 1.5;
e.hachureAngle = 60;
e.hachureGap = 1.5;
e.fill= "rgb(10,150,10)";
e.fillWeight= 3; // thicker lines for hachure
})
})
}
data =''' + INSERT + '''
draw(data)
setTimeout(function() {
location.reload();
}, 5000);
</script>
'''
print contents
f.write(contents)