import { Component , OnDestroy , OnInit } from '@angular/core' ; import { Subscription } from 'rxjs' ; import { EventService } from '@core/event.service' ; import { OafService } from '../oaf.service' ; /**
 * Display commentary information in tab on OAF product page
 */ @ Component ( { selector : 'oaf-commentary' , styleUrls : [ './commentary.component.scss' ] , templateUrl : './commentary.component.html' } ) export class CommentaryComponent implements OnDestroy , OnInit { forecast ; subscription : Subscription ; constructor ( public eventService , public oafService ) { } ngOnDestroy ( ) { this . subscription . unsubscribe ( ) ; } ngOnInit ( ) { this . subscription = this . oafService . oaf$ . subscribe ( oaf => { this . forecast = this . transformForecast ( oaf ) ; } ) ; } param oaf return transformForecast ( oaf ) { let bin , bins , forecasts , forecast , magnitudeBins , timeframe ; if ( ! oaf ) { return ; } forecasts = oaf . forecast ; timeframe = oaf . advisoryTimeFrame ; for ( let i = 0 , len = forecasts . length ; i < len ; i ++ ) { forecast = forecasts [ i ] ; if ( forecast . label === timeframe ) { forecast = JSON . parse ( JSON . stringify ( forecast ) ) ; break ; } } bins = forecast . bins ; magnitudeBins = { } ; for ( let i = 0 , len = bins . length ; i < len ; i ++ ) { bin = bins [ i ] ; magnitudeBins [ 'magnitude-' + bin . magnitude ] = bin ; } forecast . bins = magnitudeBins ; return forecast ; } param magnitude param bins return transformObservations ( magnitude , bins ) { let bin ; for ( let i = 0 , len = bins . length ; i < len ; i ++ ) { bin = bins [ i ] ; if ( bin . magnitude === magnitude ) { return bin . count ; } } return 0 ; } }