]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5207 Different enhancements
authorStas Vilchik <vilchiks@gmail.com>
Wed, 9 Jul 2014 11:26:55 +0000 (17:26 +0600)
committerStas Vilchik <vilchiks@gmail.com>
Wed, 9 Jul 2014 11:27:03 +0000 (17:27 +0600)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/measures/MeasureFilterAsTreemapWidget.java
sonar-core/src/main/resources/org/sonar/l10n/core.properties
sonar-server/src/main/coffee/widgets/base.coffee
sonar-server/src/main/coffee/widgets/treemap.coffee
sonar-server/src/main/less/style.less

index e0787c4c5a855900d93e3b18e6cef7695a3b7e6f..615c99758834a9f0b3cdb032ebf0b186875522c7 100644 (file)
@@ -31,7 +31,7 @@ import org.sonar.api.web.WidgetPropertyType;
   @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 = "maxItems", type = WidgetPropertyType.INTEGER, defaultValue = "100")
+  @WidgetProperty(key = "maxItems", type = WidgetPropertyType.INTEGER, defaultValue = "30")
 })
 public class TreemapWidget extends CoreWidget {
   public TreemapWidget() {
index f29aa59d99238fba29cc72cc4b1ded7084c31435..ba0c06d891aff7a2778d4a132ccbe447e9922c0e 100644 (file)
@@ -37,14 +37,14 @@ import static org.sonar.api.web.WidgetScope.GLOBAL;
     optional = false),
   @WidgetProperty(key = MeasureFilterAsTreemapWidget.CHART_TITLE_PROPERTY, type = WidgetPropertyType.STRING),
   @WidgetProperty(key = MeasureFilterAsTreemapWidget.SIZE_METRIC_PROPERTY, type = WidgetPropertyType.METRIC,
-    defaultValue = CoreMetrics.COMPLEXITY_KEY, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+    defaultValue = CoreMetrics.NCLOC_KEY, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
   @WidgetProperty(key = MeasureFilterAsTreemapWidget.COLOR_METRIC_PROPERTY, type = WidgetPropertyType.METRIC,
     defaultValue = CoreMetrics.COVERAGE_KEY,
     options = {WidgetConstants.FILTER_OUT_NEW_METRICS, "type:PERCENT,RATING,LEVEL"}),
   @WidgetProperty(key = MeasureFilterAsTreemapWidget.HEIGHT_PERCENTS_PROPERTY, type = WidgetPropertyType.INTEGER,
     optional = true, defaultValue = "55", description = "Height in percents of width"),
   @WidgetProperty(key = MeasureFilterAsTreemapWidget.MAX_ITEMS_PROPERTY, type = WidgetPropertyType.INTEGER,
-    defaultValue = "100")
+    defaultValue = "30")
 })
 public class MeasureFilterAsTreemapWidget extends CoreWidget {
   public static final String FILTER_PROPERTY = "filter";
index e01120de5d6d209c4f7b80576902aff0bffc4ae4..19d79438e44242c481da12f322478ce3f7d8c9a2 100644 (file)
@@ -1239,14 +1239,14 @@ widget.issue_filter.unknown_filter_warning=This widget is configured to display
 widget.treemap-widget.name=Treemap of Components
 widget.treemap-widget.description=Displays a treemap of all direct components of the selected resource.
 widget.treemap-widget.property.sizeMetric.name=Size Metric
-widget.treemap-widget.property.sizeMetric.description=Metric used for square size
+widget.treemap-widget.property.sizeMetric.desc=Metric used for square size
 widget.treemap-widget.property.colorMetric.name=Color Metric
-widget.treemap-widget.property.colorMetric.description=Metric used for square color
+widget.treemap-widget.property.colorMetric.desc=Metric used for square color
 widget.treemap-widget.property.heightInPercents.name=Height
-widget.treemap-widget.property.heightInPercents.description=Height in percents of width
+widget.treemap-widget.property.heightInPercents.desc=Height in percents of width
 widget.treemap-widget.property.chartTitle.name=Chart Title
 widget.treemap-widget.property.maxItems.name=Max Components
-widget.treemap-widget.property.maxItems.description=Maximum number of components to show
+widget.treemap-widget.property.maxItems.desc=Maximum number of components to show
 
 widget.welcome.name=Welcome
 widget.welcome.description=Welcome message used to provide links to the most valuable resources like documentation and support
@@ -1270,12 +1270,14 @@ widget.measure_filter_treemap.name=Measure Filter as Treemap
 widget.measure_filter_treemap.description=Displays the result of pre-configured measure filter as a Treemap.
 widget.measure_filter_treemap.property.filter.name=Filter
 widget.measure_filter_treemap.property.sizeMetric.name=Size Metric
+widget.measure_filter_treemap.property.sizeMetric.desc=Metric used for square size
 widget.measure_filter_treemap.property.colorMetric.name=Color Metric
+widget.measure_filter_treemap.property.colorMetric.desc=Metric used for square color
 widget.measure_filter_treemap.property.heightInPercents.name=Height
-widget.measure_filter_treemap.property.heightInPercents.description=Height in percents of width
+widget.measure_filter_treemap.property.heightInPercents.desc=Height in percents of width
 widget.measure_filter_treemap.property.chartTitle.name=Chart Title
 widget.measure_filter_treemap.property.maxItems.name=Max Components
-widget.measure_filter_treemap.property.maxItems.description=Maximum number of components to show
+widget.measure_filter_treemap.property.maxItems.desc=Maximum number of components to show
 
 widget.technical_debt_pyramid.name=Technical Debt Pyramid
 widget.technical_debt_pyramid.description=Displays the technical debt by characteristics. Characteristics located at the bottom should be addressed before those on top.
index bf0522bb8b4d9c70b13125ed6d199c175e6885a0..49103c0e7cabfc973228ca2d9c8934b295cff28b 100644 (file)
@@ -7,6 +7,7 @@ class BaseWidget
   colors4r: ['#00aa00', '#80cc00', '#f77700', '#ee0000']
   colors5: ['#ee0000', '#f77700', '#ffee00', '#80cc00', '#00aa00']
   colors5r: ['#00aa00', '#80cc00', '#ffee00', '#f77700', '#ee0000']
+  colorsLevel: ['#d4333f', '#ff9900', '#85bb43', '##b4b4b4']
   colorUnknown: '#777'
 
 
@@ -35,8 +36,12 @@ class BaseWidget
     key = @metricsPriority()[index]
     @[property] = _.extend @metrics()[key],
       key: key
-      value: (d) -> d.measures[key]?.val
-      formattedValue: (d) -> d.measures[key]?.fval
+      value: (d) ->
+        if d.measures[key]?
+          if d.measures[key].text? then d.measures[key].text else d.measures[key].val
+      formattedValue: (d) ->
+        if d.measures[key]?
+          if d.measures[key].text? then d.measures[key].text else d.measures[key].fval
     @
 
 
index 72f4f2e04d04a70a1d5c1ec9941e2304ad4e5b3e..1a55e9f273918e9c7d50e929d68ec05ead4da8c6 100644 (file)
@@ -26,6 +26,8 @@ class Treemap extends window.SonarWidgets.BaseWidget
     @cells.attr 'title', (d) => @tooltip d
     @cells.style 'background-color', (d) =>
       if @colorMetric.value(d)? then @color @colorMetric.value(d) else @colorUnknown
+    @cells.classed 'treemap-cell-drilldown', (d) ->
+      d.qualifier? && d.qualifier != 'FIL' && d.qualifier != 'CLA'
 
     prefix = @mostCommonPrefix _.pluck @components(), 'longName'
     prefixLength = prefix.length
@@ -37,7 +39,6 @@ class Treemap extends window.SonarWidgets.BaseWidget
 
     @attachEvents cellsEnter
 
-    # Show maxResultsReached message
     @maxResultsReachedLabel.style 'display', if @maxResultsReached() then 'block' else 'none'
 
 
@@ -50,8 +51,14 @@ class Treemap extends window.SonarWidgets.BaseWidget
 
 
   attachEvents: (cells) ->
-    cells.on 'click', (d) =>
-      @requestChildren d
+    cells.on 'click', (d) => @requestChildren d
+    cells.on 'dblclick', (d) => @openDashboard d
+
+
+  openDashboard: (d) ->
+    url = @options().baseUrl + encodeURIComponent(d.key)
+    url += '?metric=' + encodeURIComponent(@colorMetric.key) if d.qualifier == 'CLA' || d.qualifier == 'FIL'
+    window.location = url
 
 
   positionCells: ->
@@ -112,6 +119,28 @@ class Treemap extends window.SonarWidgets.BaseWidget
       @updateBreadcrumbs()
 
 
+  getColorScale: ->
+    return @getLevelColorScale() if @colorMetric.type == 'LEVEL'
+    return @getRatingColorScale() if @colorMetric.type == 'RATING'
+    @getPercentColorScale()
+
+
+  getPercentColorScale: ->
+    color = d3.scale.linear().domain([0, 25, 50, 75, 100])
+    color.range if @colorMetric.direction == 1 then @colors5 else @colors5r
+    color
+
+
+  getRatingColorScale: ->
+    color = d3.scale.ordinal().domain([1, 2, 3, 4, 5]).range @colors5r
+    color
+
+
+  getLevelColorScale: ->
+    color = d3.scale.ordinal().domain(['ERROR', 'WARN', 'OK', 'NONE']).range @colorsLevel
+    color
+
+
   render: (container) ->
     box = d3.select(container).append('div')
     box.classed 'sonar-d3', true
@@ -122,11 +151,8 @@ class Treemap extends window.SonarWidgets.BaseWidget
     @addMetric 'sizeMetric', 1
 
     # Configure scales
-    @color = d3.scale.linear().domain([0, 25, 50, 75, 100])
-    if @colorMetric.direction == 1
-      @color.range @colors5
-    else
-      @color.range @colors5r
+    @color = @getColorScale()
+
     @size = d3.scale.linear().domain([3, 15]).range([@sizeLow, @sizeHigh]).clamp true
 
     @treemap = d3.layout.treemap()
@@ -150,9 +176,6 @@ class Treemap extends window.SonarWidgets.BaseWidget
     @positionCells()
 
 
-  stopDrilldown: ->
-
-
   formatComponents: (data) ->
     components = _.filter data, (component) =>
       hasSizeMetric = => _.findWhere component.msr, key: @sizeMetric.key
@@ -181,7 +204,6 @@ class Treemap extends window.SonarWidgets.BaseWidget
         components = _.initial components, components.length - @options().maxItems - 1
         @updateTreemap components, components.length > @options().maxItems
         @addToBreadcrumbs _.extend d, components: components, maxResultsReached: @maxResultsReached()
-      else @stopDrilldown()
 
 
   mostCommonPrefix: (strings) ->
index b431f3df0ddceeda76b5f1a74a7087dee92c1359..21ad9a7d64170ed3a6797697c2ad52e481877713 100644 (file)
@@ -2820,7 +2820,13 @@ div.rule-title {
   border-bottom: 1px solid #fff;
   .box-sizing(border-box);
   text-align: center;
+}
+
+.sonar-d3 .treemap-cell-drilldown {
   cursor: pointer;
+  .trans(opacity);
+
+  &:hover { opacity: 0.8; }
 }
 
 .sonar-d3 .treemap-inner {