-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbokeh.service.ts
44 lines (37 loc) · 1.18 KB
/
bokeh.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Injectable } from '@angular/core';
import { MessageService } from './../../core/services/message.service';
import { filter } from 'rxjs/operators';
// this is the global hook to the bokehjs lib (without types)
declare var Bokeh: any;
@Injectable({
providedIn: 'root'
})
export class BokehService {
constructor(private msgService: MessageService) { }
public plot(id: string, item: any) {
const el = document.getElementById(id);
// first remove the previous charts as child
// this necessary, since bokeh do not let us update a chart
while (el.hasChildNodes()) {
el.removeChild(el.lastChild);
}
// be sure to include the correct dom-id as second argument
Bokeh.embed.embed_item(item, id);
}
public getChart(id: string) {
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);
}
)
}
}