Skip to content

Commit 2de27e2

Browse files
timkpainetexodus
authored andcommitted
Support perspective widget in vs-code
Signed-off-by: Tim Paine <[email protected]> Signed-off-by: Andrew Stein <[email protected]> # Conflicts: # packages/perspective-jupyterlab/src/less/index.less
1 parent e689ad5 commit 2de27e2

File tree

5 files changed

+42
-16
lines changed

5 files changed

+42
-16
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2+
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3+
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4+
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5+
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6+
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7+
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
8+
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9+
// ┃ This file is part of the Perspective library, distributed under the terms ┃
10+
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11+
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12+
13+
import THEMES from "../../../dist/css/perspective-jupyterlab.css";
14+
15+
// Export the required load_ipython_extension
16+
exports.load_css = () => {
17+
const style = document.createElement("style");
18+
style.textContent = THEMES;
19+
document.head.appendChild(style);
20+
};

packages/perspective-jupyterlab/src/js/notebook/extension.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,11 @@
1111
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
1212

1313
/* eslint-disable no-underscore-dangle */
14+
import { load_css } from "./css";
1415

1516
// This file contains the javascript that is run when the notebook is loaded.
1617
// It contains some requirejs configuration and the `load_ipython_extension`
1718
// which is required for any notebook extension.
18-
//
19-
// Some static assets may be required by the custom widget javascript. The base
20-
// url for the notebook is not known at build time and is therefore computed
21-
// dynamically.
22-
23-
import THEMES from "../../../dist/css/perspective-jupyterlab.css";
24-
2519
if (window.require) {
2620
window.require.config({
2721
map: {
@@ -33,9 +27,6 @@ if (window.require) {
3327
});
3428
}
3529

36-
// Export the required load_ipython_extension
3730
exports.load_ipython_extension = () => {
38-
const style = document.createElement("style");
39-
style.textContent = THEMES;
40-
document.head.appendChild(style);
31+
load_css();
4132
};

packages/perspective-jupyterlab/src/js/notebook/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ import "@finos/perspective-viewer-datagrid";
1414
import "@finos/perspective-viewer-d3fc";
1515
import "@finos/perspective-viewer-openlayers";
1616

17+
import { load_css } from "./css";
1718
import { PerspectiveView } from "../view";
1819
import { PerspectiveModel } from "../model";
1920

2021
exports.PerspectiveModel = PerspectiveModel;
2122
exports.PerspectiveView = PerspectiveView;
23+
24+
// Run if in vs-code
25+
if (window.vscIPyWidgets) {
26+
load_css();
27+
}

packages/perspective-jupyterlab/src/js/view.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,16 @@ export class PerspectiveView extends DOMWidgetView {
404404
table.update(updated.delta);
405405
}
406406

407-
this._client_view.on_update(
408-
(updated) => this._client_view_update_callback(updated),
409-
{ mode: "row" }
410-
);
407+
if (this._client_view) {
408+
// NOTE: if `plugin_config_changed` called before
409+
// `_handle_load_message`, this will be undefined
410+
// Ignore, as `_handle_load_message` is sure to
411+
// follow.
412+
this._client_view.on_update(
413+
(updated) => this._client_view_update_callback(updated),
414+
{ mode: "row" }
415+
);
416+
}
411417

412418
this._kernel_view.on_update(
413419
(updated) => this._kernel_view_update_callback(updated),

packages/perspective-jupyterlab/src/less/index.less

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ div.PSPContainer {
3636
}
3737

3838
// Widget height for Voila
39-
body[data-voila="voila"] .jp-OutputArea-output div.PSPContainer {
39+
// Widget height for VS Code
40+
body[data-voila="voila"] .jp-OutputArea-output div.PSPContainer,
41+
body[data-vscode-theme-id] .cell-output-ipywidget-background div.PSPContainer {
4042
min-height: 520px;
43+
height: 520px;
4144
}
4245

4346
div.PSPContainer perspective-viewer[theme="Pro Light"] {

0 commit comments

Comments
 (0)