]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3556 Fix issue by using the metric value type for formatting
authorFabrice Bellingard <bellingard@gmail.com>
Tue, 17 Jul 2012 11:59:58 +0000 (13:59 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Tue, 17 Jul 2012 11:59:58 +0000 (13:59 +0200)
plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb

index a756e495f97962d966f114e7336d2428ce3a9898..17b0543a2e560a8565839644ff8781bf1c2019b2 100644 (file)
@@ -1,7 +1,7 @@
 <%
    # Retrieve widget settings
    metric_data_map = {}
-   metric_name_map = {}
+   metric_map = {}
    metrics_specified = false
    (1..3).each do |index|
      metric=widget_properties["metric#{index}"]
@@ -11,7 +11,7 @@
        metrics_specified = true
        if measure(metric)
          metric_data_map[metric.id] = []
-         metric_name_map[metric.id] = metric.short_name
+         metric_map[metric.id] = metric
        end
      end
    end
@@ -19,7 +19,7 @@
      # No metric has been selected, it's the first time the widget is displayed: 'ncloc' is the default metric
      ncloc = Metric.by_name('ncloc')
      metric_data_map[ncloc.id] = []
-     metric_name_map[ncloc.id] = message('metric.ncloc.name')
+     metric_map[ncloc.id] = ncloc
    end
    chartHeight = widget_properties["chartHeight"]
 
      js_data = "["
      js_snapshots = "["
      js_metrics = "["
-     total_number_of_metrics = metric_name_map.keys.size()
+     total_number_of_metrics = metric_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_metrics += "\"" + metric_map[metric_id].short_name + "\","
          js_data += "["
          metric_data_map[metric_id].each() do |metric_data|
            # 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)
@@ -57,7 +57,7 @@
              # 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_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 => 1).to_s
+             m_value_localized = ProjectMeasure.new (:metric => metric_map[metric_id]).format_numeric_value(metric_data[:value], {})
              js_data += "{x:d("
              js_data += m_date.year.to_s
              js_data += ","