1- function chartMaintainability ( ) {
1+ function chartMaintainability ( withoutComment )
2+ {
3+ var chartId = withoutComment ? 'svg-maintainability-without-comments' : 'svg-maintainability' ;
24
3- var diameter = document . getElementById ( 'svg-maintainability' ) . offsetWidth ;
5+ var diameter = document . getElementById ( chartId ) . offsetWidth ;
46
57 var json = {
68 name : 'chart' ,
79 children : classes
810 } ;
911
10- var svg = d3 . select ( '#svg-maintainability' ) . append ( 'svg' )
12+ var svg = d3 . select ( '#' + chartId ) . append ( 'svg' )
1113 . attr ( 'width' , diameter )
1214 . attr ( 'height' , diameter ) ;
1315
14-
1516 var bubble = d3 . layout . pack ( )
1617 . size ( [ diameter , diameter ] )
1718 . padding ( 3 )
@@ -37,31 +38,49 @@ function chartMaintainability() {
3738 return d . r ;
3839 } )
3940 . style ( "fill" , function ( d ) {
40- if ( d . mi > 85 ) {
41- return '#8BC34A' ;
42- } else if ( d . mi > 69 ) {
43- return '#FFC107' ;
41+ if ( true === withoutComment ) {
42+ if ( d . mIwoC > 65 ) {
43+ return '#8BC34A' ;
44+ } else if ( d . mIwoC > 53 ) {
45+ return '#FFC107' ;
46+ } else {
47+ return '#F44336' ;
48+ }
4449 } else {
45- return '#F44336' ;
50+ if ( d . mi > 85 ) {
51+ return '#8BC34A' ;
52+ } else if ( d . mi > 69 ) {
53+ return '#FFC107' ;
54+ } else {
55+ return '#F44336' ;
56+ }
4657 }
4758 } )
48- . attr ( "transform" , function ( d ) {
49- return "translate(" + d . x + "," + d . y + ")" ;
50- } )
5159 . on ( 'mouseover' , function ( d ) {
52- var text = '<strong>' + d . name + '</strong>'
53- + "<br />Cyclomatic Complexity : " + d . ccn
54- + "<br />Maintainability Index: " + d . mi ;
60+ var text = '' ;
61+ if ( true === withoutComment ) {
62+ text = '<strong>' + d . name + '</strong>'
63+ + "<br />Cyclomatic Complexity : " + d . ccn
64+ + "<br />Maintainability Index (w/o comments): " + d . mIwoC ;
65+ } else {
66+ text = '<strong>' + d . name + '</strong>'
67+ + "<br />Cyclomatic Complexity : " + d . ccn
68+ + "<br />Maintainability Index: " + d . mi ;
69+ }
5570 d3 . select ( '.tooltip' ) . html ( text ) ;
56- d3 . select ( ".tooltip" ) . style ( "opacity" , 1 ) ;
71+ d3 . select ( ".tooltip" )
72+ . style ( "opacity" , 1 )
73+ . style ( "z-index" , 1 ) ;
5774 } )
5875 . on ( 'mousemove' , function ( ) {
5976 d3 . select ( ".tooltip" )
6077 . style ( "left" , ( d3 . event . pageX + 5 ) + "px" )
6178 . style ( "top" , ( d3 . event . pageY + 5 ) + "px" ) ;
6279 } )
6380 . on ( 'mouseout' , function ( ) {
64- d3 . select ( ".tooltip" ) . style ( "opacity" , 0 ) ;
81+ d3 . select ( ".tooltip" )
82+ . style ( "opacity" , 0 )
83+ . style ( "z-index" , - 1 ) ;
6584 } ) ;
6685
6786 d3 . select ( "body" )
@@ -70,12 +89,15 @@ function chartMaintainability() {
7089 . style ( "opacity" , 0 ) ;
7190
7291 // button for saving image
73- var button = d3 . select ( '#svg-maintainability' ) . append ( 'button' ) ;
92+ var button = d3 . select ( '#' + chartId ) . append ( 'button' ) ;
7493 button
7594 . classed ( 'btn-save-image' , true )
7695 . text ( 'download' )
7796 . on ( 'click' , function ( ) {
78- var svg = d3 . select ( '#svg-maintainability svg' ) [ 0 ] [ 0 ] ;
79- saveSvgAsImage ( svg , 'PhpMetrics maintainability / complexity' , 1900 , 1900 ) ;
97+ var svg = d3 . select ( '#' + chartId + ' svg' ) [ 0 ] [ 0 ] ;
98+ var nameImage = ( withoutComment )
99+ ? 'PhpMetrics maintainability without comments / complexity'
100+ : 'PhpMetrics maintainability / complexity' ;
101+ saveSvgAsImage ( svg , nameImage , 1900 , 1900 ) ;
80102 } ) ;
81- }
103+ }
0 commit comments