Commit | Line | Data |
b8a92065 |
1 | var colors = ['#ffeeaa','#afc6e9','#d5fff6','#ffccaa','#ffaaaa','#e5ff80','#e5d5ff','#ffd5e5']; |
2 | var row_triggered = false; |
be8bf746 |
3 | |
4 | function handle_row_click( row ) { |
5 | var ridx = row.parent().parent().index() |
6 | var rs = readingstats[ridx]; |
dd0c01e7 |
7 | var imghtml = $('<img>').attr( 'src', baseurl + "../images/ajax-loader.gif" ).attr( 'alt', "Loading SVG..." ); |
be8bf746 |
8 | $('#stemma_graph').empty(); |
9 | $('#stemma_graph').append( imghtml ); |
10 | if( rs.layerwits ) { |
11 | var stemma_form = { 'dot': graphdot, 'layerwits': rs.layerwits }; |
f6bfb763 |
12 | $.post( baseurl + 'graphsvg', stemma_form, function( data ) { |
13 | var oSerializer = new XMLSerializer(); |
14 | var xmlString = oSerializer.serializeToString( data.documentElement ); |
15 | loadSVG( xmlString, function () { |
16 | color_row( row ); |
17 | show_stats( rs ); |
18 | }); |
19 | }); |
20 | } else { |
21 | loadSVG( original_svg, function() { |
be8bf746 |
22 | color_row( row ); |
23 | show_stats( rs ); |
24 | }); |
be8bf746 |
25 | } |
26 | } |
d5514865 |
27 | |
f6bfb763 |
28 | // Load the SVG we are given |
29 | function loadSVG(svgData, cb) { |
30 | var svgElement = $('#stemma_graph'); |
31 | |
32 | $(svgElement).svg('destroy'); |
33 | |
34 | $(svgElement).svg({ |
35 | loadURL: svgData, |
36 | onLoad : function () { |
37 | var theSVG = svgElement.find('svg'); |
38 | var svgoffset = theSVG.offset(); |
39 | // Firefox needs a different offset, stupidly enough |
40 | var browseroffset = 1; |
41 | if( navigator.userAgent.indexOf('Firefox') > -1 ) { |
42 | browseroffset = 3; |
43 | } |
44 | var topoffset = theSVG.position().top - svgElement.position().top - browseroffset; |
45 | // If we are on Safari, we need to get rid of the 'pt' in the width/height |
46 | // specifications |
47 | theSVG.offset({ top: svgoffset.top - topoffset, left: svgoffset.left }); |
48 | if( cb ) { |
49 | cb.call(); |
50 | } |
7d301abf |
51 | theSVG.attr( 'width', '100%' ); |
f6bfb763 |
52 | } |
53 | }); |
54 | } |
55 | |
d5514865 |
56 | function color_row( row ) { |
b8a92065 |
57 | row_triggered = true; |
f007ac1e |
58 | $('ellipse').attr( {stroke:'white', fill:'#fff'} ); |
b8a92065 |
59 | $('.node').children('polygon').attr( {stroke:'#fff', fill:'#fff'} ); |
60 | $('.node').children('text').attr( {stroke:'none', fill:'#000'} ); |
61 | $('tr.active_variant_row').children('td').removeClass('cellb0 cellb1 cellb2 cellb3 cellb4 cellb5 cellb6 cellb7'); |
d5514865 |
62 | row.parent().nextAll('.clickable').children('span').click(); |
b8a92065 |
63 | $('td.active_variant_cell').removeClass('active_variant_cell'); |
64 | row_triggered = false; |
d5514865 |
65 | } |
66 | |
b8a92065 |
67 | function color_nodes( column_index, arr_node_ids, arr_greynode_ids ) { |
68 | if( !row_triggered ) { |
69 | $('tr.active_variant_row').children('td').removeClass('cellb0 cellb1 cellb2 cellb3 cellb4 cellb5 cellb6 cellb7'); |
70 | $('td.active_variant_cell').removeClass('active_variant_cell'); |
f007ac1e |
71 | $('ellipse').attr( {stroke:'white', fill:'#fff'} ); |
b8a92065 |
72 | $('.node').children('polygon').attr( {stroke:'#fff', fill:'#fff'} ); |
73 | $('.node').children('text').attr( {stroke:'none', fill:'#000'} ); |
74 | }; |
75 | $('tr.active_variant_row').removeClass('active_variant_row') |
76 | jQuery.each( arr_greynode_ids, function(index,value) { |
77 | nodes = $('.node').children('title').filter( function(index) { |
78 | return $(this).text() == value; |
79 | }) |
80 | nodes.siblings('ellipse, polygon, text').each( function( index ) { |
81 | $(this).attr( {stroke:'#ddd', fill:'#f8f8f8'} ); |
82 | }); |
83 | }); |
84 | jQuery.each( arr_node_ids, function(index,value) { |
85 | $('.node').children('title').filter( function(index) { |
86 | return $(this).text() == value; |
87 | }).siblings('ellipse').each( function( index ) { |
88 | $(this).attr( {stroke:'black', fill:colors[column_index-1]} ); |
89 | }); |
90 | }); |
91 | } |
ef3db56f |
92 | |
be8bf746 |
93 | function show_stats( rs ) { |
8c01174c |
94 | // Update the title |
95 | $('#stats_title').empty().text('Statistics for reading at ' + rs.id + ':' ); |
ef3db56f |
96 | var rshtml = $('#stats_template').clone(); |
d35db27a |
97 | if( "unsolved" in rs ) { |
ec0d9b5b |
98 | var nocalcmsg; |
99 | if( rs.unsolved == 'IDP error' ) { |
100 | nocalcmsg = $('<span>').attr('class', 'error').append( |
101 | "(Could not reach calculation server - are you offline?)" ); |
102 | } else { |
103 | nocalcmsg = "(Not yet calculated for this location - please try later)"; |
104 | } |
105 | rshtml.find('.solutionstatus').append( nocalcmsg ); |
d35db27a |
106 | } else { |
107 | $.each( rs.readings, function( idx, rdghash ) { |
108 | var rdgstats = $('#reading_template').clone(); |
109 | rdgstats.find('.readinglabel').append( rdghash.text ); |
110 | rdgstats.find('.reading_copied').append( rdghash.followed ); |
111 | rdgstats.find('.reading_changed').append( rdghash.not_followed ); |
112 | rdgstats.find('.reading_unclear').append( rdghash.follow_unknown ); |
113 | rdgstats.find('.readingroots').append( rdghash.independent_occurrence ); |
114 | if( rdghash.is_reverted ) { |
115 | rdgstats.find('.reversionroots').append( rdghash.reversions ); |
116 | } else { |
117 | rdgstats.find('.readingreversions').empty(); |
118 | } |
119 | var rdgsourcehtml = fill_parent_template( rdghash, 'source' ); |
120 | var rdgreverthtml = fill_parent_template( rdghash, 'reversion' ); |
121 | rdgstats.find('.reading_statistics').append( rdgsourcehtml ); |
122 | rdgstats.find('.reading_statistics').append( rdgreverthtml ); |
123 | // If neither, append a small spacer |
124 | if( !rdgsourcehtml && !rdgreverthtml ) { |
125 | rdgstats.find('.reading_statistics').append( '<br/>' ); |
126 | } |
127 | rshtml.append( rdgstats.contents() ); |
128 | }); |
129 | } |
8c01174c |
130 | $('#stats_container').empty().append( rshtml.contents() ); |
f7371955 |
131 | |
ef3db56f |
132 | }; |
be8bf746 |
133 | |
f7371955 |
134 | function fill_parent_template( rdghash, type ) { |
135 | var objname = type + '_parents'; |
136 | var template_id = '#reading_' + type + '_template'; |
137 | var list_class = '.reading_' + type + '_list'; |
138 | if( ! $.isEmptyObject( rdghash[objname] ) ) { |
139 | var parentstats = $( template_id ).clone(); |
140 | $.each( rdghash[objname], function( parentid, pdata ) { |
141 | var parentdesc = pdata.label; |
142 | if( pdata.relation ) { |
143 | parentdesc += ' - variant type ' + pdata.relation.type; |
144 | if( pdata.relation.annotation ) { |
145 | parentdesc += ' [ ' + pdata.relation.annotation + ' ]'; |
146 | } |
147 | } else { |
148 | parentdesc += ' - no syntactic relation'; |
149 | } |
150 | var parentitem = $('<li>').append( parentdesc ); |
151 | parentstats.find( list_class ).append( parentitem ); |
152 | }); |
153 | return( parentstats.contents() ); |
154 | } |
155 | } |
156 | |
be8bf746 |
157 | // Save the original unextended SVG for when we need it. |
158 | $(document).ready(function () { |
f6bfb763 |
159 | loadSVG( original_svg ); |
2fd8f80c |
160 | |
161 | $('#aboutlink').popupWindow({ |
162 | height:500, |
163 | width:800, |
164 | top:50, |
165 | left:50, |
166 | scrollbars:1 |
167 | }); |
168 | $('#options').dialog({ |
169 | autoOpen: false, |
8c01174c |
170 | // height: 'auto', |
2fd8f80c |
171 | width: 300, |
172 | modal: true, |
173 | buttons: { |
174 | Cancel: function() { |
175 | $(this).dialog( "close" ); |
176 | }, |
177 | Reanalyze: function() { |
178 | $('#use_variants_form').submit(); |
179 | }, |
180 | } |
181 | }); |
182 | |
be8bf746 |
183 | }); |