1
- import { IRenderMime } from " @jupyterlab/rendermime-interfaces"
2
- import { KernelMessage , Kernel } from " @jupyterlab/services"
3
- import { ReadonlyJSONObject } from " @lumino/coreutils"
4
- import { Widget } from " @lumino/widgets"
5
- import { ContextManager } from " ./manager"
1
+ import { IRenderMime } from ' @jupyterlab/rendermime-interfaces'
2
+ import { KernelMessage , Kernel } from ' @jupyterlab/services'
3
+ import { ReadonlyJSONObject } from ' @lumino/coreutils'
4
+ import { Widget } from ' @lumino/widgets'
5
+ import { ContextManager } from ' ./manager'
6
6
7
7
export declare interface KernelProxy {
8
8
// copied from https://github.com/jupyterlab/jupyterlab/blob/master/packages/services/src/kernel/default.ts#L605
9
- registerCommTarget ( targetName : string , callback : ( comm : Kernel . IComm , msg : KernelMessage . ICommOpenMsg ) => void ) : void
9
+ registerCommTarget (
10
+ targetName : string ,
11
+ callback : ( comm : Kernel . IComm , msg : KernelMessage . ICommOpenMsg ) => void
12
+ ) : void
10
13
}
11
14
12
15
declare const Bokeh : any
13
16
14
- function poll ( fn : ( ) => boolean , wait : number = 1000 , interval : number = 100 ) : Promise < void > {
17
+ function poll ( fn : ( ) => boolean , wait = 1000 , interval = 100 ) : Promise < void > {
15
18
return new Promise ( ( resolve , reject ) => {
16
19
if ( fn ( ) ) {
17
20
resolve ( )
@@ -24,7 +27,7 @@ function poll(fn: () => boolean, wait: number = 1000, interval: number = 100): P
24
27
wait -= interval
25
28
if ( wait <= 0 ) {
26
29
clearInterval ( id )
27
- reject ( new Error ( " timeout" ) )
30
+ reject ( new Error ( ' timeout' ) )
28
31
}
29
32
} , interval )
30
33
}
@@ -34,10 +37,10 @@ function poll(fn: () => boolean, wait: number = 1000, interval: number = 100): P
34
37
/**
35
38
* The MIME types for BokehJS.
36
39
*/
37
- const HTML_MIME_TYPE = " text/html"
38
- const JS_MIME_TYPE = " application/javascript"
39
- export const BOKEHJS_LOAD_MIME_TYPE = " application/vnd.bokehjs_load.v0+json"
40
- export const BOKEHJS_EXEC_MIME_TYPE = " application/vnd.bokehjs_exec.v0+json"
40
+ const HTML_MIME_TYPE = ' text/html'
41
+ const JS_MIME_TYPE = ' application/javascript'
42
+ export const BOKEHJS_LOAD_MIME_TYPE = ' application/vnd.bokehjs_load.v0+json'
43
+ export const BOKEHJS_EXEC_MIME_TYPE = ' application/vnd.bokehjs_exec.v0+json'
41
44
42
45
/**
43
46
* Load BokehJS and CSS into the DOM
@@ -48,7 +51,7 @@ export class BokehJSLoad extends Widget implements IRenderMime.IRenderer {
48
51
49
52
constructor ( _options : IRenderMime . IRendererOptions ) {
50
53
super ( )
51
- this . _script_element = document . createElement ( " script" )
54
+ this . _script_element = document . createElement ( ' script' )
52
55
}
53
56
54
57
renderModel ( model : IRenderMime . IMimeModel ) : Promise < void > {
@@ -76,7 +79,7 @@ export class BokehJSExec extends Widget implements IRenderMime.IRenderer {
76
79
77
80
constructor ( _options : IRenderMime . IRendererOptions , manager : ContextManager ) {
78
81
super ( )
79
- this . _script_element = document . createElement ( " script" )
82
+ this . _script_element = document . createElement ( ' script' )
80
83
this . _manager = manager
81
84
}
82
85
@@ -87,31 +90,38 @@ export class BokehJSExec extends Widget implements IRenderMime.IRenderer {
87
90
// I'm a static document
88
91
const data = model . data [ this . _js_mimetype ] as string
89
92
this . _script_element . textContent = data
90
- await poll ( ( ) => typeof Bokeh !== " undefined" )
93
+ await poll ( ( ) => typeof Bokeh !== ' undefined' )
91
94
this . _document_id = metadata . id as string
92
- const { _manager} = this
95
+ const { _manager } = this
93
96
const kernel_proxy : KernelProxy = {
94
97
registerCommTarget ( targetName , callback ) {
95
98
const kernel = _manager ! . context . sessionContext . session ?. kernel
96
- if ( kernel != null )
99
+ if ( kernel != null ) {
97
100
kernel . registerCommTarget ( targetName , callback )
98
- } ,
101
+ }
102
+ }
99
103
}
100
104
Bokeh . embed . kernels [ this . _document_id ] = kernel_proxy
101
- _manager ! . context . sessionContext . statusChanged . connect ( ( _session , status ) => {
102
- if ( status == "restarting" || status === "dead" ) {
103
- delete Bokeh . embed . kernels [ this . _document_id ! ]
104
- }
105
- } , this )
105
+ _manager ! . context . sessionContext . statusChanged . connect (
106
+ ( _session , status ) => {
107
+ if ( status == 'restarting' || status === 'dead' ) {
108
+ delete Bokeh . embed . kernels [ this . _document_id ! ]
109
+ }
110
+ } ,
111
+ this
112
+ )
106
113
} else if ( metadata . server_id !== undefined ) {
107
114
// I'm a server document
108
115
this . _server_id = metadata . server_id as string
109
116
const data = model . data [ this . _html_mimetype ] as string
110
- const d = document . createElement ( " div" )
117
+ const d = document . createElement ( ' div' )
111
118
d . innerHTML = data
112
119
const script_attrs : NamedNodeMap = d . children [ 0 ] . attributes
113
120
for ( const i in script_attrs ) {
114
- this . _script_element . setAttribute ( script_attrs [ i ] . name , script_attrs [ i ] . value )
121
+ this . _script_element . setAttribute (
122
+ script_attrs [ i ] . name ,
123
+ script_attrs [ i ] . value
124
+ )
115
125
}
116
126
this . _script_element . textContent = d . textContent
117
127
}
@@ -120,18 +130,20 @@ export class BokehJSExec extends Widget implements IRenderMime.IRenderer {
120
130
}
121
131
122
132
dispose ( ) : void {
123
- if ( this . isDisposed )
133
+ if ( this . isDisposed ) {
124
134
return
135
+ }
125
136
126
- super . dispose ( ) ;
137
+ super . dispose ( )
127
138
128
139
if ( this . _server_id ) {
129
- const content : KernelMessage . IExecuteRequestMsg [ " content" ] = {
130
- code : `import bokeh.io.notebook as ion; ion.destroy_server("${ this . _server_id } ")` ,
140
+ const content : KernelMessage . IExecuteRequestMsg [ ' content' ] = {
141
+ code : `import bokeh.io.notebook as ion; ion.destroy_server("${ this . _server_id } ")`
131
142
}
132
143
const kernel = this . _manager ! . context . sessionContext . session ?. kernel
133
- if ( kernel != null )
144
+ if ( kernel != null ) {
134
145
kernel . requestExecute ( content , true )
146
+ }
135
147
this . _server_id = null
136
148
} else if ( this . _document_id ) {
137
149
if ( Bokeh . embed . kernels !== undefined ) {
0 commit comments