Skip to content

Commit 89edb98

Browse files
committed
update modebar buttons when locale changes
1 parent bab2a5b commit 89edb98

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/components/modebar/modebar.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ proto.update = function(graphInfo, buttons) {
5252
else this.element.className = 'modebar';
5353

5454
// if buttons or logo have changed, redraw modebar interior
55-
var needsNewButtons = !this.hasButtons(buttons),
56-
needsNewLogo = (this.hasLogo !== context.displaylogo);
55+
var needsNewButtons = !this.hasButtons(buttons);
56+
var needsNewLogo = (this.hasLogo !== context.displaylogo);
57+
var needsNewLocale = (this.locale !== context.locale);
5758

58-
if(needsNewButtons || needsNewLogo) {
59+
this.locale = context.locale;
60+
61+
if(needsNewButtons || needsNewLogo || needsNewLocale) {
5962
this.removeAllButtons();
6063

6164
this.updateButtons(buttons);

test/jasmine/tests/localize_test.js

+34
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,38 @@ describe('localization', function() {
369369
.catch(failTest)
370370
.then(done);
371371
});
372+
373+
it('updates ticks and modebar tooltips on Plotly.react', function(done) {
374+
Plotly.register({
375+
moduleType: 'locale',
376+
name: 'xx',
377+
dictionary: {Zoom: 'Bigger'},
378+
format: {month: '%Y %b'}
379+
});
380+
381+
function getZoomTip() {
382+
return gd.querySelector('.modebar-btn[data-val="zoom"]').getAttribute('data-title');
383+
}
384+
385+
plot('en')
386+
.then(function() {
387+
expect(firstXLabel()).toBe('Jan 2001');
388+
expect(getZoomTip()).toBe('Zoom');
389+
390+
return Plotly.react(gd, gd.data, gd.layout, {locale: 'xx'});
391+
})
392+
.then(function() {
393+
expect(firstXLabel()).toBe('2001 Jan');
394+
expect(getZoomTip()).toBe('Bigger');
395+
396+
// this is discouraged usage, but it works
397+
return Plotly.plot(gd, [], {}, {locale: 'en'});
398+
})
399+
.then(function() {
400+
expect(firstXLabel()).toBe('Jan 2001');
401+
expect(getZoomTip()).toBe('Zoom');
402+
})
403+
.catch(failTest)
404+
.then(done);
405+
});
372406
});

0 commit comments

Comments
 (0)