| 54 | private stopped: boolean = false; |
| 55 | |
| 56 | private processData(data: {[name: string]: number}) { |
| 57 | let counts: FunctionStat[] = []; |
| 58 | |
| 59 | // tslint:disable-next-line:forin |
| 60 | for (const key in data) { |
| 61 | counts.push({ name: key, count: data[key] }); |
| 62 | } |
| 63 | |
| 64 | counts.sort((a, b) => { |
| 65 | if (a.count < b.count) { return 1; } |
| 66 | else if (a.count > b.count) { return -1; } |
| 67 | else { return 0; } |
| 68 | }); |
| 69 | |
| 70 | if (counts.length > 10) { |
| 71 | const top9 = counts.slice(0, 9); |
| 72 | const remainder = counts.slice(9); |
| 73 | |
| 74 | let total = 0; |
| 75 | remainder.forEach((c) => total += c.count); |
| 76 | |
| 77 | counts = top9; |
| 78 | counts.push({ name: '**Other**', count: total }); |
| 79 | } |
| 80 | |
| 81 | return counts; |
| 82 | } |
| 83 | |
| 84 | constructor(private datasource: GraphDataSource) { |
| 85 | const wrapper = d3.select('.graph-container').append('div').attr('class', 'graph-wrapper'); |