X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=root%2Fjs%2Fstexaminer.js;h=a846cd077fd8e006a9d50a12f91813a05887456e;hb=196f6e1241a689baca699d703db5f29aefe29d6b;hp=2a9e10e6eb62dd178aadb8ae9e02be307cbea4ff;hpb=5089c3b7ca7a4bc7b7ef1668707dbbc771a60d98;p=scpubgit%2Fstemmaweb.git
diff --git a/root/js/stexaminer.js b/root/js/stexaminer.js
index 2a9e10e..a846cd0 100644
--- a/root/js/stexaminer.js
+++ b/root/js/stexaminer.js
@@ -1,27 +1,58 @@
var colors = ['#ffeeaa','#afc6e9','#d5fff6','#ffccaa','#ffaaaa','#e5ff80','#e5d5ff','#ffd5e5'];
var row_triggered = false;
-var original_svg;
function handle_row_click( row ) {
var ridx = row.parent().parent().index()
var rs = readingstats[ridx];
- var imghtml = ''
+ var imghtml = $('
').attr( 'src', baseurl + "../images/ajax-loader.gif" ).attr( 'alt', "Loading SVG..." );
$('#stemma_graph').empty();
$('#stemma_graph').append( imghtml );
if( rs.layerwits ) {
var stemma_form = { 'dot': graphdot, 'layerwits': rs.layerwits };
- $('#stemma_graph').load( 'graphsvg', stemma_form, function() {
+ $.post( baseurl + 'graphsvg', stemma_form, function( data ) {
+ var oSerializer = new XMLSerializer();
+ var xmlString = oSerializer.serializeToString( data.documentElement );
+ loadSVG( xmlString, function () {
+ color_row( row );
+ show_stats( rs );
+ });
+ });
+ } else {
+ loadSVG( original_svg, function() {
color_row( row );
show_stats( rs );
});
- } else {
- $('#stemma_graph').empty();
- $('#stemma_graph').append( original_svg );
- color_row( row );
- show_stats( rs );
}
}
+// Load the SVG we are given
+function loadSVG(svgData, cb) {
+ var svgElement = $('#stemma_graph');
+
+ $(svgElement).svg('destroy');
+
+ $(svgElement).svg({
+ loadURL: svgData,
+ onLoad : function () {
+ var theSVG = svgElement.find('svg');
+ var svgoffset = theSVG.offset();
+ // Firefox needs a different offset, stupidly enough
+ var browseroffset = 1;
+ if( navigator.userAgent.indexOf('Firefox') > -1 ) {
+ browseroffset = 3;
+ }
+ var topoffset = theSVG.position().top - svgElement.position().top - browseroffset;
+ // If we are on Safari, we need to get rid of the 'pt' in the width/height
+ // specifications
+ theSVG.offset({ top: svgoffset.top - topoffset, left: svgoffset.left });
+ if( cb ) {
+ cb.call();
+ }
+ theSVG.attr( 'width', '100%' );
+ }
+ });
+}
+
function color_row( row ) {
row_triggered = true;
$('ellipse').attr( {stroke:'white', fill:'#fff'} );
@@ -60,39 +91,93 @@ function color_nodes( column_index, arr_node_ids, arr_greynode_ids ) {
}
function show_stats( rs ) {
+ // Update the title
+ $('#stats_title').empty().text('Statistics for reading at ' + rs.id + ':' );
var rshtml = $('#stats_template').clone();
- rshtml.find('#statrank').append( rs.id );
- $.each( rs.readings, function( idx, rdghash ) {
- var rdgstats = $('#reading_template').clone();
- rdgstats.find('.readinglabel').append( rdghash.text );
- rdgstats.find('.reading_copied').append( rdghash.followed );
- rdgstats.find('.reading_changed').append( rdghash.not_followed );
- rdgstats.find('.reading_unclear').append( rdghash.follow_unknown );
- rdgstats.find('.readingroots').append( rdghash.independent_occurrence );
- if( ! $.isEmptyObject( rdghash.reading_parents ) ) {
- var parentstats = $('#reading_parent_template').clone();
- $.each( rdghash.reading_parents, function( parentid, pdata ) {
- var parentdesc = pdata.label;
- if( pdata.relation ) {
- parentdesc += ' - variant type ' + pdata.relation.type;
- if( pdata.relation.annotation ) {
- parentdesc += ' [ ' + pdata.relation.annotation + ' ]';
- }
- } else {
- parentdesc += ' - no syntactic relation';
- }
- var parentitem = $('