Skip to content

Commit 7916edf

Browse files
authored
Merge pull request #7212 from plotly/drop-title-text-str
Drop support for passing a string to the `title` attribute, and drop support for deprecated attributes `titlefont`, `titleposition`, `titleside`, and `titleoffset`
2 parents d5bd3aa + 8a0362d commit 7916edf

25 files changed

+223
-6242
lines changed

draftlogs/7212_remove.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Drop support for passing a string to the `title` attribute, and drop support for deprecated attributes `titlefont`, `titleposition`, `titleside`, and `titleoffset` [[#7212](https://github.com/plotly/plotly.js/pull/7212)]

src/components/colorbar/attributes.js

+2-33
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,10 @@ module.exports = overrideAll({
212212
title: {
213213
text: {
214214
valType: 'string',
215-
description: [
216-
'Sets the title of the color bar.',
217-
'Note that before the existence of `title.text`, the title\'s',
218-
'contents used to be defined as the `title` attribute itself.',
219-
'This behavior has been deprecated.'
220-
].join(' ')
215+
description: 'Sets the title of the color bar.'
221216
},
222217
font: fontAttrs({
223-
description: [
224-
'Sets this color bar\'s title font.',
225-
'Note that the title\'s font used to be set',
226-
'by the now deprecated `titlefont` attribute.'
227-
].join(' ')
218+
description: 'Sets this color bar\'s title font.'
228219
}),
229220
side: {
230221
valType: 'enumerated',
@@ -234,29 +225,7 @@ module.exports = overrideAll({
234225
'with respect to the color bar.',
235226
'Defaults to *top* when `orientation` if *v* and ',
236227
'defaults to *right* when `orientation` if *h*.',
237-
'Note that the title\'s location used to be set',
238-
'by the now deprecated `titleside` attribute.'
239228
].join(' ')
240229
}
241230
},
242-
243-
_deprecated: {
244-
title: {
245-
valType: 'string',
246-
description: [
247-
'Deprecated in favor of color bar\'s `title.text`.',
248-
'Note that value of color bar\'s `title` is no longer a simple',
249-
'*string* but a set of sub-attributes.'
250-
].join(' ')
251-
},
252-
titlefont: fontAttrs({
253-
description: 'Deprecated in favor of color bar\'s `title.font`.'
254-
}),
255-
titleside: {
256-
valType: 'enumerated',
257-
values: ['right', 'top', 'bottom'],
258-
dflt: 'top',
259-
description: 'Deprecated in favor of color bar\'s `title.side`.'
260-
}
261-
}
262231
}, 'colorbars', 'from-root');

src/components/titles/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ var SUBTITLE_PADDING_EM = 1.6;
2222
* @param {DOM element} gd - the graphDiv
2323
* @param {string} titleClass - the css class of this title
2424
* @param {object} options - how and what to draw
25-
* propContainer - the layout object containing `title` and `titlefont`
26-
* attributes that apply to this title
25+
* propContainer - the layout object containing the `title` attribute that
26+
* applies to this title
2727
* propName - the full name of the title property (for Plotly.relayout)
2828
* [traceIndex] - include only if this property applies to one trace
2929
* (such as a colorbar title) - then editing pipes to Plotly.restyle

src/plot_api/helpers.js

-70
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,6 @@ exports.cleanLayout = function(layout) {
9090
delete ax.autotick;
9191
}
9292

93-
cleanTitle(ax);
94-
} else if(polarAttrRegex && polarAttrRegex.test(key)) {
95-
// modifications for polar
96-
97-
var polar = layout[key];
98-
cleanTitle(polar.radialaxis);
99-
} else if(ternaryAttrRegex && ternaryAttrRegex.test(key)) {
100-
// modifications for ternary
101-
102-
var ternary = layout[key];
103-
cleanTitle(ternary.aaxis);
104-
cleanTitle(ternary.baxis);
105-
cleanTitle(ternary.caxis);
106-
} else if(sceneAttrRegex && sceneAttrRegex.test(key)) {
107-
// modifications for 3D scenes
108-
109-
var scene = layout[key];
110-
111-
// clean axis titles
112-
cleanTitle(scene.xaxis);
113-
cleanTitle(scene.yaxis);
114-
cleanTitle(scene.zaxis);
11593
}
11694
}
11795

@@ -165,9 +143,6 @@ exports.cleanLayout = function(layout) {
165143
}
166144
}
167145

168-
// clean plot title
169-
cleanTitle(layout);
170-
171146
/*
172147
* Moved from rotate -> orbit for dragmode
173148
*/
@@ -193,44 +168,6 @@ function cleanAxRef(container, attr) {
193168
}
194169
}
195170

