Repository navigation
Add subtitle to plots - #7012
Conversation
commented
Jun 5, 2024
I think word wrap is out of the scope of this PR. cc: #382 |
commented
Jun 5, 2024
|
@emilykl Do you think that the height of subtitle should push the margins? |
commented
Jun 5, 2024
|
This is quite minor. "title": {
"text": "A simple plot",
"subtitle": {
"text": ""
}
}, |
commented
Jun 6, 2024
|
Just addressed a baseline update in #7019. |
commented
Jun 6, 2024
@archmoj I would say "Yes, obviously", except that it looks like currently, even the height of the title doesn't push the margins -- if you add too many lines to the title, it will overlap the chart (see codepen). So I think if we make the subtitle push the margins dynamically, we need to make that the behavior for the title as well. I guess the other option would be to push the margin by a fixed amount if there is a subtitle present. I'm not sure whether that's necessary though; the current amount of space looks OK to me if the subtitle is one or two lines. |
commented
Jun 6, 2024
good catch, thanks. Do you know where this styling is set in the code? I think this is probably also related to the bug I noticed where the size of the text currently being edited is too large for the subtitle. |
commented
Jun 17, 2024
|
For subtitles please add a French (or other languages that you know) translation to Line 13 in caf32e5 |
Co-authored-by: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com>
commented
Jul 9, 2024
@archmoj Good catch. I've modified the logic so that the subtitle is rendered even if there is no title (or the title is just a placeholder). But the placement is a bit odd since the subtitle is positioned according to the height of the title, and the title height is 0. Would you suggest any changes here? I'm inclined to leave as-is since this is a pretty rare edge case and doing anything more complicated would be kind of tricky and involve a bunch of extra logic. |
commented
Jul 9, 2024
If an empty title ( |
commented
Jul 9, 2024
This one is fixed now. |
| var OPPOSITE_SIDE = require('../../constants/alignment').OPPOSITE_SIDE; | ||
| var numStripRE = / [XY][0-9]* /; | ||
| var MATHJAX_PADDING_MULTIPLIER = 0.85; | ||
| var EXTRA_SPACING_BETWEEN_TITLE_AND_SUBTITLE = 0; |
There was a problem hiding this comment.
Although I kind of like the current positioning of subtitle which is compact;
I was wondering the correct value for this constant might be 1.3
plotly.js/src/constants/alignment.js
Line 34 in 8b1f5bd
This is why:
If I call
Plotly.newPlot(gd, [{y: [1, 2]}], {title: {text: 'title', subtitle: {text: 'subtittle'}}});the subtitle render closer compared to when I call
Plotly.newPlot(gd, [{y: [1, 2]}], {title: {text: 'title<br><sub>subtittle</sub>'}}); So perhaps you could try using (LINE_SPACING - 1) * title.font.size in your calculations?
There was a problem hiding this comment.
@archmoj Do you think the subtitle looks better with additional spacing?
I'd prefer not to change the spacing just to match the appearance of <sub>, since that spacing is arbitrary.
I prefer the more compact look.
commented
Jul 11, 2024
This renders OK now after the fixes. |
commented
Jul 11, 2024
|
@emilykl Would you try taking into account the height of subtitle text in the |
| "subtitle": { | ||
| "editType": "layoutstyle", | ||
| "font": { | ||
| "color": { | ||
| "editType": "layoutstyle", | ||
| "valType": "color" | ||
| }, |
There was a problem hiding this comment.
@emilykl Do any of the property values inherit from layout.title?
Also, layout.title.subtitle.font.size is 70% of layout.title.font.size unless set?
commented
Jul 16, 2024
commented
Jul 18, 2024
|
Thanks @emilykl for this great PR 🏆 |
commented
Jul 18, 2024
commented
Aug 7, 2024
|
Thanks for this feature! |


Closes #6856
Adds ability to add a subtitle to plots.
layout.title.subtitle.fonteditable: true