Skip to content

Commit 6797c9d

Browse files
first cut at automatic margins for long labels
1 parent 0d99411 commit 6797c9d

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/plots/cartesian/axes.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
var d3 = require('d3');
1313
var isNumeric = require('fast-isnumeric');
14+
var Plots = require('../../plots/plots');
1415

1516
var Registry = require('../../registry');
1617
var Lib = require('../../lib');
@@ -2100,10 +2101,23 @@ axes.doTicks = function(gd, axid, skipTitle) {
21002101
}
21012102
}
21022103

2104+
function doAutoMargins() {
2105+
var marginPush = ax.titlefont.size + 15 +
2106+
(axLetter === 'x' ? ax._boundingBox.height : ax._boundingBox.width);
2107+
2108+
if(!ax._marginPush || ax._marginPush < marginPush) {
2109+
ax._marginPush = marginPush;
2110+
var pushParams = {x: 0, y: 0, r: 0, l: 0, t: 0, b: 0};
2111+
pushParams[ax.side[0]] = marginPush;
2112+
Plots.autoMargin(gd, ax._name, pushParams);
2113+
}
2114+
}
2115+
21032116
var done = Lib.syncOrAsync([
21042117
allLabelsReady,
21052118
fixLabelOverlaps,
2106-
calcBoundingBox
2119+
calcBoundingBox,
2120+
doAutoMargins
21072121
]);
21082122
if(done && done.then) gd._promises.push(done);
21092123
return done;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"data": [{
3+
"type": "scatter",
4+
"name": "loooooong x",
5+
"x": [
6+
"short label 1", "loooooong label 1",
7+
"short label 2", "loooooong label 2",
8+
"short label 3", "loooooong label 3",
9+
"short label 4", "loooooong label 4",
10+
"short label 5", "loooooong label 5"
11+
],
12+
"y": [
13+
"short label 1", "loooooong label 1",
14+
"short label 2", "loooooong label 2",
15+
"short label 3", "loooooong label 3",
16+
"short label 4", "loooooong label 4",
17+
"short label 5", "loooooong label 5"
18+
]
19+
},
20+
{
21+
"yaxis": "y2",
22+
"type": "scatter",
23+
"name": "loooooong y",
24+
"x":["looooooooooooonger"],
25+
"y":["loooooonger"]
26+
}
27+
],
28+
"layout": {
29+
"xaxis": {"title": "X Axis Title", "titlefont": {"size": 80}},
30+
"yaxis": {"title": "Y Axis Title", "titlefont": {"size": 40}},
31+
"yaxis2": {
32+
"title": "Y2 Axis Title",
33+
"overlaying": "y",
34+
"side": "right"
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)