remove HACK from tradition build script
[scpubgit/stemmatology.git] / stemmaweb / root / js / relationship.js
CommitLineData
7fd1d97a 1function getTextPath() {
2 var currpath = window.location.pathname
93daee83 3 // Get rid of trailing slash
7fd1d97a 4 if( currpath.lastIndexOf('/') == currpath.length - 1 ) {
5 currpath = currpath.slice( 0, currpath.length - 1)
6 };
93daee83 7 // Get rid of query parameters
8 if( currpath.lastIndexOf('?') != -1 ) {
9 currpath = currpath.slice( 0, currpath.lastIndexOf('?') );
10 };
7fd1d97a 11 var path_elements = currpath.split('/');
12 var textid = path_elements.pop();
13 var basepath = path_elements.join( '/' );
14 var path_parts = [ basepath, textid ];
15 return path_parts;
581aee24 16}
17
72874569 18function getRelativePath() {
19 var path_parts = getTextPath();
20 return path_parts[0];
21}
22
23function getRelationshipURL() {
24 var path_parts = getTextPath();
25 return path_parts[0] + '/' + path_parts[1] + '/relationships';
581aee24 26}
27
28function svgEnlargementLoaded() {
63213207 29 //Give some visual evidence that we are working
30 $('#loading_overlay').show();
31 lo_height = $("#enlargement_container").outerHeight();
32 lo_width = $("#enlargement_container").outerWidth();
33 $("#loading_overlay").height( lo_height );
34 $("#loading_overlay").width( lo_width );
35 $("#loading_overlay").offset( $("#enlargement_container").offset() );
36 $("#loading_message").offset(
37 { 'top': lo_height / 2 - $("#loading_message").height() / 2,
38 'left': lo_width / 2 - $("#loading_message").width() / 2 });
72874569 39 //Set viewbox widht and height to widht and height of $('#svgenlargement svg').
40 //This is essential to make sure zooming and panning works properly.
41 $('#svgenlargement ellipse').attr( {stroke:'green', fill:'#b3f36d'} );
42 var graph_svg = $('#svgenlargement svg');
43 var svg_g = $('#svgenlargement svg g')[0];
44 svg_root = graph_svg.svg().svg('get').root();
45 svg_root.viewBox.baseVal.width = graph_svg.attr( 'width' );
46 svg_root.viewBox.baseVal.height = graph_svg.attr( 'height' );
47 //Now set scale and translate so svg height is about 150px and vertically centered in viewbox.
48 //This is just to create a nice starting enlargement.
49 var initial_svg_height = 250;
50 var scale = initial_svg_height/graph_svg.attr( 'height' );
51 var additional_translate = (graph_svg.attr( 'height' ) - initial_svg_height)/(2*scale);
52 var transform = svg_g.getAttribute('transform');
53 var translate = parseFloat( transform.match( /translate\([^\)]*\)/ )[0].split('(')[1].split(' ')[1].split(')')[0] );
54 translate += additional_translate;
55 var transform = 'rotate(0) scale(' + scale + ') translate(4 ' + translate + ')';
56 svg_g.setAttribute('transform', transform);
57 //used to calculate min and max zoom level:
93daee83 58 start_element_height = $("#svgenlargement .node title:contains('START#')").siblings('ellipse')[0].getBBox().height;
63213207 59 add_relations( function() { $('#loading_overlay').hide(); });
7fd1d97a 60}
61
63213207 62function add_relations( callback_fn ) {
72874569 63 var basepath = getRelativePath();
64 var textrelpath = getRelationshipURL();
65 $.getJSON( basepath + '/definitions', function(data) {
7fd1d97a 66 var rel_types = data.types.sort();
72874569 67 $.getJSON( textrelpath,
7fd1d97a 68 function(data) {
69 $.each(data, function( index, rel_info ) {
70 var type_index = $.inArray(rel_info.type, rel_types);
93daee83 71 var source_found = get_ellipse( rel_info.source );
72 var target_found = get_ellipse( rel_info.target );
73 if( type_index != -1 && source_found.size() && target_found.size() ) {
72874569 74 var relation = relation_manager.create( rel_info.source, rel_info.target, type_index );
75 relation.data( 'type', rel_info.type );
76 relation.data( 'scope', rel_info.scope );
31aaf446 77 relation.data( 'note', rel_info.note );
72874569 78 var node_obj = get_node_obj(rel_info.source);
79 node_obj.set_draggable( false );
80 node_obj.ellipse.data( 'node_obj', null );
81 node_obj = get_node_obj(rel_info.target);
82 node_obj.set_draggable( false );
83 node_obj.ellipse.data( 'node_obj', null );
7fd1d97a 84 }
63213207 85 });
86 callback_fn.call();
72874569 87 });
7fd1d97a 88 });
581aee24 89}
90
91function get_ellipse( node_id ) {
92 return $('#svgenlargement .node').children('title').filter( function(index) {
93 return $(this).text() == node_id;
94 }).siblings('ellipse');
95}
96
97function get_node_obj( node_id ) {
72874569 98 var node_ellipse = get_ellipse( node_id );
99 if( node_ellipse.data( 'node_obj' ) == null ) {
100 node_ellipse.data( 'node_obj', new node_obj(node_ellipse) );
101 };
102 return node_ellipse.data( 'node_obj' );
581aee24 103}
104
105function get_edge( edge_id ) {
106 return $('#svgenlargement .edge').filter( function(index) {
107 return $(this).children( 'title' ).text() == $('<div/>').html(edge_id).text() ;
108 });
109}
110
111function node_obj(ellipse) {
112 this.ellipse = ellipse;
113 var self = this;
114
115 this.x = 0;
116 this.y = 0;
117 this.dx = 0;
118 this.dy = 0;
119 this.node_elements = node_elements_for(self.ellipse);
120
121 this.get_id = function() {
122 return self.ellipse.siblings('title').text()
123 }
124
125 this.set_draggable = function( draggable ) {
126 if( draggable ) {
127 self.ellipse.attr( {stroke:'black', fill:'#fff'} );
128 self.ellipse.mousedown( this.mousedown_listener );
129 self.ellipse.hover( this.enter_node, this.leave_node );
130 } else {
131 self.ellipse.unbind('mouseenter').unbind('mouseleave').unbind('mousedown');
132 self.ellipse.attr( {stroke:'green', fill:'#b3f36d'} );
133 }
134 }
135
136 this.mousedown_listener = function(evt) {
137 evt.stopPropagation();
138 self.x = evt.clientX;
139 self.y = evt.clientY;
140 $('body').mousemove( self.mousemove_listener );
141 $('body').mouseup( self.mouseup_listener );
142 self.ellipse.unbind('mouseenter').unbind('mouseleave')
143 self.ellipse.attr( 'fill', '#ff66ff' );
144 first_node_g_element = $("#svgenlargement g .node" ).filter( ":first" );
145 if( first_node_g_element.attr('id') !== self.get_g().attr('id') ) { self.get_g().insertBefore( first_node_g_element ) };
146 }
147
148 this.mousemove_listener = function(evt) {
72874569 149 self.dx = (evt.clientX - self.x) / mouse_scale;
150 self.dy = (evt.clientY - self.y) / mouse_scale;
581aee24 151 self.move_elements();
152 }
153
154 this.mouseup_listener = function(evt) {
155 if( $('ellipse[fill="#ffccff"]').size() > 0 ) {
156 var source_node_id = self.ellipse.siblings('title').text();
157 var target_node_id = $('ellipse[fill="#ffccff"]').siblings("title").text();
158 $('#source_node_id').val( source_node_id );
159 $('#target_node_id').val( target_node_id );
160 $('#dialog-form').dialog( 'open' );
161 };
162 $('body').unbind('mousemove');
163 $('body').unbind('mouseup');
164 self.ellipse.attr( 'fill', '#fff' );
165 self.ellipse.hover( self.enter_node, self.leave_node );
72874569 166 self.reset_elements();
581aee24 167 }
168
169 this.cpos = function() {
170 return { x: self.ellipse.attr('cx'), y: self.ellipse.attr('cy') };
171 }
172
173 this.get_g = function() {
174 return self.ellipse.parent('g');
175 }
176
177 this.enter_node = function(evt) {
178 self.ellipse.attr( 'fill', '#ffccff' );
179 }
180
181 this.leave_node = function(evt) {
182 self.ellipse.attr( 'fill', '#fff' );
183 }
184
185 this.greyout_edges = function() {
186 $.each( self.node_elements, function(index, value) {
187 value.grey_out('.edge');
188 });
189 }
190
191 this.ungreyout_edges = function() {
192 $.each( self.node_elements, function(index, value) {
193 value.un_grey_out('.edge');
194 });
195 }
196
197 this.move_elements = function() {
198 $.each( self.node_elements, function(index, value) {
199 value.move(self.dx,self.dy);
200 });
201 }
202
203 this.reset_elements = function() {
204 $.each( self.node_elements, function(index, value) {
205 value.reset();
206 });
207 }
208
209 this.update_elements = function() {
210 self.node_elements = node_elements_for(self.ellipse);
211 }
212
213 self.set_draggable( true );
214}
215
216function svgshape( shape_element ) {
217 this.shape = shape_element;
218 this.move = function(dx,dy) {
219 this.shape.attr( "transform", "translate(" + dx + " " + dy + ")" );
220 }
221 this.reset = function() {
222 this.shape.attr( "transform", "translate( 0, 0 )" );
223 }
224 this.grey_out = function(filter) {
225 if( this.shape.parent(filter).size() != 0 ) {
226 this.shape.attr({'stroke':'#e5e5e5', 'fill':'#e5e5e5'});
227 }
228 }
229 this.un_grey_out = function(filter) {
230 if( this.shape.parent(filter).size() != 0 ) {
231 this.shape.attr({'stroke':'#000000', 'fill':'#000000'});
232 }
233 }
234}
235
236function svgpath( path_element, svg_element ) {
237 this.svg_element = svg_element;
238 this.path = path_element;
239 this.x = this.path.x;
240 this.y = this.path.y;
241 this.move = function(dx,dy) {
242 this.path.x = this.x + dx;
243 this.path.y = this.y + dy;
244 }
245 this.reset = function() {
246 this.path.x = this.x;
247 this.path.y = this.y;
248 }
249 this.grey_out = function(filter) {
250 if( this.svg_element.parent(filter).size() != 0 ) {
251 this.svg_element.attr('stroke', '#e5e5e5');
252 this.svg_element.siblings('text').attr('fill', '#e5e5e5');
253 }
254 }
255 this.un_grey_out = function(filter) {
256 if( this.svg_element.parent(filter).size() != 0 ) {
257 this.svg_element.attr('stroke', '#000000');
258 this.svg_element.siblings('text').attr('fill', '#000000');
259 }
260 }
261}
262
263function node_elements_for( ellipse ) {
264 node_elements = get_edge_elements_for( ellipse );
265 node_elements.push( new svgshape( ellipse.siblings('text') ) );
266 node_elements.push( new svgshape( ellipse ) );
267 return node_elements;
268}
269
270function get_edge_elements_for( ellipse ) {
271 edge_elements = new Array();
272 node_id = ellipse.siblings('title').text();
273 edge_in_pattern = new RegExp( node_id + '$' );
274 edge_out_pattern = new RegExp( '^' + node_id );
275 $.each( $('#svgenlargement .edge,#svgenlargement .relation').children('title'), function(index) {
276 title = $(this).text();
277 if( edge_in_pattern.test(title) ) {
278 polygon = $(this).siblings('polygon');
279 if( polygon.size() > 0 ) {
280 edge_elements.push( new svgshape( polygon ) );
281 }
282 path_segments = $(this).siblings('path')[0].pathSegList;
283 edge_elements.push( new svgpath( path_segments.getItem(path_segments.numberOfItems - 1), $(this).siblings('path') ) );
284 }
285 if( edge_out_pattern.test(title) ) {
286 path_segments = $(this).siblings('path')[0].pathSegList;
287 edge_elements.push( new svgpath( path_segments.getItem(0), $(this).siblings('path') ) );
288 }
289 });
290 return edge_elements;
291}
292
293function relation_factory() {
294 var self = this;
295 this.color_memo = null;
296 //TODO: colors hard coded for now
297 this.temp_color = '#FFA14F';
298 this.relation_colors = [ "#5CCCCC", "#67E667", "#F9FE72", "#6B90D4", "#FF7673", "#E467B3", "#AA67D5", "#8370D8", "#FFC173" ];
299
300 this.create_temporary = function( source_node_id, target_node_id ) {
72874569 301 var relation = $('#svgenlargement .relation').filter( function(index) {
302 var relation_id = $(this).children('title').text();
581aee24 303 if( ( relation_id == ( source_node_id + '->' + target_node_id ) ) || ( relation_id == ( target_node_id + '->' + source_node_id ) ) ) {
72874569 304 return true;
305 }
306 } );
307 if( relation.size() == 0 ) {
581aee24 308 draw_relation( source_node_id, target_node_id, self.temp_color );
309 } else {
310 self.color_memo = relation.children('path').attr( 'stroke' );
311 relation.children('path').attr( 'stroke', self.temp_color );
312 }
313 }
314 this.remove_temporary = function() {
315 var path_element = $('#svgenlargement .relation').children('path[stroke="' + self.temp_color + '"]');
316 if( self.color_memo != null ) {
317 path_element.attr( 'stroke', self.color_memo );
318 self.color_memo = null;
319 } else {
72874569 320 var temporary = path_element.parent('g').remove();
321 temporary.empty();
322 temporary = null;
581aee24 323 }
324 }
325 this.create = function( source_node_id, target_node_id, color_index ) {
326 //TODO: Protect from (color_)index out of bound..
327 var relation_color = self.relation_colors[ color_index ];
72874569 328 var relation = draw_relation( source_node_id, target_node_id, relation_color );
329 get_node_obj( source_node_id ).update_elements();
330 get_node_obj( target_node_id ).update_elements();
331 return relation;
581aee24 332 }
72874569 333 this.toggle_active = function( relation_id ) {
334 var relation = $("#svgenlargement .relation:has(title:contains('" + relation_id + "'))");
335 var relation_path = relation.children('path');
336 if( !relation.data( 'active' ) ) {
337 relation_path.css( {'cursor':'pointer'} );
338 relation_path.mouseenter( function(event) {
339 outerTimer = setTimeout( function() {
340 timer = setTimeout( function() {
341 var title = relation.children('title').text();
342 var source_node_id = title.substring( 0, title.indexOf( "->" ) );
343 var target_node_id = title.substring( (title.indexOf( "->" ) + 2) );
344 $('#delete_source_node_id').val( source_node_id );
345 $('#delete_target_node_id').val( target_node_id );
346 self.showinfo(relation);
347 }, 500 )
348 }, 1000 );
349 });
350 relation_path.mouseleave( function(event) {
351 clearTimeout(outerTimer);
352 if( timer != null ) { clearTimeout(timer); }
353 });
354 relation.data( 'active', true );
355 } else {
356 relation_path.unbind( 'mouseenter' );
357 relation_path.unbind( 'mouseleave' );
358 relation_path.css( {'cursor':'inherit'} );
359 relation.data( 'active', false );
360 }
361 }
362 this.showinfo = function(relation) {
31aaf446 363 var htmlstr = 'type: ' + relation.data( 'type' ) + '<br/>scope: ' + relation.data( 'scope' );
364 if( relation.data( 'note' ) ) {
365 htmlstr = htmlstr + '<br/>note: ' + relation.data( 'note' );
366 }
367 $('#delete-form-text').html( htmlstr );
72874569 368 var points = relation.children('path').attr('d').slice(1).replace('C',' ').split(' ');
369 var xs = parseFloat( points[0].split(',')[0] );
370 var xe = parseFloat( points[1].split(',')[0] );
371 var ys = parseFloat( points[0].split(',')[1] );
372 var ye = parseFloat( points[3].split(',')[1] );
373 var p = svg_root.createSVGPoint();
374 p.x = xs + ((xe-xs)*1.1);
375 p.y = ye - ((ye-ys)/2);
376 var ctm = svg_root.children[0].getScreenCTM();
377 var nx = p.matrixTransform(ctm).x;
378 var ny = p.matrixTransform(ctm).y;
379 var dialog_aria = $ ("div[aria-labelledby='ui-dialog-title-delete-form']");
380 $('#delete-form').dialog( 'open' );
381 dialog_aria.offset({ left: nx, top: ny });
382 }
383 this.remove = function( relation_id ) {
384 var relation = $("#svgenlargement .relation:has(title:contains('" + relation_id + "'))");
385 relation.remove();
581aee24 386 }
387}
388
389function draw_relation( source_id, target_id, relation_color ) {
72874569 390 var source_ellipse = get_ellipse( source_id );
391 var target_ellipse = get_ellipse( target_id );
392 var svg = $('#svgenlargement').children('svg').svg().svg('get');
393 var path = svg.createPath();
394 var sx = parseInt( source_ellipse.attr('cx') );
395 var rx = parseInt( source_ellipse.attr('rx') );
396 var sy = parseInt( source_ellipse.attr('cy') );
397 var ex = parseInt( target_ellipse.attr('cx') );
398 var ey = parseInt( target_ellipse.attr('cy') );
399 var relation = svg.group( $("#svgenlargement svg g"), {'class':'relation'} );
400 svg.title( relation, source_id + '->' + target_id );
401 svg.path( relation, path.move( sx, sy ).curveC( sx + (2*rx), sy, ex + (2*rx), ey, ex, ey ), {fill: 'none', stroke: relation_color, strokeWidth: 4});
581aee24 402 var relation_element = $('#svgenlargement .relation').filter( ':last' );
403 relation_element.insertBefore( $('#svgenlargement g g').filter(':first') );
72874569 404 return relation_element;
581aee24 405}
406
72874569 407
581aee24 408$(document).ready(function () {
72874569 409
410 timer = null;
581aee24 411 relation_manager = new relation_factory();
72874569 412 $('#update_workspace_button').data('locked', false);
581aee24 413
72874569 414 $('#enlargement').mousedown(function (event) {
581aee24 415 $(this)
72874569 416 .data('down', true)
417 .data('x', event.clientX)
418 .data('y', event.clientY)
419 .data('scrollLeft', this.scrollLeft)
420 stateTf = svg_root.children[0].getCTM().inverse();
421 var p = svg_root.createSVGPoint();
422 p.x = event.clientX;
423 p.y = event.clientY;
424 stateOrigin = p.matrixTransform(stateTf);
425 return false;
581aee24 426 }).mouseup(function (event) {
72874569 427 $(this).data('down', false);
581aee24 428 }).mousemove(function (event) {
72874569 429 if( timer != null ) { clearTimeout(timer); }
430 if ( ($(this).data('down') == true) && ($('#update_workspace_button').data('locked') == false) ) {
431 var p = svg_root.createSVGPoint();
432 p.x = event.clientX;
433 p.y = event.clientY;
434 p = p.matrixTransform(stateTf);
435 var matrix = stateTf.inverse().translate(p.x - stateOrigin.x, p.y - stateOrigin.y);
436 var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";
437 svg_root.children[0].setAttribute("transform", s);
581aee24 438 }
439 }).mousewheel(function (event, delta) {
72874569 440 event.returnValue = false;
441 event.preventDefault();
442 if ( $('#update_workspace_button').data('locked') == false ) {
443 if( delta < -9 ) { delta = -9 };
444 var z = 1 + delta/10;
445 var g = svg_root.children[0];
446 if( (z<1 && (g.getScreenCTM().a * start_element_height) > 4.0) || (z>1 && (g.getScreenCTM().a * start_element_height) < 100) ) {
447 var root = svg_root;
448 var p = root.createSVGPoint();
449 p.x = event.clientX;
450 p.y = event.clientY;
451 p = p.matrixTransform(g.getCTM().inverse());
452 var k = root.createSVGMatrix().translate(p.x, p.y).scale(z).translate(-p.x, -p.y);
453 var matrix = g.getCTM().multiply(k);
454 var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";
455 g.setAttribute("transform", s);
456 }
457 }
581aee24 458 }).css({
459 'overflow' : 'hidden',
460 'cursor' : '-moz-grab'
461 });
462
463
464 $( "#dialog-form" ).dialog({
465 autoOpen: false,
466 height: 270,
467 width: 290,
468 modal: true,
469 buttons: {
470 "Ok": function() {
471 $('#status').empty();
472 form_values = $('#collapse_node_form').serialize()
72874569 473 ncpath = getRelationshipURL();
474 $(':button :contains("Ok")').attr("disabled", true);
581aee24 475 var jqjson = $.post( ncpath, form_values, function(data) {
476 $.each( data, function(item, source_target) {
72874569 477 var relation = relation_manager.create( source_target[0], source_target[1], $('#rel_type').attr('selectedIndex') );
478 relation.data( 'type', $('#rel_type :selected').text() );
479 relation.data( 'scope', $('#scope :selected').text() );
31aaf446 480 relation.data( 'note', $('#note').val() );
72874569 481 relation_manager.toggle_active( relation.children('title').text() );
581aee24 482 });
581aee24 483 $( "#dialog-form" ).dialog( "close" );
72874569 484 }, 'json' );
581aee24 485 },
486 Cancel: function() {
581aee24 487 $( this ).dialog( "close" );
488 }
489 },
490 create: function(event, ui) {
491 $(this).data( 'relation_drawn', false );
492 //TODO? Err handling?
72874569 493 var basepath = getRelativePath();
494 var jqjson = $.getJSON( basepath + '/definitions', function(data) {
581aee24 495 var types = data.types.sort();
496 $.each( types, function(index, value) {
497 $('#rel_type').append( $('<option>').attr( "value", value ).text(value) );
498 $('#keymaplist').append( $('<li>').css( "border-color", relation_manager.relation_colors[index] ).text(value) );
499 });
500 var scopes = data.scopes;
501 $.each( scopes, function(index, value) {
502 $('#scope').append( $('<option>').attr( "value", value ).text(value) );
503 });
504 });
505 },
506 open: function() {
507 relation_manager.create_temporary( $('#source_node_id').val(), $('#target_node_id').val() );
72874569 508 $(".ui-widget-overlay").css("background", "none");
509 $("#dialog_overlay").show();
510 $("#dialog_overlay").height( $("#enlargement_container").height() );
63213207 511 $("#dialog_overlay").width( $("#enlargement_container").innerWidth() );
72874569 512 $("#dialog_overlay").offset( $("#enlargement_container").offset() );
581aee24 513 },
514 close: function() {
72874569 515 relation_manager.remove_temporary();
581aee24 516 $( '#status' ).empty();
517 $("#dialog_overlay").hide();
518 }
519 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
72874569 520 if( ( ajaxSettings.type == 'POST' ) && jqXHR.status == 403 ) {
521 var errobj = jQuery.parseJSON( jqXHR.responseText );
522 $('#status').append( '<p class="error">Error: ' + errobj.error + '</br>The relationship cannot be made.</p>' );
581aee24 523 }
524 } );
525
72874569 526 $( "#delete-form" ).dialog({
527 autoOpen: false,
31aaf446 528 height: 135,
72874569 529 width: 160,
530 modal: false,
531 buttons: {
532 Cancel: function() {
533 $( this ).dialog( "close" );
534 },
535 Delete: function() {
536 form_values = $('#delete_relation_form').serialize()
537 ncpath = getRelationshipURL()
538 var jqjson = $.ajax({ url: ncpath, data: form_values, success: function(data) {
539 $.each( data, function(item, source_target) {
540 relation_manager.remove( source_target[0] + '->' + source_target[1] );
541 });
542 $( "#delete-form" ).dialog( "close" );
543 }, dataType: 'json', type: 'DELETE' });
544 }
545 },
546 create: function(event, ui) {
547 var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ).css( 'width', '100%' );
548 buttonset.find( "button:contains('Cancel')" ).css( 'float', 'right' );
549 var dialog_aria = $("div[aria-labelledby='ui-dialog-title-delete-form']");
550 dialog_aria.mouseenter( function() {
551 if( mouseWait != null ) { clearTimeout(mouseWait) };
552 })
553 dialog_aria.mouseleave( function() {
554 mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 );
555 })
556 },
557 open: function() {
558 mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 );
559 },
560 close: function() {
561 }
562 });
563
581aee24 564 $('#update_workspace_button').click( function() {
565 var svg_enlargement = $('#svgenlargement').svg().svg('get').root();
72874569 566 mouse_scale = svg_root.children[0].getScreenCTM().a;
567 if( $(this).data('locked') == true ) {
568 $('#svgenlargement ellipse' ).each( function( index ) {
569 if( $(this).data( 'node_obj' ) != null ) {
570 $(this).data( 'node_obj' ).ungreyout_edges();
571 $(this).data( 'node_obj' ).set_draggable( false );
572 var node_id = $(this).data( 'node_obj' ).get_id();
573 toggle_relation_active( node_id );
574 $(this).data( 'node_obj', null );
575 }
581aee24 576 })
581aee24 577 $(this).data('locked', false);
72874569 578 $(this).css('background-position', '0px 44px');
581aee24 579 } else {
72874569 580 var left = $('#enlargement').offset().left;
581 var right = left + $('#enlargement').width();
582 var tf = svg_root.children[0].getScreenCTM().inverse();
583 var p = svg_root.createSVGPoint();
584 p.x=left;
585 p.y=100;
586 var cx_min = p.matrixTransform(tf).x;
587 p.x=right;
588 var cx_max = p.matrixTransform(tf).x;
589 $('#svgenlargement ellipse').each( function( index ) {
590 var cx = parseInt( $(this).attr('cx') );
591 if( cx > cx_min && cx < cx_max) {
592 if( $(this).data( 'node_obj' ) == null ) {
593 $(this).data( 'node_obj', new node_obj( $(this) ) );
594 } else {
595 $(this).data( 'node_obj' ).set_draggable( true );
596 }
597 $(this).data( 'node_obj' ).greyout_edges();
598 var node_id = $(this).data( 'node_obj' ).get_id();
599 toggle_relation_active( node_id );
581aee24 600 }
72874569 601 });
602 $(this).css('background-position', '0px 0px');
581aee24 603 $(this).data('locked', true );
581aee24 604 }
605 });
606
9ca77245 607 $('.helptag').popupWindow({
608 height:500,
609 width:800,
610 top:50,
611 left:50,
612 scrollbars:1
613 });
614
615
72874569 616 function toggle_relation_active( node_id ) {
617 $('#svgenlargement .relation').find( "title:contains('" + node_id + "')" ).each( function(index) {
618 matchid = new RegExp( "^" + node_id );
619 if( $(this).text().match( matchid ) != null ) {
620 relation_manager.toggle_active( $(this).text() );
621 };
622 });
581aee24 623 }
581aee24 624
72874569 625});
581aee24 626
627