From b525a1a435a402a47f178af93a235c83c3323c35 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Wed, 16 Sep 2015 14:19:57 +0200 Subject: [PATCH] SONAR-6687 Treemap should not show items with zero size --- .../src/main/js/libs/widgets/treemap.js | 25 ++++++++++++++++--- .../resources/org/sonar/l10n/core.properties | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/server/sonar-web/src/main/js/libs/widgets/treemap.js b/server/sonar-web/src/main/js/libs/widgets/treemap.js index 87fe0548044..a4007265382 100644 --- a/server/sonar-web/src/main/js/libs/widgets/treemap.js +++ b/server/sonar-web/src/main/js/libs/widgets/treemap.js @@ -13,6 +13,14 @@ Treemap.prototype.sizeHigh = 18; + Treemap.prototype.filterComponents = function () { + var that = this, + components = this.components().filter(function (d) { + return that.sizeMetric.value(d) != null; + }); + this.components(components); + }; + Treemap.prototype.getNodes = function () { return this.treemap .nodes({ children: this.components() }) @@ -23,6 +31,13 @@ Treemap.prototype.renderTreemap = function () { var that = this; + this.filterComponents(); + if (!this.components().length) { + this.maxResultsReachedLabel + .text(window.t('treemap.all_measures_undefined')) + .style('display', 'block'); + return; + } var nodes = this.getNodes(); this.color = that.getColorScale(); this.cells = this.box.selectAll('.treemap-cell').data(nodes); @@ -251,10 +266,12 @@ Treemap.prototype.update = function () { this.width(this.box.property('offsetWidth')); this.height(this.width() / 100.0 * this.options().heightInPercents); - this.box.style('height', (this.height()) + 'px'); - this.treemap.size([this.width(), this.height()]); - this.cells.data(this.getNodes()); - return this.positionCells(); + if (this.components().length) { + this.box.style('height', (this.height()) + 'px'); + this.treemap.size([this.width(), this.height()]); + this.cells.data(this.getNodes()); + this.positionCells(); + } }; Treemap.prototype.formatComponents = function (data) { diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 4de4f16ea38..e0b4d1bb954 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -2204,6 +2204,7 @@ provisioning.no_analysis=No analysis has been performed since creation. The only # #------------------------------------------------------------------------------ treemap.open_dashboard=Open Dashboard +treemap.all_measures_undefined=The widget cannot be displayed, because all components don't have the size measure. #------------------------------------------------------------------------------ -- 2.39.5