import { Component , OnInit } from '@angular/core' ; import { Subscription } from 'rxjs' ; import { EventService } from '@core/event.service' ; import { DyfiService } from '../dyfi.service' ; /**
 * Generate RESPONSES VS. TIME tab for dyfi product page
 */ @ Component ( { selector : 'dyfi-responses-vs-time' , styleUrls : [ './responses-vs-time.component.scss' ] , templateUrl : './responses-vs-time.component.html' } ) export class ResponsesVsTimeComponent implements OnInit { autoScale = true ; colorScheme = { domain : [ '#34e16d' ] } ; dyfiSeries : any ; gradient = false ; product : any = null ; showLegend = false ; showXAxis = true ; showXAxisLabel = true ; showYAxis = true ; showYAxisLabel = true ; subs = new Subscription ( ) ; xAxisLabel = null ; xAxisTicks = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 ] ; xScaleMax = null ; xScaleType = 'linear' ; yAxisLabel = 'Number of Responses' ; constructor ( public dyfiService , public eventService ) { } ngOnInit ( ) { this . subs . add ( this . dyfiService . plotNumResp$ . subscribe ( series => { this . onDyfiSeries ( series ) ; } ) ) ; this . subs . add ( this . eventService . product$ . subscribe ( product => { this . onProduct ( product ) ; } ) ) ; } onDyfiSeries ( dyfiData ) { if ( dyfiData === null || ! dyfiData ) { this . dyfiSeries = null ; return ; } const prefUnit = dyfiData . preferred_unit ; this . xAxisLabel = `Time since earthquake (${ prefUnit })` ; if ( prefUnit === 'hours' ) { this . xScaleMax = 24 ; } else { this . xAxisTicks = null ; } this . dyfiSeries = dyfiData ; } param product onProduct ( product ) { this . product = product ; this . dyfiService . getNumResp ( product ) ; } param value xAxisTickFormatting ( value ) { return value ; } }