-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
widget.ts
72 lines (60 loc) · 2.08 KB
/
widget.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/******************************************************************************
*
* Copyright (c) 2018, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/
import {Message} from "@phosphor/messaging";
import {DOMWidgetView} from "@jupyter-widgets/base";
import {PerspectiveViewerOptions} from "@finos/perspective-viewer";
import {PerspectiveWidget, PerspectiveWidgetOptions} from "@finos/perspective-phosphor";
import perspective from "@finos/perspective";
import * as wasm from "@finos/perspective/dist/umd/psp.async.wasm";
import * as worker from "!!file-worker-loader?inline=true!@finos/perspective/dist/umd/perspective.wasm.worker.js";
if (perspective) {
perspective.override({wasm, worker});
} else {
console.warn("Perspective was undefined in jlab - wasm load errors may occur");
}
export type PerspectiveJupyterWidgetOptions = {
view: DOMWidgetView;
};
/**
* PerspectiveJupyterWidget is the ipywidgets front-end for the Perspective Jupyterlab plugin.
*/
export class PerspectiveJupyterWidget extends PerspectiveWidget {
constructor(name = "Perspective", options: PerspectiveViewerOptions & PerspectiveJupyterWidgetOptions & PerspectiveWidgetOptions) {
const view = options.view;
delete options.view;
super(name, options);
this._view = view;
}
/**
* Process the phosphor message.
*
* Any custom phosphor widget used inside a Jupyter widget should override
* the processMessage function like this.
*/
processMessage(msg: Message) {
super.processMessage(msg);
this._view.processPhosphorMessage(msg);
}
/**
* Dispose the widget.
*
* This causes the view to be destroyed as well with 'remove'
*/
dispose() {
if (this.isDisposed) {
return;
}
super.dispose();
if (this._view) {
this._view.remove();
}
this._view = null;
}
private _view: DOMWidgetView;
}