Commit | Line | Data |
81422c40 |
1 | var colors = ['#ffeeaa','#afc6e9','#d5fff6','#ffccaa','#ffaaaa','#e5ff80','#e5d5ff','#ffd5e5']; |
361134f0 |
2 | var row_triggered = false; |
f8d13166 |
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 | } |
23306161 |
24 | |
25 | function color_row( row ) { |
361134f0 |
26 | row_triggered = true; |
57acbbe2 |
27 | $('ellipse').attr( {stroke:'white', fill:'#fff'} ); |
119157ee |
28 | $('.node').children('polygon').attr( {stroke:'#fff', fill:'#fff'} ); |
29 | $('.node').children('text').attr( {stroke:'none', fill:'#000'} ); |
d5c17cec |
30 | $('tr.active_variant_row').children('td').removeClass('cellb0 cellb1 cellb2 cellb3 cellb4 cellb5 cellb6 cellb7'); |
23306161 |
31 | row.parent().nextAll('.clickable').children('span').click(); |
d5c17cec |
32 | $('td.active_variant_cell').removeClass('active_variant_cell'); |
361134f0 |
33 | row_triggered = false; |
23306161 |
34 | } |
35 | |
82fd8e05 |
36 | function color_nodes( column_index, arr_node_ids, arr_greynode_ids ) { |
d5c17cec |
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'); |
57acbbe2 |
40 | $('ellipse').attr( {stroke:'white', fill:'#fff'} ); |
119157ee |
41 | $('.node').children('polygon').attr( {stroke:'#fff', fill:'#fff'} ); |
42 | $('.node').children('text').attr( {stroke:'none', fill:'#000'} ); |
82fd8e05 |
43 | }; |
d5c17cec |
44 | $('tr.active_variant_row').removeClass('active_variant_row') |
82fd8e05 |
45 | jQuery.each( arr_greynode_ids, function(index,value) { |
119157ee |
46 | nodes = $('.node').children('title').filter( function(index) { |
82fd8e05 |
47 | return $(this).text() == value; |
119157ee |
48 | }) |
49 | nodes.siblings('ellipse, polygon, text').each( function( index ) { |
50 | $(this).attr( {stroke:'#ddd', fill:'#f8f8f8'} ); |
82fd8e05 |
51 | }); |
52 | }); |
dbcf12a6 |
53 | jQuery.each( arr_node_ids, function(index,value) { |
54 | $('.node').children('title').filter( function(index) { |
55 | return $(this).text() == value; |
94a077d6 |
56 | }).siblings('ellipse').each( function( index ) { |
361134f0 |
57 | $(this).attr( {stroke:'black', fill:colors[column_index-1]} ); |
58 | }); |
dbcf12a6 |
59 | }); |
60 | } |
3751a3c2 |
61 | |
f8d13166 |
62 | function show_stats( rs ) { |
3751a3c2 |
63 | var rshtml = $('#stats_template').clone(); |
64 | rshtml.find('#statrank').append( rs.id ); |
a9426c6d |
65 | if( "unsolved" in rs ) { |
66 | rshtml.find('.solutionstatus').append( |
67 | "(Not yet calculated for this location - please try later)"); |
68 | } else { |
69 | $.each( rs.readings, function( idx, rdghash ) { |
70 | var rdgstats = $('#reading_template').clone(); |
71 | rdgstats.find('.readinglabel').append( rdghash.text ); |
72 | rdgstats.find('.reading_copied').append( rdghash.followed ); |
73 | rdgstats.find('.reading_changed').append( rdghash.not_followed ); |
74 | rdgstats.find('.reading_unclear').append( rdghash.follow_unknown ); |
75 | rdgstats.find('.readingroots').append( rdghash.independent_occurrence ); |
76 | if( rdghash.is_reverted ) { |
77 | rdgstats.find('.reversionroots').append( rdghash.reversions ); |
78 | } else { |
79 | rdgstats.find('.readingreversions').empty(); |
80 | } |
81 | var rdgsourcehtml = fill_parent_template( rdghash, 'source' ); |
82 | var rdgreverthtml = fill_parent_template( rdghash, 'reversion' ); |
83 | rdgstats.find('.reading_statistics').append( rdgsourcehtml ); |
84 | rdgstats.find('.reading_statistics').append( rdgreverthtml ); |
85 | // If neither, append a small spacer |
86 | if( !rdgsourcehtml && !rdgreverthtml ) { |
87 | rdgstats.find('.reading_statistics').append( '<br/>' ); |
88 | } |
89 | rshtml.append( rdgstats.contents() ); |
90 | }); |
91 | } |
3751a3c2 |
92 | $('#row_statistics').empty(); |
93 | $('#row_statistics').append( rshtml.contents() ); |
ee53ab0d |
94 | |
3751a3c2 |
95 | }; |
f8d13166 |
96 | |
ee53ab0d |
97 | function fill_parent_template( rdghash, type ) { |
98 | var objname = type + '_parents'; |
99 | var template_id = '#reading_' + type + '_template'; |
100 | var list_class = '.reading_' + type + '_list'; |
101 | if( ! $.isEmptyObject( rdghash[objname] ) ) { |
102 | var parentstats = $( template_id ).clone(); |
103 | $.each( rdghash[objname], function( parentid, pdata ) { |
104 | var parentdesc = pdata.label; |
105 | if( pdata.relation ) { |
106 | parentdesc += ' - variant type ' + pdata.relation.type; |
107 | if( pdata.relation.annotation ) { |
108 | parentdesc += ' [ ' + pdata.relation.annotation + ' ]'; |
109 | } |
110 | } else { |
111 | parentdesc += ' - no syntactic relation'; |
112 | } |
113 | var parentitem = $('<li>').append( parentdesc ); |
114 | parentstats.find( list_class ).append( parentitem ); |
115 | }); |
116 | return( parentstats.contents() ); |
117 | } |
118 | } |
119 | |
f8d13166 |
120 | // Save the original unextended SVG for when we need it. |
121 | $(document).ready(function () { |
122 | original_svg = $('#stemma_graph > svg').clone(); |
26cea87c |
123 | |
124 | $('#aboutlink').popupWindow({ |
125 | height:500, |
126 | width:800, |
127 | top:50, |
128 | left:50, |
129 | scrollbars:1 |
130 | }); |
131 | $('#options').dialog({ |
132 | autoOpen: false, |
133 | height: 200, |
134 | width: 300, |
135 | modal: true, |
136 | buttons: { |
137 | Cancel: function() { |
138 | $(this).dialog( "close" ); |
139 | }, |
140 | Reanalyze: function() { |
141 | $('#use_variants_form').submit(); |
142 | }, |
143 | } |
144 | }); |
145 | |
f8d13166 |
146 | }); |