Skip to content

Commit

Permalink
fix ax automargin for multi-line ax titles
Browse files Browse the repository at this point in the history
- automargin-multiline-titles and
  automargin-rangeslider-and-sidepush now push the
  bottom enough to make their axis title visible
  • Loading branch information
etpinard committed Sep 4, 2019
1 parent daa88e0 commit 40f1b24
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
21 changes: 19 additions & 2 deletions src/components/rangeslider/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
'use strict';

var axisIDs = require('../../plots/cartesian/axis_ids');
var svgTextUtils = require('../../lib/svg_text_utils');
var constants = require('./constants');
var LINE_SPACING = require('../../constants/alignment').LINE_SPACING;
var name = constants.name;

function isVisible(ax) {
Expand Down Expand Up @@ -42,15 +44,30 @@ exports.makeData = function(fullLayout) {
};

exports.autoMarginOpts = function(gd, ax) {
var fullLayout = gd._fullLayout;
var opts = ax[name];
var bottomDepth = ax.side === 'bottom' ? ax._depth : 0;
var axLetter = ax._id.charAt(0);

var bottomDepth = 0;
var titleHeight = 0;
if(ax.side === 'bottom') {
bottomDepth = ax._depth;
if(ax.title.text !== fullLayout._dfltTitle[axLetter]) {
// as in rangeslider/draw.js
titleHeight = 1.5 * ax.title.font.size + 10 + opts._offsetShift;
// multi-line extra bump
var extraLines = (ax.title.text.match(svgTextUtils.BR_TAG_ALL) || []).length;
titleHeight += extraLines * ax.title.font.size * LINE_SPACING;
}
}

return {
x: 0,
y: ax._counterDomainMin,
l: 0,
r: 0,
t: 0,
b: opts._height + gd._fullLayout.margin.b + bottomDepth,
b: opts._height + bottomDepth + Math.max(fullLayout.margin.b, titleHeight),
pad: constants.extraPad + opts._offsetShift * 2
};
};
1 change: 1 addition & 0 deletions src/lib/svg_text_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ var SPLIT_TAGS = /(<[^<>]*>)/;
var ONE_TAG = /<(\/?)([^ >]*)(\s+(.*))?>/i;

var BR_TAG = /<br(\s+.*)?>/i;
exports.BR_TAG_ALL = /<br(\s+.*)?>/gi;

/*
* style and href: pull them out of either single or double quotes. Also
Expand Down
6 changes: 4 additions & 2 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1934,9 +1934,11 @@ axes.drawOne = function(gd, ax, opts) {
ax.position :
ax._anchorAxis.domain[domainIndices[0]];

// TODO won't work for multi-line titles !!
if(ax.title.text !== fullLayout._dfltTitle[axLetter]) {
push[s] += ax.title.font.size;
var extraLines = (ax.title.text.match(svgTextUtils.BR_TAG_ALL) || []).length;
push[s] += extraLines ?
ax.title.font.size * (extraLines + 1) * LINE_SPACING :
ax.title.font.size;
}

if(ax.mirror) {
Expand Down
Binary file modified test/image/baselines/automargin-multiline-titles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/automargin-rangeslider-and-sidepush.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 40f1b24

Please sign in to comment.