import { ElementRef } from '@angular/core' ; import * as Highcharts from 'highcharts' ; import { AsyncSubject , Observable } from 'rxjs' ; license author Felix Itzenplitz
 *  author Timothy A. Perez (contributor)
  export type Point = number | [ number , number ] | Highcharts . Point ; export class Chart { private refSubject : AsyncSubject < Highcharts . Chart > = new AsyncSubject ( ) ; ref$ : Observable < Highcharts . Chart > = this . refSubject . asObservable ( ) ; ref : Highcharts . Chart ; constructor ( private options = { series : [ ] } ) { } param point param serieIndex param redraw param shift addPoint ( point , serieIndex = 0 , redraw = true , shift = false ) { this . ref$ . subscribe ( chart => { if ( chart . series . length > serieIndex ) { chart . series [ serieIndex ] . addPoint ( point , redraw , shift ) ; } } ) ; } param series param redraw param animation addSeries ( series , redraw = true , animation ) { this . ref$ . subscribe ( chart => { chart . addSeries ( series , redraw , animation ) ; } ) ; } param pointIndex param serieIndex removePoint ( pointIndex , serieIndex = 0 ) { this . ref$ . subscribe ( chart => { if ( chart . series . length > serieIndex && chart . series [ serieIndex ] . data . length > pointIndex ) { chart . series [ serieIndex ] . removePoint ( pointIndex , true ) ; } } ) ; } param seriesIndex removeSeries ( seriesIndex ) { this . ref$ . subscribe ( chart => { if ( chart . series . length > seriesIndex ) { chart . series [ seriesIndex ] . remove ( true ) ; } } ) ; } init ( el ) { if ( ! this . ref ) { Highcharts . chart ( el . nativeElement , this . options , chart => { if ( ! this . ref ) { this . refSubject . next ( chart ) ; this . ref = chart ; this . refSubject . complete ( ) ; } } ) ; } } destroy ( ) { if ( this . ref ) { this . options = this . ref . options ; this . ref . destroy ( ) ; this . ref = undefined ; this . refSubject = new AsyncSubject ( ) ; this . ref$ = this . refSubject . asObservable ( ) ; } } }