diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-12-18 10:38:02 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-12-18 10:38:22 +0100 |
commit | b8189d2d8c4cf3432db51392ff0589552105fc1c (patch) | |
tree | c1e931c174622c3313f972003bf330969a249760 | |
parent | bdab023b4702e193017ed6f3a8365efc7e779f8b (diff) | |
download | sonarqube-b8189d2d8c4cf3432db51392ff0589552105fc1c.tar.gz sonarqube-b8189d2d8c4cf3432db51392ff0589552105fc1c.zip |
Fix ability to configure height of treemaps
7 files changed, 21 insertions, 12 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterTreemapWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterTreemapWidget.java index dc0256edd4b..267b5b48573 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterTreemapWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterTreemapWidget.java @@ -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() { diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java index c1beb2258df..8ac21eaa09d 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java @@ -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() { diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb index 53c2fae8967..259ed662c38 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb @@ -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) diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/treemap.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/treemap.html.erb index 75f765a35b1..68aafa104e1 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/treemap.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/treemap.html.erb @@ -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} %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_treemap.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_treemap.rb index ea7b5ec85f9..f4d70b014d9 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_treemap.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_treemap.rb @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_treemap.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_treemap.html.erb index 1e9270036bd..91f47ceae51 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_treemap.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_treemap.html.erb @@ -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 diff --git a/sonar-server/src/main/webapp/javascripts/application.js b/sonar-server/src/main/webapp/javascripts/application.js index da287a6ef9b..2c26c8de674 100644 --- a/sonar-server/src/main/webapp/javascripts/application.js +++ b/sonar-server/src/main/webapp/javascripts/application.js @@ -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(); }; |