196-
/**
197-
* Cleans up old title attribute structure (flat) in favor of the new one (nested).
198-
*
199-
* @param {Object} titleContainer - an object potentially including deprecated title attributes
200-
*/
201-
function cleanTitle(titleContainer) {
202-
if(titleContainer) {
203-
// title -> title.text
204-
// (although title used to be a string attribute,
205-
// numbers are accepted as well)
206-
if(typeof titleContainer.title === 'string' || typeof titleContainer.title === 'number') {
207-
titleContainer.title = {
208-
text: titleContainer.title
209-
};
210-
}
211-
212-
rewireAttr('titlefont', 'font');
213-
rewireAttr('titleposition', 'position');
214-
rewireAttr('titleside', 'side');
215-
rewireAttr('titleoffset', 'offset');
216-
}
217-
218-
function rewireAttr(oldAttrName, newAttrName) {
219-
var oldAttrSet = titleContainer[oldAttrName];
220-
var newAttrSet = titleContainer.title && titleContainer.title[newAttrName];
221-
222-
if(oldAttrSet && !newAttrSet) {
223-
// Ensure title object exists
224-
if(!titleContainer.title) {
225-
titleContainer.title = {};
226-
}
227-
228-
titleContainer.title[newAttrName] = titleContainer[oldAttrName];
229-
delete titleContainer[oldAttrName];
230-
}
231-
}
232-
}
233-
234171
/*
235172
* cleanData: Make a few changes to the data for backward compatibility
236173
* before it gets used for anything. Modifies the data traces users provide.
@@ -410,13 +347,6 @@ exports.cleanData = function(data) {
410347
delete trace.autobiny;
411348
delete trace.ybins;
412349
}
413-
414-
cleanTitle(trace);
415-
if(trace.colorbar) cleanTitle(trace.colorbar);
416-
if(trace.marker && trace.marker.colorbar) cleanTitle(trace.marker.colorbar);
417-
if(trace.line && trace.line.colorbar) cleanTitle(trace.line.colorbar);
418-
if(trace.aaxis) cleanTitle(trace.aaxis);
419-
if(trace.baxis) cleanTitle(trace.baxis);
420350
}
421351
};
422352

src/plot_api/plot_api.js

-46
Original file line numberDiff line numberDiff line change
@@ -1397,8 +1397,6 @@ function _restyle(gd, aobj, traces) {
13971397
var eventData = Lib.extendDeepAll({}, aobj);
13981398
var i;
13991399

1400-
cleanDeprecatedAttributeKeys(aobj);
1401-
14021400
// initialize flags
14031401
var flags = editTypes.traceFlags();
14041402

@@ -1700,49 +1698,6 @@ function _restyle(gd, aobj, traces) {
17001698
};
17011699
}
17021700

1703-
/**
1704-
* Converts deprecated attribute keys to
1705-
* the current API to ensure backwards compatibility.
1706-
*
1707-
* This is needed for the update mechanism to determine which
1708-
* subroutines to run based on the actual attribute
1709-
* definitions (that don't include the deprecated ones).
1710-
*
1711-
* E.g. Maps {'xaxis.title': 'A chart'} to {'xaxis.title.text': 'A chart'}
1712-
* and {titlefont: {...}} to {'title.font': {...}}.
1713-
*
1714-
* @param aobj
1715-
*/
1716-
function cleanDeprecatedAttributeKeys(aobj) {
1717-
var oldAxisTitleRegex = Lib.counterRegex('axis', '\.title', false, false);
1718-
var colorbarRegex = /colorbar\.title$/;
1719-
var keys = Object.keys(aobj);
1720-
var i, key, value;
1721-
1722-
for(i = 0; i < keys.length; i++) {
1723-
key = keys[i];
1724-
value = aobj[key];
1725-
1726-
if((key === 'title' || oldAxisTitleRegex.test(key) || colorbarRegex.test(key)) &&
1727-
(typeof value === 'string' || typeof value === 'number')) {
1728-
replace(key, key.replace('title', 'title.text'));
1729-
} else if(key.indexOf('titlefont') > -1 && key.indexOf('grouptitlefont') === -1) {
1730-
replace(key, key.replace('titlefont', 'title.font'));
1731-
} else if(key.indexOf('titleposition') > -1) {
1732-
replace(key, key.replace('titleposition', 'title.position'));
1733-
} else if(key.indexOf('titleside') > -1) {
1734-
replace(key, key.replace('titleside', 'title.side'));
1735-
} else if(key.indexOf('titleoffset') > -1) {
1736-
replace(key, key.replace('titleoffset', 'title.offset'));
1737-
}
1738-
}
1739-
1740-
function replace(oldAttrStr, newAttrStr) {
1741-
aobj[newAttrStr] = aobj[oldAttrStr];
1742-
delete aobj[oldAttrStr];
1743-
}
1744-
}
1745-
17461701
/**
17471702
* relayout: update layout attributes of an existing plot
17481703
*
@@ -1926,7 +1881,6 @@ function _relayout(gd, aobj) {
19261881

19271882
var arrayStr, i, j;
19281883

1929-
cleanDeprecatedAttributeKeys(aobj);
19301884
keys = Object.keys(aobj);
19311885

19321886
// look for 'allaxes', split out into all axes

src/plots/cartesian/layout_attributes.js

+2-26
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,11 @@ module.exports = {
207207
text: {
208208
valType: 'string',
209209
editType: 'ticks',
210-
description: [
211-
'Sets the title of this axis.',
212-
'Note that before the existence of `title.text`, the title\'s',
213-
'contents used to be defined as the `title` attribute itself.',
214-
'This behavior has been deprecated.'
215-
].join(' ')
210+
description: 'Sets the title of this axis.'
216211
},
217212
font: fontAttrs({
218213
editType: 'ticks',
219-
description: [
220-
'Sets this axis\' title font.',
221-
'Note that the title\'s font used to be customized',
222-
'by the now deprecated `titlefont` attribute.'
223-
].join(' ')
214+
description: 'Sets this axis\' title font.'
224215
}),
225216
standoff: {
226217
valType: 'number',
@@ -1250,20 +1241,5 @@ module.exports = {
12501241
'Set `tickmode` to *linear* for `autotick` *false*.'
12511242
].join(' ')
12521243
},
1253-
title: {
1254-
valType: 'string',
1255-
editType: 'ticks',
1256-
description: [
1257-
'Value of `title` is no longer a simple *string* but a set of sub-attributes.',
1258-
'To set the axis\' title, please use `title.text` now.'
1259-
].join(' ')
1260-
},
1261-
titlefont: fontAttrs({
1262-
editType: 'ticks',
1263-
description: [
1264-
'Former `titlefont` is now the sub-attribute `font` of `title`.',
1265-
'To customize title font properties, please use `title.font` now.'
1266-
].join(' ')
1267-
})
12681244
}
12691245
};

src/plots/cartesian/tick_label_defaults.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = function handleTickLabelDefaults(containerIn, containerOut, coe
2727
var position = containerOut.ticklabelposition || '';
2828
var dfltFontColor = position.indexOf('inside') !== -1 ?
2929
contrast(options.bgColor) :
30-
// as with titlefont.color, inherit axis.color only if one was
30+
// as with title.font.color, inherit axis.color only if one was
3131
// explicitly provided
3232
(contColor && contColor !== layoutAttributes.color.dflt) ?
3333
contColor : font.color;

src/plots/gl3d/layout/axis_attributes.js

-4
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,4 @@ module.exports = overrideAll({
121121
zeroline: axesAttrs.zeroline,
122122
zerolinecolor: axesAttrs.zerolinecolor,
123123
zerolinewidth: axesAttrs.zerolinewidth,
124-
_deprecated: {
125-
title: axesAttrs._deprecated.title,
126-
titlefont: axesAttrs._deprecated.titlefont
127-
}
128124
}, 'plot', 'from-root');

src/plots/layout_attributes.js

+2-28
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,11 @@ module.exports = {
2626
text: {
2727
valType: 'string',
2828
editType: 'layoutstyle',
29-
description: [
30-
'Sets the plot\'s title.',
31-
'Note that before the existence of `title.text`, the title\'s',
32-
'contents used to be defined as the `title` attribute itself.',
33-
'This behavior has been deprecated.'
34-
].join(' ')
29+
description: 'Sets the plot\'s title.'
3530
},
3631
font: fontAttrs({
3732
editType: 'layoutstyle',
38-
description: [
39-
'Sets the title font.',
40-
'Note that the title\'s font used to be customized',
41-
'by the now deprecated `titlefont` attribute.'
42-
].join(' ')
33+
description: 'Sets the title font.'
4334
}),
4435
subtitle: {
4536
text: {
@@ -460,21 +451,4 @@ module.exports = {
460451
].join(' '),
461452
editType: 'none'
462453
}),
463-
_deprecated: {
464-
title: {
465-
valType: 'string',
466-
editType: 'layoutstyle',
467-
description: [
468-
'Value of `title` is no longer a simple *string* but a set of sub-attributes.',
469-
'To set the contents of the title, please use `title.text` now.'
470-
].join(' ')
471-
},
472-
titlefont: fontAttrs({
473-
editType: 'layoutstyle',
474-
description: [
475-
'Former `titlefont` is now the sub-attribute `font` of `title`.',
476-
'To customize title font properties, please use `title.font` now.'
477-
].join(' ')
478-
})
479-
}
480454
};

src/plots/polar/layout_attributes.js

-5
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,6 @@ var radialAxisAttrs = {
146146
},
147147

148148
editType: 'calc',
149-
150-
_deprecated: {
151-
title: axesAttrs._deprecated.title,
152-
titlefont: axesAttrs._deprecated.titlefont
153-
}
154149
};
155150

156151
extendFlat(

src/plots/ternary/layout_attributes.js

-4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ var ternaryAxesAttrs = {
6262
'all the minima set to zero.'
6363
].join(' ')
6464
},
65-
_deprecated: {
66-
title: axesAttrs._deprecated.title,
67-
titlefont: axesAttrs._deprecated.titlefont
68-
}
6965
};
7066

7167
var attrs = module.exports = overrideAll({

0 commit comments

Comments
 (0)