b38d8421739ea88cd3e70345ee904349b8f455e0
[scpubgit/stemmatology.git] / stemmaweb / root / js / stexaminer.js
1 var colors = ['#ffeeaa','#afc6e9','#d5fff6','#ffccaa','#ffaaaa','#e5ff80','#e5d5ff','#ffd5e5'];
2 var row_triggered = false;
3 var original_svg;
4
5 function handle_row_click( row ) {
6         var ridx = row.parent().parent().index()
7         var rs = readingstats[ridx];
8     var imghtml = '<img src="../images/ajax-loader.gif" alt="Loading SVG..."/>'
9     $('#stemma_graph').empty();
10     $('#stemma_graph').append( imghtml );
11         if( rs.layerwits ) {
12                 var stemma_form = { 'dot': graphdot, 'layerwits': rs.layerwits };
13                 $('#stemma_graph').load( 'graphsvg', stemma_form, function() {
14                         color_row( row );
15                         show_stats( rs );
16                 });
17         } else {
18                 $('#stemma_graph').empty();
19                 $('#stemma_graph').append( original_svg );
20                 color_row( row );
21                 show_stats( rs );
22         }
23 }
24
25 function color_row( row ) {
26     row_triggered = true;
27     $('ellipse').attr( {stroke:'white', fill:'#fff'} );
28     $('.node').children('polygon').attr( {stroke:'#fff', fill:'#fff'} );
29     $('.node').children('text').attr( {stroke:'none', fill:'#000'} );
30     $('tr.active_variant_row').children('td').removeClass('cellb0 cellb1 cellb2 cellb3 cellb4 cellb5 cellb6 cellb7'); 
31     row.parent().nextAll('.clickable').children('span').click();
32     $('td.active_variant_cell').removeClass('active_variant_cell');
33     row_triggered = false;
34 }
35
36 function color_nodes( column_index, arr_node_ids, arr_greynode_ids ) {
37   if( !row_triggered ) {
38     $('tr.active_variant_row').children('td').removeClass('cellb0 cellb1 cellb2 cellb3 cellb4 cellb5 cellb6 cellb7'); 
39     $('td.active_variant_cell').removeClass('active_variant_cell');
40     $('ellipse').attr( {stroke:'white', fill:'#fff'} );
41     $('.node').children('polygon').attr( {stroke:'#fff', fill:'#fff'} );
42     $('.node').children('text').attr( {stroke:'none', fill:'#000'} );
43   }; 
44   $('tr.active_variant_row').removeClass('active_variant_row') 
45   jQuery.each( arr_greynode_ids, function(index,value) {
46     nodes = $('.node').children('title').filter( function(index) {
47       return $(this).text() == value;
48     })
49     nodes.siblings('ellipse, polygon, text').each( function( index ) {
50         $(this).attr( {stroke:'#ddd', fill:'#f8f8f8'} );
51       });
52   });
53   jQuery.each( arr_node_ids, function(index,value) {
54     $('.node').children('title').filter( function(index) {
55       return $(this).text() == value;
56     }).siblings('ellipse').each( function( index ) {
57         $(this).attr( {stroke:'black', fill:colors[column_index-1]} );
58       });
59   });
60 }
61
62 function show_stats( rs ) {
63         var rshtml = $('#stats_template').clone();
64         rshtml.find('#statrank').append( rs.id );
65         $.each( rs.readings, function( idx, rdghash ) {
66                 var readinglabel = rdghash.readingid;
67                 if( rdghash.text ) {
68                         readinglabel = rdghash.text;
69                 }
70                 var readingroots = rdghash.independent_occurrence.join( ', ' );
71                 var rdgstats = $('#reading_template').clone();
72                 rdgstats.find('.readinglabel').append( readinglabel );
73                 rdgstats.find('.reading_copied').append( rdghash.followed );
74                 rdgstats.find('.reading_changed').append( rdghash.not_followed );
75                 rdgstats.find('.reading_unclear').append( rdghash.follow_unknown );
76                 rdgstats.find('.readingroots').append( readingroots );
77                 if( ! $.isEmptyObject( rdghash.reading_parents ) ) {
78                         var parentstats = $('#reading_parent_template').clone();
79                         $.each( rdghash.reading_parents, function( parentid, pdata ) {
80                                 var parentdesc = pdata.label;
81                                 if( pdata.relation ) {
82                                         parentdesc += ' - variant type ' + pdata.relation.type;
83                                         if( pdata.relation.annotation ) {
84                                                 parentdesc += ' [ ' + pdata.relation.annotation + ' ]';
85                                         }
86                                 } else {
87                                         parentdesc += ' - no syntactic relation';
88                                 }
89                                 var parentitem = $('<li>').append( parentdesc );
90                                 parentstats.find('.reading_parent_list').append( parentitem );
91                         });
92                         rdgstats.find('.reading_statistics').append( parentstats.contents() );
93                 }
94                 rshtml.append( rdgstats.contents() );
95         });
96         $('#row_statistics').empty();
97         $('#row_statistics').append( rshtml.contents() );
98 };
99
100 // Save the original unextended SVG for when we need it.
101 $(document).ready(function () {
102         original_svg = $('#stemma_graph > svg').clone();
103 });