aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2014-07-08 23:02:40 +0600
committerStas Vilchik <vilchiks@gmail.com>2014-07-08 23:02:56 +0600
commit70edcaa052727c5fb844e391d894b2f1202fe0ad (patch)
tree6643c6aee910470556af01ee03b2b81b58edfa5c /plugins
parent79ab08f123b13eb52c1f2c6ab828a2586ac8aaa3 (diff)
downloadsonarqube-70edcaa052727c5fb844e391d894b2f1202fe0ad.tar.gz
sonarqube-70edcaa052727c5fb844e391d894b2f1202fe0ad.zip
SONAR-5207 Dynamic size of labels. Show labels in two lines. l10n messages.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java6
-rw-r--r--plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/treemap.html.erb90
2 files changed, 83 insertions, 13 deletions
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 6ce87b3be75..e0787c4c5a8 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
@@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+
package org.sonar.plugins.core.widgets;
import org.sonar.api.measures.CoreMetrics;
@@ -25,14 +26,15 @@ import org.sonar.api.web.WidgetProperty;
import org.sonar.api.web.WidgetPropertyType;
@WidgetProperties({
+ @WidgetProperty(key = "chartTitle", type = WidgetPropertyType.STRING),
@WidgetProperty(key = "sizeMetric", type = WidgetPropertyType.METRIC, defaultValue = CoreMetrics.NCLOC_KEY, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
@WidgetProperty(key = "colorMetric", type = WidgetPropertyType.METRIC, defaultValue = CoreMetrics.COVERAGE_KEY,
options = {WidgetConstants.FILTER_OUT_NEW_METRICS, "type:PERCENT,RATING,LEVEL"}),
- @WidgetProperty(key = "heightInPercents", type = WidgetPropertyType.INTEGER, optional = true, defaultValue = "55")
+ @WidgetProperty(key = "heightInPercents", type = WidgetPropertyType.INTEGER, optional = true, defaultValue = "55"),
+ @WidgetProperty(key = "maxItems", type = WidgetPropertyType.INTEGER, defaultValue = "100")
})
public class TreemapWidget extends CoreWidget {
public TreemapWidget() {
- // do not use the id "treemap" to avoid conflict with the same CSS class
super("treemap-widget", "Treemap of Components", "/org/sonar/plugins/core/widgets/treemap.html.erb");
}
}
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 2dccace2b6f..55c2c87796a 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
@@ -1,13 +1,81 @@
<%
- size_metric = widget_properties['sizeMetric']
- color_metric = widget_properties['colorMetric']
-
- filter = MeasureFilter.new
- filter.set_criteria_value(:base, @resource.key)
- 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)
+ containerId = 'project-file-widget' + widget.id.to_s
+ colorMetric = widget_properties['colorMetric']
+ sizeMetric = widget_properties['sizeMetric']
+ chartTitle = widget_properties['chartTitle']
+ maxItems = widget_properties['maxItems'].to_i
%>
-<%= render :partial => "measures/display_treemap", :locals => {:edit_mode => false, :widget_id => widget.id, :filter => filter} %>
+
+<div class="treemap-widget" id="<%= containerId %>">
+ <!--[if lte IE 8 ]> <h3><%= message('widget.unsupported_browser_warning') -%></h3> <![endif]-->
+
+ <!--[if (gte IE 9)|!(IE)]><!-->
+ <% if chartTitle %>
+ <h3 style="margin-bottom: 5px;"><%= h(chartTitle) -%></h3>
+ <% end %>
+ <!--<![endif]-->
+</div>
+
+<!--[if (gte IE 9)|!(IE)]><!-->
+<script>
+ (function () {
+ <%
+ filter = MeasureFilter.new
+ filter.set_criteria_value(:base, @resource.key)
+ filter.set_criteria_value(:display, 'treemap')
+ filter.set_criteria_value(:tmSize, sizeMetric.key) if sizeMetric
+ filter.set_criteria_value(:tmColor, colorMetric.key) if colorMetric
+ filter.set_criteria_value(:tmHeight, widget_properties['heightInPercents'])
+ filter.execute(self, :user => current_user)
+ %>
+
+ var data = {
+ metrics: {
+ <%= colorMetric.name -%>: {
+ name: '<%= colorMetric.short_name -%>',
+ direction: <%= colorMetric.direction -%>
+ },
+ <%= 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 : "null" -%>, fval: '<%= color ? color.formatted_value : "-" -%>' },
+ <%= sizeMetric.name -%>: { val: <%= size ? size.value : "null" -%>, fval: '<%= size ? size.formatted_value : "-" -%>' }
+ }
+ },
+ <% end %>
+ ]
+ },
+ widget = new SonarWidgets.Treemap();
+
+ widget
+ .metrics(data.metrics)
+ .metricsPriority(['<%= colorMetric.name -%>', '<%= sizeMetric.name -%>'])
+ .components(data.components)
+ .options({
+ heightInPercents: '<%= widget_properties['heightInPercents'] -%>',
+ maxItems: <%= maxItems -%>,
+ maxItemsReachedMessage: '<%= message("widget.measure_filter_histogram.max_items_reached", :params => [maxItems]) -%>',
+ baseUrl: baseUrl + '/dashboard/index/',
+ noData: '<%= message('no_data') -%>'
+ })
+ .render('#<%= containerId -%>');
+
+ autoResize(500, function() {
+ widget.update('#<%= containerId -%>');
+ });
+ })();
+</script>
+<!--<![endif]-->