Skip to content

Commit 68c6165

Browse files
committed
Initial pass with hard-coded automargin params
1 parent b03f295 commit 68c6165

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

src/components/titles/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ function draw(gd, titleClass, options) {
7777
else if(prop.indexOf('colorbar' !== -1)) editAttr = 'colorbarTitleText';
7878
var editable = gd._context.edits[editAttr];
7979

80+
if(editAttr === 'titleText' && title.automargin === true) {
81+
// TODO: Could there ever be more than one title?
82+
var titleID = 'title.automargin';
83+
Plots.allowAutoMargin(gd, titleID);
84+
// TODO: Remove hard-coding
85+
Plots.autoMargin(gd, titleID, {
86+
x: 0.5,
87+
y: 1,
88+
l: 0,
89+
r: 0,
90+
t: 50,
91+
b: 0});
92+
}
93+
8094
if(txt === '') opacity = 0;
8195
// look for placeholder text while stripping out numbers from eg X2, Y3
8296
// this is just for backward compatibility with the old version that had

src/plot_api/plot_api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ function _doPlot(gd, data, layout, config) {
277277

278278
subroutines.drawMarginPushers(gd);
279279
Axes.allowAutoMargin(gd);
280+
Plots.allowAutoMargin(gd, 'title.automargin');
280281

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

src/plots/layout_attributes.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ module.exports = {
125125
'Padding is muted if the respective anchor value is *middle*/*center*.'
126126
].join(' ')
127127
}),
128+
automargin: {
129+
valType: 'boolean',
130+
dflt: false,
131+
role: 'info',
132+
editType: 'plot',
133+
description: [
134+
'Determines whether the title can automatically push the figure margins.'
135+
].join(' ')
136+
},
128137
editType: 'layoutstyle'
129138
},
130139
uniformtext: {

src/plots/plots.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,7 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) {
14891489
coerce('title.pad.r');
14901490
coerce('title.pad.b');
14911491
coerce('title.pad.l');
1492+
coerce('title.automargin');
14921493

14931494
var uniformtextMode = coerce('uniformtext.mode');
14941495
if(uniformtextMode) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"data": [
3+
{
4+
"showlegend": false,
5+
"type": "scatter",
6+
"x": [
7+
1,
8+
2,
9+
3
10+
],
11+
"y": [
12+
4,
13+
5,
14+
6
15+
]
16+
}],
17+
"layout": {
18+
"margin": {"t":0, "b": 0, "l": 0, "r": 0},
19+
"yaxis": {
20+
"automargin": true,
21+
"title": {"text": "Y-axis"}
22+
},
23+
"xaxis": {"automargin": true,
24+
"title": {"text": "X-axis"}
25+
},
26+
"title": {
27+
"automargin": true,
28+
"text": "Some text"
29+
}
30+
}
31+
}

test/plot-schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9425,6 +9425,13 @@
94259425
}
94269426
},
94279427
"title": {
9428+
"automargin": {
9429+
"description": "Determines whether the title can automatically push the figure margins.",
9430+
"dflt": false,
9431+
"editType": "plot",
9432+
"role": "info",
9433+
"valType": "boolean"
9434+
},
94289435
"editType": "layoutstyle",
94299436
"font": {
94309437
"color": {

0 commit comments

Comments
 (0)