Commit | Line | Data |
8cd2e785 |
1 | function edges_of( ellipse ) { |
2 | var edges = new Array(); |
3 | var node_id = ellipse.parent().attr('id'); |
4 | var edge_in_pattern = new RegExp( node_id + '$' ); |
5 | $.each( $('#svgenlargement .edge'), function(index) { |
6 | title = $(this).children('title').text(); |
7 | if( title.search( node_id ) > -1 ) { |
8 | var edge = new Edge( $(this) ); |
9 | edge.node_id = node_id; |
10 | if( edge_in_pattern.test(title) ) { |
11 | edge.is_incoming = true; |
12 | } |
13 | edges.push( edge ); |
14 | } |
15 | } ); |
16 | return edges; |
17 | } |
18 | |
19 | function Edge( g_elem ) { |
20 | |
21 | var self = this; |
22 | |
23 | this.g_elem = g_elem; |
24 | this.witnesses = g_elem.children('text').text().split( /,\s*/ ); |
25 | this.is_incoming = false; |
26 | |
27 | this.detach_witnesses = function( witnesses_to_detach ) { |
28 | var detached = []; |
29 | var left = ''; |
30 | var clone = null; |
31 | $.each( witnesses_to_detach, function( index, witness_to_detach ) { |
32 | witness_index = self.witnesses.indexOf( witness_to_detach ); |
33 | if( witness_index > -1 ) { |
34 | self.witnesses.splice( witness_index, 1 ); |
35 | detached.push( witness_to_detach ); |
36 | } |
37 | } ); |
38 | if( detached != '' ) { |
39 | clone = self.clone_for( detached ); |
40 | } |
41 | var remaining = self.create_label( self.witnesses ); |
42 | if( remaining == '' ) { |
43 | self.g_elem.remove(); |
44 | } else { |
45 | self.g_elem.children('text').text( remaining ); |
46 | } |
47 | return clone; |
48 | } |
49 | |
50 | this.get_label = function() { |
51 | return self.g_elem.children('text').text(); |
52 | } |
53 | |
54 | this.create_label = function( witnesses ) { |
55 | var label = ''; |
56 | $.each( witnesses, function( index, witness ) { |
57 | label = label + witness + ', '; |
58 | } ); |
59 | label = label.replace( /, $/, '' ); |
60 | return label; |
61 | } |
62 | |
63 | this.clone_for = function( witnesses ) { |
64 | var label = self.create_label( witnesses ); |
65 | var clone = g_elem.clone(); |
66 | clone.children('text').text( label ); |
67 | clone = new Edge( clone ); |
68 | clone.is_incoming = self.is_incoming; |
69 | return clone; |
70 | } |
71 | |
72 | this.attach = function( node_id_maybe ) { |
73 | //update title |
74 | return null; |
75 | } |
76 | |
77 | } |