njpipeorgan / wolfram-language-notebook

Notebook support for Wolfram Language in VS Code
Apache License 2.0
159 stars 11 forks source link

notebook cell output showing wrong colors #23

Closed The3DWizard closed 2 years ago

The3DWizard commented 2 years ago

First, let me thank you for this great extension. I have been looking for something like this for quite some time. And now to the problem :) ...

Describe the bug Colors seem to be presented wrong. Let's say I want to do a simple Plot and have a Red Background using Plot[Sin[x], {x, 1, 2*Pi}, Background->Red] I get the image shown below. The image clearly does not show a pure red background. Same goes for different colors and different Graphics creations like Graphics[{Red, Disk[{0,0}]}], which leads to the same wrong color output. It seems that there is some color adjustment done by default, which leads to wrong color output.

Expected behavior The colors should display according to code input.

Screenshots image

Environment

njpipeorgan commented 2 years ago

Thanks for the feedback. I guess that you are using a dark vscode theme. In dark themes, the color of the images are rendered with inverted brightness (white becomes black, red looks brighter, yellow looks darker).

The3DWizard commented 2 years ago

Thanks for the reply. Yes I do use dark theme, dark theme is the default on mac. Using light theme fixes the problem. Any way to fix it while still using dark theme?

njpipeorgan commented 2 years ago

I should first note that this behavior is meant to be a feature. There are complicated outputs sometimes that can only be rasterized by the kernel and displayed as images, but an output from the kernel is (and should) not be dependent on the theme of the editor. When the background is assumed by the kernel to be white, those images will not fit with a dark theme, and vice versa. So I came up with this solution, which is to do some "post-processing" (invert the brightness) to the images when the editor is in a dark theme.

To solve the issue you had, I have added a setting "rendering.invertBrightnessInDarkThemes" to control the color of the images, and it works when you re-evaluate the cell. You can test it with this vsix.

Ideally, the setting can be in effect as soon as it is changed, but it is impossible as for now because there is no proper way in which the notebook controller (managing the settings) can communicate with the renderer (rendering the images).

An alternative approach is to do it image by image: effectively an widget can be added to each image to control whether the color should change with the theme. But it has a downside of not being able to keep the setting when reopening the notebook.