Skip to content

Commit 2dcd2c9

Browse files
authored
Merge pull request #7730 from silversonicaxel/feature-notifier
Add notifier boolean configuration
2 parents 36baa98 + 33f6298 commit 2dcd2c9

File tree

8 files changed

+61
-24
lines changed

8 files changed

+61
-24
lines changed

draftlogs/7730_add.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add `displayNotifier` configuration property to set the display of notifier in the top right area of the viewport [[#7730](https://github.com/plotly/plotly.js/pull/7730)], with thanks to @silversonicaxel for the contribution!

src/components/legend/handle_click.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ exports.handleItemClick = function handleItemClick(g, gd, legendObj, mode) {
3131
if(mode === 'toggle' && legendObj.itemdoubleclick === 'toggleothers' &&
3232
SHOWISOLATETIP && gd.data && gd._context.showTips
3333
) {
34-
Lib.notifier(Lib._(gd, 'Double-click on legend to isolate one trace'), 'long');
34+
Lib.notifier(Lib._(gd, 'Double-click on legend to isolate one trace'), 'long', gd);
3535
SHOWISOLATETIP = false;
3636
}
3737

@@ -323,7 +323,7 @@ exports.handleTitleClick = function handleTitleClick(gd, legendObj, mode) {
323323
const item = allLegendItems[i];
324324
const inThisLegend = isInLegend(item);
325325

326-
// If item is not in this legend, skip if in toggle mode
326+
// If item is not in this legend, skip if in toggle mode
327327
// or if item is not displayed in the legend
328328
if(!inThisLegend) {
329329
const notDisplayed = (item.showlegend !== true && !item.legendgroup);

src/components/modebar/buttons.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ modeBarButtons.toImage = {
4949
var toImageButtonOptions = gd._context.toImageButtonOptions;
5050
var opts = {format: toImageButtonOptions.format || 'png'};
5151

52-
Lib.notifier(_(gd, 'Taking snapshot - this may take a few seconds'), 'long');
52+
Lib.notifier(_(gd, 'Taking snapshot - this may take a few seconds'), 'long', gd);
5353

5454
['filename', 'width', 'height', 'scale'].forEach(function(key) {
5555
if(key in toImageButtonOptions) {
@@ -58,12 +58,12 @@ modeBarButtons.toImage = {
5858
});
5959

6060
Registry.call('downloadImage', gd, opts)
61-
.then(function(filename) {
62-
Lib.notifier(_(gd, 'Snapshot succeeded') + ' - ' + filename, 'long');
63-
})
64-
.catch(function() {
65-
Lib.notifier(_(gd, 'Sorry, there was a problem downloading your snapshot!'), 'long');
66-
});
61+
.then(function(filename) {
62+
Lib.notifier(_(gd, 'Snapshot succeeded') + ' - ' + filename, 'long', gd);
63+
})
64+
.catch(function() {
65+
Lib.notifier(_(gd, 'Sorry, there was a problem downloading your snapshot!'), 'long', gd);
66+
});
6767
}
6868
};
6969

src/lib/notifier.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ var NOTEDATA = [];
77

88
/**
99
* notifier
10-
* @param {String} text The person's user name
11-
* @param {Number} [delay=1000] The delay time in milliseconds
12-
* or 'long' which provides 2000 ms delay time.
10+
* @param {string} text - The message to display in the notification
11+
* @param {number|'long'|'stick'} [displayLength=1000] - Display duration in ms,
12+
* 'long' for 3000ms, or 'stick' to keep until manually closed
13+
* @param {object} [gd] - Plot div; if provided and gd._context.displayNotifier === false, notification is suppressed
1314
* @return {undefined} this function does not return a value
1415
*/
15-
module.exports = function(text, displayLength) {
16+
module.exports = function(text, displayLength, gd) {
17+
if(gd?._context?.displayNotifier === false) return;
1618
if(NOTEDATA.indexOf(text) !== -1) return;
1719

1820
NOTEDATA.push(text);
@@ -63,15 +65,15 @@ module.exports = function(text, displayLength) {
6365

6466
if(displayLength === 'stick') {
6567
note.transition()
66-
.duration(350)
67-
.style('opacity', 1);
68+
.duration(350)
69+
.style('opacity', 1);
6870
} else {
6971
note.transition()
70-
.duration(700)
71-
.style('opacity', 1)
72+
.duration(700)
73+
.style('opacity', 1)
7274
.transition()
73-
.delay(ts)
74-
.call(killNote);
75+
.delay(ts)
76+
.call(killNote);
7577
}
7678
});
7779
};

src/plot_api/plot_config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ var configAttributes = {
221221
].join(' ')
222222
},
223223

224+
displayNotifier: {
225+
valType: 'boolean',
226+
dflt: true,
227+
description: 'Determines whether or not notifier is displayed.'
228+
},
229+
224230
showLink: {
225231
valType: 'boolean',
226232
dflt: false,

src/plots/cartesian/dragbox.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,9 +792,9 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
792792
r1 !== undefined;
793793

794794
if((hasRangeInitial && (
795-
(r0 !== undefined && r0 !== ax.range[0]) ||
796-
(r1 !== undefined && r1 !== ax.range[1])
797-
)) ||
795+
(r0 !== undefined && r0 !== ax.range[0]) ||
796+
(r1 !== undefined && r1 !== ax.range[1])
797+
)) ||
798798
(!hasRangeInitial && ax.autorange !== true)
799799
) {
800800
doubleClickConfig = 'reset';
@@ -1209,7 +1209,7 @@ function removeZoombox(gd) {
12091209

12101210
function showDoubleClickNotifier(gd) {
12111211
if(SHOWZOOMOUTTIP && gd.data && gd._context.showTips) {
1212-
Lib.notifier(Lib._(gd, 'Double-click to zoom back out'), 'long');
1212+
Lib.notifier(Lib._(gd, 'Double-click to zoom back out'), 'long', gd);
12131213
SHOWZOOMOUTTIP = false;
12141214
}
12151215
}

src/plots/ternary/ternary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ proto.initInteractions = function() {
678678
Registry.call('_guiRelayout', gd, makeUpdate(mins));
679679

680680
if(SHOWZOOMOUTTIP && gd.data && gd._context.showTips) {
681-
Lib.notifier(_(gd, 'Double-click to zoom back out'), 'long');
681+
Lib.notifier(_(gd, 'Double-click to zoom back out'), 'long', gd);
682682
SHOWZOOMOUTTIP = false;
683683
}
684684
}

test/jasmine/tests/lib_test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,6 +2105,34 @@ describe('Test lib.js:', function () {
21052105
_run([]);
21062106
});
21072107
});
2108+
2109+
describe('should respect notifier config option', function () {
2110+
var query = '.notifier-note';
2111+
2112+
beforeEach(function (done) {
2113+
d3SelectAll(query).each(function () {
2114+
d3Select(this).select('button').node().click();
2115+
});
2116+
setTimeout(done, 1000);
2117+
});
2118+
2119+
it('with true', function () {
2120+
var gd = { _context: { displayNotifier: true } };
2121+
Lib.notifier('test message', 'long', gd);
2122+
expect(d3SelectAll(query).size()).toBe(1);
2123+
});
2124+
2125+
it('with false', function () {
2126+
var gd = { _context: { displayNotifier: false } };
2127+
Lib.notifier('test message', 'long', gd);
2128+
expect(d3SelectAll(query).size()).toBe(0);
2129+
});
2130+
2131+
it('when gd has no _context', function () {
2132+
Lib.notifier('test message', 'long');
2133+
expect(d3SelectAll(query).size()).toBe(1);
2134+
});
2135+
});
21082136
});
21092137

21102138
describe('keyedContainer', function () {

0 commit comments

Comments
 (0)