Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build/esbuild/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ async function buildAll() {
path.join(extensionFolder, 'dist', 'webviews', 'webview-side', 'dataframeRenderer', 'dataframeRenderer.js'),
{ target: 'web', watch: isWatchMode }
),
build(
path.join(extensionFolder, 'src', 'webviews', 'webview-side', 'vega-renderer', 'index.ts'),
path.join(extensionFolder, 'dist', 'webviews', 'webview-side', 'vegaRenderer', 'vegaRenderer.js'),
{ target: 'web', watch: isWatchMode }
),
build(
path.join(extensionFolder, 'src', 'webviews', 'webview-side', 'variable-view', 'index.tsx'),
path.join(extensionFolder, 'dist', 'webviews', 'webview-side', 'viewers', 'variableView.js'),
Expand Down
1,716 changes: 1,621 additions & 95 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,15 @@
"application/vnd.deepnote.dataframe.v3+json"
],
"requiresMessaging": "optional"
},
{
"id": "deepnote-vega-renderer",
"displayName": "Deepnote Vega Chart Renderer",
"entrypoint": "./dist/webviews/webview-side/vegaRenderer/vegaRenderer.js",
"mimeTypes": [
"application/vnd.vega.v5+json"
],
"requiresMessaging": "optional"
}
],
"viewsContainers": {
Expand Down Expand Up @@ -2127,6 +2136,7 @@
"bootstrap-less": "^3.3.8",
"clsx": "^2.1.1",
"cross-fetch": "^3.1.5",
"d3-format": "^3.1.0",
"encoding": "^0.1.13",
"fast-deep-equal": "^2.0.1",
"format-util": "^1.0.5",
Expand All @@ -2152,6 +2162,7 @@
"react-redux": "^7.1.1",
"react-svg-pan-zoom": "3.9.0",
"react-svgmt": "1.1.11",
"react-vega": "^7.7.1",
"react-virtualized": "^9.21.1",
"redux": "^4.0.4",
"redux-logger": "^3.0.6",
Expand All @@ -2168,6 +2179,9 @@
"tcp-port-used": "^1.0.1",
"tmp": "^0.2.4",
"url-parse": "^1.5.10",
"vega": "^5.33.0",
"vega-embed": "^6.25.0",
"vega-lite": "^5.21.0",
"vscode-debugprotocol": "^1.41.0",
"vscode-languageclient": "8.0.2-next.5",
"vscode-tas-client": "^0.1.84",
Expand All @@ -2188,6 +2202,7 @@
"@types/chai-arrays": "^2.0.1",
"@types/chai-as-promised": "^7.1.6",
"@types/cors": "^2.8.6",
"@types/d3-format": "^3.0.4",
"@types/debug": "^4.1.5",
"@types/dedent": "^0.7.0",
"@types/del": "^4.0.0",
Expand Down
9 changes: 5 additions & 4 deletions src/kernels/execution/cellExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import { KernelError } from '../errors/kernelError';
import { getCachedSysPrefix } from '../../platform/interpreter/helpers';
import { getCellMetadata } from '../../platform/common/utils';
import { NotebookCellExecutionState, notebookCellExecutions } from '../../platform/notebooks/cellExecutionStateService';
import { createBlockFromPocket } from '../../notebooks/deepnote/pocket';
import { createPythonCode } from '@deepnote/blocks';
import { DeepnoteDataConverter } from '../../notebooks/deepnote/deepnoteDataConverter';

/**
* Factory for CellExecution objects.
Expand Down Expand Up @@ -416,10 +416,11 @@ export class CellExecution implements ICellExecution, IDisposable {
metadata: this.cell.metadata,
outputs: [...(this.cell.outputs || [])]
};
const deepnoteBlock = createBlockFromPocket(cellData, this.cell.index);

// Use createPythonCode to generate code with table state already included
logger.info(`Cell ${this.cell.index}: Using createPythonCode to generate execution code with table state`);
const dataConverter = new DeepnoteDataConverter();
const deepnoteBlock = dataConverter.convertCellToBlock(cellData, this.cell.index);

logger.info(`Cell ${this.cell.index}: Using createPythonCode for ${deepnoteBlock.type} block`);
code = createPythonCode(deepnoteBlock);

// Generate metadata from our cell (some kernels expect this.)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { NotebookCellData, NotebookCellKind } from 'vscode';

import type { BlockConverter } from './blockConverter';
import type { DeepnoteBlock } from '../deepnoteTypes';

type DataframeFilter = {
column: string;
operator:
| 'is-equal'
| 'is-not-equal'
| 'is-one-of'
| 'is-not-one-of'
| 'is-not-null'
| 'is-null'
| 'text-contains'
| 'text-does-not-contain'
| 'greater-than'
| 'greater-than-or-equal'
| 'less-than'
| 'less-than-or-equal'
| 'between'
| 'outside-of'
| 'is-relative-today'
| 'is-after'
| 'is-before'
| 'is-on';
comparativeValues: string[];
};

interface FilterMetadata {
/** @deprecated Use advancedFilters instead */
filter?: unknown;
advancedFilters?: DataframeFilter[];
}

interface VisualizationCellMetadata {
deepnote_variable_name?: string;
deepnote_visualization_spec?: Record<string, unknown>;
deepnote_config_collapsed?: boolean;
deepnote_chart_height?: number;
deepnote_chart_filter?: FilterMetadata;
}

/**
* Converter for Deepnote visualization blocks (chart blocks).
* Displays blocks as editable JSON with variable name, spec, and filters.
* The JSON is converted to Python code at execution time.
*/
export class VisualizationBlockConverter implements BlockConverter {
applyChangesToBlock(block: DeepnoteBlock, cell: NotebookCellData): void {
block.content = '';

// Parse the JSON from the cell to update metadata
try {
const config = JSON.parse(cell.value || '{}');

block.metadata = {
...block.metadata,
deepnote_variable_name: config.variable || '',
deepnote_visualization_spec: config.spec || {},
deepnote_chart_filter: {
advancedFilters: config.filters || []
}
};
} catch (error) {
// If JSON parsing fails, leave metadata unchanged
console.warn('Failed to parse visualization JSON:', error);
}
}

canConvert(blockType: string): boolean {
return blockType.toLowerCase() === 'visualization';
}

convertToCell(block: DeepnoteBlock): NotebookCellData {
const metadata = block.metadata as VisualizationCellMetadata | undefined;
const variableName = metadata?.deepnote_variable_name || 'df';
const spec = metadata?.deepnote_visualization_spec || {};
const filters = metadata?.deepnote_chart_filter?.advancedFilters || [];

// Create a clean JSON representation that users can edit
const config = {
variable: variableName,
spec: spec,
filters: filters
};

const jsonContent = JSON.stringify(config, null, 2);
const cell = new NotebookCellData(NotebookCellKind.Code, jsonContent, 'python');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting Python here makes VSC show linting errors (e.g. false is unknown variable), but setting it as JSON blocks us from intercepting its execution, not sure why


return cell;
}

getSupportedTypes(): string[] {
return ['visualization'];
}
}
Loading