From cccff0d764532ba5fa2c94034206efa8ea01459e Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Thu, 22 Nov 2018 13:36:10 -0500 Subject: [PATCH 1/2] implement watermark config option --- build/plotcss.js | 4 ++-- src/components/modebar/manage.js | 5 ++++- src/components/modebar/modebar.js | 11 ++++++++--- src/css/_modebar.scss | 4 ++-- src/plot_api/plot_config.js | 3 +++ 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/build/plotcss.js b/build/plotcss.js index 71ad375f264..f07b126de8c 100644 --- a/build/plotcss.js +++ b/build/plotcss.js @@ -32,8 +32,8 @@ var rules = { "X .cursor-ne-resize": "cursor:ne-resize;", "X .cursor-grab": "cursor:-webkit-grab;cursor:grab;", "X .modebar": "position:absolute;top:2px;right:2px;z-index:1001;", - "X .modebar--hover": "opacity:0;-webkit-transition:opacity 0.3s ease 0s;-moz-transition:opacity 0.3s ease 0s;-ms-transition:opacity 0.3s ease 0s;-o-transition:opacity 0.3s ease 0s;transition:opacity 0.3s ease 0s;", - "X:hover .modebar--hover": "opacity:1;", + "X .modebar--hover>:not(.watermark)": "opacity:0;-webkit-transition:opacity 0.3s ease 0s;-moz-transition:opacity 0.3s ease 0s;-ms-transition:opacity 0.3s ease 0s;-o-transition:opacity 0.3s ease 0s;transition:opacity 0.3s ease 0s;", + "X:hover .modebar--hover .modebar-group": "opacity:1;", "X .modebar-group": "float:left;display:inline-block;box-sizing:border-box;margin-left:8px;position:relative;vertical-align:middle;white-space:nowrap;", "X .modebar-btn": "position:relative;font-size:16px;padding:3px 4px;height:22px;cursor:pointer;line-height:normal;box-sizing:border-box;", "X .modebar-btn svg": "position:relative;top:2px;", diff --git a/src/components/modebar/manage.js b/src/components/modebar/manage.js index d455fcf8856..1eb9341c0f6 100644 --- a/src/components/modebar/manage.js +++ b/src/components/modebar/manage.js @@ -29,7 +29,7 @@ module.exports = function manageModeBar(gd) { context = gd._context, modeBar = fullLayout._modeBar; - if(!context.displayModeBar) { + if(!context.displayModeBar && !context.watermark) { if(modeBar) { modeBar.destroy(); delete fullLayout._modeBar; @@ -57,6 +57,9 @@ module.exports = function manageModeBar(gd) { if(Array.isArray(customButtons) && customButtons.length) { buttonGroups = fillCustomButton(customButtons); } + else if(!context.displayModeBar && context.watermark) { + buttonGroups = []; + } else { buttonGroups = getButtonGroups( gd, diff --git a/src/components/modebar/modebar.js b/src/components/modebar/modebar.js index 6928d133aa3..70f44d8cabb 100644 --- a/src/components/modebar/modebar.js +++ b/src/components/modebar/modebar.js @@ -80,11 +80,16 @@ proto.update = function(graphInfo, buttons) { this.updateButtons(buttons); - if(context.displaylogo) { + if(context.watermark || context.displaylogo) { + var logoGroup = this.getLogo(); + if(context.watermark) { + logoGroup.className = logoGroup.className + ' watermark'; + } + if(fullLayout.modebar.orientation === 'v') { - this.element.prepend(this.getLogo()); + this.element.prepend(logoGroup); } else { - this.element.appendChild(this.getLogo()); + this.element.appendChild(logoGroup); } this.hasLogo = true; diff --git a/src/css/_modebar.scss b/src/css/_modebar.scss index a81f644e485..d2aaf1fa51c 100644 --- a/src/css/_modebar.scss +++ b/src/css/_modebar.scss @@ -5,12 +5,12 @@ z-index: 1001; } -.modebar--hover { +.modebar--hover > :not(.watermark) { opacity: 0; @include vendor('transition', opacity 0.3s ease 0s); } -&:hover .modebar--hover { +&:hover .modebar--hover .modebar-group { opacity: 1; } diff --git a/src/plot_api/plot_config.js b/src/plot_api/plot_config.js index a3751322ec5..0f195c73db5 100644 --- a/src/plot_api/plot_config.js +++ b/src/plot_api/plot_config.js @@ -133,6 +133,9 @@ module.exports = { // add the plotly logo on the end of the mode bar displaylogo: true, + // watermark the images with the company's logo + watermark: false, + // increase the pixel ratio for Gl plot images plotGlPixelRatio: 2, From df10f7026c574b15833d2c735018ac8444502647 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Thu, 22 Nov 2018 18:18:23 -0500 Subject: [PATCH 2/2] test watermark config option --- test/jasmine/tests/modebar_test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/jasmine/tests/modebar_test.js b/test/jasmine/tests/modebar_test.js index 8c2267bb3cf..341380caf58 100644 --- a/test/jasmine/tests/modebar_test.js +++ b/test/jasmine/tests/modebar_test.js @@ -756,6 +756,16 @@ describe('ModeBar', function() { expect(countLogo(gd._fullLayout._modeBar)).toEqual(0); }); + it('always displays the logo if watermark config arg is true', function() { + var gd = getMockGraphInfo(); + gd._context.displaylogo = false; + gd._context.displayModeBar = false; + gd._context.watermark = true; + manageModeBar(gd); + expect(countLogo(gd._fullLayout._modeBar)).toEqual(1); + expect(countButtons(gd._fullLayout._modeBar)).toEqual(1); + }); + // gives 11 buttons in 5 groups by default function setupGraphInfo() { var gd = getMockGraphInfo(['x'], ['y']);