Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Remove inline styles that break plots in strict CSP setups#7109

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
archmoj merged 5 commits intoplotly:masterfrommartian111:csp-no-inline-style
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from1 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
PrevPrevious commit
NextNext commit
Fix unit tests and bug applying bgcolor with relayout
Fixed unit tests by updating the expectations as appropriate to matchthe changed logic in Pull Request#7109. This revealed a bug wherebackground 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.
  • Loading branch information
@martian111
martian111 committedOct 20, 2024
commita2eeaf00d3f9739c20b335abded753735d505b1e
6 changes: 5 additions & 1 deletionsrc/components/modebar/modebar.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,8 +54,12 @@ proto.update = function(graphInfo, buttons) {
}

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

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

Expand Down
35 changes: 2 additions & 33 deletionstest/jasmine/tests/modebar_test.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1544,33 +1544,6 @@ describe('ModeBar', function() {
expect(style.fill).toBe(color);
}

function getStyleRule() {
var uid = gd._fullLayout._uid;
var ownerNode = document.getElementById('plotly.js-style-modebar-' + uid);
var styleSheets = document.styleSheets;
for(var i = 0; i < styleSheets.length; i++) {
var ss = styleSheets[i];
if(ss.ownerNode === ownerNode) return ss;
}
}

it('create an associated style element and destroy it on purge', function(done) {
var styleSelector, style;
Plotly.newPlot(gd, [], {})
.then(function() {
styleSelector = 'style[id*="modebar-' + gd._fullLayout._uid + '"]';

style = document.querySelector(styleSelector);
expect(style).toBeTruthy();
})
.then(function() {
Plotly.purge(gd);
style = document.querySelector(styleSelector);
expect(style).toBeNull();
})
.then(done, done.fail);
});

it('changes icon colors', function(done) {
Plotly.newPlot(gd, [], {modebar: { color: colors[0]}})
.then(function() {
Expand DownExpand Up@@ -1602,14 +1575,12 @@ describe('ModeBar', function() {
Plotly.newPlot(gd, [], {modebar: { bgcolor: colors[0]}})
.then(function() {
style = window.getComputedStyle(gd._fullLayout._modeBar.element.querySelector('.modebar-group'));
expect(style.backgroundColor).toBe('rgba(0, 0, 0, 0)');
expect(getStyleRule().rules[3].style.backgroundColor).toBe(colors[0]);
expect(style.backgroundColor).toBe(colors[0]);
})
.then(function() { return Plotly.relayout(gd, 'modebar.bgcolor', colors[1]); })
.then(function() {
style = window.getComputedStyle(gd._fullLayout._modeBar.element.querySelector('.modebar-group'));
expect(style.backgroundColor).toBe('rgba(0, 0, 0, 0)');
expect(getStyleRule().rules[3].style.backgroundColor).toBe(colors[1]);
expect(style.backgroundColor).toBe(colors[1]);
})
.then(done, done.fail);
});
Expand All@@ -1619,13 +1590,11 @@ describe('ModeBar', function() {
.then(function() {
style = window.getComputedStyle(gd._fullLayout._modeBar.element.querySelector('.modebar-group'));
expect(style.backgroundColor).toBe(colors[0]);
expect(getStyleRule().rules[3].style.backgroundColor).toBe(colors[0]);
})
.then(function() { return Plotly.relayout(gd, 'modebar.bgcolor', colors[1]); })
.then(function() {
style = window.getComputedStyle(gd._fullLayout._modeBar.element.querySelector('.modebar-group'));
expect(style.backgroundColor).toBe(colors[1]);
expect(getStyleRule().rules[3].style.backgroundColor).toBe(colors[1]);
})
.then(done, done.fail);
});
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp