MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / translateDisplayDataOutput

Function translateDisplayDataOutput

src/kernels/execution/helpers.ts:242–284  ·  view source on GitHub ↗

* Converts a Jupyter display cell output into a VSCode cell output format. * Handles sizing, adding backgrounds to images and the like. * E.g. Jupyter cell output contains metadata to add backgrounds to images.

(
    output: nbformat.IDisplayData | nbformat.IDisplayUpdate | nbformat.IExecuteResult,
    cellIndex?: number,
    cellId?: string,
    cellMetadata?: Record<string, unknown>
)

Source from the content-addressed store, hash-verified

240 * E.g. Jupyter cell output contains metadata to add backgrounds to images.
241 */
242function translateDisplayDataOutput(
243 output: nbformat.IDisplayData | nbformat.IDisplayUpdate | nbformat.IExecuteResult,
244 cellIndex?: number,
245 cellId?: string,
246 cellMetadata?: Record<string, unknown>
247): NotebookCellOutput {
248 // Metadata could be as follows:
249 // We'll have metadata specific to each mime type as well as generic metadata.
250 /*
251 IDisplayData = {
252 output_type: 'display_data',
253 data: {
254 'image/jpg': '/////'
255 'image/png': '/////'
256 'text/plain': '/////'
257 },
258 metadata: {
259 'image/png': '/////',
260 'background': true,
261 'xyz': '///
262 }
263 }
264 */
265 const deepnotePocket = cellMetadata?.__deepnotePocket as Pocket | undefined;
266 const deepnoteBlockType = deepnotePocket?.type;
267
268 const metadata = getOutputMetadata(output, cellIndex, cellId, cellMetadata);
269 // If we have SVG or PNG, then add special metadata to indicate whether to display `open plot`
270 if ('image/svg+xml' in output.data || 'image/png' in output.data) {
271 metadata.__displayOpenPlotIcon = true;
272 }
273 const items: NotebookCellOutputItem[] = [];
274 if (output.data) {
275 // eslint-disable-next-line no-restricted-syntax
276 for (const key in output.data) {
277 // TODO - remove this once this is handled in the deepnote-toolkit
278 let effectiveKey = deepnoteBlockType === 'big-number' ? CHART_BIG_NUMBER_MIME_TYPE : key;
279 items.push(convertJupyterOutputToBuffer(effectiveKey, output.data[key] ?? output.data[effectiveKey]));
280 }
281 }
282
283 return new NotebookCellOutput(sortOutputItemsBasedOnDisplayOrder(items), metadata);
284}
285
286function translateStreamOutput(
287 output: nbformat.IStream,

Callers 1

Calls 4

getOutputMetadataFunction · 0.85
pushMethod · 0.65

Tested by

no test coverage detected