Skip to content

Commit 0a53eb8

Browse files
Fix trace alignment after title automargin
1 parent 21da158 commit 0a53eb8

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

src/plot_api/plot_api.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,11 @@ function _doPlot(gd, data, layout, config) {
288288
Plots.clearAutoMarginIds(gd);
289289

290290
subroutines.drawMarginPushers(gd);
291+
var title = gd._fullLayout.title;
292+
var titlePushesMargin = title.text && title.automargin;
293+
if (titlePushesMargin) subroutines.drawMainTitle(gd);
291294
Axes.allowAutoMargin(gd);
292-
if (gd._fullLayout.title.text && gd._fullLayout.title.automargin) Plots.allowAutoMargin(gd, 'title.automargin');
295+
if (titlePushesMargin) Plots.allowAutoMargin(gd, 'title.automargin');
293296

294297
// TODO can this be moved elsewhere?
295298
if (fullLayout._has('pie')) {

test/jasmine/tests/titles_test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,53 @@ describe('Title automargining', function() {
882882

883883
afterEach(destroyGraphDiv);
884884

885+
it('keeps cartesian traces aligned with axes when controls also expand margins', function(done) {
886+
Plotly.newPlot(gd, [{
887+
x: [1, 2, 3],
888+
y: [2, 1, 3],
889+
mode: 'lines+markers',
890+
line: {simplify: false}
891+
}], {
892+
margin: {autoexpand: true, t: 0},
893+
title: {
894+
text: 'Title',
895+
automargin: true,
896+
font: {size: 36}
897+
},
898+
sliders: [{
899+
pad: {t: 30},
900+
x: 0.05,
901+
len: 0.95,
902+
steps: [
903+
{label: '0', method: 'update', args: [{}, {}]},
904+
{label: '1', method: 'update', args: [{}, {}]}
905+
]
906+
}],
907+
updatemenus: [{
908+
type: 'buttons',
909+
x: 0.05,
910+
y: 0,
911+
xanchor: 'right',
912+
yanchor: 'top',
913+
direction: 'left',
914+
pad: {t: 60, r: 20},
915+
buttons: [{label: 'Play', method: 'skip'}]
916+
}]
917+
}).then(function() {
918+
var plot = d3Select(gd);
919+
var point = plot.select('.scatterlayer .point').node();
920+
var yTick;
921+
922+
plot.selectAll('.ytick').each(function() {
923+
if(d3Select(this).select('text').text() === '2') yTick = this;
924+
});
925+
926+
expect(point).not.toBeNull();
927+
expect(yTick).toBeDefined();
928+
expect(point.getCTM().f).toBeCloseTo(yTick.querySelector('text').getCTM().f, 6);
929+
}).then(done, done.fail);
930+
});
931+
885932
it('should avoid overlap with container for yref=paper and allow padding', function(done) {
886933
Plotly.newPlot(gd, data, {
887934
margin: {t: 0, b: 0, l: 0, r: 0},

0 commit comments

Comments
 (0)