diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-02-20 15:53:35 +0100 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-03-02 17:42:14 +0100 |
commit | f48b42fdc9a7e389311304403afa6021556dc82b (patch) | |
tree | eda4d2e1b65dbfd349511d858c76c731fee16f2e /server | |
parent | db229037bdb6e7a8ab8289efbe791bd75a6295db (diff) | |
download | sonarqube-f48b42fdc9a7e389311304403afa6021556dc82b.tar.gz sonarqube-f48b42fdc9a7e389311304403afa6021556dc82b.zip |
SONAR-6123 Show js tooltips for bubble chart instead of text before the chart
Diffstat (limited to 'server')
-rw-r--r-- | server/sonar-web/src/main/js/application.js | 33 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/common/handlebars-extensions.js | 28 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/widgets/bubble-chart.js | 79 |
3 files changed, 60 insertions, 80 deletions
diff --git a/server/sonar-web/src/main/js/application.js b/server/sonar-web/src/main/js/application.js index 9362987d90b..de273f721dd 100644 --- a/server/sonar-web/src/main/js/application.js +++ b/server/sonar-web/src/main/js/application.js @@ -333,6 +333,39 @@ function openPopup(url, popupId) { } +function collapsedDirFromPath (path) { + var limit = 30; + if (typeof path === 'string') { + var tokens = _.initial(path.split('/')); + if (tokens.length > 2) { + var head = _.first(tokens), + tail = _.last(tokens), + middle = _.initial(_.rest(tokens)), + cut = false; + while (middle.join().length > limit && middle.length > 0) { + middle.shift(); + cut = true; + } + var body = [].concat(head, cut ? ['...'] : [], middle, tail); + return body.join('/') + '/'; + } else { + return tokens.join('/') + '/'; + } + } else { + return null; + } +} + +function fileFromPath (path) { + if (typeof path === 'string') { + var tokens = path.split('/'); + return _.last(tokens); + } else { + return null; + } +} + + jQuery(function () { // Process login link in order to add the anchor diff --git a/server/sonar-web/src/main/js/common/handlebars-extensions.js b/server/sonar-web/src/main/js/common/handlebars-extensions.js index 36f89fd0214..2dddae877d2 100644 --- a/server/sonar-web/src/main/js/common/handlebars-extensions.js +++ b/server/sonar-web/src/main/js/common/handlebars-extensions.js @@ -473,35 +473,11 @@ }); Handlebars.registerHelper('collapsedDirFromPath', function (path) { - var limit = 30; - if (typeof path === 'string') { - var tokens = _.initial(path.split('/')); - if (tokens.length > 2) { - var head = _.first(tokens), - tail = _.last(tokens), - middle = _.initial(_.rest(tokens)), - cut = false; - while (middle.join().length > limit && middle.length > 0) { - middle.shift(); - cut = true; - } - var body = [].concat(head, cut ? ['...'] : [], middle, tail); - return body.join('/') + '/'; - } else { - return tokens.join('/') + '/'; - } - } else { - return null; - } + return collapsedDirFromPath(path); }); Handlebars.registerHelper('fileFromPath', function (path) { - if (typeof path === 'string') { - var tokens = path.split('/'); - return _.last(tokens); - } else { - return null; - } + return fileFromPath(path); }); Handlebars.registerHelper('repeat', function (number, options) { diff --git a/server/sonar-web/src/main/js/widgets/bubble-chart.js b/server/sonar-web/src/main/js/widgets/bubble-chart.js index 1e5860a4f9f..d8f3377dbd6 100644 --- a/server/sonar-web/src/main/js/widgets/bubble-chart.js +++ b/server/sonar-web/src/main/js/widgets/bubble-chart.js @@ -208,7 +208,27 @@ window.SonarWidgets = window.SonarWidgets == null ? {} : window.SonarWidgets; .style('stroke', function () { return widget.bubbleColor(); }) - .style('transition', 'all 0.2s ease'); + .style('transition', 'all 0.2s ease') + + .attr('title', function (d) { + var xMetricName = widget.metrics()[widget.xMetric].name, + yMetricName = widget.metrics()[widget.yMetric].name, + sizeMetricName = widget.metrics()[widget.sizeMetric].name, + + xMetricValue = d.measures[widget.xMetric].fval, + yMetricValue = d.measures[widget.yMetric].fval, + sizeMetricValue = d.measures[widget.sizeMetric].fval; + + return '<div class="text-left">' + + collapsedDirFromPath(d.longName) + '<br>' + + fileFromPath(d.longName) + '<br>' + '<br>' + + xMetricName + ': ' + xMetricValue + '<br>' + + yMetricName + ': ' + yMetricValue + '<br>' + + sizeMetricName + ': ' + sizeMetricValue + + '</div>'; + }) + .attr('data-placement', 'bottom') + .attr('data-toggle', 'tooltip'); this.items.exit().remove(); @@ -224,43 +244,13 @@ window.SonarWidgets = window.SonarWidgets == null ? {} : window.SonarWidgets; .on('click', function (d) { window.location = widget.options().baseUrl + '?id=' + encodeURIComponent(d.key); }) - .on('mouseenter', function (d) { + .on('mouseenter', function () { d3.select(this).select('circle') .style('fill-opacity', 0.8); - - widget.infoDate.text(d.longName); - - var metricLineList = [ - { - metric: widget.metrics()[widget.xMetric].name, - value: d.measures[widget.xMetric].fval - }, - { - metric: widget.metrics()[widget.yMetric].name, - value: d.measures[widget.yMetric].fval - }, - { - metric: widget.metrics()[widget.sizeMetric].name, - value: (!!d.measures[widget.sizeMetric] ? d.measures[widget.sizeMetric].fval : '–') - } - ]; - - var lastX = 0; - widget.infoMetrics - .data(metricLineList) - .text(function(m) { return m.metric + ': ' + m.value; }) - .attr('transform', function(d2, i) { - var posX = lastX; - lastX += widget.infoMetricWidth[i]; - return trans(posX, 20); - }); }) .on('mouseleave', function () { d3.select(this).select('circle') .style('fill-opacity', 0.2); - - widget.infoDate.text(''); - widget.infoMetrics.text(''); }); }; @@ -302,26 +292,6 @@ window.SonarWidgets = window.SonarWidgets == null ? {} : window.SonarWidgets; this.gGrid.selectAll('line') .style('stroke', '#000') .style('stroke-opacity', 0.25); - - - // Configure info placeholders - this.infoWrap - .attr('transform', trans(-this.margin().left, -this.margin().top + 20)); - - this.infoDate - .style('text-anchor', 'start') - .style('font-weight', 'bold'); - - var metricLines = [this.metrics().x, this.metrics().y, this.metrics().size]; - this.infoMetrics = this.infoWrap.selectAll('.metric') - .data(metricLines); - this.infoMetrics.enter().append('text').attr('class', 'metric info-text-small') - .text(function(d) { return d; }); - this.infoMetricWidth = []; - this.infoMetrics.each(function() { - widget.infoMetricWidth.push(this.getComputedTextLength() + 140); - }); - this.infoMetrics.text(''); }; @@ -342,9 +312,10 @@ window.SonarWidgets = window.SonarWidgets == null ? {} : window.SonarWidgets; this.initBubbleEvents(); this.initAxes(); this.initGrid(); - this.update(containerS); + jQuery('[data-toggle="tooltip"]').tooltip({ container: 'body', html: true }); + return this; }; @@ -542,7 +513,7 @@ window.SonarWidgets = window.SonarWidgets == null ? {} : window.SonarWidgets; window.SonarWidgets.BubbleChart.defaults = { width: 350, height: 150, - margin: { top: 60, right: 10, bottom: 50, left: 70 }, + margin: { top: 10, right: 10, bottom: 50, left: 70 }, xLog: false, yLog: false, bubbleColor: '#4b9fd5', |