diff --git a/Front/skydivelogs-app/src/app/list-of-tunnel-flights/list-of-tunnel-flights.component.ts b/Front/skydivelogs-app/src/app/list-of-tunnel-flights/list-of-tunnel-flights.component.ts index 0742b73..c8f65be 100644 --- a/Front/skydivelogs-app/src/app/list-of-tunnel-flights/list-of-tunnel-flights.component.ts +++ b/Front/skydivelogs-app/src/app/list-of-tunnel-flights/list-of-tunnel-flights.component.ts @@ -146,7 +146,8 @@ export class ListOfTunnelFlightsComponent implements OnInit { this.barChartData = { labels: allMonths, datasets: [ - { data: cumulatedTime, label: 'Time in tunnel' } + { data: cumulatedTime, label: 'Time in tunnel' }, + { data: cumulatedTime, label: 'Time in tunnel 2' } ] }; @@ -168,21 +169,49 @@ export class ListOfTunnelFlightsComponent implements OnInit { } private getCumulatedTimeByMonth(stats: TunnelFlightByMonth[], allMonths: string[]): Array { - let results: Array = []; + // type GraphModel = { + // data: number[]; + // label: string; + // } + + // let results: Array = []; + + // for (let i = 0; i < allMonths.length; i++) { + // const month = allMonths[i]; + // let tmp = stats.filter((d) => d.month == month); + + // let sum: number = 0; + // if (tmp.length > 0){ + // tmp.forEach(a => sum += a.nb); + // } + + // results.push(sum); + // } + + // return results; + + let arr3 = Array.from({length: allMonths.length + 1}, (v, k) => 0); + let disctintType = stats.map(item => item.type).filter((value, index, self) => self.indexOf(value) === index); + let disctintType2 = Array.from(new Set(stats.map((item) => item.type))) + + let results = new Map(); for (let i = 0; i < allMonths.length; i++) { const month = allMonths[i]; let tmp = stats.filter((d) => d.month == month); - let sum = 0; - if (tmp.length == 1){ - sum = tmp[0].nb; + if (tmp.length > 0){ + tmp.forEach(a => { + if (!results.has(a.type)) { + results.set(a.type, [a.nb]) + } else { + results[a.type].push(a.nb); + } + }); } - - results.push(sum); } - return results; + return new Array(); } private footer = (tooltipItems) => { diff --git a/Front/skydivelogs-app/src/models/tunnel-flight.ts b/Front/skydivelogs-app/src/models/tunnel-flight.ts index ca2e1a8..bfc9442 100644 --- a/Front/skydivelogs-app/src/models/tunnel-flight.ts +++ b/Front/skydivelogs-app/src/models/tunnel-flight.ts @@ -48,10 +48,12 @@ export class TunnelFlight { export class TunnelFlightByMonth { constructor(data: any) { this.month = data.label; + this.type = data.label2; this.nb = data.nb; } public month: string; + public type: string; public nb: number; } @@ -61,5 +63,6 @@ export class TunnelFlightByMonthResp { } public label: string; + public label2: string; public nb: number; } \ No newline at end of file