Skip to content

Commit 18af009

Browse files
committed
annotate values
1 parent 3090cac commit 18af009

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Diff for: src/components/StackChart.js

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class StackChart extends Component {
77
render() {
88
// const dataTotals = require('../data/coverage-summary.json');
99
const fileSet = this.props.fileSet;
10+
// If props exist for data reurn them, otherwise return defaults
1011
const totalData = () => {
1112
if (this.props.data) {
1213
return this.props.data;
@@ -16,13 +17,15 @@ class StackChart extends Component {
1617
return dataObj;
1718
};
1819
let dataTotals = totalData();
20+
// Filter the target file groups and return 'statements' for our metric
1921
const dataSet = Object.keys(dataTotals)
2022
.filter((d) => {
2123
return d.includes(fileSet);
2224
})
2325
.map((d) => {
2426
return dataTotals[d]['statements'];
2527
});
28+
// Sum the statement values for one or many items
2629
const sumValues = (obj, key) => Object.values(obj).reduce((a, b) => {
2730
if (!b) {
2831
return a[key];
@@ -31,7 +34,9 @@ class StackChart extends Component {
3134
});
3235
let sTotal = dataSet.length >= 2 ? sumValues(dataSet, 'total') : dataSet[0].total;
3336
let sCovered = dataSet.length >= 2 ? sumValues(dataSet, 'covered') : dataSet[0].covered;
37+
// Work out precentage from totaled values
3438
let sPct = sCovered/sTotal*100;
39+
// Set the data
3540
const data = [{
3641
pct: sPct,
3742
diff: 100 - sPct

0 commit comments

Comments
 (0)