Skip to content

Commit f15fed6

Browse files
committed
Enable render of legacy vega-lite outputs
1 parent 4a187b2 commit f15fed6

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,7 @@
21432143
"fs-extra": "^4.0.3",
21442144
"glob": "^7.1.2",
21452145
"iconv-lite": "^0.6.3",
2146+
"immer": "^10.1.3",
21462147
"inversify": "^6.0.1",
21472148
"isomorphic-ws": "^4.0.1",
21482149
"jquery": "^3.6.0",

src/notebooks/deepnote/deepnoteDataConverter.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import { addPocketToCellMetadata, createBlockFromPocket } from './pocket';
99
import { TextBlockConverter } from './converters/textBlockConverter';
1010
import { MarkdownBlockConverter } from './converters/markdownBlockConverter';
1111
import { VisualizationBlockConverter } from './converters/visualizationBlockConverter';
12+
import { compile as convertVegaLiteSpecToVega } from 'vega-lite';
13+
import { produce } from 'immer';
14+
import type { Field } from 'vega-lite/build/src/channeldef';
15+
import type { LayerSpec, TopLevel } from 'vega-lite/build/src/spec';
1216

1317
/**
1418
* Utility class for converting between Deepnote block structures and VS Code notebook cells.
@@ -295,6 +299,26 @@ export class DeepnoteDataConverter {
295299
);
296300
}
297301

302+
if (data['application/vnd.vegalite.v5+json']) {
303+
const patchedVegaLiteSpec = produce(
304+
data['application/vnd.vegalite.v5+json'] as TopLevel<LayerSpec<Field>>,
305+
(draft) => {
306+
draft.height = 'container';
307+
draft.width = 'container';
308+
309+
draft.autosize = {
310+
type: 'fit'
311+
};
312+
if (!draft.config) {
313+
draft.config = {};
314+
}
315+
draft.config.customFormatTypes = true;
316+
}
317+
);
318+
const vegaSpec = convertVegaLiteSpecToVega(patchedVegaLiteSpec).spec;
319+
items.push(NotebookCellOutputItem.json(vegaSpec, 'application/vnd.vega.v5+json'));
320+
}
321+
298322
if (data['application/json']) {
299323
items.push(NotebookCellOutputItem.json(data['application/json'], 'application/json'));
300324
}

0 commit comments

Comments
 (0)