From a17eea27fecfb8ddadd6dd2e5b822a0a90b8eb95 Mon Sep 17 00:00:00 2001
From: Mikael Salson <mikael.salson@univ-lille1.fr>
Date: Tue, 24 Jul 2018 12:16:51 +0200
Subject: [PATCH] js/model.js: Display diversity with retro-compatibility

Diversity is now output under an Array by  (see #1941) but
this was not the case previously. We deal with both possibilities.

Fixes #3416
---
 browser/js/model.js | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/browser/js/model.js b/browser/js/model.js
index 538f583d50..64c0fce566 100644
--- a/browser/js/model.js
+++ b/browser/js/model.js
@@ -516,6 +516,21 @@ changeAlleleNotation: function(alleleNotation) {
             command = this.samples.commandline[time]
         return command;
     },
+
+    getDiversity: function(key, time) {
+	time = typeof time !== 'undefined' ? time : this.t
+	if (typeof this.diversity != 'undefined' &&
+	    typeof this.diversity[key] != 'undefined') {
+
+	    // Diversity may not be stored in an Array for retrocompatiblitiy reasons
+	    // See #1941 and #3416
+	    if (typeof this.diversity[key][time] != 'undefined') {
+		return this.diversity[key][time].toFixed(3);
+	    } else {
+		return this.diversity[key].toFixed(3);
+	    }
+	}
+    },
     
     /**
      * return date of software run given a time/sample index <br>
@@ -1235,7 +1250,7 @@ changeAlleleNotation: function(alleleNotation) {
         if ( typeof this.diversity != 'undefined') {
             html += "<tr><td class='header' colspan='2'> diversity </td></tr>"
             for (var key in this.diversity) {
-                html += "<tr><td> " + key.replace('index_', '') + "</td><td>" + this.diversity[key].toFixed(3) + '</td></tr>'
+                html += "<tr><td> " + key.replace('index_', '') + "</td><td>" + this.getDiversity(key, timeID) + '</td></tr>'
             }
         }
 
-- 
GitLab