Skip to content
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

Default plots to PNG output, and support showing PNGs or SVGs in the existing PlotViewer control #7140

Merged
merged 15 commits into from
Aug 18, 2021

Conversation

IanMatthewHuff
Copy link
Member

@IanMatthewHuff IanMatthewHuff commented Aug 14, 2021

For #6913

  • Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR).
  • Title summarizes what is changing.
  • Has a news entry file (remember to thank yourself!).
  • Appropriate comments and documentation strings in the code.
  • Has sufficient logging.
  • Has telemetry for enhancements.
  • Unit tests & system/integration tests are added/updated.
  • Test plan is updated as appropriate.
  • package-lock.json has been regenerated by running npm install (if dependencies have changed).

@@ -1809,8 +1809,8 @@
},
"jupyter.enablePlotViewer": {
"type": "boolean",
"default": true,
"description": "Modify plot output so that it can be expanded into a plot viewer window.",
"default": false,
Copy link
Member Author

Choose a reason for hiding this comment

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

We might need to discuss this. I feel that customers might still want the old behavior, so I left the setting in, but defaulted it to false instead of true, so they can opt into getting the extra SVGs if they want. My code will prefer SVG output to any PNG output if present.

export const MatplotLibInitSvg = `import matplotlib\n%matplotlib inline\n${Identifiers.MatplotLibDefaultParams} = dict(matplotlib.rcParams)\n%config InlineBackend.figure_formats = ['svg', 'png']`;
export const MatplotLibInitPng = `import matplotlib\n%matplotlib inline\n${Identifiers.MatplotLibDefaultParams} = dict(matplotlib.rcParams)\n%config InlineBackend.figure_formats = ['png']`;
export const ConfigSvg = `%config InlineBackend.figure_formats = ['svg', 'png']`;
export const ConfigPng = `%config InlineBackend.figure_formats = ['png']`;
Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like this has been broken for a long time / forever? For multiples it seems to take {} or [], but for the singular it can't:
image
Docs are a little funny on this, they say set, but the example uses a list?
image

Guessing we didn't notice this before as png is Jupyter default I'm pretty sure. So it would fail to run, but then just get PNG anyways from the Jupyter default.

@@ -821,6 +823,16 @@ export class JupyterNotebookBase implements INotebook {
// get a request to update style
await this.executeSilently(matplobInit, cancelToken);

const useDark = this.applicationService.activeColorTheme.kind === ColorThemeKind.Dark;
Copy link
Member Author

Choose a reason for hiding this comment

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

This code was in the kernel.ts version, but not here so I added it as it looks correct for native theming.

!isResourceNativeNotebook(this._resource, this.vscNotebook, this.fs)
? CodeSnippets.ConfigSvg
: CodeSnippets.ConfigPng;
settings && settings.enablePlotViewer ? CodeSnippets.ConfigSvg : CodeSnippets.ConfigPng;
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the !isResourceNativeNotebook as Native notebooks can now use the setting to opt into getting the SVGs if they want.

This code also doesn't look to have worked before. The check for isNativeNotebook was here, but not in the kernel.ts version. So this init would run first and set to [png] then the init in the native kernel.ts code would run and set to [png, svg] so native notebooks were always getting the SVGs unless the setting was off.

@IanMatthewHuff IanMatthewHuff marked this pull request as ready for review August 14, 2021 20:59
@IanMatthewHuff IanMatthewHuff requested a review from a team as a code owner August 14, 2021 20:59
@codecov-commenter
Copy link

codecov-commenter commented Aug 14, 2021

Codecov Report

Merging #7140 (0d221f3) into main (4b45024) will decrease coverage by 0%.
The diff coverage is 46%.

@@          Coverage Diff          @@
##            main   #7140   +/-   ##
=====================================
- Coverage     64%     64%   -1%     
=====================================
  Files        362     362           
  Lines      22887   22879    -8     
  Branches    3430    3431    +1     
=====================================
- Hits       14825   14777   -48     
- Misses      6751    6799   +48     
+ Partials    1311    1303    -8     
Impacted Files Coverage Δ
...ent/datascience/jupyter/kernels/kernelExecution.ts 59% <ø> (-1%) ⬇️
...tascience/jupyter/liveshare/hostJupyterNotebook.ts 55% <ø> (ø)
...datascience/jupyter/liveshare/hostJupyterServer.ts 70% <ø> (-1%) ⬇️
...ce/raw-kernel/liveshare/hostRawNotebookProvider.ts 77% <ø> (-1%) ⬇️
src/client/datascience/types.ts 100% <ø> (ø)
...nt/datascience/notebook/outputs/plotViewHandler.ts 25% <14%> (-5%) ⬇️
src/client/datascience/jupyter/kernels/kernel.ts 61% <44%> (-2%) ⬇️
src/client/datascience/jupyter/jupyterNotebook.ts 46% <57%> (-4%) ⬇️
src/client/datascience/constants.ts 99% <100%> (ø)
...ient/datascience/jupyter/kernels/kernelProvider.ts 95% <100%> (+<1%) ⬆️
... and 15 more

@@ -2095,6 +2095,7 @@
"glob": "^7.1.2",
"hash.js": "^1.1.7",
"iconv-lite": "^0.4.21",
"image-size": "^1.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

@DonJayamanne image-size was added here.

Copy link
Contributor

@DonJayamanne DonJayamanne left a comment

Choose a reason for hiding this comment

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

Please move initialization into Kernel, else rest if great.

@@ -287,93 +283,6 @@ export class JupyterNotebookBase implements INotebook {
return this.session ? this.session.waitForIdle(timeoutMs) : Promise.resolve();
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Intialize code (working dir / startup commands / plot init) now all moved from Notebook into Kernel.

Copy link
Member Author

Choose a reason for hiding this comment

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

Gave a quick peek with notebooks and IW. Startup command, new working directory, and plots all looked good after a notebook start as well as after a kernel restart.

Copy link
Member Author

Choose a reason for hiding this comment

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

@DonJayamanne could you take a re-look? It's still blocked on the change requested.

@IanMatthewHuff
Copy link
Member Author

@DavidKutu @rchiodo Tagged for a re-review since I made a big bigger change to move init code only into Kernel versus Notebook.

@IanMatthewHuff IanMatthewHuff merged commit e8c763b into main Aug 18, 2021
@IanMatthewHuff IanMatthewHuff deleted the dev/ianhu/imagePlotViewerSupport branch August 18, 2021 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants