Passed
Push — master ( c84e5c...0e0008 )
by philippe
04:14
created

doc/phpmetrics/js/graph-licenses.js   A

Complexity

Total Complexity 5
Complexity/F 1

Size

Lines of Code 52
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 35
dl 0
loc 52
rs 10
c 1
b 0
f 0
cc 0
nc 1
mnd 0
bc 5
fnc 5
bpm 1
cpm 1
noi 2
1
function chartLicenses(json) {
2
3
    var diameter = document.getElementById('svg-licenses').offsetWidth;
0 ignored issues
show
Unused Code introduced by
The variable diameter seems to be never used. Consider removing it.
Loading history...
4
5
    var svg = d3.select('#svg-licenses').append('svg'),
0 ignored issues
show
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
6
        width = 300,//document.getElementById('svg-licenses').offsetWidth,
7
        height = 300,//document.getElementById('svg-licenses').offsetWidth,
8
        radius = Math.min(width, height) / 2;
9
10
    //var r = 300; // outer radius
11
12
    var color = d3.scale.ordinal()
13
        .range(["#BBDEFB", "#90CAF9", "#64B5F6", "#42A5F5", "#2196F3", "#1E88E5", "#1976D2", "#1565C0", "#0D47A1"]);
14
15
    svg
16
        .attr("width", width)
17
        .attr("height", height);
18
19
    var group = svg.append("g")
20
        .attr("transform", "translate(" + Math.ceil(width / 2) + ", " + Math.ceil(height / 2) + ")"); // set center of pie
21
22
    var arc = d3.svg.arc()
23
        .innerRadius(radius - 10)
24
        .outerRadius(0);
25
26
    var pie = d3.layout.pie()
27
        .value(function (d) {
28
            return d.value;
29
        });
30
31
    var arcs = group.selectAll(".arc")
32
        .data(pie(json))
33
        .enter()
34
        .append("g")
35
        .attr("class", "arc");
36
37
    arcs.append("path")
38
        .attr("d", arc) // here the arc function works on every record d of data
39
        .attr("fill", function (d) {
40
            return color(d.data.value);
41
        });
42
43
    arcs.append("text")
44
        .attr("transform", function (d) {
45
            return "translate(" + arc.centroid(d) + ")";
46
        })
47
        .attr("text-anchor", "middle")
48
        .attr('color', '#FFF')
49
        .text(function (d) {
50
            return d.data.name;
51
        });
52
}