From: Jess Robinson Date: Tue, 21 Jul 2015 15:36:56 +0000 (+0000) Subject: Re-order/fix node merging (also works for multiple nodes in a row) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1240cd027b82c52ab9b1bd92373231be71e3352d;p=scpubgit%2Fstemmaweb.git Re-order/fix node merging (also works for multiple nodes in a row) --- diff --git a/root/js/detach_helpers.js b/root/js/detach_helpers.js index c9f035a..3ee609c 100644 --- a/root/js/detach_helpers.js +++ b/root/js/detach_helpers.js @@ -115,8 +115,7 @@ function Edge( g_elem ) { var dy = (target_cy - source_cy); end_point_arrowhead.reposition( dx, dy ); edge_path.reposition( dx, dy ); - // var new_title = g_elem.children('title').text().replace( self.end_node_id, target_node_id ); - // console.log( new_title ); + g_elem.children('title').text(g_elem.children('title').text().replace( self.end_node_id, target_node_id )); } } } @@ -149,6 +148,7 @@ function Edge( g_elem ) { var dx = (target_cx + target_rx) - (source_cx + source_rx); var dy = (target_cy - source_cy); edge_path.reposition( dx, dy ); + self.g_elem.children('title').text(self.g_elem.children('title').text().replace( self.start_node_id, target_node_id )); } } diff --git a/root/js/relationship.js b/root/js/relationship.js index 158aeb2..cd22943 100644 --- a/root/js/relationship.js +++ b/root/js/relationship.js @@ -876,11 +876,27 @@ function merge_node( source_node_id, target_node_id ) { $( jq( source_node_id ) ).remove(); } +function merge_left( source_node_id, target_node_id ) { + $.each( edges_of( get_ellipse( source_node_id ) ), function( index, edge ) { + if( edge.is_incoming == true ) { + edge.attach_endpoint( target_node_id ); + } + } ); + $( jq( source_node_id ) ).remove(); +} + function compress_nodes(readings) { //add text of other readings to 1st reading var first = get_ellipse(readings[0]); + var first = get_ellipse(readings[0]); var first_title = first.parent().find('text')[0]; + var last_edges = edges_of(get_ellipse(readings[readings.length-1])); + for (var i = 0; i < last_edges.length; i++) { + if(last_edges[i].is_incoming == false) { + var last = last_edges[i]; + } + } for (var i = 1; i < readings.length; i++) { var cur = get_ellipse(readings[i]); @@ -889,38 +905,53 @@ function compress_nodes(readings) { first_title.textContent += " " + cur_title.textContent; }; - //delete all others + // Reattach last external edge to new to-be-merged node: NB: We + // can't to this after the removal as startpoint wants the cx etc + // of the ellipse the edge is moving from.. +// last.attach_startpoint(readings[0]); + + + // do this once: + var x = parseInt(first[0].getAttribute('cx'), 10); + first[0].setAttribute('rx', 4.5 * first_title.textContent.length); + + if (text_direction !== "BI") { + first[0].setAttribute('cx', x + first_title.textContent.length + 20); + first_title.setAttribute('x', first[0].getAttribute('cx')); + } + + //merge then delete all others for (var i = 1; i < readings.length; i++) { var node = get_ellipse(readings[i]); var rid = readings[i-1] + '->' + readings[i]; - //[].slice.call(s.getElementsByTagName('title')).find(function(elem){return elem.textContent=='r64.2->r66.2'}).parentNode.remove() - var titles = svg_root.getElementsByTagName('title'); var titlesArray = [].slice.call(titles); + // old edge, delete after moving stuff around! if (titlesArray.length > 0) { var title = titlesArray.find(function(elem){ return elem.textContent === rid; }); - - if (title && title.parentNode) { - title.parentNode.remove(); - } } - var x = parseInt(first[0].getAttribute('cx'), 10); + //[].slice.call(s.getElementsByTagName('title')).find(function(elem){return elem.textContent=='r64.2->r66.2'}).parentNode.remove() - first[0].setAttribute('rx', 4.5 * first_title.textContent.length); + // only merge start on the last one, else, we get ourselves confused! + if(readings[i] == readings[readings.length-1]) { + merge_node(readings[i], readings[0]); + } else { + merge_left(readings[i], readings[0]); + } - if (text_direction !== "BI") { - first[0].setAttribute('cx', x + first_title.textContent.length + 20); - first_title.setAttribute('x', first[0].getAttribute('cx')); + if (title && title.parentNode) { + title.parentNode.remove(); } - merge_node(readings[i], readings[0]); - //node.parent().remove(); } + + get_node_obj(readings[0]).update_elements(); + } function Marquee() {