Please disable Adblockers and enable JavaScript for domain CEWebS.cs.univie.ac.at! We have NO ADS, but they may interfere with some of our course material.
Name: orgviz-js/lib/jsfiddle_old.js
1: | var file = "http://cpee.org/~demo/orgviz/organisation_informatik.xml"; var xpath = "/o:organisation/o:units/o:unit|/o:organisation/o:roles/o:role"; |
2: | var subjectsin = "/o:organisation/o:subjects/o:subject"; |
3: | var nopts = null; |
4: | var nodes2 = []; |
5: | if (!Array.prototype.last){ |
6: | Array.prototype.last = function(){ |
7: | return this[this.length - 1]; |
8: | }; |
9: | }; |
10: | |
11: | var Node = function(id,type,opts) { |
12: | this.type = type; |
13: | this.id = id; |
14: | this.rank = 0; |
15: | this.parents = []; |
16: | this.group = 0; |
17: | this.numsubjects = 0; |
18: | this.subjects = []; |
19: | //this.twidth = SVG.width_of(id); |
20: | //this.theight = SVG.height_of(id); |
21: | //new instance variable for all elements of opts |
22: | for (var i in opts) { |
23: | if(opts.hasOwnProperty(i)) eval("this."+i+" = "+opts[i]+";"); |
24: | } |
25: | }; |
26: | |
27: | var Subject = function(shortid){ |
28: | this.shortid = shortid; |
29: | Subject.counter += 1; |
30: | this.id = "s"+Subject.counter; |
31: | this.relations = []; |
32: | }; |
33: | |
34: | Subject.counter = 0; |
35: | |
36: | var Relation = function(unit, role){ |
37: | this.unit = unit; |
38: | this.role = role; |
39: | }; |
40: | |
41: | function onlyUnique(value, index, self) { |
42: | return self.indexOf(value) === index; |
43: | } |
44: | |
45: | var GraphWorker = function(file,xpath,subjects,nopts){ |
46: | this.nodes = []; |
47: | this.subjects = []; |
48: | this.maxsubjects = 0; |
49: | this.paths = []; |
50: | |
51: | this.nsResolver = function(prefix) { |
52: | return prefix == 'o' ? "http://cpee.org/ns/organisation/1.0" : null ; |
53: | }; |
54: | |
55: | this.processData = function(data) { |
56: | var evalue = data.evaluate('/o:organisation/o:units/o:unit|/o:organisation/o:roles/o:role', |
57: | data, |
58: | nsResolver, |
59: | XPathResult.ORDERED_NODE_ITERATOR_TYPE, |
60: | null); |
61: | var node = evalue.iterateNext(); |
62: | for(; node && !evalue.invalidIteratorState; ) { |
63: | var type = node.localName; |
64: | var id = node.id; |
65: | var curr = new Node(id, type, nopts); |
66: | var numsubjects = data.evaluate('count(' + subjects.replace(/\/*$/,'') + '[o:relation[@' + type + |
67: | '="' + id + '"]])', |
68: | data, |
69: | nsResolver, |
70: | XPathResult.NUMBER_TYPE, |
71: | null); |
72: | curr.numsubjects = numsubjects.numberValue; |
73: | if(curr.numsubjects > this.maxsubjects) this.maxsubjects = curr.numsubjects; |
74: | |
75: | nodes2.push(node); |
76: | for(var i = 0; i < node.childNodes.length; ++i) { |
77: | var child = node.childNodes[i]; |
78: | if(child.nodeName == "parent") { |
79: | var pa = child.textContent; |
80: | //console.log(node.parentNode.childNodes.length); |
81: | for(var j = 0; j < node.parentNode.childNodes.length; ++j) { |
82: | var pid = node.parentNode.childNodes[j]; |
83: | if(pid.id == pa) { |
84: | curr.parents.push(pid); |
85: | } |
86: | } |
87: | } |
88: | } |
89: | nodes.push(curr); |
90: | node = evalue.iterateNext(); |
91: | } |
92: | |
93: | var subjectIterator = data.evaluate(subjects.replace(/\/*$/,''), |
94: | data, |
95: | nsResolver, |
96: | XPathResult.ORDERED_NODE_ITERATOR_TYPE, |
97: | null); |
98: | var subject = subjectIterator.iterateNext(); |
99: | for( ; subject && !subjectIterator.invalidIteratorState; ) { |
100: | var s = new Subject(subject.id); |
101: | for(var i = 0; i < subject.childNodes.length; ++i) { |
102: | var child = subject.childNodes[i]; |
103: | if(child.nodeName == "relation") { |
104: | var unit = nodes.filter(function(e) { return e.id == child.attributes["unit"].nodeValue }); |
105: | var role = nodes.filter(function(e) { return e.id == child.attributes["role"].nodeValue }); |
106: | unit.subjects = []; |
107: | unit.subjects.push(s); |
108: | unit = unit.filter( onlyUnique ); |
109: | role.subjects = []; |
110: | role.subjects.push(s); |
111: | role = role.filter( onlyUnique ); |
112: | if(unit && role ) { |
113: | s.relations.push( new Relation(unit,role) ); |
114: | } |
115: | } |
116: | } |
117: | this.subjects.push(s); |
118: | subject = subjectIterator.iterateNext(); |
119: | } |
120: | |
121: | console.log(this.subjects); |
122: | console.log(nodes); |
123: | |
124: | for(var node in nodes) { |
125: | this.paths.push([node]); |
126: | calculate_path(this.paths, this.paths.last()); |
127: | } |
128: | }; |
129: | |
130: | var calculate_path = function(paths, path) { |
131: | var parents = path.last().parents |
132: | }; |
133: | |
134: | var client = new XMLHttpRequest(); |
135: | client.onload = function() { |
136: | if(this.status == 200 ) |
137: | { |
138: | //console.log(this.responseXML); |
139: | processData(this.responseXML); |
140: | } else { |
141: | console.log(this); |
142: | } |
143: | }; |
144: | client.open("GET", file, true); |
145: | client.send(null); |
146: | }; |
147: | |
148: | GraphWorker(file,xpath,subjectsin,nopts); |