-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsvg-export.html
192 lines (176 loc) · 6.04 KB
/
svg-export.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
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
<!doctype html>
<html>
<head>
<title>Network | Images With Borders</title>
<style type="text/css">
body {
font: 10pt arial;
}
#mynetwork {
width: 800px;
height: 800px;
border: 1px solid lightgray;
background-color:#333333;
}
</style>
<script type="text/javascript" src="vis.js"></script>
<script type="text/javascript" src="canvas2svg.js"></script>
<link href="vis-network.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var DIR = 'img/soft-scraps-icons/';
var nodes = null;
var edges = null;
var network = null;
var options = null;
// Called when the Visualization API is loaded.
function draw() {
// create people.
// value corresponds with the age of the person
var DIR = './img/';
nodes = [
{id: 1, shape: 'image', image: DIR + '1.png'},
{id: 2, shape: 'image', image: DIR + '2.png'},
{id: 3, shape: 'image', image: DIR + '3.png'},
{id: 4, shape: 'image', image: DIR + '4.png', label:"pictures by this guy!"},
{id: 5, shape: 'image', image: DIR + '5.png'},
{id: 6, shape: 'image', image: DIR + '6.png'},
{id: 7, shape: 'image', image: DIR + '7.png'},
{id: 8, shape: 'image', image: DIR + '8.png'},
{id: 9, shape: 'image', image: DIR + '9.png'},
{id: 10, shape: 'image', image: DIR + '10.png'},
{id: 11, shape: 'image', image: DIR + '11.png'},
{id: 12, shape: 'image', image: DIR + '12.png'},
{id: 13, shape: 'image', image: DIR + '13.png'},
{id: 14, shape: 'image', image: DIR + '14.png'},
{id: 15, shape: 'image', image: DIR + 'missing.png', brokenImage: DIR + 'missingBrokenImage.png', label:"when images\nfail\nto load"},
{id: 16, shape: 'image', image: DIR + 'anotherMissing.png', brokenImage: DIR + '9.png', label:"fallback image in action"}
];
// create connections between people
// value corresponds with the amount of contact between two people
edges = [
{from: 1, to: 2},
{from: 2, to: 3},
{from: 2, to: 4},
{from: 4, to: 5},
{from: 4, to: 10},
{from: 4, to: 6},
{from: 6, to: 7},
{from: 7, to: 8},
{from: 8, to: 9},
{from: 8, to: 10},
{from: 10, to: 11},
{from: 11, to: 12},
{from: 12, to: 13},
{from: 13, to: 14},
{from: 9, to: 16}
];
// create a network
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges
};
options = {
nodes: {
borderWidth:4,
size:30,
color: {
border: '#406897',
background: '#6AAFFF'
},
font:{color:'#eeeeee'},
shapeProperties: {
useBorderWithImage:true
}
},
edges: {
color: 'lightgray'
}
};
network = new vis.Network(container, data, options);
}
C2S.prototype.circle = CanvasRenderingContext2D.prototype.circle;
C2S.prototype.square = CanvasRenderingContext2D.prototype.square;
C2S.prototype.triangle = CanvasRenderingContext2D.prototype.triangle;
C2S.prototype.triangleDown = CanvasRenderingContext2D.prototype.triangleDown;
C2S.prototype.star = CanvasRenderingContext2D.prototype.star;
C2S.prototype.diamond = CanvasRenderingContext2D.prototype.diamond;
C2S.prototype.roundRect = CanvasRenderingContext2D.prototype.roundRect;
C2S.prototype.ellipse_vis = CanvasRenderingContext2D.prototype.ellipse_vis;
C2S.prototype.database = CanvasRenderingContext2D.prototype.database;
C2S.prototype.arrowEndpoint = CanvasRenderingContext2D.prototype.arrowEndpoint;
C2S.prototype.circleEndpoint = CanvasRenderingContext2D.prototype.circleEndpoint;
C2S.prototype.dashedLine = CanvasRenderingContext2D.prototype.dashedLine;
function exportSvg()
{
var networkContainer = network.body.container;
var ctx = new C2S({width: networkContainer.clientWidth, height: networkContainer.clientWidth, embedImages: true});
var canvasProto = network.canvas.__proto__;
var currentGetContext = canvasProto.getContext;
canvasProto.getContext = function()
{
return ctx;
}
var svgOptions = {
nodes: {
shapeProperties: {
interpolation: false //so images are not scaled svg will get full image
},
scaling: { label: { drawThreshold : 0} },
font:{color:'#000000'}
},
edges: {
scaling: { label: { drawThreshold : 0} }
}
};
network.setOptions(svgOptions);
network.redraw();
network.setOptions(options);
canvasProto.getContext = currentGetContext;
ctx.waitForComplete(function()
{
var svg = ctx.getSerializedSvg();
showSvg(svg);
});
}
function showSvg(svg)
{
var svgBlob = new Blob([svg], {type: 'image/svg+xml'});
openBlob(svgBlob, "network.svg");
}
function openBlob(blob, fileName)
{
if(window.navigator && window.navigator.msSaveOrOpenBlob)
{
//blobToDataURL(blob, function(dataurl){window.open(dataurl);});
window.navigator.msSaveOrOpenBlob(blob,fileName);
}
else
{
var a = document.getElementById("blobLink");
if(!a)
{
a = document.createElement("a");
document.body.appendChild(a);
a.setAttribute("id", "blobLink");
a.style = "display: none";
}
var data = window.URL.createObjectURL(blob);
a.href = data;
a.download = fileName;
a.click();
setTimeout(function()
{
// For Firefox it is necessary to delay revoking the ObjectURL
window.URL.revokeObjectURL(data);
}
, 100);
}
}
</script>
</head>
<body onload="draw()">
<input type="button" onclick="exportSvg();" value="Export SVG"/>
<div id="mynetwork"></div>
</body>
</html>