1
1
import React , { Component } from 'react' ;
2
- import { BarStackHorizontal } from '@vx/shape' ;
3
- import { Group } from '@vx/group' ;
4
- import { scaleBand , scaleLinear , scaleOrdinal } from '@vx/scale' ;
2
+ import { BarStackHorizontal } from '@vx/shape' ;
3
+ import { Group } from '@vx/group' ;
4
+ import { scaleBand , scaleLinear , scaleOrdinal } from '@vx/scale' ;
5
5
6
6
class StackChart extends Component {
7
7
render ( ) {
8
- // const dataTotals = require('../data/coverage-summary.json');
9
- const fileSet = this . props . fileSet ;
8
+ const { fileSet } = this . props ;
10
9
// If props exist for data reurn them, otherwise return defaults
11
10
const totalData = ( ) => {
12
- if ( this . props . data ) {
13
- return this . props . data ;
11
+ if ( this . props . data ) { // eslint-disable-line react/destructuring-assignment
12
+ return this . props . data ; // eslint-disable-line react/destructuring-assignment
14
13
}
15
- let dataObj = { } ;
16
- dataObj [ fileSet ] = { statements : { total : 1 , covered : 0 , skipped : 0 , pct : 0 } } ;
14
+ const dataObj = { } ;
15
+ dataObj [ fileSet ] = {
16
+ statements : {
17
+ total : 1 , covered : 0 , skipped : 0 , pct : 0 ,
18
+ } ,
19
+ } ;
17
20
return dataObj ;
18
21
} ;
19
- let dataTotals = totalData ( ) ;
22
+ const dataTotals = totalData ( ) ;
20
23
// Filter the target file groups and return 'statements' for our metric
21
24
const dataSet = Object . keys ( dataTotals )
22
- . filter ( ( d ) => {
23
- return d . includes ( fileSet ) ;
24
- } )
25
- . map ( ( d ) => {
26
- return dataTotals [ d ] [ 'statements' ] ;
27
- } ) ;
25
+ . filter ( d => d . includes ( fileSet ) )
26
+ . map ( d => dataTotals [ d ] . statements ) ;
28
27
// Sum the statement values for one or many items
29
28
const sumValues = ( obj , key ) => Object . values ( obj ) . reduce ( ( a , b ) => {
30
29
if ( ! b ) {
31
30
return a [ key ] ;
32
31
}
33
32
return typeof a === 'object' ? a [ key ] + b [ key ] : a + b [ key ] ;
34
33
} ) ;
35
- let sTotal = dataSet . length >= 2 ? sumValues ( dataSet , 'total' ) : dataSet [ 0 ] . total ;
36
- let sCovered = dataSet . length >= 2 ? sumValues ( dataSet , 'covered' ) : dataSet [ 0 ] . covered ;
34
+ const sTotal = dataSet . length >= 2 ? sumValues ( dataSet , 'total' ) : dataSet [ 0 ] . total ;
35
+ const sCovered = dataSet . length >= 2 ? sumValues ( dataSet , 'covered' ) : dataSet [ 0 ] . covered ;
37
36
// Work out precentage from totaled values
38
- let sPct = sCovered / sTotal * 100 ;
37
+ const sPct = sCovered / sTotal * 100 ;
39
38
// Set the data
40
39
const data = [ {
41
40
pct : sPct ,
42
- diff : 100 - sPct
41
+ diff : 100 - sPct ,
43
42
} ] ;
44
43
const keys = Object . keys ( data [ 0 ] ) . map ( d => d ) ;
45
- const width = parseInt ( ( document . documentElement . offsetWidth / 8 - 5 ) . toFixed ( 0 ) , 10 ) ;
44
+ const width = parseInt ( ( document . documentElement . offsetWidth / 8 - 5 ) . toFixed ( 0 ) , 10 ) ;
46
45
const height = 80 ;
47
46
const margin = {
48
47
top : 40 ,
49
48
left : 0 ,
50
49
right : 20 ,
51
- bottom : 20
50
+ bottom : 20 ,
52
51
} ;
53
52
if ( width < 10 ) return null ;
54
53
@@ -60,16 +59,16 @@ class StackChart extends Component {
60
59
const xScale = scaleLinear ( {
61
60
rangeRound : [ 0 , xMax ] ,
62
61
domain : [ 0 , 100 ] ,
63
- nice : true
62
+ nice : true ,
64
63
} ) ;
65
64
const yScale = scaleBand ( {
66
65
rangeRound : [ 40 , 0 ] ,
67
66
domain : 1 ,
68
- padding : 0.4
67
+ padding : 0.4 ,
69
68
} ) ;
70
69
const zScale = scaleOrdinal ( {
71
70
domain : keys ,
72
- range : [ '#55CA01' , '#F0FFE4' ]
71
+ range : [ '#55CA01' , '#F0FFE4' ] ,
73
72
} ) ;
74
73
75
74
return (
@@ -87,23 +86,23 @@ class StackChart extends Component {
87
86
zScale = { zScale }
88
87
/>
89
88
< text
90
- dy = { "-.7em" }
89
+ dy = "-.7em"
91
90
fontSize = { 16 }
92
91
fontWeight = { 200 }
93
- textAnchor = { "left" }
94
- style = { { pointerEvents : " none" } }
95
- fill = { "#F2F2F2" }
92
+ textAnchor = "left"
93
+ style = { { pointerEvents : ' none' } }
94
+ fill = "#F2F2F2"
96
95
>
97
96
{ fileSet }
98
97
</ text >
99
98
< text
100
- dy = { "1.1em" }
101
- dx = { ".3em" }
99
+ dy = "1.1em"
100
+ dx = ".3em"
102
101
fontSize = { 16 }
103
102
fontWeight = { 200 }
104
- textAnchor = { "left" }
105
- style = { { pointerEvents : " none" } }
106
- fill = { "#001E40" }
103
+ textAnchor = "left"
104
+ style = { { pointerEvents : ' none' } }
105
+ fill = "#001E40"
107
106
>
108
107
{ sPct . toFixed ( ) }
109
108
</ text >
0 commit comments