File tree 1 file changed +5
-0
lines changed
1 file changed +5
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ class StackChart extends Component {
7
7
render ( ) {
8
8
// const dataTotals = require('../data/coverage-summary.json');
9
9
const fileSet = this . props . fileSet ;
10
+ // If props exist for data reurn them, otherwise return defaults
10
11
const totalData = ( ) => {
11
12
if ( this . props . data ) {
12
13
return this . props . data ;
@@ -16,13 +17,15 @@ class StackChart extends Component {
16
17
return dataObj ;
17
18
} ;
18
19
let dataTotals = totalData ( ) ;
20
+ // Filter the target file groups and return 'statements' for our metric
19
21
const dataSet = Object . keys ( dataTotals )
20
22
. filter ( ( d ) => {
21
23
return d . includes ( fileSet ) ;
22
24
} )
23
25
. map ( ( d ) => {
24
26
return dataTotals [ d ] [ 'statements' ] ;
25
27
} ) ;
28
+ // Sum the statement values for one or many items
26
29
const sumValues = ( obj , key ) => Object . values ( obj ) . reduce ( ( a , b ) => {
27
30
if ( ! b ) {
28
31
return a [ key ] ;
@@ -31,7 +34,9 @@ class StackChart extends Component {
31
34
} ) ;
32
35
let sTotal = dataSet . length >= 2 ? sumValues ( dataSet , 'total' ) : dataSet [ 0 ] . total ;
33
36
let sCovered = dataSet . length >= 2 ? sumValues ( dataSet , 'covered' ) : dataSet [ 0 ] . covered ;
37
+ // Work out precentage from totaled values
34
38
let sPct = sCovered / sTotal * 100 ;
39
+ // Set the data
35
40
const data = [ {
36
41
pct : sPct ,
37
42
diff : 100 - sPct
You can’t perform that action at this time.
0 commit comments