Skip to content

Commit dd003ce

Browse files
committed
set setBackground config option in setPlotContext
- instead of in `plot_config.js` declaration
1 parent 3d19676 commit dd003ce

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

src/plot_api/plot_api.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var Polar = require('../plots/polar');
2525
var initInteractions = require('../plots/cartesian/graph_interact');
2626

2727
var Drawing = require('../components/drawing');
28+
var Color = require('../components/color');
2829
var ErrorBars = require('../components/errorbars');
2930
var xmlnsNamespaces = require('../constants/xmlns_namespaces');
3031
var svgTextUtils = require('../lib/svg_text_utils');
@@ -390,10 +391,17 @@ Plotly.plot = function(gd, data, layout, config) {
390391
});
391392
};
392393

394+
function setBackground(gd, bgColor) {
395+
try {
396+
gd._fullLayout._paper.style('background', bgColor);
397+
} catch(e) {
398+
Lib.error(e);
399+
}
400+
}
393401

394402
function opaqueSetBackground(gd, bgColor) {
395403
gd._fullLayout._paperdiv.style('background', 'white');
396-
Plotly.defaultConfig.setBackground(gd, bgColor);
404+
setBackground(gd, bgColor);
397405
}
398406

399407
function setPlotContext(gd, config) {
@@ -460,6 +468,11 @@ function setPlotContext(gd, config) {
460468
if(context.displayModeBar === 'hover' && !hasHover) {
461469
context.displayModeBar = true;
462470
}
471+
472+
// default and fallback for setBackground
473+
if(context.setBackground === 'transparent' || typeof context.setBackground !== 'function') {
474+
context.setBackground = setBackground;
475+
}
463476
}
464477

465478
function plotPolar(gd, data, layout) {

src/plot_api/plot_config.js

+3-17
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
'use strict';
1010

11-
/* eslint-disable no-console */
12-
1311
/**
1412
* This will be transferred over to gd and overridden by
1513
* config args to Plotly.plot.
@@ -109,8 +107,9 @@ module.exports = {
109107
plotGlPixelRatio: 2,
110108

111109
// function to add the background color to a different container
112-
// or 'opaque' to ensure there's white behind it
113-
setBackground: defaultSetBackground,
110+
// or 'opaque' to ensure there's white behind it,
111+
// or any other custom function of gd
112+
setBackground: 'transparent',
114113

115114
// URL to topojson files used in geo charts
116115
topojsonURL: 'https://cdn.plot.ly/',
@@ -128,16 +127,3 @@ module.exports = {
128127
// specification needed
129128
globalTransforms: []
130129
};
131-
132-
// where and how the background gets set can be overridden by context
133-
// so we define the default (plotly.js) behavior here
134-
function defaultSetBackground(gd, bgColor) {
135-
try {
136-
gd._fullLayout._paper.style('background', bgColor);
137-
}
138-
catch(e) {
139-
if(module.exports.logging > 0) {
140-
console.error(e);
141-
}
142-
}
143-
}

0 commit comments

Comments
 (0)