Skip to content

Commit 8ffa227

Browse files
authored
Merge pull request #8045 from plotly/bugfix/7750-margin-pushers-again
Fix plot shifting on axis when automargin applied to title
2 parents d0c808b + 42fa76e commit 8ffa227

4 files changed

Lines changed: 50 additions & 4 deletions

File tree

‎draftlogs/8045_fix.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Keep cartesian traces aligned with their axes when an automargin title is combined with any component that expands the margins [[#8045](https://github.com/plotly/plotly.js/pull/8045)]

‎src/plot_api/plot_api.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ function _doPlot(gd, data, layout, config) {
331331
function marginPushersAgain() {
332332
if (!Plots.didMarginChange(oldMargins, fullLayout._size)) return;
333333

334-
return Lib.syncOrAsync([marginPushers, subroutines.layoutStyles], gd);
334+
return marginPushers();
335335
}
336336

337337
function positionAndAutorange() {

‎test/jasmine/tests/plot_api_react_test.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,7 @@ describe('@noCIdep Plotly.react', function() {
210210
return Plotly.react(gd, data, layout);
211211
})
212212
.then(function() {
213-
// we get an extra call to layoutStyles from marginPushersAgain due to the colorbar.
214-
// Really need to simplify that pipeline...
215-
countCalls({plot: 1, layoutStyles: 1});
213+
countCalls({plot: 1});
216214

217215
layout.scene.camera = {up: {x: 1, y: 0, z: -1}};
218216

‎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)