Skip to content

Improve Plotly.toImage #1939

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 16 commits into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@ function opaqueSetBackground(gd, bgColor) {
setBackground(gd, bgColor);
}

function blendSetBackground(gd, bgColor) {
var blend = Color.combine(bgColor, 'white');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implements this (old) image server logic in plotly.js

Copy link
Collaborator

Choose a reason for hiding this comment

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

doesn't this end up visually equivalent to opaqueSetBackground? And if so can we remove opaqueSetBackground?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RE 'opaque' vs 'blend', they don't generate the same PNG (gm compare generates a diff) but I can't find a case where the diff is detectable to my 👀

So, I guess a can make the new image server use 'opaque' instead of 'blend' and 🔪 blendSetBackground.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 22a598b

setBackground(gd, blend);
}

function setPlotContext(gd, config) {
if(!gd._context) gd._context = Lib.extendDeep({}, Plotly.defaultConfig);
var context = gd._context;
Expand All @@ -416,10 +421,15 @@ function setPlotContext(gd, config) {
key = keys[i];
if(key === 'editable' || key === 'edits') continue;
if(key in context) {
if(key === 'setBackground' && config[key] === 'opaque') {
context[key] = opaqueSetBackground;
if(key === 'setBackground') {
if(config[key] === 'opaque') {
context[key] = opaqueSetBackground;
} else if(config[key] === 'blend') {
context[key] = blendSetBackground;
}
} else {
context[key] = config[key];
}
else context[key] = config[key];
}
}

Expand Down
1 change: 1 addition & 0 deletions src/plot_api/plot_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ module.exports = {

// function to add the background color to a different container
// or 'opaque' to ensure there's white behind it,
// or 'blend' to blend bg color with white,
// or any other custom function of gd
setBackground: 'transparent',

Expand Down