-
Notifications
You must be signed in to change notification settings - Fork 4
feat(charts): Add visualization blocks support #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9ec77aa
feat(charts): Add visualization blocks support
OlegWock 22e9044
Merge branch 'main' into oleh/grn-4778-support-chart-blocks
OlegWock 2385420
Fix typing issues
OlegWock 64761dd
Fix formatting
OlegWock 75ce3a2
Fix tests
OlegWock c695b8d
Update according to rabbit comments
OlegWock be08703
Cleanup
OlegWock 4a187b2
Set cell language to JSON
OlegWock f15fed6
Enable render of legacy vega-lite outputs
OlegWock bed6e2a
Merge branch 'main' into oleh/grn-4778-support-chart-blocks
OlegWock edc90da
Fix test
OlegWock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/notebooks/deepnote/converters/visualizationBlockConverter.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| 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_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, 'JSON'); | ||
|
|
||
| return cell; | ||
| } | ||
|
|
||
| getSupportedTypes(): string[] { | ||
| return ['visualization']; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.