From d5a18084379c287c2f031177d930267bcbfe0274 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Tue, 22 Nov 2011 17:15:39 +0100 Subject: [PATCH] SONAR-2816 Internationalize numbers displayed in the TimeLine widget --- .../org/sonar/plugins/core/widgets/timeline.html.erb | 10 +++++++--- .../src/main/webapp/javascripts/protovis-sonar.js | 12 ++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb index 83795e61ed9..665ee10775b 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb @@ -48,7 +48,9 @@ if metric_count_per_snapshot_id[metric_data[:sid]]==total_number_of_metrics m_date = metric_data[:date] # Only Oracle returns a Time object, so let's parse this string if it's not a Time instance - m_date = Time.parse(metric_data[:date]) unless m_date.is_a? Time + m_date = Time.parse(metric_data[:date]) unless m_date.is_a? Time + m_value = sprintf( "%0.02f", metric_data[:value]) + m_value_localized = (m_value.end_with? '.00') ? number_with_precision(metric_data[:value], :precision => 0).to_s : number_with_precision(metric_data[:value], :precision => 2).to_s js_data += "{x:d(" js_data += m_date.year.to_s js_data += "," @@ -63,8 +65,10 @@ js_data += "," js_data += m_date.sec.to_s js_data += "),y:" - js_data += sprintf( "%0.02f", metric_data[:value]) - js_data += "}," + js_data += m_value + js_data += ",yl:\"" + js_data += m_value_localized + js_data += "\"}," if index == 0 # we fill the js_snapshots array (no need to do this more than once) js_snapshots += "{sid:" diff --git a/sonar-server/src/main/webapp/javascripts/protovis-sonar.js b/sonar-server/src/main/webapp/javascripts/protovis-sonar.js index 95547a43268..0fa5a591ecc 100755 --- a/sonar-server/src/main/webapp/javascripts/protovis-sonar.js +++ b/sonar-server/src/main/webapp/javascripts/protovis-sonar.js @@ -213,8 +213,8 @@ SonarWidgets.StackArea.prototype.render = function() { * Displays the evolution of metrics on a line chart, displaying related events. * * Parameters of the Timeline class: - * - data: array of arrays, each containing maps {x,y} where x is a (JS) date and y is a number value (representing a metric value at - * a given time). The {x,y} maps must be sorted by ascending date. + * - data: array of arrays, each containing maps {x,y,yl} where x is a (JS) date, y is a number value (representing a metric value at + * a given time), and yl the localized value of y. The {x,y, yl} maps must be sorted by ascending date. * - metrics: array of metric names. The order is important as it defines which array of the "data" parameter represents which metric. * - snapshots: array of maps {sid,d} where sid is the snapshot id and d is the locale-formatted date of the snapshot. The {sid,d} * maps must be sorted by ascending date. @@ -229,8 +229,8 @@ function d(y,m,d,h,min,s) { return new Date(y,m,d,h,min,s); } var data = [ - [{x:d(2011,5,15,0,1,0),y:912.00},{x:d(2011,6,21,0,1,0)], - [{x:d(2011,5,15,0,1,0),y:52.20},{x:d(2011,6,21,0,1,0),y:52.10}] + [{x:d(2011,5,15,0,1,0),y:912.00,yl:"912"},{x:d(2011,6,21,0,1,0),y:152.10,yl:"152.10"}], + [{x:d(2011,5,15,0,1,0),y:52.20,yi:"52.20"},{x:d(2011,6,21,0,1,0),y:1452.10,yi:"1,452.10"}] ]; var metrics = ["Lines of code","Rules compliance"]; var snapshots = [{sid:1,d:"June 15, 2011 00:01"},{sid:30,d:"July 21, 2011 00:01"}]; @@ -336,7 +336,7 @@ SonarWidgets.Timeline.prototype.render = function() { .interpolate(function() {return interpolate;}) .lineWidth(2); - /* The mouseover dots and label in footer. */ + /* The mouseover dots and label in header. */ line.add(pv.Dot) .data(function(d) {return [d[idx]];}) .fillStyle(function() {return line.strokeStyle();}) @@ -349,7 +349,7 @@ SonarWidgets.Timeline.prototype.render = function() { .top(function() {return 10 + this.parent.index * 14;}) .anchor("right").add(pv.Label) .font(headerFont) - .text(function(d) {return metrics[this.parent.index] + ": " + d.y.toFixed(2);}); + .text(function(d) {return metrics[this.parent.index] + ": " + d.yl;}); /* The date of the selected dot in the header. */ vis.add(pv.Label) -- 2.39.5