Skip to content

Commit da5cc5f

Browse files
committed
use contrast color with new logo
1 parent 5963038 commit da5cc5f

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/components/modebar/modebar.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var d3 = require('@plotly/d3');
44
var isNumeric = require('fast-isnumeric');
55

66
var Lib = require('../../lib');
7+
var Color = require('../color');
78
var Icons = require('../../fonts/ploticon');
89
var version = require('../../version').version;
910

@@ -62,6 +63,12 @@ proto.update = function(graphInfo, buttons) {
6263
Lib.addRelatedStyleRule(modeBarId, '#' + modeBarId + ' .modebar-btn:hover .icon path', 'fill: ' + style.activecolor);
6364
Lib.addRelatedStyleRule(modeBarId, '#' + modeBarId + ' .modebar-btn.active .icon path', 'fill: ' + style.activecolor);
6465

66+
// logo constrast color
67+
var logoId = modeBarId + '-logo';
68+
var logoSelector = context.displayModeBar === 'hover' ? '.plotlyjsicon' : '';
69+
Lib.deleteRelatedStyleRule(logoId);
70+
Lib.addRelatedStyleRule(logoId, logoSelector + ' .cls-bg-contrast', 'fill: ' + Color.contrast(fullLayout.paper_bgcolor));
71+
6572
// if buttons or logo have changed, redraw modebar interior
6673
var needsNewButtons = !this.hasButtons(buttons);
6774
var needsNewLogo = (this.hasLogo !== context.displaylogo);
@@ -75,7 +82,7 @@ proto.update = function(graphInfo, buttons) {
7582
this.updateButtons(buttons);
7683

7784
if(context.watermark || context.displaylogo) {
78-
var logoGroup = this.getLogo();
85+
var logoGroup = this.getLogo(graphInfo);
7986
if(context.watermark) {
8087
logoGroup.className = logoGroup.className + ' watermark';
8188
}
@@ -292,7 +299,7 @@ function jsVersion(str) {
292299
/**
293300
* @return {HTMLDivElement} The logo image wrapped in a group
294301
*/
295-
proto.getLogo = function() {
302+
proto.getLogo = function(graphInfo) {
296303
var group = this.createGroup();
297304
var a = document.createElement('a');
298305

@@ -303,6 +310,15 @@ proto.getLogo = function() {
303310

304311
a.appendChild(this.createIcon(Icons.newplotlylogo));
305312

313+
var context = graphInfo._context;
314+
var fullLayout = graphInfo._fullLayout;
315+
var modeBarId = 'modebar-' + fullLayout._uid;
316+
317+
var logoId = modeBarId + '-logo';
318+
var logoSelector = context.displayModeBar === 'hover' ? '.plotlyjsicon' : '';
319+
Lib.deleteRelatedStyleRule(logoId);
320+
Lib.addRelatedStyleRule(logoId, logoSelector + ' .cls-bg-contrast', 'fill: ' + Color.contrast(fullLayout.paper_bgcolor));
321+
306322
group.appendChild(a);
307323
return group;
308324
};
@@ -318,6 +334,7 @@ proto.removeAllButtons = function() {
318334
proto.destroy = function() {
319335
Lib.removeElement(this.container.querySelector('.modebar'));
320336
Lib.deleteRelatedStyleRule(this._uid);
337+
Lib.deleteRelatedStyleRule(this._uid + '-logo');
321338
};
322339

323340
function createModeBar(gd, buttons) {

src/fonts/ploticon.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ module.exports = {
169169
'<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'21 21 90 90\'>',
170170
'<defs>',
171171
' <style>',
172-
' .cls-0{fill:#777; stroke:#FFF; strokewidth:2;}',
172+
' .cls-bg-contrast{}',
173173
' .cls-1{fill:#F26;}',
174174
' .cls-2{fill:#D69;}',
175175
' .cls-3{fill:#BAC;}',
@@ -184,10 +184,10 @@ module.exports = {
184184
' <circle class=\'cls-2\' cx=\'54\' cy=\'30\' r=\'6\'/>',
185185
' <circle class=\'cls-1\' cx=\'30\' cy=\'30\' r=\'6\'/>',
186186
' <circle class=\'cls-1\' cx=\'30\' cy=\'54\' r=\'6\'/>',
187-
' <path class=\'cls-0\' d=\'M30,72a6,6,0,0,0-6,6v24a6,6,0,0,0,12,0V78A6,6,0,0,0,30,72Z\'/>',
188-
' <path class=\'cls-0\' d=\'M78,72a6,6,0,0,0-6,6v24a6,6,0,0,0,12,0V78A6,6,0,0,0,78,72Z\'/>',
189-
' <path class=\'cls-0\' d=\'M54,48a6,6,0,0,0-6,6v48a6,6,0,0,0,12,0V54A6,6,0,0,0,54,48Z\'/>',
190-
' <path class=\'cls-0\' d=\'M102,48a6,6,0,0,0-6,6v48a6,6,0,0,0,12,0V54A6,6,0,0,0,102,48Z\'/>',
187+
' <path class=\'cls-bg-contrast\' d=\'M30,72a6,6,0,0,0-6,6v24a6,6,0,0,0,12,0V78A6,6,0,0,0,30,72Z\'/>',
188+
' <path class=\'cls-bg-contrast\' d=\'M78,72a6,6,0,0,0-6,6v24a6,6,0,0,0,12,0V78A6,6,0,0,0,78,72Z\'/>',
189+
' <path class=\'cls-bg-contrast\' d=\'M54,48a6,6,0,0,0-6,6v48a6,6,0,0,0,12,0V54A6,6,0,0,0,54,48Z\'/>',
190+
' <path class=\'cls-bg-contrast\' d=\'M102,48a6,6,0,0,0-6,6v48a6,6,0,0,0,12,0V54A6,6,0,0,0,102,48Z\'/>',
191191
' </g>',
192192
'</svg>'
193193
].join('')

0 commit comments

Comments
 (0)