X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=root%2Fjs%2Frelationship.js;h=7298613bb1d7103d3fb10c82310796ec6ec565a2;hb=e538eccb6632fce7d1088899b2d4b81346e25fba;hp=14c06765b9e4c4340f176fe3ef219ab54415e6ee;hpb=5539cba31aece1048961e1c0845c0996390cf3b4;p=scpubgit%2Fstemmaweb.git diff --git a/root/js/relationship.js b/root/js/relationship.js index 14c0676..7298613 100644 --- a/root/js/relationship.js +++ b/root/js/relationship.js @@ -5,6 +5,17 @@ var start_element_height = 0; var reltypes = {}; var readingdata = {}; +function arrayUnique(array) { + var a = array.concat(); + for(var i=0; i 0 ) { + $('ellipse[fill="#9999ff"]').each( function() { + $(this).data( 'node_obj' ).set_draggable( false ); + } ); + } + self.set_draggable( true ) + }); + } else { + $(self.ellipse).attr( {stroke:'black', fill:'#fff'} ); + self.ellipse.siblings('text').attr('class', ''); + $(self.ellipse).parent().unbind(); + $('body').unbind('mousemove'); + $('body').unbind('mouseup'); + } + } + this.set_draggable = function( draggable ) { if( draggable && editable ) { - $(self.ellipse).attr( {stroke:'black', fill:'#fff'} ); + $(self.ellipse).attr( {stroke:'black', fill:'#9999ff'} ); $(self.ellipse).parent().mousedown( this.mousedown_listener ); - $(self.ellipse).parent().hover( this.enter_node, this.leave_node ); + $(self.ellipse).parent().unbind( 'mouseenter' ).unbind( 'mouseleave' ); self.ellipse.siblings('text').attr('class', 'noselect draggable'); } else { + $(self.ellipse).attr( {stroke:'black', fill:'#fff'} ); self.ellipse.siblings('text').attr('class', ''); - $(self.ellipse).parent().unbind( 'mouseenter' ).unbind( 'mouseleave' ).unbind( 'mousedown' ); - color_inactive( self.ellipse ); + $(self.ellipse).parent().unbind( 'mousedown '); + $(self.ellipse).parent().mousedown( function(evt) { evt.stopPropagation() } ); + $(self.ellipse).parent().hover( this.enter_node, this.leave_node ); } } @@ -296,7 +339,7 @@ function node_obj(ellipse) { $('body').mousemove( self.mousemove_listener ); $('body').mouseup( self.mouseup_listener ); $(self.ellipse).parent().unbind('mouseenter').unbind('mouseleave') - self.ellipse.attr( 'fill', '#ff66ff' ); + self.ellipse.attr( 'fill', '#6b6bb2' ); first_node_g_element = $("#svgenlargement g .node" ).filter( ":first" ); if( first_node_g_element.attr('id') !== self.get_g().attr('id') ) { self.get_g().insertBefore( first_node_g_element ) }; } @@ -324,8 +367,7 @@ function node_obj(ellipse) { }; $('body').unbind('mousemove'); $('body').unbind('mouseup'); - self.ellipse.attr( 'fill', '#fff' ); - $(self.ellipse).parent().hover( self.enter_node, self.leave_node ); + self.ellipse.attr( 'fill', '#9999ff' ); self.reset_elements(); } @@ -373,7 +415,11 @@ function node_obj(ellipse) { self.node_elements = node_elements_for(self.ellipse); } - self.set_draggable( true ); + this.get_witnesses = function() { + return readingdata[self.get_id()].witnesses + } + + self.set_selectable( true ); } function svgshape( shape_element ) { @@ -521,11 +567,11 @@ function relation_factory() { } } this.showinfo = function(relation) { - var htmlstr = 'type: ' + relation.data( 'type' ) + '
scope: ' + relation.data( 'scope' ); + $('#delete_relation_type').text( relation.data('type') ); + $('#delete_relation_scope').text( relation.data('scope') ); if( relation.data( 'note' ) ) { - htmlstr = htmlstr + '
note: ' + relation.data( 'note' ); + $('#delete_relation_note').text('note: ' + relation.data( 'note' ) ); } - $('#delete-form-text').html( htmlstr ); var points = relation.children('path').attr('d').slice(1).replace('C',' ').split(' '); var xs = parseFloat( points[0].split(',')[0] ); var xe = parseFloat( points[1].split(',')[0] ); @@ -583,29 +629,128 @@ function draw_relation( source_id, target_id, relation_color ) { return relation_element; } +function Marquee() { + + var self = this; + + this.x = 0; + this.y = 0; + this.dx = 0; + this.dy = 0; + this.enlargementOffset = $('#svgenlargement').offset(); + this.svg_rect = $('#svgenlargement svg').svg('get'); + + this.show = function( event ) { + // TODO: uncolor possible selected + // TODO: unless SHIFT? + self.x = event.clientX; + self.y = event.clientY; + p = svg_root.createSVGPoint(); + p.x = event.clientX - self.enlargementOffset.left; + p.y = event.clientY - self.enlargementOffset.top; + self.svg_rect.rect( p.x, p.y, 0, 0, { fill: 'black', 'fill-opacity': '0.1', stroke: 'black', 'stroke-dasharray': '4,2', strokeWidth: '0.02em', id: 'marquee' } ); + }; + + this.expand = function( event ) { + self.dx = (event.clientX - self.x); + self.dy = (event.clientY - self.y); + var rect = $('#marquee'); + if( rect.length != 0 ) { + var rect_w = Math.abs( self.dx ); + var rect_h = Math.abs( self.dy ); + var rect_x = self.x - self.enlargementOffset.left; + var rect_y = self.y - self.enlargementOffset.top; + if( self.dx < 0 ) { rect_x = rect_x - rect_w } + if( self.dy < 0 ) { rect_y = rect_y - rect_h } + rect.attr("x", rect_x).attr("y", rect_y).attr("width", rect_w).attr("height", rect_h); + } + }; + + this.select = function() { + var rect = $('#marquee'); + if( rect.length != 0 ) { + //unselect any possible selected first + if( $('ellipse[fill="#9999ff"]').size() > 0 ) { + $('ellipse[fill="#9999ff"]').each( function() { + $(this).data( 'node_obj' ).set_draggable( false ); + } ); + } + //compute dimension of marquee + var left = $('#marquee').offset().left; + var top = $('#marquee').offset().top; + var right = left + parseInt( $('#marquee').attr( 'width' ) ); + var bottom = top + parseInt( $('#marquee').attr( 'height' ) ); + var tf = svg_root_element.getScreenCTM().inverse(); + var p = svg_root.createSVGPoint(); + p.x=left; + p.y=top; + var cx_min = p.matrixTransform(tf).x; + var cy_min = p.matrixTransform(tf).y; + p.x=right; + p.y=bottom; + var cx_max = p.matrixTransform(tf).x; + var cy_max = p.matrixTransform(tf).y; + //select any node with its center inside the marquee + //also merge witness sets from nodes + var witnesses = []; + $('#svgenlargement ellipse').each( function( index ) { + var cx = parseInt( $(this).attr('cx') ); + var cy = parseInt( $(this).attr('cy') ); + if( cx > cx_min && cx < cx_max) { + if( cy > cy_min && cy < cy_max) { + // we actually heve no real 'selected' state for nodes, except coloring + $(this).attr( 'fill', '#9999ff' ); + var this_witnesses = $(this).data( 'node_obj' ).get_witnesses(); + witnesses = arrayUnique( witnesses.concat( this_witnesses ) ); + } + } + }); + if( $('ellipse[fill="#9999ff"]').size() > 0 ) { + //add interesectio of witnesses sets to the multi select form and open it + $.each( witnesses, function( index, value ) { + $('#multipleselect-form').append( '' + value + '
' ); + }); + $('#multipleselect-form').dialog( 'open' ); + } + self.svg_rect.remove( $('#marquee') ); + } + }; + + this.unselect = function() { + $('ellipse[fill="#9999ff"]').attr( 'fill', '#fff' ); + } + +} + $(document).ready(function () { timer = null; relation_manager = new relation_factory(); - $('#update_workspace_button').data('locked', false); + $('#update_workspace_button').data('locked', false); + $('#enlargement').mousedown(function (event) { $(this) .data('down', true) .data('x', event.clientX) .data('y', event.clientY) .data('scrollLeft', this.scrollLeft) - stateTf = svg_root_element.getCTM().inverse(); - var p = svg_root.createSVGPoint(); - p.x = event.clientX; - p.y = event.clientY; - stateOrigin = p.matrixTransform(stateTf); - event.returnValue = false; - event.preventDefault(); - return false; + stateTf = svg_root_element.getCTM().inverse(); + var p = svg_root.createSVGPoint(); + p.x = event.clientX; + p.y = event.clientY; + stateOrigin = p.matrixTransform(stateTf); + + // Activate marquee if in interaction mode + if( $('#update_workspace_button').data('locked') == true ) { marquee.show( event ) }; + + event.returnValue = false; + event.preventDefault(); + return false; }).mouseup(function (event) { - $(this).data('down', false); + marquee.select(); + $(this).data('down', false); }).mousemove(function (event) { if( timer != null ) { clearTimeout(timer); } if ( ($(this).data('down') == true) && ($('#update_workspace_button').data('locked') == false) ) { @@ -617,6 +762,7 @@ $(document).ready(function () { var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")"; svg_root_element.setAttribute("transform", s); } + marquee.expand( event ); event.returnValue = false; event.preventDefault(); }).mousewheel(function (event, delta) { @@ -647,6 +793,7 @@ $(document).ready(function () { 'cursor' : '-moz-grab' }); + if( editable ) { $( "#dialog-form" ).dialog({ autoOpen: false, @@ -682,12 +829,21 @@ $(document).ready(function () { }, create: function(event, ui) { $(this).data( 'relation_drawn', false ); + $('#rel_type').data( 'changed_after_open', false ); $.each( relationship_types, function(index, typedef) { $('#rel_type').append( $('