From: Stas Vilchik Date: Mon, 7 Apr 2014 06:52:45 +0000 (+0600) Subject: SONAR-3113 Word Cloud Chart X-Git-Tag: 4.3~123 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c93815f0193ebccc8150fb47cdccd878ae572e36;p=sonarqube.git SONAR-3113 Word Cloud Chart --- diff --git a/sonar-server/Gruntfile.coffee b/sonar-server/Gruntfile.coffee index b23d262ef18..ffcc8519dc5 100644 --- a/sonar-server/Gruntfile.coffee +++ b/sonar-server/Gruntfile.coffee @@ -71,6 +71,7 @@ module.exports = (grunt) -> '<%= pkg.assets %>js/widgets/stack-area.js' '<%= pkg.assets %>js/widgets/pie-chart.js' '<%= pkg.assets %>js/widgets/histogram.js' + '<%= pkg.assets %>js/widgets/word-cloud.js' '<%= pkg.assets %>js/top-search.js' '<%= pkg.assets %>js/sortable.js' '<%= pkg.assets %>js/common/inputs.js' @@ -103,6 +104,7 @@ module.exports = (grunt) -> '<%= pkg.assets %>js/widgets/stack-area.js' '<%= pkg.assets %>js/widgets/pie-chart.js' '<%= pkg.assets %>js/widgets/histogram.js' + '<%= pkg.assets %>js/widgets/word-cloud.js' '<%= pkg.assets %>js/top-search.js' '<%= pkg.assets %>js/sortable.js' '<%= pkg.assets %>js/common/inputs.js' @@ -214,7 +216,7 @@ module.exports = (grunt) -> coffee: files: '<%= pkg.sources %>coffee/**/*.coffee' - tasks: ['coffee:build'] + tasks: ['coffee:build', 'copy:js', 'concat:dev'] js: files: '<%= pkg.sources %>js/**/*.js' diff --git a/sonar-server/src/main/coffee/widgets/word-cloud.coffee b/sonar-server/src/main/coffee/widgets/word-cloud.coffee new file mode 100644 index 00000000000..8a942a1440a --- /dev/null +++ b/sonar-server/src/main/coffee/widgets/word-cloud.coffee @@ -0,0 +1,77 @@ +# Some helper functions + +# Gets or sets parameter +param = (name, value) -> + unless value? + return this[name] + else + this[name] = value + return @ + + +window.SonarWidgets ?= {} + +window.SonarWidgets.WordCloud = -> + @_components = [] + @_metrics = [] + @_metricsPriority = [] + @_width = window.SonarWidgets.WordCloud.defaults.width + @_height = window.SonarWidgets.WordCloud.defaults.height + @_margin = window.SonarWidgets.WordCloud.defaults.margin + @_legendWidth = window.SonarWidgets.WordCloud.defaults.legendWidth + @_legendMargin = window.SonarWidgets.WordCloud.defaults.legendMargin + @_detailsWidth = window.SonarWidgets.WordCloud.defaults.detailsWidth + @_options = {} + + @_lineHeight = 20 + + # Export global variables + @metrics = (_) -> param.call(this, '_metrics', _) + @metricsPriority = (_) -> param.call(this, '_metricsPriority', _) + @components = (_) -> param.call(this, '_components', _) + @width = (_) -> param.call(this, '_width', _) + @height = (_) -> param.call(this, '_height', _) + @margin = (_) -> param.call(this, '_margin', _) + @legendWidth = (_) -> param.call(this, '_legendWidth', _) + @legendMargin = (_) -> param.call(this, '_legendMargin', _) + @detailsWidth = (_) -> param.call(this, '_detailsWidth', _) + @options = (_) -> param.call(this, '_options', _) + @ + + +window.SonarWidgets.WordCloud.prototype.render = (container) -> + @box = d3.select(container).append('div').classed 'sonar-d3', true + + # Configure metrics + @colorMetric = @metricsPriority()[0] + @getColorMetric = (d) => d.measures[@colorMetric].val + @sizeMetric = @metricsPriority()[1] + @getSizeMetric = (d) => d.measures[@sizeMetric].val + + # Configure scales + @color = d3.scale.linear().domain([0, 100]).range(['#d62728', '#1f77b4']) + sizeDomain = d3.extent @components(), (d) => @getSizeMetric d + @size = d3.scale.linear().domain(sizeDomain).range([10, 24]) + + @update container + @ + + +window.SonarWidgets.WordCloud.prototype.update = -> + # Configure words + @words = @box.selectAll('a').data @components() + @words.enter().append('a').classed('cloud-word', true).text (d) -> d.name + @words.style 'color', (d) => @color @getColorMetric d + @words.style 'font-size', (d) => "#{@size @getSizeMetric d}px" + @words.exit().remove() + + + + + +window.SonarWidgets.WordCloud.defaults = + width: 350 + height: 300 + margin: { top: 10, right: 10, bottom: 10, left: 10 } + legendWidth: 160 + legendMargin: 30 \ No newline at end of file diff --git a/sonar-server/src/main/less/style.less b/sonar-server/src/main/less/style.less index 637166dadf8..9e50e752215 100644 --- a/sonar-server/src/main/less/style.less +++ b/sonar-server/src/main/less/style.less @@ -2751,6 +2751,13 @@ div.rule-title { transition: all 0.3s ease; } +.sonar-d3 .cloud-word { + display: inline-block; + vertical-align: baseline; + white-space: nowrap; + margin-right: 14px; +} + /* ------------------- Admin pages ------------------- */ .admin-page-title {