Skip to content

Commit 067f757

Browse files
committed
Merge remote-tracking branch 'origin/main' into tomaskislan/grn-4762-support-big-number-blocks
2 parents 68567e0 + f5cec10 commit 067f757

File tree

11 files changed

+2325
-148
lines changed

11 files changed

+2325
-148
lines changed

build/esbuild/build.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ async function buildAll() {
343343
),
344344
{ target: 'web', watch: isWatchMode }
345345
),
346+
build(
347+
path.join(extensionFolder, 'src', 'webviews', 'webview-side', 'vega-renderer', 'index.ts'),
348+
path.join(extensionFolder, 'dist', 'webviews', 'webview-side', 'vegaRenderer', 'vegaRenderer.js'),
349+
{ target: 'web', watch: isWatchMode }
350+
),
346351
build(
347352
path.join(extensionFolder, 'src', 'webviews', 'webview-side', 'variable-view', 'index.tsx'),
348353
path.join(extensionFolder, 'dist', 'webviews', 'webview-side', 'viewers', 'variableView.js'),

package-lock.json

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

package.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,17 @@
18541854
"entrypoint": "./dist/webviews/webview-side/chartBigNumberRenderer/chartBigNumberRenderer.js",
18551855
"mimeTypes": [
18561856
"application/vnd.deepnote.chart.big-number+json"
1857-
]
1857+
],
1858+
"requiresMessaging": "optional"
1859+
},
1860+
{
1861+
"id": "deepnote-vega-renderer",
1862+
"displayName": "Deepnote Vega Chart Renderer",
1863+
"entrypoint": "./dist/webviews/webview-side/vegaRenderer/vegaRenderer.js",
1864+
"mimeTypes": [
1865+
"application/vnd.vega.v5+json"
1866+
],
1867+
"requiresMessaging": "optional"
18581868
}
18591869
],
18601870
"viewsContainers": {
@@ -2170,12 +2180,14 @@
21702180
"bootstrap-less": "^3.3.8",
21712181
"clsx": "^2.1.1",
21722182
"cross-fetch": "^3.1.5",
2183+
"d3-format": "^3.1.0",
21732184
"encoding": "^0.1.13",
21742185
"fast-deep-equal": "^2.0.1",
21752186
"format-util": "^1.0.5",
21762187
"fs-extra": "^4.0.3",
21772188
"glob": "^7.1.2",
21782189
"iconv-lite": "^0.6.3",
2190+
"immer": "^10.1.3",
21792191
"inversify": "^6.0.1",
21802192
"isomorphic-ws": "^4.0.1",
21812193
"jquery": "^3.6.0",
@@ -2195,6 +2207,7 @@
21952207
"react-redux": "^7.1.1",
21962208
"react-svg-pan-zoom": "3.9.0",
21972209
"react-svgmt": "1.1.11",
2210+
"react-vega": "^7.7.1",
21982211
"react-virtualized": "^9.21.1",
21992212
"redux": "^4.0.4",
22002213
"redux-logger": "^3.0.6",
@@ -2211,6 +2224,9 @@
22112224
"tcp-port-used": "^1.0.1",
22122225
"tmp": "^0.2.4",
22132226
"url-parse": "^1.5.10",
2227+
"vega": "^5.33.0",
2228+
"vega-embed": "^6.25.0",
2229+
"vega-lite": "^5.21.0",
22142230
"vscode-debugprotocol": "^1.41.0",
22152231
"vscode-languageclient": "8.0.2-next.5",
22162232
"vscode-tas-client": "^0.1.84",
@@ -2232,6 +2248,7 @@
22322248
"@types/chai-arrays": "^2.0.1",
22332249
"@types/chai-as-promised": "^7.1.6",
22342250
"@types/cors": "^2.8.6",
2251+
"@types/d3-format": "^3.0.4",
22352252
"@types/debug": "^4.1.5",
22362253
"@types/dedent": "^0.7.0",
22372254
"@types/del": "^4.0.0",

src/kernels/execution/cellExecution.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ import { KernelError } from '../errors/kernelError';
3333
import { getCachedSysPrefix } from '../../platform/interpreter/helpers';
3434
import { getCellMetadata } from '../../platform/common/utils';
3535
import { NotebookCellExecutionState, notebookCellExecutions } from '../../platform/notebooks/cellExecutionStateService';
36-
import { createBlockFromPocket } from '../../platform/deepnote/pocket';
37-
import { DeepnoteBigNumberMetadataSchema } from '../../notebooks/deepnote/deepnoteSchemas';
36+
import { DeepnoteDataConverter } from '../../notebooks/deepnote/deepnoteDataConverter';
3837

3938
/**
4039
* Factory for CellExecution objects.
@@ -417,25 +416,26 @@ export class CellExecution implements ICellExecution, IDisposable {
417416
metadata: this.cell.metadata,
418417
outputs: [...(this.cell.outputs || [])]
419418
};
420-
const deepnoteBlock = createBlockFromPocket(cellData, this.cell.index);
421419

422-
if (deepnoteBlock.type === 'big-number') {
423-
try {
424-
deepnoteBlock.metadata = {
425-
...deepnoteBlock.metadata,
426-
...DeepnoteBigNumberMetadataSchema.parse(JSON.parse(deepnoteBlock.content || '{}'))
427-
};
428-
} catch (ex) {
429-
logger.error(
430-
`Cell execution failed to parse big number metadata, for cell Index ${this.cell.index}`,
431-
ex
432-
);
433-
return this.completedWithErrors(ex);
434-
}
435-
}
420+
// if (deepnoteBlock.type === 'big-number') {
421+
// try {
422+
// deepnoteBlock.metadata = {
423+
// ...deepnoteBlock.metadata,
424+
// ...DeepnoteBigNumberMetadataSchema.parse(JSON.parse(deepnoteBlock.content || '{}'))
425+
// };
426+
// } catch (ex) {
427+
// logger.error(
428+
// `Cell execution failed to parse big number metadata, for cell Index ${this.cell.index}`,
429+
// ex
430+
// );
431+
// return this.completedWithErrors(ex);
432+
// }
433+
// }
434+
435+
const dataConverter = new DeepnoteDataConverter();
436+
const deepnoteBlock = dataConverter.convertCellToBlock(cellData, this.cell.index);
436437

437-
// Use createPythonCode to generate code with table state already included
438-
logger.info(`Cell ${this.cell.index}: Using createPythonCode to generate execution code with table state`);
438+
logger.info(`Cell ${this.cell.index}: Using createPythonCode for ${deepnoteBlock.type} block`);
439439
code = createPythonCode(deepnoteBlock);
440440

441441
// Generate metadata from our cell (some kernels expect this.)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { NotebookCellData, NotebookCellKind } from 'vscode';
2+
3+
import type { BlockConverter } from './blockConverter';
4+
import type { DeepnoteBlock } from '../deepnoteTypes';
5+
6+
type DataframeFilter = {
7+
column: string;
8+
operator:
9+
| 'is-equal'
10+
| 'is-not-equal'
11+
| 'is-one-of'
12+
| 'is-not-one-of'
13+
| 'is-not-null'
14+
| 'is-null'
15+
| 'text-contains'
16+
| 'text-does-not-contain'
17+
| 'greater-than'
18+
| 'greater-than-or-equal'
19+
| 'less-than'
20+
| 'less-than-or-equal'
21+
| 'between'
22+
| 'outside-of'
23+
| 'is-relative-today'
24+
| 'is-after'
25+
| 'is-before'
26+
| 'is-on';
27+
comparativeValues: string[];
28+
};
29+
30+
interface FilterMetadata {
31+
/** @deprecated Use advancedFilters instead */
32+
filter?: unknown;
33+
advancedFilters?: DataframeFilter[];
34+
}
35+
36+
interface VisualizationCellMetadata {
37+
deepnote_variable_name?: string;
38+
deepnote_visualization_spec?: Record<string, unknown>;
39+
deepnote_chart_filter?: FilterMetadata;
40+
}
41+
42+
/**
43+
* Converter for Deepnote visualization blocks (chart blocks).
44+
* Displays blocks as editable JSON with variable name, spec, and filters.
45+
* The JSON is converted to Python code at execution time.
46+
*/
47+
export class VisualizationBlockConverter implements BlockConverter {
48+
applyChangesToBlock(block: DeepnoteBlock, cell: NotebookCellData): void {
49+
block.content = '';
50+
51+
// Parse the JSON from the cell to update metadata
52+
try {
53+
const config = JSON.parse(cell.value || '{}');
54+
55+
block.metadata = {
56+
...block.metadata,
57+
deepnote_variable_name: config.variable || '',
58+
deepnote_visualization_spec: config.spec || {},
59+
deepnote_chart_filter: {
60+
advancedFilters: config.filters || []
61+
}
62+
};
63+
} catch (error) {
64+
// If JSON parsing fails, leave metadata unchanged
65+
console.warn('Failed to parse visualization JSON:', error);
66+
}
67+
}
68+
69+
canConvert(blockType: string): boolean {
70+
return blockType.toLowerCase() === 'visualization';
71+
}
72+
73+
convertToCell(block: DeepnoteBlock): NotebookCellData {
74+
const metadata = block.metadata as VisualizationCellMetadata | undefined;
75+
const variableName = metadata?.deepnote_variable_name || 'df';
76+
const spec = metadata?.deepnote_visualization_spec || {};
77+
const filters = metadata?.deepnote_chart_filter?.advancedFilters || [];
78+
79+
// Create a clean JSON representation that users can edit
80+
const config = {
81+
variable: variableName,
82+
spec: spec,
83+
filters: filters
84+
};
85+
86+
const jsonContent = JSON.stringify(config, null, 2);
87+
const cell = new NotebookCellData(NotebookCellKind.Code, jsonContent, 'JSON');
88+
89+
return cell;
90+
}
91+
92+
getSupportedTypes(): string[] {
93+
return ['visualization'];
94+
}
95+
}

0 commit comments

Comments
 (0)