diff --git a/draftlogs/7571_fix.md b/draftlogs/7571_fix.md new file mode 100644 index 00000000000..c672c3db524 --- /dev/null +++ b/draftlogs/7571_fix.md @@ -0,0 +1 @@ +- Fix `layout.title.subtitle` does not properly clear/remove from the chart when `subtitle` object is not in place, or `subtitle.text` set to `null`, empty string, or whitespace-only values. [[#7571](https://github.com/plotly/plotly.js/pull/7571)] diff --git a/src/components/titles/index.js b/src/components/titles/index.js index 6637343cdad..8a360a5153c 100644 --- a/src/components/titles/index.js +++ b/src/components/titles/index.js @@ -81,7 +81,7 @@ function draw(gd, titleClass, options) { var subtitleEnabled = !!subtitleProp; var subtitlePlaceholder = options.subtitlePlaceholder; var subtitle = (cont.title || {}).subtitle || {text: '', font: {}}; - var subtitleTxt = subtitle.text.trim(); + var subtitleTxt = (subtitle.text || '').trim(); var subtitleIsPlaceholder = false; var subtitleOpacity = 1; @@ -160,7 +160,7 @@ function draw(gd, titleClass, options) { var subtitleClass = titleClass + '-subtitle'; var subtitleElShouldExist = subtitleTxt || editable; - if(subtitleEnabled && subtitleElShouldExist) { + if(subtitleEnabled) { subtitleEl = group.selectAll('text.' + subtitleClass) .data(subtitleElShouldExist ? [0] : []); subtitleEl.enter().append('text'); @@ -231,7 +231,7 @@ function draw(gd, titleClass, options) { .attr(attributes) .call(svgTextUtils.convertToTspans, gd, adjustSubtitlePosition); - if(subtitleEl) { + if(subtitleEl && !subtitleEl.empty()) { // Set subtitle y position based on bottom of title // We need to check the Mathjax group as well, in case the Mathjax // has already rendered @@ -405,7 +405,7 @@ function draw(gd, titleClass, options) { } el.classed('js-placeholder', titleIsPlaceholder); - if(subtitleEl) subtitleEl.classed('js-placeholder', subtitleIsPlaceholder); + if(subtitleEl && !subtitleEl.empty()) subtitleEl.classed('js-placeholder', subtitleIsPlaceholder); return group; }