Skip to content

Commit a2eeaf0

Browse files
committed
Fix unit tests and bug applying bgcolor with relayout
Fixed unit tests by updating the expectations as appropriate to match the changed logic in Pull Request #7109. This revealed a bug where background color changes applied using `Plotly.relayout()` were missed. This bug was also fixed in this change in order to get all unit tests, as updated, to pass.
1 parent 3f97ec6 commit a2eeaf0

File tree

2 files changed

+7
-34
lines changed

2 files changed

+7
-34
lines changed

src/components/modebar/modebar.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ proto.update = function(graphInfo, buttons) {
5454
}
5555

5656
var style = fullLayout.modebar;
57-
var bgSelector = context.displayModeBar === 'hover' ? '.js-plotly-plot .plotly:hover ' : '';
5857

58+
// set style for modebar-group directly instead of inline CSS that's not allowed by strict CSP's
59+
var groupSelector = '#' + modeBarId + ' .modebar-group';
60+
document.querySelectorAll(groupSelector).forEach(function(group) {
61+
group.style.backgroundColor = style.bgcolor;
62+
});
5963
// set styles on hover using event listeners instead of inline CSS that's not allowed by strict CSP's
6064
Lib.setStyleOnHover('#' + modeBarId + ' .modebar-btn', '.active', '.icon path', 'fill: ' + style.activecolor, 'fill: ' + style.color);
6165

test/jasmine/tests/modebar_test.js

+2-33
Original file line numberDiff line numberDiff line change
@@ -1544,33 +1544,6 @@ describe('ModeBar', function() {
15441544
expect(style.fill).toBe(color);
15451545
}
15461546

1547-
function getStyleRule() {
1548-
var uid = gd._fullLayout._uid;
1549-
var ownerNode = document.getElementById('plotly.js-style-modebar-' + uid);
1550-
var styleSheets = document.styleSheets;
1551-
for(var i = 0; i < styleSheets.length; i++) {
1552-
var ss = styleSheets[i];
1553-
if(ss.ownerNode === ownerNode) return ss;
1554-
}
1555-
}
1556-
1557-
it('create an associated style element and destroy it on purge', function(done) {
1558-
var styleSelector, style;
1559-
Plotly.newPlot(gd, [], {})
1560-
.then(function() {
1561-
styleSelector = 'style[id*="modebar-' + gd._fullLayout._uid + '"]';
1562-
1563-
style = document.querySelector(styleSelector);
1564-
expect(style).toBeTruthy();
1565-
})
1566-
.then(function() {
1567-
Plotly.purge(gd);
1568-
style = document.querySelector(styleSelector);
1569-
expect(style).toBeNull();
1570-
})
1571-
.then(done, done.fail);
1572-
});
1573-
15741547
it('changes icon colors', function(done) {
15751548
Plotly.newPlot(gd, [], {modebar: { color: colors[0]}})
15761549
.then(function() {
@@ -1602,14 +1575,12 @@ describe('ModeBar', function() {
16021575
Plotly.newPlot(gd, [], {modebar: { bgcolor: colors[0]}})
16031576
.then(function() {
16041577
style = window.getComputedStyle(gd._fullLayout._modeBar.element.querySelector('.modebar-group'));
1605-
expect(style.backgroundColor).toBe('rgba(0, 0, 0, 0)');
1606-
expect(getStyleRule().rules[3].style.backgroundColor).toBe(colors[0]);
1578+
expect(style.backgroundColor).toBe(colors[0]);
16071579
})
16081580
.then(function() { return Plotly.relayout(gd, 'modebar.bgcolor', colors[1]); })
16091581
.then(function() {
16101582
style = window.getComputedStyle(gd._fullLayout._modeBar.element.querySelector('.modebar-group'));
1611-
expect(style.backgroundColor).toBe('rgba(0, 0, 0, 0)');
1612-
expect(getStyleRule().rules[3].style.backgroundColor).toBe(colors[1]);
1583+
expect(style.backgroundColor).toBe(colors[1]);
16131584
})
16141585
.then(done, done.fail);
16151586
});
@@ -1619,13 +1590,11 @@ describe('ModeBar', function() {
16191590
.then(function() {
16201591
style = window.getComputedStyle(gd._fullLayout._modeBar.element.querySelector('.modebar-group'));
16211592
expect(style.backgroundColor).toBe(colors[0]);
1622-
expect(getStyleRule().rules[3].style.backgroundColor).toBe(colors[0]);
16231593
})
16241594
.then(function() { return Plotly.relayout(gd, 'modebar.bgcolor', colors[1]); })
16251595
.then(function() {
16261596
style = window.getComputedStyle(gd._fullLayout._modeBar.element.querySelector('.modebar-group'));
16271597
expect(style.backgroundColor).toBe(colors[1]);
1628-
expect(getStyleRule().rules[3].style.backgroundColor).toBe(colors[1]);
16291598
})
16301599
.then(done, done.fail);
16311600
});

0 commit comments

Comments
 (0)