@@ -14,8 +14,8 @@ var interactConstants = require('../../constants/interactions');
14
14
15
15
var OPPOSITE_SIDE = require ( '../../constants/alignment' ) . OPPOSITE_SIDE ;
16
16
var numStripRE = / [ X Y ] [ 0 - 9 ] * / ;
17
- var MATHJAX_PADDING_MULTIPLIER = 0.85 ;
18
- var EXTRA_SPACING_BETWEEN_TITLE_AND_SUBTITLE = 0 ;
17
+ var SUBTITLE_PADDING_MATHJAX_EM = 1.6 ;
18
+ var SUBTITLE_PADDING_EM = 1.6 ;
19
19
20
20
/**
21
21
* Titles - (re)draw titles on the axes and plot:
@@ -207,12 +207,11 @@ function draw(gd, titleClass, options) {
207
207
208
208
var subtitleElement = d3 . select ( titleElMathGroup . node ( ) . parentNode ) . select ( '.' + subtitleClass ) ;
209
209
if ( ! subtitleElement . empty ( ) ) {
210
- var titleMathHeight = titleElMathGroup . node ( ) . getBBox ( ) . height ;
211
- if ( titleMathHeight ) {
212
- // Increase the y position of the subtitle by the height of the title,
213
- // plus a bit of padding
214
- var newSubtitleY = Number ( subtitleElement . attr ( 'y' ) ) + titleMathHeight + MATHJAX_PADDING_MULTIPLIER * subFontSize + EXTRA_SPACING_BETWEEN_TITLE_AND_SUBTITLE ;
215
- subtitleElement . attr ( 'y' , newSubtitleY ) ;
210
+ var titleElMathBbox = titleElMathGroup . node ( ) . getBBox ( ) ;
211
+ if ( titleElMathBbox . height ) {
212
+ // Position subtitle based on bottom of Mathjax title
213
+ var subtitleY = titleElMathBbox . y + titleElMathBbox . height + ( SUBTITLE_PADDING_MATHJAX_EM * subFontSize ) ;
214
+ subtitleElement . attr ( 'y' , subtitleY ) ;
216
215
}
217
216
}
218
217
}
@@ -233,15 +232,16 @@ function draw(gd, titleClass, options) {
233
232
. call ( svgTextUtils . convertToTspans , gd , adjustSubtitlePosition ) ;
234
233
235
234
if ( subtitleEl ) {
236
- // Increase the subtitle y position so that it is drawn below the subtitle
237
- // We need to check the height of the MathJax group as well, in case the MathJax
235
+ // Set subtitle y position based on bottom of title
236
+ // We need to check the Mathjax group as well, in case the Mathjax
238
237
// has already rendered
239
- var titleElHeight = titleEl . node ( ) . getBBox ( ) . height ;
240
238
var titleElMathGroup = group . select ( '.' + titleClass + '-math-group' ) ;
241
- var titleElMathHeight = titleElMathGroup . node ( ) ? titleElMathGroup . node ( ) . getBBox ( ) . height : 0 ;
242
- var subtitleShift = titleElMathHeight ? titleElMathHeight + ( MATHJAX_PADDING_MULTIPLIER * subFontSize ) : titleElHeight ;
239
+ var titleElBbox = titleEl . node ( ) . getBBox ( ) ;
240
+ var titleElMathBbox = titleElMathGroup . node ( ) ? titleElMathGroup . node ( ) . getBBox ( ) : undefined ;
241
+ var subtitleY = titleElMathBbox ? titleElMathBbox . y + titleElMathBbox . height + ( SUBTITLE_PADDING_MATHJAX_EM * subFontSize ) : titleElBbox . y + titleElBbox . height + ( SUBTITLE_PADDING_EM * subFontSize ) ;
242
+
243
243
var subtitleAttributes = Lib . extendFlat ( { } , attributes , {
244
- y : subtitleShift + EXTRA_SPACING_BETWEEN_TITLE_AND_SUBTITLE + attributes . y
244
+ y : subtitleY
245
245
} ) ;
246
246
247
247
subtitleEl . attr ( 'transform' , transformVal ) ;
@@ -380,9 +380,9 @@ function draw(gd, titleClass, options) {
380
380
// Adjust subtitle position now that title placeholder has been added
381
381
// Only adjust if subtitle is enabled and title text was originally empty
382
382
if ( subtitleEnabled && ! txt ) {
383
- var ht = Drawing . bBox ( el . node ( ) ) . height ;
384
- var newSubtitleY = Number ( subtitleEl . attr ( 'y' ) ) + ht + EXTRA_SPACING_BETWEEN_TITLE_AND_SUBTITLE ;
385
- subtitleEl . attr ( 'y' , newSubtitleY ) ;
383
+ var titleElBbox = Drawing . bBox ( el . node ( ) ) ;
384
+ var subtitleY = titleElBbox . y + titleElBbox . height + ( SUBTITLE_PADDING_EM * subFontSize ) ;
385
+ subtitleEl . attr ( 'y' , subtitleY ) ;
386
386
}
387
387
388
388
if ( ! subtitleTxt ) {
0 commit comments