Daniel@0
|
1 /* Part of DML (Digital Music Laboratory)
|
Daniel@0
|
2 Copyright 2014-2015 Samer Abdallah, University College London
|
Daniel@0
|
3 Distributed under GPL v3
|
Daniel@0
|
4 */
|
Daniel@0
|
5
|
Daniel@0
|
6 /* clears the graph display element */
|
Daniel@0
|
7 function clear_output() { $('#output').html(''); }
|
Daniel@0
|
8
|
Daniel@0
|
9 /* Following are three different ways to load a pan/zoom enabled SVG
|
Daniel@0
|
10 * element into the #output element. */
|
Daniel@0
|
11
|
Daniel@0
|
12 /* USING JQUERY: loads SVG content from a URL into an element identified
|
Daniel@0
|
13 * by a jQuery selector. Pan/Zoom controls are then enabled for the SVG element. */
|
Daniel@0
|
14 function load_svg(sel,url) {
|
Daniel@0
|
15 target=$(sel);
|
Daniel@0
|
16 target.load(url, function () {
|
Daniel@0
|
17 console.log("SVG loaded");
|
Daniel@0
|
18 svg=target.find('svg');
|
Daniel@0
|
19 svg.attr('width','100%').attr('height','100%');
|
Daniel@0
|
20 svgPanZoom(svg.get(0),{
|
Daniel@0
|
21 zoomEnabled: true,
|
Daniel@0
|
22 controlIconsEnabled: true,
|
Daniel@0
|
23 fit: true,
|
Daniel@0
|
24 center: true
|
Daniel@0
|
25 });
|
Daniel@0
|
26 });
|
Daniel@0
|
27 }
|
Daniel@0
|
28
|
Daniel@0
|
29 /* USING OBJECT element. No good. */
|
Daniel@0
|
30 function load_object(sel,url) {
|
Daniel@0
|
31 console.log(url);
|
Daniel@0
|
32 var obj=$('<object id="obj" width="100%" height="100%" type="image/svg+xml" data="'+url+'"></object>');
|
Daniel@0
|
33 $('#output').html(obj);
|
Daniel@0
|
34 // cannot get hold of SVG element here for some reason...
|
Daniel@0
|
35 // var svg=obj.get(0).contentDocument.getElementsByTagName('svg')[0];
|
Daniel@0
|
36 }
|
Daniel@0
|
37
|
Daniel@0
|
38 /* Using SVG element with xlink:href attribute to link to content
|
Daniel@0
|
39 * This does not seem so good for some reason... */
|
Daniel@0
|
40 function load_svg_href(sel,url) {
|
Daniel@0
|
41 var svg=$('<svg id="svg" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><image x="0" y="0" width="100%" height="100%" xlink:href="'+url+'"></image></svg>');
|
Daniel@0
|
42 sel.html(svg);
|
Daniel@0
|
43 svgPanZoom('#svg',{
|
Daniel@0
|
44 zoomEnabled: true,
|
Daniel@0
|
45 controlIconsEnabled: true,
|
Daniel@0
|
46 fit: true,
|
Daniel@0
|
47 center: true
|
Daniel@0
|
48 });
|
Daniel@0
|
49 }
|
Daniel@0
|
50
|
Daniel@0
|
51 /* Gets module name from #module and loads callgraph into #output */
|
Daniel@0
|
52 function update_svg(loc) {
|
Daniel@0
|
53 var module=$('#module').val();
|
Daniel@0
|
54 load_svg('#output',loc+"?format=svg&module="+module);
|
Daniel@0
|
55 }
|