-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconduit.html
72 lines (65 loc) · 4.78 KB
/
conduit.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
<!doctype html>
<html>
<head>
<title>POA Graph Alignment</title>
<script type="text/javascript" src="https://visjs.github.io/vis-network/standalone/umd/vis-network.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script>
</head>
<body>
<button id="downloadPDF">Download PDF</button>
<div id="mynetwork"></div>
<script type="text/javascript">
document.getElementById("downloadPDF").addEventListener("click", () => {
const canvas = document.getElementsByTagName("canvas")[0];
const myImage = canvas.toDataURL("image/png,1.0");
// Adjust width and height
const imgWidth = (canvas.width * 20) / 240;
const imgHeight = (canvas.height * 20) / 240;
// jspdf changes
const pdf = new jsPDF('p', 'mm', 'a4');
pdf.addImage(myImage, 'PNG', 15, 2, imgWidth, imgHeight); // 2: 19
pdf.save('Download.pdf');
});
// create an array with nodes
const nodes = new vis.DataSet([
{id: 0, label: "C", fixed:{x: true, y: true}, x: 0 , y: 0, color: {border: '#002D72', background: '#68ACE5'}, font: {color : "#000000", bold : true, face : "courier", size : 40}, size : 100},
{id: 1, label: "O", fixed:{x: true, y: true}, x: 150 , y: 0, color: {border: '#002D72', background: '#68ACE5'}, font: {color : "#000000", bold : true, face : "courier", size : 40}, size : 100},
{id: 2, label: "N", fixed:{x: true, y: true}, x: 300 , y: 0, color: {border: '#002D72', background: '#68ACE5'}, font: {color : "#000000", bold : true, face : "courier", size : 40}, size : 100},
{id: 3, label: "D", fixed:{x: true, y: true}, x: 450 , y: 0, color: {border: '#002D72', background: '#68ACE5'}, font: {color : "#000000", bold : true, face : "courier", size : 40}, size : 100},
{id: 4, label: "U", fixed:{x: true, y: true}, x: 600 , y: 0, color: {border: '#002D72', background: '#68ACE5'}, font: {color : "#000000", bold : true, face : "courier", size : 40}, size : 100},
{id: 5, label: "I", fixed:{x: true, y: true}, x: 750 , y: 0, color: {border: '#002D72', background: '#68ACE5'}, font: {color : "#000000", bold : true, face : "courier", size : 40}, size : 100},
{id: 6, label: "T", fixed:{x: true, y: true}, x: 900 , y: 0, color: {border: '#002D72', background: '#68ACE5'}, font: {color : "#000000", bold : true, face : "courier", size : 40}, size : 100},
{id: 7, fixed:{x: true, y: true}, x: 150 , y: -100, color: {border: '#000000', background: '#D3D3D3'}, font: {color : "#000000", bold : true, face : "courier", size : 40}, size : 100},
{id: 8, fixed:{x: true, y: true}, x: 600 , y: 100, color: {border: '#000000', background: '#D3D3D3'}, font: {color : "#000000", bold : true, face : "courier", size : 40}, size : 100},
]);
// create an array with edges
const edges = new vis.DataSet([
{from: 0, to: 1, color: 'red', value: 1, arrows: {to : {enabled : true, scaleFactor : 0.5}},arrowStrikethrough : false},
{from: 1, to: 2, color: 'red', value: 1, arrows: {to : {enabled : true, scaleFactor : 0.5}},arrowStrikethrough : false},
{from: 2, to: 3, color: 'red', value: 1, arrows: {to : {enabled : true, scaleFactor : 0.5}},arrowStrikethrough : false},
{from: 3, to: 4, color: 'red', value: 1, arrows: {to : {enabled : true, scaleFactor : 0.5}},arrowStrikethrough : false},
{from: 4, to: 5, color: 'red', value: 1, arrows: {to : {enabled : true, scaleFactor : 0.5}},arrowStrikethrough : false},
{from: 5, to: 6, color: 'red', value: 1, arrows: {to : {enabled : true, scaleFactor : 0.5}},arrowStrikethrough : false},
{from: 0, to: 7, color: 'black', value: 1, arrows: {to : {enabled : true, scaleFactor : 1}},arrowStrikethrough : false},
{from: 7, to: 3, color: 'black', value: 1, arrows: {to : {enabled : true, scaleFactor : 1}},arrowStrikethrough : false},
{from: 2, to: 8, color: 'black', value: 1, arrows: {to : {enabled : true, scaleFactor : 1}},arrowStrikethrough : false},
{from: 8, to: 6, color: 'black', value: 1, arrows: {to : {enabled : true, scaleFactor : 1}},arrowStrikethrough : false},
{from: 1, to: 7, color: 'grey', value: 1},
{from: 7, to: 1, color: 'grey', value: 1},
{from: 4, to: 8, color: 'grey', value: 1},
{from: 8, to: 4, color: 'grey', value: 1},
]);
// create a network
const container = document.getElementById("mynetwork");
const data = {
nodes: nodes,
edges: edges
};
const options = {
width: "100%",
height: "800px"
};
const network = new vis.Network(container, data, options);
</script>
</body>
</html>