Skip to content
Draft
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
1 change: 1 addition & 0 deletions draftlogs/7958_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Keep Cartesian traces aligned with axes when automargin titles are combined with sliders or update menus [[#7958](https://github.com/plotly/plotly.js/pull/7958)]
5 changes: 4 additions & 1 deletion src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,11 @@ function _doPlot(gd, data, layout, config) {
Plots.clearAutoMarginIds(gd);

subroutines.drawMarginPushers(gd);
var title = gd._fullLayout.title;
var titlePushesMargin = title.text && title.automargin;
if (titlePushesMargin) subroutines.drawMainTitle(gd);
Axes.allowAutoMargin(gd);
if (gd._fullLayout.title.text && gd._fullLayout.title.automargin) Plots.allowAutoMargin(gd, 'title.automargin');
if (titlePushesMargin) Plots.allowAutoMargin(gd, 'title.automargin');

// TODO can this be moved elsewhere?
if (fullLayout._has('pie')) {
Expand Down
47 changes: 47 additions & 0 deletions test/jasmine/tests/titles_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,53 @@ describe('Title automargining', function() {

afterEach(destroyGraphDiv);

it('keeps cartesian traces aligned with axes when controls also expand margins', function(done) {
Plotly.newPlot(gd, [{
x: [1, 2, 3],
y: [2, 1, 3],
mode: 'lines+markers',
line: {simplify: false}
}], {
margin: {autoexpand: true, t: 0},
title: {
text: 'Title',
automargin: true,
font: {size: 36}
},
sliders: [{
pad: {t: 30},
x: 0.05,
len: 0.95,
steps: [
{label: '0', method: 'update', args: [{}, {}]},
{label: '1', method: 'update', args: [{}, {}]}
]
}],
updatemenus: [{
type: 'buttons',
x: 0.05,
y: 0,
xanchor: 'right',
yanchor: 'top',
direction: 'left',
pad: {t: 60, r: 20},
buttons: [{label: 'Play', method: 'skip'}]
}]
}).then(function() {
var plot = d3Select(gd);
var point = plot.select('.scatterlayer .point').node();
var yTick;

plot.selectAll('.ytick').each(function() {
if(d3Select(this).select('text').text() === '2') yTick = this;
});

expect(point).not.toBeNull();
expect(yTick).toBeDefined();
expect(point.getCTM().f).toBeCloseTo(yTick.querySelector('text').getCTM().f, 6);
}).then(done, done.fail);
});

it('should avoid overlap with container for yref=paper and allow padding', function(done) {
Plotly.newPlot(gd, data, {
margin: {t: 0, b: 0, l: 0, r: 0},
Expand Down