]> source.dussan.org Git - sonarqube.git/commitdiff
Fix ability to configure height of treemaps
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 18 Dec 2012 09:38:02 +0000 (10:38 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 18 Dec 2012 09:38:22 +0000 (10:38 +0100)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterTreemapWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java
plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb
plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/treemap.html.erb
sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_treemap.rb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_treemap.html.erb
sonar-server/src/main/webapp/javascripts/application.js

index dc0256edd4b9cb18e43d040ae5d42c6fedfdf2ce..267b5b48573a8ce361a873047c63dbaf68379ab3 100644 (file)
@@ -32,12 +32,14 @@ import static org.sonar.api.web.WidgetScope.GLOBAL;
 @WidgetProperties({
   @WidgetProperty(key = MeasureFilterTreemapWidget.FILTER_PROPERTY, type = WidgetPropertyType.FILTER, optional = false),
   @WidgetProperty(key = MeasureFilterTreemapWidget.SIZE_METRIC_PROPERTY, type = WidgetPropertyType.METRIC, optional = true),
-  @WidgetProperty(key = MeasureFilterTreemapWidget.COLOR_METRIC_PROPERTY, type = WidgetPropertyType.METRIC, optional = true, options = "type:PERCENT")
+  @WidgetProperty(key = MeasureFilterTreemapWidget.COLOR_METRIC_PROPERTY, type = WidgetPropertyType.METRIC, optional = true, options = "type:PERCENT"),
+  @WidgetProperty(key = MeasureFilterTreemapWidget.HEIGHT_PERCENTS_PROPERTY, type = WidgetPropertyType.INTEGER, optional = true, defaultValue = "55", description = "Height in percents of width")
 })
 public class MeasureFilterTreemapWidget extends CoreWidget {
   public static final String FILTER_PROPERTY = "filter";
   public static final String SIZE_METRIC_PROPERTY = "sizeMetric";
   public static final String COLOR_METRIC_PROPERTY = "colorMetric";
+  public static final String HEIGHT_PERCENTS_PROPERTY = "heightInPercents";
   public static final String ID = "measure_filter_treemap";
 
   public MeasureFilterTreemapWidget() {
index c1beb2258df30b5c297ad47d2d5fd2edd8134f47..8ac21eaa09d676edac0102dd79bdd9e8180464f4 100644 (file)
@@ -25,8 +25,9 @@ import org.sonar.api.web.WidgetProperty;
 import org.sonar.api.web.WidgetPropertyType;
 
 @WidgetProperties({
-  @WidgetProperty(key = "sizeMetric", type = WidgetPropertyType.METRIC, defaultValue = CoreMetrics.NCLOC_KEY, description = "Default metric for size"),
-  @WidgetProperty(key = "colorMetric", type = WidgetPropertyType.METRIC, defaultValue = CoreMetrics.VIOLATIONS_DENSITY_KEY, description = "Default metric for color")
+  @WidgetProperty(key = "sizeMetric", type = WidgetPropertyType.METRIC, defaultValue = CoreMetrics.NCLOC_KEY, description = "Metric used for square size"),
+  @WidgetProperty(key = "colorMetric", type = WidgetPropertyType.METRIC, defaultValue = CoreMetrics.VIOLATIONS_DENSITY_KEY, description = "Metric used for square color"),
+  @WidgetProperty(key = "heightInPercents", type = WidgetPropertyType.INTEGER, optional = true, defaultValue = "55", description = "Height in percents of width")
 })
 public class TreemapWidget extends CoreWidget {
   public TreemapWidget() {
index 53c2fae8967fabe6c9d3ee60217440392c5fee19..259ed662c38674343cec081e2d5dc6214bedff3d 100644 (file)
@@ -15,6 +15,8 @@
        filter.set_criteria_value(:tmColor, color_metric.key)
        url_options[:tmColor]=color_metric.key
      end
+     filter.set_criteria_value(:tmHeight, widget_properties['heightInPercents'])
+
 
      if !filter.require_authentication? || logged_in?
        filter.execute(self, :user => current_user)
index 75f765a35b1050026d7415a69e920adaf96e90eb..68aafa104e1551f35b8687ff364547f64fad0d86 100644 (file)
@@ -3,10 +3,11 @@
    color_metric = widget_properties['colorMetric']
 
    filter = MeasureFilter.new
-   filter.set_criteria_value('baseId', @resource.id)
-   filter.set_criteria_value('display', 'treemap')
-   filter.set_criteria_value('tmSize', size_metric.key) if size_metric
-   filter.set_criteria_value('tmColor', color_metric.key) if color_metric
+   filter.set_criteria_value(:baseId, @resource.id)
+   filter.set_criteria_value(:display, 'treemap')
+   filter.set_criteria_value(:tmSize, size_metric.key) if size_metric
+   filter.set_criteria_value(:tmColor, color_metric.key) if color_metric
+   filter.set_criteria_value(:tmHeight, widget_properties['heightInPercents'])
    filter.execute(self, :user => current_user)
 %>
 <%= render :partial => "measures/display_treemap", :locals => {:edit_mode => false, :widget => widget, :filter => filter} %>
index ea7b5ec85f9c1d52ae74b037b70f31d50d7caf9d..f4d70b014d9c3459a25c8de2ccfb7b8fc359d1f7 100644 (file)
@@ -24,13 +24,16 @@ class MeasureFilterDisplayTreemap < MeasureFilterDisplay
   KEY = :treemap
   PROPERTY_KEYS = Set.new([:tmSize, :tmColor])
   MAX_RESULTS = 1000
-  attr_reader :id, :size, :size_metric, :color_metric
+  DEFAULT_HEIGHT_PERCENTS = 55
+  attr_reader :id, :size, :size_metric, :color_metric, :height_percents
 
   def initialize(filter, options)
     super(filter, options)
 
     @size_metric = Metric.by_key(@filter.criteria(:tmSize)||'ncloc')
     @color_metric = Metric.by_key(@filter.criteria(:tmColor)||'violations_density')
+    @height_percents = (@filter.criteria(:tmHeight) || DEFAULT_HEIGHT_PERCENTS).to_i
+    @height_percents = DEFAULT_HEIGHT_PERCENTS if @height_percents<=0
     @filter.metrics=([@size_metric, @color_metric].compact)
     @id_count = 0
 
index 1e9270036bdf525e45a310d7092e102d545b472f..91f47ceae5149106a30be9d51d6de506c3a7ec24 100644 (file)
@@ -48,7 +48,7 @@
       <td class="right" valign="bottom">
         <a href="#" class="button" id="exit-edit"><%= message 'close' -%></a>
         <% if filter.owner?(current_user) %>
-          <a id="save-columns" href="<%= url_for params.merge({:action => 'save_form', :id => filter.id}) -%>" class="button open-modal"><%= message('save_and_close') -%></a>
+          <a id="save-columns" href="<%= url_for params.merge({:action => 'save_form', :id => filter.id}) -%>" class="button open-modal"><%= message('measure_filter.close_and_save') -%></a>
         <% end %>
       </td>
     </tr>
@@ -92,7 +92,7 @@
   </div>
 
   <script>
-    new Treemap(<%= treemap_id -%>, '<%= filter.display.size_metric.key  -%>', '<%= filter.display.color_metric ? filter.display.color_metric.key : '' -%>');
+    new Treemap(<%= treemap_id -%>, '<%= filter.display.size_metric.key  -%>', '<%= filter.display.color_metric ? filter.display.color_metric.key : '' -%>', <%= filter.display.height_percents -%>);
   </script>
 
 <% end %>
\ No newline at end of file
index da287a6ef9b75a59263e7e387d0b79e59470f255..2c26c8de67465793e3e2059613d9577bc5a87357 100644 (file)
@@ -166,13 +166,13 @@ var TreemapContext = function (rid, label) {
  * tm-bc-#{id} : required breadcrumb
  * tm-loading-#{id} : optional loading icon
  */
-var Treemap = function (id, sizeMetric, colorMetric) {
+var Treemap = function (id, sizeMetric, colorMetric, heightPercents) {
   this.id = id;
   this.sizeMetric = sizeMetric;
   this.colorMetric = colorMetric;
   this.breadcrumb = [];
   treemaps[id] = this;
-  this.rootNode().height(this.rootNode().width() * 0.55);
+  this.rootNode().height(this.rootNode().width() * heightPercents / 100);
   this.initNodes();
 
 };