aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/components/source-viewer/measures-overlay.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-web/src/main/js/components/source-viewer/measures-overlay.js')
-rw-r--r--server/sonar-web/src/main/js/components/source-viewer/measures-overlay.js51
1 files changed, 50 insertions, 1 deletions
diff --git a/server/sonar-web/src/main/js/components/source-viewer/measures-overlay.js b/server/sonar-web/src/main/js/components/source-viewer/measures-overlay.js
index 723265766ad..20e4789ba4e 100644
--- a/server/sonar-web/src/main/js/components/source-viewer/measures-overlay.js
+++ b/server/sonar-web/src/main/js/components/source-viewer/measures-overlay.js
@@ -30,9 +30,58 @@ export default ModalView.extend({
});
},
+ initPieChart: function () {
+ var trans = function (left, top) {
+ return 'translate(' + left + ', ' + top + ')';
+ };
+
+ var defaults = {
+ size: 40,
+ thickness: 8,
+ color: '#1f77b4',
+ baseColor: '#e6e6e6'
+ };
+
+ this.$('.js-pie-chart').each(function () {
+ var data = [
+ $(this).data('value'),
+ $(this).data('max') - $(this).data('value')
+ ],
+ options = _.defaults($(this).data(), defaults),
+ radius = options.size / 2;
+
+ var container = d3.select(this),
+ svg = container.append('svg')
+ .attr('width', options.size)
+ .attr('height', options.size),
+ plot = svg.append('g')
+ .attr('transform', trans(radius, radius)),
+ arc = d3.svg.arc()
+ .innerRadius(radius - options.thickness)
+ .outerRadius(radius),
+ pie = d3.layout.pie()
+ .sort(null)
+ .value(function (d) {
+ return d;
+ }),
+ colors = function (i) {
+ return i === 0 ? options.color : options.baseColor;
+ },
+ sectors = plot.selectAll('path')
+ .data(pie(data));
+
+ sectors.enter()
+ .append('path')
+ .style('fill', function (d, i) {
+ return colors(i);
+ })
+ .attr('d', arc);
+ });
+ },
+
onRender: function () {
ModalView.prototype.onRender.apply(this, arguments);
- this.$('.js-pie-chart').pieChart();
+ this.initPieChart();
this.$('.js-test-list').scrollTop(this.testsScroll);
},