X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=stemmaweb%2Froot%2Fjs%2Frelationship.js;h=807b5d4dc44b82ef5dab13bf2139b5799c50e0ee;hb=4aa3aa3db8d45952a7ede6ffac2a06ec2d18c6e3;hp=608d1edca349fe6e0146c05ba8cae3899be0fd99;hpb=7fd1d97a0e7b50b8f0e30190aeb62eaaf239552c;p=scpubgit%2Fstemmatology.git diff --git a/stemmaweb/root/js/relationship.js b/stemmaweb/root/js/relationship.js index 608d1ed..807b5d4 100644 --- a/stemmaweb/root/js/relationship.js +++ b/stemmaweb/root/js/relationship.js @@ -1,8 +1,20 @@ +var MARGIN=30; +var svg_root = null; +var svg_root_element = null; +var start_element_height = 0; +var reltypes = {}; +var readingdata = {}; + function getTextPath() { - var currpath = window.location.pathname + var currpath = window.location.pathname; + // Get rid of trailing slash if( currpath.lastIndexOf('/') == currpath.length - 1 ) { currpath = currpath.slice( 0, currpath.length - 1) }; + // Get rid of query parameters + if( currpath.lastIndexOf('?') != -1 ) { + currpath = currpath.slice( 0, currpath.lastIndexOf('?') ); + }; var path_elements = currpath.split('/'); var textid = path_elements.pop(); var basepath = path_elements.join( '/' ); @@ -10,74 +22,240 @@ function getTextPath() { return path_parts; } -function svgLoaded() { - // some initial scaling - var svg_element = $('#svgbasics').children('svg'); - var svg_graph = svg_element.svg().svg('get').root(); - var svg_vbwidth = svg_graph.viewBox.baseVal.width; - var svg_vbheight = svg_graph.viewBox.baseVal.height; - var scroll_padding = $('#graph_container').width(); - // (Use attr('width') to set width attr, otherwise style="width: npx;" is set.) - var svg_element_width = svg_vbwidth/svg_vbheight * parseInt(svg_element.attr('height')); - svg_element_width += scroll_padding; - svg_element.attr( 'width', svg_element_width ); - $('ellipse').attr( {stroke:'black', fill:'#fff'} ); +function getRelativePath() { + var path_parts = getTextPath(); + return path_parts[0]; +} + +function getTextURL( which ) { + var path_parts = getTextPath(); + return path_parts[0] + '/' + path_parts[1] + '/' + which; +} + +function getReadingURL( reading_id ) { + var path_parts = getTextPath(); + return path_parts[0] + '/' + path_parts[1] + '/reading/' + reading_id; +} + +// Make an XML ID into a valid selector +function jq(myid) { + return '#' + myid.replace(/(:|\.)/g,'\\$1'); +} + +// Actions for opening the reading panel +function node_dblclick_listener( evt ) { + // Open the reading dialogue for the given node. + // First get the reading info + var reading_id = $(this).attr('id'); + var reading_info = readingdata[reading_id]; + // and then populate the dialog box with it. + // Set the easy properties first + $('#reading-form').dialog( 'option', 'title', 'Reading information for "' + reading_info['text'] + '"' ); + $('#reading_id').val( reading_id ); + toggle_checkbox( $('#reading_is_nonsense'), reading_info['is_nonsense'] ); + toggle_checkbox( $('#reading_grammar_invalid'), reading_info['grammar_invalid'] ); + // Use .text as a backup for .normal_form + var normal_form = reading_info['normal_form']; + if( !normal_form ) { + normal_form = reading_info['text']; + } + var nfboxsize = 10; + if( normal_form.length > 9 ) { + nfboxsize = normal_form.length + 1; + } + $('#reading_normal_form').attr( 'size', nfboxsize ) + $('#reading_normal_form').val( normal_form ); + // Now do the morphological properties. + morphology_form( reading_info['lexemes'] ); + // and then open the dialog. + $('#reading-form').dialog("open"); +} + +function toggle_checkbox( box, value ) { + if( value == null ) { + value = false; + } + box.attr('checked', value ); +} + +function morphology_form ( lexlist ) { + $('#morphology').empty(); + $.each( lexlist, function( idx, lex ) { + var morphoptions = []; + if( 'wordform_matchlist' in lex ) { + $.each( lex['wordform_matchlist'], function( tdx, tag ) { + var tagstr = stringify_wordform( tag ); + morphoptions.push( tagstr ); + }); + } + var formtag = 'morphology_' + idx; + var formstr = ''; + if( 'form' in lex ) { + formstr = stringify_wordform( lex['form'] ); + } + var form_morph_elements = morph_elements( + formtag, lex['string'], formstr, morphoptions ); + $.each( form_morph_elements, function( idx, el ) { + $('#morphology').append( el ); + }); + }); +} + +function stringify_wordform ( tag ) { + if( tag ) { + var elements = tag.split(' // '); + return elements[1] + ' // ' + elements[2]; + } + return '' +} + +function morph_elements ( formtag, formtxt, currform, morphoptions ) { + var clicktag = '(Click to select)'; + if ( !currform ) { + currform = clicktag; + } + var formlabel = $('