]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3825 support cloud rendering
authorSimon Brandhof <simon.brandhof@gmail.com>
Sun, 25 Nov 2012 22:37:55 +0000 (23:37 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 26 Nov 2012 12:57:41 +0000 (13:57 +0100)
sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_cloud.html.erb [new file with mode: 0644]

index 8986cbf5d931ffde53d3becdcef690facd84a674..7b3f3f6ab27f7d92e60dabe33dcbeec1c2e99943 100644 (file)
@@ -73,4 +73,17 @@ module MeasuresHelper
 
     "<a href='#' class='measure-filter-star #{style}' filter-id='#{filter.id}' title='#{title}'></a>"
   end
+
+  CLOUD_MIN_SIZE_PERCENT=60.0
+  CLOUD_MAX_SIZE_PERCENT=240.0
+
+  def cloud_font_size(value, min_size_value, max_size_value)
+    divisor=max_size_value - min_size_value
+    size=CLOUD_MIN_SIZE_PERCENT
+    if divisor!=0.0
+      multiplier=(CLOUD_MAX_SIZE_PERCENT - CLOUD_MIN_SIZE_PERCENT)/divisor
+      size=CLOUD_MIN_SIZE_PERCENT + ((max_size_value - (max_size_value-(value - min_size_value)))*multiplier)
+    end
+    size.to_i
+  end
 end
index 087b92b61db0b7413308a620b1c06a5a0421590b..1312994d8e2e8bc84cfae2e55f6fc0c1eab1f40e 100644 (file)
@@ -113,6 +113,8 @@ class MeasureFilter < ActiveRecord::Base
   end
 
   class TreemapDisplay < Display
+    attr_reader :columns
+
     KEY = :treemap
 
     def initialize(filter)
@@ -122,7 +124,27 @@ class MeasureFilter < ActiveRecord::Base
     end
   end
 
-  DISPLAYS = [ListDisplay, TreemapDisplay]
+  class CloudDisplay < Display
+    attr_reader :columns
+
+    KEY = :cloud
+
+    def initialize(filter)
+      filter.set_criteria_default_value('sort', 'name')
+      filter.set_criteria_default_value('asc', 'true')
+      @metric_ids = [size_metric.id, color_metric.id]
+    end
+
+    def size_metric
+      @size_metric ||= Metric.by_key('function_complexity')
+    end
+
+    def color_metric
+      @color_metric ||= Metric.by_key('violations_density')
+    end
+  end
+
+  DISPLAYS = [ListDisplay, TreemapDisplay, CloudDisplay]
 
   SUPPORTED_CRITERIA_KEYS=Set.new([:qualifiers, :scopes, :onFavourites, :base, :onBaseComponents, :languages, :fromDate, :toDate, :beforeDays, :afterDays,
                                    :keyRegexp, :nameRegexp,
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_cloud.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_cloud.html.erb
new file mode 100644 (file)
index 0000000..517dae4
--- /dev/null
@@ -0,0 +1,35 @@
+<div>
+  <%
+     color_options={
+       :check_alert_status => false,
+       :min_color => Color::RGB.from_html("EE0000"), # red
+       :mean_color => Color::RGB.from_html("4D05B1"), # purple
+       :max_color => Color::RGB.from_html("2360BF") # blue
+     }
+     size_measure_values = @filter.results.map do |result|
+       size_measure = result.measure(@filter.display.size_metric)
+       size_measure.value if size_measure
+     end.compact
+
+     min_size_value=(size_measure_values.empty? ? 0.0 : size_measure_values.min)
+     max_size_value=(size_measure_values.empty? ? 0.0 : size_measure_values.max)
+
+     @filter.results.each do |result|
+       size_measure=result.measure(@filter.display.size_metric)
+       if size_measure && size_measure.value
+         color_measure=result.measure(@filter.display.color_metric)
+         if result.snapshot.source_code?
+          link="of(#{result.snapshot.project_id})"
+         else
+           link="ov(#{result.snapshot.project_id})"
+         end
+
+         title="#{result.snapshot.resource.long_name} | #{@filter.display.size_metric.short_name}: #{size_measure.formatted_value}"
+         if color_measure && color_measure.value
+           title += " | #{@filter.display.color_metric.short_name}: #{color_measure.formatted_value}"
+         end
+  %>
+      <a href="#" onclick="<%= link -%>" title="<%= title -%>"><span style="font-size: <%= cloud_font_size(size_measure.value, min_size_value, max_size_value) -%>%;color: <%= MeasureColor.color(color_measure, color_options).html -%>"><%= result.snapshot.resource.name %></span></a>
+    <% end
+       end %>
+</div>
\ No newline at end of file