'<%= pkg.assets %>js/widgets/pie-chart.js'
'<%= pkg.assets %>js/widgets/histogram.js'
'<%= pkg.assets %>js/widgets/word-cloud.js'
+ '<%= pkg.assets %>js/widgets/tag-cloud.js'
'<%= pkg.assets %>js/widgets/treemap.js'
'<%= pkg.assets %>js/graphics/pie-chart.js'
'<%= pkg.assets %>js/top-search.js'
'<%= pkg.assets %>js/widgets/pie-chart.js'
'<%= pkg.assets %>js/widgets/histogram.js'
'<%= pkg.assets %>js/widgets/word-cloud.js'
+ '<%= pkg.assets %>js/widgets/tag-cloud.js'
'<%= pkg.assets %>js/widgets/treemap.js'
'<%= pkg.assets %>js/graphics/pie-chart.js'
'<%= pkg.assets %>js/top-search.js'
tooltip: (d) ->
title = d.longName
- title += "\n#{@colorMetric.name}: #{@colorMetric.formattedValue d}" if @colorMetric.value(d)?
- title += "\n#{@sizeMetric.name}: #{@sizeMetric.formattedValue d}" if @sizeMetric.value(d)?
+ title += "\n#{@colorMetric.name}: #{@colorMetric.formattedValue d}" if @colorMetric and @colorMetric.value(d)?
+ title += "\n#{@sizeMetric.name}: #{@sizeMetric.formattedValue d}" if @sizeMetric and @sizeMetric.value(d)?
title
--- /dev/null
+class TagCloud extends window.SonarWidgets.BaseWidget
+ sizeLow: 10
+ sizeHigh: 24
+
+
+ constructor: ->
+ @addField 'width', []
+ @addField 'height', []
+ @addField 'tags', []
+ @addField 'maxResultsReached', false
+ super
+
+
+ renderWords: ->
+ words = @wordContainer.selectAll('.cloud-word').data @tags()
+
+ wordsEnter = words.enter().append('a').classed 'cloud-word', true
+ wordsEnter.text (d) -> d.key
+ wordsEnter.attr 'href', (d) =>
+ url = @options().baseUrl + '|tags=' + d.key
+ url
+ wordsEnter.attr 'title', (d) => @tooltip d
+
+ words.style 'font-size', (d) =>
+ "#{@size d.value}px"
+
+ words.sort (a, b) =>
+ if a.key.toLowerCase() > b.key.toLowerCase() then 1 else -1
+
+
+ render: (container) ->
+ box = d3.select(container).append('div')
+ box.classed 'sonar-d3', true
+ box.classed 'cloud-widget', true
+ @wordContainer = box.append 'div'
+
+ sizeDomain = d3.extent @tags(), (d) => d.value
+ @size = d3.scale.linear().domain(sizeDomain).range [@sizeLow, @sizeHigh]
+
+ # Show maxResultsReached message
+ if @maxResultsReached()
+ maxResultsReachedLabel = box.append('div').text @options().maxItemsReachedMessage
+ maxResultsReachedLabel.classed 'max-results-reached-message', true
+
+ @renderWords()
+
+ super
+
+
+ parseSource: (response) ->
+ @tags(response.tags)
+
+
+window.SonarWidgets.TagCloud = TagCloud
d3.json(this.source(), function(error, response) {
if (response && !error) {
that.hideSpinner();
- if (response.components.length > 0) {
+ if (typeof(response.components) === 'undefined' || response.components.length > 0) {
that.widget = new SonarWidgets[that.type()]();
- that.widget
- .metrics(response.metrics)
- .metricsPriority(that.metricsPriority())
- .components(response.components)
- .options(that.options());
+ that.widget.metricsPriority(that.metricsPriority());
+ that.widget.options(that.options())
+ that.widget.metrics(response.metrics);
+ that.widget.components(response.components);
+ if(typeof(that.widget.parseSource) === 'function') {
+ that.widget.parseSource(response);
+ }
if (typeof that.widget.maxResultsReached === 'function') {
- that.widget.maxResultsReached(response.paging.pages > 1);
+ that.widget.maxResultsReached(response.paging != null && response.paging.pages > 1);
}
if (that.height()) {
that.widget.height(that.height());