Skip to content

Update modebar buttons when locale changes #2592

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 6 additions & 3 deletions src/components/modebar/modebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ proto.update = function(graphInfo, buttons) {
else this.element.className = 'modebar';

// if buttons or logo have changed, redraw modebar interior
var needsNewButtons = !this.hasButtons(buttons),
needsNewLogo = (this.hasLogo !== context.displaylogo);
var needsNewButtons = !this.hasButtons(buttons);
var needsNewLogo = (this.hasLogo !== context.displaylogo);
var needsNewLocale = (this.locale !== context.locale);

if(needsNewButtons || needsNewLogo) {
this.locale = context.locale;

if(needsNewButtons || needsNewLogo || needsNewLocale) {
this.removeAllButtons();

this.updateButtons(buttons);
Expand Down
34 changes: 34 additions & 0 deletions test/jasmine/tests/localize_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,38 @@ describe('localization', function() {
.catch(failTest)
.then(done);
});

it('updates ticks and modebar tooltips on Plotly.react', function(done) {
Plotly.register({
moduleType: 'locale',
name: 'xx',
dictionary: {Zoom: 'Bigger'},
format: {month: '%Y %b'}
});

function getZoomTip() {
return gd.querySelector('.modebar-btn[data-val="zoom"]').getAttribute('data-title');
}

plot('en')
.then(function() {
expect(firstXLabel()).toBe('Jan 2001');
expect(getZoomTip()).toBe('Zoom');

return Plotly.react(gd, gd.data, gd.layout, {locale: 'xx'});
})
.then(function() {
expect(firstXLabel()).toBe('2001 Jan');
expect(getZoomTip()).toBe('Bigger');

// this is discouraged usage, but it works
return Plotly.plot(gd, [], {}, {locale: 'en'});
})
.then(function() {
expect(firstXLabel()).toBe('Jan 2001');
expect(getZoomTip()).toBe('Zoom');
})
.catch(failTest)
.then(done);
});
});