From cc6dea0631fd8a21df72d90abc0a61bec59d132d Mon Sep 17 00:00:00 2001 From: Kevin Cunnane Date: Tue, 2 Jul 2019 18:08:38 -0700 Subject: [PATCH] Add Plotly output support to notebooks With this change, Plotly types will be successfully rendered in a Notebook. Currently they have a default width of 700px with a scrollbar if the window size is smaller (this matches other notebook viewers). The Plotly library is dynamically required to avoid startup time perf hits. This is something we could look at for other components too. --- package.json | 2 + src/bootstrap-window.js | 3 +- .../parts/notebook/cellViews/media/output.css | 5 + .../parts/notebook/notebook.contribution.ts | 26 +- .../outputs/plotlyOutput.component.ts | 157 ++ src/typings/index.d.ts | 1 + .../modules/@types/plotly.js-dist/index.d.ts | 1423 +++++++++++++++++ yarn.lock | 17 + 8 files changed, 1631 insertions(+), 3 deletions(-) create mode 100644 src/sql/workbench/parts/notebook/outputs/plotlyOutput.component.ts create mode 100644 src/typings/modules/@types/plotly.js-dist/index.d.ts diff --git a/package.json b/package.json index 1c630d5ae2..8c7f2a8edd 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "@angular/platform-browser-dynamic": "~4.1.3", "@angular/router": "~4.1.3", "@angular/upgrade": "~4.1.3", + "@types/plotly.js": "^1.44.9", "angular2-grid": "2.0.6", "angular2-slickgrid": "github:Microsoft/angular2-slickgrid#1.4.6", "ansi_up": "^3.0.0", @@ -60,6 +61,7 @@ "native-watchdog": "1.0.0", "ng2-charts": "^1.6.0", "node-pty": "0.9.0-beta9", + "plotly.js-dist": "^1.48.3", "reflect-metadata": "^0.1.8", "rxjs": "5.4.0", "sanitize-html": "^1.19.1", diff --git a/src/bootstrap-window.js b/src/bootstrap-window.js index b1d54acd3c..ae00a364c9 100644 --- a/src/bootstrap-window.js +++ b/src/bootstrap-window.js @@ -121,7 +121,8 @@ exports.load = function (modulePaths, resultCallback, options) { 'rxjs/Subject', 'rxjs/Observer', 'htmlparser2', - 'sanitize' + 'sanitize', + 'plotly.js-dist' ]); // {{SQL CARBON EDIT}} - End diff --git a/src/sql/workbench/parts/notebook/cellViews/media/output.css b/src/sql/workbench/parts/notebook/cellViews/media/output.css index 9b56567c70..b90be6ab6e 100644 --- a/src/sql/workbench/parts/notebook/cellViews/media/output.css +++ b/src/sql/workbench/parts/notebook/cellViews/media/output.css @@ -463,3 +463,8 @@ output-component .jp-RenderedHTMLCommon > *:last-child { .jp-RenderedPDF { font-size: var(--jp-ui-font-size1); } + +plotly-output .plotly-wrapper { + display: block; + overflow-y: hidden; +} diff --git a/src/sql/workbench/parts/notebook/notebook.contribution.ts b/src/sql/workbench/parts/notebook/notebook.contribution.ts index 437ddd4942..72f5a22301 100644 --- a/src/sql/workbench/parts/notebook/notebook.contribution.ts +++ b/src/sql/workbench/parts/notebook/notebook.contribution.ts @@ -19,6 +19,7 @@ import product from 'vs/platform/product/node/product'; import { registerComponentType } from 'sql/workbench/parts/notebook/outputs/mimeRegistry'; import { MimeRendererComponent as MimeRendererComponent } from 'sql/workbench/parts/notebook/outputs/mimeRenderer.component'; import { MarkdownOutputComponent } from 'sql/workbench/parts/notebook/outputs/markdownOutput.component'; +import { PlotlyOutputComponent } from 'sql/workbench/parts/notebook/outputs/plotlyOutput.component'; // Model View editor registration const viewModelEditorDescriptor = new EditorDescriptor( @@ -138,7 +139,6 @@ registerComponentType({ /** * A mime renderer component for LaTeX. - * This will be replaced by a dedicated component in the future */ registerComponentType({ mimeTypes: ['text/latex'], @@ -150,7 +150,6 @@ registerComponentType({ /** * A mime renderer component for Markdown. - * This will be replaced by a dedicated component in the future */ registerComponentType({ mimeTypes: ['text/markdown'], @@ -159,3 +158,26 @@ registerComponentType({ ctor: MarkdownOutputComponent, selector: MarkdownOutputComponent.SELECTOR }); + +/** + * A mime renderer component for Plotly graphs. + */ +registerComponentType({ + mimeTypes: ['application/vnd.plotly.v1+json'], + rank: 45, + safe: true, + ctor: PlotlyOutputComponent, + selector: PlotlyOutputComponent.SELECTOR +}); +/** + * A mime renderer component for Plotly HTML output + * that will ensure this gets ignored if possible since it's only output + * on offline init and adds a