From d163695d58b77e1fca590725520dfb57862548ca Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Fri, 26 Aug 2011 18:06:54 +0200 Subject: SONAR-2074 Improve timeline widget - Default height set to 80 pixels - Events are displayed by default - Space added between measures in the footer - Adapt left margin to be able to display the max number on the Y axis - Chart displayed even if no values for a selected metric --- .../sonar/plugins/core/widgets/TimelineWidget.java | 2 +- .../sonar/plugins/core/widgets/timeline.html.erb | 48 +++++++++++----------- 2 files changed, 26 insertions(+), 24 deletions(-) (limited to 'plugins') diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimelineWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimelineWidget.java index 7483f0018cc..bceb37b2a0c 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimelineWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimelineWidget.java @@ -31,7 +31,7 @@ import org.sonar.api.web.WidgetPropertyType; @WidgetProperty(key = "metric1", type = WidgetPropertyType.METRIC, defaultValue = "ncloc"), @WidgetProperty(key = "metric2", type = WidgetPropertyType.METRIC), @WidgetProperty(key = "metric3", type = WidgetPropertyType.METRIC), - @WidgetProperty(key = "displayEvents", type = WidgetPropertyType.BOOLEAN), + @WidgetProperty(key = "hideEvents", type = WidgetPropertyType.BOOLEAN), @WidgetProperty(key = "chartHeight", type = WidgetPropertyType.INTEGER) } ) 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 806d77f7a7c..88c1d07cdb5 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 @@ -33,37 +33,39 @@ js_snapshots = "[" js_metrics = "[" metric_data_map.keys.each_with_index() do |metric_id, index| - 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 += "),\"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] - js_snapshots += ",\"d\":\"" - js_snapshots += human_short_date(m_date) - js_snapshots += "\"}," + 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 += "),\"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] + js_snapshots += ",\"d\":\"" + js_snapshots += human_short_date(m_date) + js_snapshots += "\"}," + end end + js_data += "]," end - js_data += "]," end js_data += "]" js_snapshots += "]" js_metrics += "]" # Prepare also event structure if required - if widget_properties["displayEvents"] + unless widget_properties["hideEvents"] events = {} Event.find(:all, :conditions => {:resource_id => @resource.id}, :order => 'event_date').each() do |event| if events[event.event_date] -- cgit v1.2.3