From 2f325440c87dfb8a5abc327d563c8b0d70e641d8 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Mon, 19 Sep 2011 17:52:06 +0200 Subject: [PATCH] SONAR-2074 Fix bug on Timeline widget when metric values are missing Indeed, Protovis can't display multiple arrays if they have disjoined X-axis value sets. --- .../plugins/core/widgets/timeline.html.erb | 59 +++++++++++-------- 1 file changed, 35 insertions(+), 24 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 253db4ade60..8926d741323 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 @@ -23,7 +23,14 @@ if from_date options[:from] = from_date end + metric_count_per_snapshot_id = {} TrendsChart.time_machine_measures(@resource, metric_data_map.keys, options).each() do |trend_item| + sid = trend_item["sid"] + if metric_count_per_snapshot_id[sid] + metric_count_per_snapshot_id[sid] += 1 + else + metric_count_per_snapshot_id[sid] = 1 + end metric_data_map[trend_item["metric_id"].to_i] << {:date => trend_item["created_at"], :value => trend_item["value"], :sid => trend_item["sid"]} end @@ -31,35 +38,39 @@ js_data = "[" js_snapshots = "[" js_metrics = "[" + total_number_of_metrics = metric_name_map.keys.size() metric_data_map.keys.each_with_index() do |metric_id, index| unless metric_data_map[metric_id].empty? js_metrics += "\"" + metric_name_map[metric_id] + "\"," js_data += "[" metric_data_map[metric_id].each() do |metric_data| - m_date = Time.parse(metric_data[:date]) - js_data += "{x:d(" - js_data += m_date.year.to_s - js_data += "," - # Need to decrease by 1 the month as the JS Date object start months at 0 (= January) - js_data += (m_date.month - 1).to_s - js_data += "," - js_data += m_date.day.to_s - js_data += "," - js_data += m_date.hour.to_s - js_data += "," - js_data += m_date.min.to_s - js_data += "," - js_data += m_date.sec.to_s - js_data += "),y:" - js_data += sprintf( "%0.02f", metric_data[:value]) - js_data += "}," - if index == 0 - # we fill the js_snapshots array (no need to do this more than once) - js_snapshots += "{sid:" - js_snapshots += metric_data[:sid].to_s - js_snapshots += ",d:\"" - js_snapshots += l m_date, :format => :long - js_snapshots += "\"}," + # for every metric value, we need to check that the corresponding snapshot has values for each metric (if not, Protovis won't be able to display) + if metric_count_per_snapshot_id[metric_data[:sid]]==total_number_of_metrics + m_date = Time.parse(metric_data[:date]) + js_data += "{x:d(" + js_data += m_date.year.to_s + js_data += "," + # Need to decrease by 1 the month as the JS Date object start months at 0 (= January) + js_data += (m_date.month - 1).to_s + js_data += "," + js_data += m_date.day.to_s + js_data += "," + js_data += m_date.hour.to_s + js_data += "," + js_data += m_date.min.to_s + js_data += "," + js_data += m_date.sec.to_s + js_data += "),y:" + js_data += sprintf( "%0.02f", metric_data[:value]) + js_data += "}," + if index == 0 + # we fill the js_snapshots array (no need to do this more than once) + js_snapshots += "{sid:" + js_snapshots += metric_data[:sid].to_s + js_snapshots += ",d:\"" + js_snapshots += human_short_date m_date + js_snapshots += "\"}," + end end end js_data = js_data.chomp(',') + "]," -- 2.39.5