Skip to content

Commit 8199d38

Browse files
committed
fixup axis title position when having inside tick labels
1 parent 2c3298d commit 8199d38

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

src/plots/cartesian/axes.js

+20-11
Original file line numberDiff line numberDiff line change
@@ -3334,27 +3334,36 @@ function drawTitle(gd, ax) {
33343334
var axId = ax._id;
33353335
var axLetter = axId.charAt(0);
33363336
var fontSize = ax.title.font.size;
3337-
33383337
var titleStandoff;
33393338

33403339
if(ax.title.hasOwnProperty('standoff')) {
33413340
titleStandoff = ax._depth + ax.title.standoff + approxTitleDepth(ax);
33423341
} else {
3342+
var isInside = (ax.ticklabelposition || '').indexOf('inside') !== -1;
3343+
33433344
if(ax.type === 'multicategory') {
33443345
titleStandoff = ax._depth;
33453346
} else {
3346-
var offsetBase = 1.5;
3347-
titleStandoff = 10 + fontSize * offsetBase + (ax.linewidth ? ax.linewidth - 1 : 0);
3347+
var offsetBase = 1.5 * fontSize;
3348+
if(isInside) {
3349+
offsetBase = 0.5 * fontSize;
3350+
if(ax.ticks === 'outside') {
3351+
offsetBase += ax.ticklen;
3352+
}
3353+
}
3354+
titleStandoff = 10 + offsetBase + (ax.linewidth ? ax.linewidth - 1 : 0);
33483355
}
33493356

3350-
if(axLetter === 'x') {
3351-
titleStandoff += ax.side === 'top' ?
3352-
fontSize * (ax.showticklabels ? 1 : 0) :
3353-
fontSize * (ax.showticklabels ? 1.5 : 0.5);
3354-
} else {
3355-
titleStandoff += ax.side === 'right' ?
3356-
fontSize * (ax.showticklabels ? 1 : 0.5) :
3357-
fontSize * (ax.showticklabels ? 0.5 : 0);
3357+
if(!isInside) {
3358+
if(axLetter === 'x') {
3359+
titleStandoff += ax.side === 'top' ?
3360+
fontSize * (ax.showticklabels ? 1 : 0) :
3361+
fontSize * (ax.showticklabels ? 1.5 : 0.5);
3362+
} else {
3363+
titleStandoff += ax.side === 'right' ?
3364+
fontSize * (ax.showticklabels ? 1 : 0.5) :
3365+
fontSize * (ax.showticklabels ? 0.5 : 0);
3366+
}
33583367
}
33593368
}
33603369

2.73 KB
Loading

test/image/mocks/ticklabelposition-4.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -3281,9 +3281,11 @@
32813281
"tracegroupgap": 0
32823282
},
32833283
"title": {
3284+
"font": {
3285+
"size": 24
3286+
},
32843287
"text": "custom tick labels with ticklabelmode=\"period\""
32853288
},
3286-
32873289
"xaxis": {
32883290
"anchor": "y",
32893291
"domain": [
@@ -3295,7 +3297,11 @@
32953297
"tickformat": "%b\n%Y",
32963298
"ticklabelmode": "period",
32973299
"ticklabelposition": "inside",
3300+
"ticklen": 5,
32983301
"title": {
3302+
"font": {
3303+
"size": 20
3304+
},
32993305
"text": "date"
33003306
}
33013307
},
@@ -3308,7 +3314,11 @@
33083314
"linewidth": 2,
33093315
"side": "right",
33103316
"ticklabelposition": "inside top",
3317+
"ticklen": 10,
33113318
"title": {
3319+
"font": {
3320+
"size": 20
3321+
},
33123322
"text": "value"
33133323
}
33143324
}

0 commit comments

Comments
 (0)