diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2014-04-09 12:24:29 +0600 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2014-04-09 12:24:29 +0600 |
commit | 4294f6606c2303dd06f3a79f169e39da6d88236b (patch) | |
tree | 4a4c7ac697fcee8d4a9c8182e4e4b7c7963d7efb | |
parent | cf3c13a41eb8135422b6b9c8d3541b7bec2d6857 (diff) | |
download | sonarqube-4294f6606c2303dd06f3a79f169e39da6d88236b.tar.gz sonarqube-4294f6606c2303dd06f3a79f169e39da6d88236b.zip |
SONAR-3113 Project Level Cloud Chart
4 files changed, 79 insertions, 10 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ProjectFileCloudWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ProjectFileCloudWidget.java index 3af7c9b380a..5a36eb4d5b9 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ProjectFileCloudWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ProjectFileCloudWidget.java @@ -27,7 +27,6 @@ import org.sonar.api.web.WidgetPropertyType; @WidgetProperties({ @WidgetProperty(key = "chartTitle", type = WidgetPropertyType.STRING), - @WidgetProperty(key = "filter", type = WidgetPropertyType.FILTER, optional = false), @WidgetProperty(key = "colorMetric", type = WidgetPropertyType.METRIC, defaultValue = CoreMetrics.COVERAGE_KEY, options = "type:PERCENT"), @WidgetProperty(key = "sizeMetric", type = WidgetPropertyType.METRIC, defaultValue = CoreMetrics.COMPLEXITY_KEY, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}), @WidgetProperty(key = "maxItems", type = WidgetPropertyType.INTEGER, defaultValue = "100"), diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measures/measure_filter_cloud.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measures/measure_filter_cloud.html.erb index 4e8a9440fc0..da50f56ff13 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measures/measure_filter_cloud.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measures/measure_filter_cloud.html.erb @@ -29,10 +29,10 @@ query = [ 'filter=<%= filterId -%>', 'metrics=' + metrics.join(','), - 'fields=name,qualifier', + 'fields=name,longName,qualifier', 'pageSize=<%= maxItems -%>', 'page=1', - 'sort=metric:' + metrics[0], + 'sort=metric:' + metrics[1], 'asc=false' ].join('&'), widget = new SonarWidgets.Widget(); diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/project_file_cloud.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/project_file_cloud.html.erb index 01379bfd9ae..68c152a6f51 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/project_file_cloud.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/project_file_cloud.html.erb @@ -1,15 +1,13 @@ <% containerId = 'project-file-widget' + widget.id.to_s + colorMetric = widget_properties['colorMetric'] + sizeMetric = widget_properties['sizeMetric'] chartTitle = widget_properties['chartTitle'] - filterId = widget_properties['filter'].to_i maxItems = widget_properties['maxItems'].to_i reverseColor = widget_properties['reverseColor'] - - filter = MeasureFilter.find_by_id(filterId.to_i) - @widget_title = link_to h(filter.name), {:controller => 'measures', :action => 'filter', :id => filter.id, :display => 'list'} %> -<div class="histogram-widget" id="<%= containerId %>"> +<div class="word-cloud-widget" id="<%= containerId %>"> <!--[if lte IE 8 ]> <h3><%= message('widget.unsupported_browser_warning') -%></h3> <![endif]--> <!--[if (gte IE 9)|!(IE)]><!--> @@ -18,3 +16,62 @@ <% end %> <!--<![endif]--> </div> + +<!--[if (gte IE 9)|!(IE)]><!--> +<script> + (function () { + <% + filter = MeasureFilter.new + # Test files should not be returned + qualifiers = Api::Utils.java_facade.getResourceLeavesQualifiers(@project.qualifier).to_a.reject {|q| q == 'UTS'} + filter.criteria = {:qualifiers => qualifiers, :base => @project.key, :pageSize => maxItems, :sort => 'metric:' + sizeMetric.name, :asc => false} + filter.metrics = [colorMetric.name, sizeMetric.name] + filter.execute(self, :user => current_user) + %> + + var data = { + metrics: { + <%= colorMetric.name -%>: { + name: '<%= colorMetric.short_name -%>' + }, + <%= sizeMetric.name -%>: { + name: '<%= sizeMetric.short_name -%>' + } + }, + components: [ + <% + filter.rows.each do |row| + color = row.measure(colorMetric) + size = row.measure(sizeMetric) + %> + { + key: '<%= escape_javascript row.resource.key -%>', + name: '<%= escape_javascript row.resource.name -%>', + longName: '<%= escape_javascript row.resource.long_name -%>', + qualifier: '<%= escape_javascript row.resource.qualifier -%>', + measures: { + <%= colorMetric.name -%>: { val: <%= color ? color.value : 0 -%>, fval: '<%= color ? color.formatted_value : "-" -%>' }, + <%= sizeMetric.name -%>: { val: <%= size ? size.value : 0 -%>, fval: '<%= size ? size.formatted_value : "-" -%>' } + } + }, + <% end %> + ] + }, + widget = new SonarWidgets.WordCloud(); + + widget + .metrics(data.metrics) + .metricsPriority(['<%= colorMetric.name -%>', '<%= sizeMetric.name -%>']) + .components(data.components) + .options({ + baseUrl: baseUrl + '/dashboard/index/', + reverseColor: <%= reverseColor -%> + }) + .render('#<%= containerId -%>'); + + autoResize(500, function() { + widget.update('#<%= containerId -%>'); + }); + })(); +</script> +<!--<![endif]--> diff --git a/sonar-server/src/main/coffee/widgets/word-cloud.coffee b/sonar-server/src/main/coffee/widgets/word-cloud.coffee index 39560337ca7..21ecefb2ff2 100644 --- a/sonar-server/src/main/coffee/widgets/word-cloud.coffee +++ b/sonar-server/src/main/coffee/widgets/word-cloud.coffee @@ -41,12 +41,15 @@ window.SonarWidgets.WordCloud = -> window.SonarWidgets.WordCloud.prototype.render = (container) -> @box = d3.select(container).append('div').classed 'sonar-d3', true + @box.style 'text-align', 'center' # Configure metrics @colorMetric = @metricsPriority()[0] - @getColorMetric = (d) => d.measures[@colorMetric].val + @getColorMetric = (d) => d.measures[@colorMetric]?.val + @getFColorMetric = (d) => d.measures[@colorMetric]?.fval @sizeMetric = @metricsPriority()[1] - @getSizeMetric = (d) => d.measures[@sizeMetric].val + @getSizeMetric = (d) => d.measures[@sizeMetric]?.val + @getFSizeMetric = (d) => d.measures[@sizeMetric]?.fval # Configure scales @color = d3.scale.linear().domain([0, 100]) @@ -72,10 +75,20 @@ window.SonarWidgets.WordCloud.prototype.update = -> url = @options().baseUrl + encodeURIComponent(d.key) url += '?metric=' + encodeURIComponent(@colorMetric) if d.qualifier == 'CLA' || d.qualifier == 'FIL' url + wordsEnter.attr 'title', (d) => + title = d.longName + title += " | #{@metrics()[@colorMetric].name}: #{@getFColorMetric d}" if @getFColorMetric d + title += " | #{@metrics()[@sizeMetric].name}: #{@getFSizeMetric d}" if @getFSizeMetric d + title @words.style 'color', (d) => @color @getColorMetric d @words.style 'font-size', (d) => "#{@size @getSizeMetric d}px" + @words.sort (a, b) => + if a.name.toLowerCase() > b.name.toLowerCase() then 1 else -1 + + console.log @words + @words.exit().remove() |