-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add subtitle to plots #7012
Add subtitle to plots #7012
Conversation
I think word wrap is out of the scope of this PR. cc: #382 |
@emilykl Do you think that the height of subtitle should push the margins? |
This is quite minor. "title": {
"text": "A simple plot",
"subtitle": {
"text": ""
}
}, |
Just addressed a baseline update in #7019. |
@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. |
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. |
For subtitles please add a French (or other languages that you know) translation to Line 13 in caf32e5
|
Co-authored-by: Mojtaba Samimi <[email protected]>
@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. |
If an empty title ( |
This one is fixed now. |
src/components/titles/index.js
Outdated
@@ -14,6 +14,8 @@ var interactConstants = require('../../constants/interactions'); | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
LINE_SPACING: 1.3, |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
This renders OK now after the fixes. |
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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?
Thanks @emilykl for this great PR 🏆 |
Thanks for this feature! |
Closes #6856
Adds ability to add a subtitle to plots.
layout.title.subtitle.font
editable: true