-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add subtitle to plots #7012
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
Changes from 1 commit
24ed9c9
7469d8e
3afc2e7
13f8b2a
cf5eb51
4a55ff2
625ea53
972836e
f6e9781
35a6599
60a6287
7eb9e52
7e9fcf9
3190382
608740f
183518c
2452a48
8bce81b
2aca950
ade53d3
13af030
b2a26e0
2790ec7
03638ee
8210b58
496ccc7
15754fa
f2cbc23
f3842e0
e3813f2
e70e521
e9e8adb
0d154bb
2aa2b8f
527ff8d
28d30ee
aa7b0a6
db5de4d
154f481
6701eee
313301c
423dfd3
cef06c8
7cc019d
b7cda0b
ec166a3
8e44892
e189245
de628de
47a5b82
b8942ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -14,7 +14,8 @@ var interactConstants = require('../../constants/interactions'); | |||
|
||||
var OPPOSITE_SIDE = require('../../constants/alignment').OPPOSITE_SIDE; | ||||
var numStripRE = / [XY][0-9]* /; | ||||
var MATHJAX_PADDING_BOTTOM = 10; | ||||
var MATHJAX_PADDING_MULTIPLIER = 0.83; | ||||
var EXTRA_SPACING_BETWEEN_TITLE_AND_SUBTITLE = 0; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; plotly.js/src/constants/alignment.js Line 34 in 8b1f5bd
This is why: 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 I prefer the more compact look. |
||||
|
||||
/** | ||||
* Titles - (re)draw titles on the axes and plot: | ||||
|
@@ -79,12 +80,12 @@ function draw(gd, titleClass, options) { | |||
var subtitleProp = options.subtitlePropName; | ||||
var subtitleEnabled = !!subtitleProp; | ||||
var subtitlePlaceholder = options.subtitlePlaceholder; | ||||
var subtitle = (cont.title || {}).subtitle; | ||||
var subtitleTxt = (subtitle && subtitle.text ? subtitle.text : '').trim(); | ||||
var subtitle = (cont.title || {}).subtitle || {text: '', font: {}}; | ||||
var subtitleTxt = subtitle.text.trim(); | ||||
var subtitleIsPlaceholder = false; | ||||
var subtitleOpacity = 1; | ||||
|
||||
var subtitleFont = subtitle && subtitle.font ? subtitle.font : {}; | ||||
var subtitleFont = subtitle.font; | ||||
var subFontFamily = subtitleFont.family; | ||||
var subFontSize = subtitleFont.size; | ||||
var subFontColor = subtitleFont.color; | ||||
|
@@ -210,7 +211,7 @@ function draw(gd, titleClass, options) { | |||
if(titleMathHeight) { | ||||
// Increase the y position of the subtitle by the height of the title, | ||||
// plus a bit of padding | ||||
var newSubtitleY = Number(subtitleElement.attr('y')) + titleMathHeight + MATHJAX_PADDING_BOTTOM; | ||||
var newSubtitleY = Number(subtitleElement.attr('y')) + titleMathHeight + MATHJAX_PADDING_MULTIPLIER * subFontSize + EXTRA_SPACING_BETWEEN_TITLE_AND_SUBTITLE; | ||||
subtitleElement.attr('y', newSubtitleY); | ||||
} | ||||
} | ||||
|
@@ -238,9 +239,9 @@ function draw(gd, titleClass, options) { | |||
var titleElHeight = titleEl.node().getBBox().height; | ||||
var titleElMathGroup = group.select('.' + titleClass + '-math-group'); | ||||
var titleElMathHeight = titleElMathGroup.node() ? titleElMathGroup.node().getBBox().height : 0; | ||||
var subtitleShift = titleElMathHeight ? titleElMathHeight + MATHJAX_PADDING_BOTTOM : titleElHeight; | ||||
var subtitleShift = titleElMathHeight ? titleElMathHeight + (MATHJAX_PADDING_MULTIPLIER * subFontSize) : titleElHeight; | ||||
var subtitleAttributes = Lib.extendFlat({}, attributes, { | ||||
y: subtitleShift + attributes.y | ||||
y: subtitleShift + EXTRA_SPACING_BETWEEN_TITLE_AND_SUBTITLE + attributes.y | ||||
}); | ||||
|
||||
subtitleEl.attr('transform', transformVal); | ||||
|
@@ -380,7 +381,7 @@ function draw(gd, titleClass, options) { | |||
// Only adjust if subtitle is enabled and title text was originally empty | ||||
if(subtitleEnabled && !txt) { | ||||
var ht = Drawing.bBox(el.node()).height; | ||||
var newSubtitleY = Number(subtitleEl.attr('y')) + ht; | ||||
var newSubtitleY = Number(subtitleEl.attr('y')) + ht + EXTRA_SPACING_BETWEEN_TITLE_AND_SUBTITLE; | ||||
subtitleEl.attr('y', newSubtitleY); | ||||
} | ||||
|
||||
|
Uh oh!
There was an error while loading. Please reload this page.