Skip to content

Commit 888b1d2

Browse files
committed
Display tensorflow vis panel only when used
1 parent dc26c61 commit 888b1d2

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@
184184
{
185185
"name": "Tensorflow Visualization",
186186
"id": "tfjs-vis",
187-
"type": "webview"
187+
"type": "webview",
188+
"when": "node_notebook.tfjs-vis.used && !config.node_notebook.disableTensorflowVis"
188189
}
189190
]
190191
},
@@ -232,6 +233,12 @@
232233
"description": "Register ts-node that allows importing TypeScript modules without the user having to transpile TypeScript into JavaScript.",
233234
"scope": "machine"
234235
},
236+
"node_notebook.disableTensorflowVis": {
237+
"type": "boolean",
238+
"default": false,
239+
"description": "Disables the Tensorflow Visualization panel (even if @tensorflow/tfjs-vis is used the panel will not be displayed.",
240+
"scope": "machine"
241+
},
235242
"node_notebook.disablePseudoTerminal": {
236243
"type": "boolean",
237244
"default": false,

src/client/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@ import { renderHeatmap, renderLayer, valuesDistribution } from './common';
1010
console.log('Inside VIS');
1111
const api = acquireVsCodeApi();
1212
window.addEventListener('message', (e) => onMessage(e.data));
13-
api.postMessage({ type: 'loaded', data: 'Hi' });
14-
api.postMessage({ type: 'initialized' });
13+
api.postMessage({ type: 'loaded' });
1514

1615
function onMessage(data?: { _type?: 'helloWorld' } | TensorFlowVis | any) {
1716
if (!data || !data.type) {
1817
return;
1918
}
2019
switch (data.type) {
21-
case 'helloWorld':
22-
api.postMessage({ type: 'helloBack', data: 'Something' });
23-
break;
2420
case 'tensorFlowVis': {
2521
handleTensorFlowMessage(data);
2622
}

src/extension/content/provider.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,5 @@ function outputToStorageFormat(output: NotebookCellOutput): CellOutput {
163163
}
164164
function storageFormatToOutput(output: CellOutput): NotebookCellOutput {
165165
const items = output.items.map(storageFormatToOutputItem);
166-
return {
167-
items
168-
};
166+
return new NotebookCellOutput(items);
169167
}

src/extension/tfjsvis/index.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,30 @@ import { TensorFlowVis } from '../server/types';
33
import { registerDisposable } from '../utils';
44

55
const viewType = 'tfjs-vis';
6+
function shouldShowPanel(request: TensorFlowVis['request']) {
7+
switch (request) {
8+
case 'registerfitcallback':
9+
case 'fitcallback':
10+
return false;
11+
default:
12+
return true;
13+
}
14+
}
615
export class TensorflowVisClient implements WebviewViewProvider {
716
private static view?: WebviewView;
817
private static cachedMessages: TensorFlowVis[] = [];
18+
private static viewVisibilitySet?: boolean;
919

1020
constructor(private readonly extensionUri: Uri) {}
1121
public static sendMessage(message: TensorFlowVis) {
1222
TensorflowVisClient.sendMessageInternal(message);
1323
}
1424
private static async sendMessageInternal(message: TensorFlowVis) {
15-
if (!TensorflowVisClient.view && message.request === 'show') {
16-
await commands.executeCommand(`${viewType}.focus`);
17-
} else if (!TensorflowVisClient.view && message.type === 'tensorFlowVis') {
25+
if (!TensorflowVisClient.view && shouldShowPanel(message.request)) {
26+
void commands.executeCommand('setContext', 'node_notebook.tfjs-vis.used', true);
1827
await commands.executeCommand(`${viewType}.focus`);
1928
}
20-
if (message.request == 'show' && TensorflowVisClient.view) {
29+
if (shouldShowPanel(message.request) && TensorflowVisClient.view) {
2130
if (!TensorflowVisClient.view.visible) {
2231
TensorflowVisClient.view.show(true);
2332
}
@@ -27,15 +36,15 @@ export class TensorflowVisClient implements WebviewViewProvider {
2736
TensorflowVisClient.sendMessages();
2837
}
2938
private static sendMessages() {
30-
if (!TensorflowVisClient.view) {
39+
if (!TensorflowVisClient.view || !TensorflowVisClient.viewVisibilitySet) {
3140
return;
3241
}
3342
while (TensorflowVisClient.cachedMessages.length) {
3443
const message = TensorflowVisClient.cachedMessages.shift();
3544
if (!message) {
3645
continue;
3746
}
38-
if (message.request == 'show') {
47+
if (shouldShowPanel(message.request)) {
3948
if (!TensorflowVisClient.view.visible) {
4049
TensorflowVisClient.view.show(true);
4150
}
@@ -66,17 +75,10 @@ export class TensorflowVisClient implements WebviewViewProvider {
6675

6776
webviewView.webview.onDidReceiveMessage((data) => {
6877
switch (data.type) {
69-
case 'helloBack': {
70-
window.showInformationMessage(data.data);
71-
break;
72-
}
73-
case 'initialized': {
74-
window.showInformationMessage(data.data);
78+
case 'loaded': {
79+
TensorflowVisClient.viewVisibilitySet = true;
7580
TensorflowVisClient.sendMessages();
76-
break;
77-
}
78-
case 'clicked': {
79-
window.showInformationMessage(data.data);
81+
8082
break;
8183
}
8284
case 'tensorFlowVis': {

0 commit comments

Comments
 (0)