import { Injectable } from '@angular/core' ; import { MessageService } from './../../core/services/message.service' ; import { filter } from 'rxjs/operators' ; declare var Bokeh ; @ Injectable ( { providedIn : 'root' } ) export class BokehService { constructor ( private msgService ) { } public plot ( id , item ) { const el = document . getElementById ( id ) ; while ( el . hasChildNodes ( ) ) { el . removeChild ( el . lastChild ) ; } Bokeh . embed . embed_item ( item , id ) ; } public getChart ( id ) { const callbackId = 'plot' ; const msg = { name : 'addChart' , args : [ id , callbackId ] , action : 'default' } ; this . msgService . sendMsg ( msg ) ; this . msgService . awaitMessage ( ) . pipe ( filter ( msg => msg . name == callbackId ) ) . subscribe ( msg => { this . plot ( msg . args . id , msg . args . item ) ; } ) ; } }