Skip to content

Commit

Permalink
Merge pull request #7212 from plotly/drop-title-text-str
Browse files Browse the repository at this point in the history
Drop support for passing a string to the `title` attribute, and drop support for deprecated attributes `titlefont`, `titleposition`, `titleside`,  and `titleoffset`
  • Loading branch information
emilykl authored Oct 9, 2024
2 parents d5bd3aa + 8a0362d commit 7916edf
Show file tree
Hide file tree
Showing 25 changed files with 223 additions and 6,242 deletions.
1 change: 1 addition & 0 deletions draftlogs/7212_remove.md
Original file line number Diff line number Diff line change
@@ -0,0 +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)]
35 changes: 2 additions & 33 deletions src/components/colorbar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,10 @@ module.exports = overrideAll({
title: {
text: {
valType: 'string',
description: [
'Sets the title of the color bar.',
'Note that before the existence of `title.text`, the title\'s',
'contents used to be defined as the `title` attribute itself.',
'This behavior has been deprecated.'
].join(' ')
description: 'Sets the title of the color bar.'
},
font: fontAttrs({
description: [
'Sets this color bar\'s title font.',
'Note that the title\'s font used to be set',
'by the now deprecated `titlefont` attribute.'
].join(' ')
description: 'Sets this color bar\'s title font.'
}),
side: {
valType: 'enumerated',
Expand All @@ -234,29 +225,7 @@ module.exports = overrideAll({
'with respect to the color bar.',
'Defaults to *top* when `orientation` if *v* and ',
'defaults to *right* when `orientation` if *h*.',
'Note that the title\'s location used to be set',
'by the now deprecated `titleside` attribute.'
].join(' ')
}
},

_deprecated: {
title: {
valType: 'string',
description: [
'Deprecated in favor of color bar\'s `title.text`.',
'Note that value of color bar\'s `title` is no longer a simple',
'*string* but a set of sub-attributes.'
].join(' ')
},
titlefont: fontAttrs({
description: 'Deprecated in favor of color bar\'s `title.font`.'
}),
titleside: {
valType: 'enumerated',
values: ['right', 'top', 'bottom'],
dflt: 'top',
description: 'Deprecated in favor of color bar\'s `title.side`.'
}
}
}, 'colorbars', 'from-root');
4 changes: 2 additions & 2 deletions src/components/titles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ var SUBTITLE_PADDING_EM = 1.6;
* @param {DOM element} gd - the graphDiv
* @param {string} titleClass - the css class of this title
* @param {object} options - how and what to draw
* propContainer - the layout object containing `title` and `titlefont`
* attributes that apply to this title
* propContainer - the layout object containing the `title` attribute that
* applies to this title
* propName - the full name of the title property (for Plotly.relayout)
* [traceIndex] - include only if this property applies to one trace
* (such as a colorbar title) - then editing pipes to Plotly.restyle
Expand Down
70 changes: 0 additions & 70 deletions src/plot_api/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,6 @@ exports.cleanLayout = function(layout) {
delete ax.autotick;
}

cleanTitle(ax);
} else if(polarAttrRegex && polarAttrRegex.test(key)) {
// modifications for polar

var polar = layout[key];
cleanTitle(polar.radialaxis);
} else if(ternaryAttrRegex && ternaryAttrRegex.test(key)) {
// modifications for ternary

var ternary = layout[key];
cleanTitle(ternary.aaxis);
cleanTitle(ternary.baxis);
cleanTitle(ternary.caxis);
} else if(sceneAttrRegex && sceneAttrRegex.test(key)) {
// modifications for 3D scenes

var scene = layout[key];

// clean axis titles
cleanTitle(scene.xaxis);
cleanTitle(scene.yaxis);
cleanTitle(scene.zaxis);
}
}

Expand Down Expand Up @@ -165,9 +143,6 @@ exports.cleanLayout = function(layout) {
}
}

// clean plot title
cleanTitle(layout);

/*
* Moved from rotate -> orbit for dragmode
*/
Expand All @@ -193,44 +168,6 @@ function cleanAxRef(container, attr) {
}
}

/**
* Cleans up old title attribute structure (flat) in favor of the new one (nested).
*
* @param {Object} titleContainer - an object potentially including deprecated title attributes
*/
function cleanTitle(titleContainer) {
if(titleContainer) {
// title -> title.text
// (although title used to be a string attribute,
// numbers are accepted as well)
if(typeof titleContainer.title === 'string' || typeof titleContainer.title === 'number') {
titleContainer.title = {
text: titleContainer.title
};
}

rewireAttr('titlefont', 'font');
rewireAttr('titleposition', 'position');
rewireAttr('titleside', 'side');
rewireAttr('titleoffset', 'offset');
}

function rewireAttr(oldAttrName, newAttrName) {
var oldAttrSet = titleContainer[oldAttrName];
var newAttrSet = titleContainer.title && titleContainer.title[newAttrName];

if(oldAttrSet && !newAttrSet) {
// Ensure title object exists
if(!titleContainer.title) {
titleContainer.title = {};
}

titleContainer.title[newAttrName] = titleContainer[oldAttrName];
delete titleContainer[oldAttrName];
}
}
}

/*
* cleanData: Make a few changes to the data for backward compatibility
* before it gets used for anything. Modifies the data traces users provide.
Expand Down Expand Up @@ -410,13 +347,6 @@ exports.cleanData = function(data) {
delete trace.autobiny;
delete trace.ybins;
}

cleanTitle(trace);
if(trace.colorbar) cleanTitle(trace.colorbar);
if(trace.marker && trace.marker.colorbar) cleanTitle(trace.marker.colorbar);
if(trace.line && trace.line.colorbar) cleanTitle(trace.line.colorbar);
if(trace.aaxis) cleanTitle(trace.aaxis);
if(trace.baxis) cleanTitle(trace.baxis);
}
};

Expand Down
46 changes: 0 additions & 46 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1397,8 +1397,6 @@ function _restyle(gd, aobj, traces) {
var eventData = Lib.extendDeepAll({}, aobj);
var i;

cleanDeprecatedAttributeKeys(aobj);

// initialize flags
var flags = editTypes.traceFlags();

Expand Down Expand Up @@ -1700,49 +1698,6 @@ function _restyle(gd, aobj, traces) {
};
}

/**
* Converts deprecated attribute keys to
* the current API to ensure backwards compatibility.
*
* This is needed for the update mechanism to determine which
* subroutines to run based on the actual attribute
* definitions (that don't include the deprecated ones).
*
* E.g. Maps {'xaxis.title': 'A chart'} to {'xaxis.title.text': 'A chart'}
* and {titlefont: {...}} to {'title.font': {...}}.
*
* @param aobj
*/
function cleanDeprecatedAttributeKeys(aobj) {
var oldAxisTitleRegex = Lib.counterRegex('axis', '\.title', false, false);
var colorbarRegex = /colorbar\.title$/;
var keys = Object.keys(aobj);
var i, key, value;

for(i = 0; i < keys.length; i++) {
key = keys[i];
value = aobj[key];

if((key === 'title' || oldAxisTitleRegex.test(key) || colorbarRegex.test(key)) &&
(typeof value === 'string' || typeof value === 'number')) {
replace(key, key.replace('title', 'title.text'));
} else if(key.indexOf('titlefont') > -1 && key.indexOf('grouptitlefont') === -1) {
replace(key, key.replace('titlefont', 'title.font'));
} else if(key.indexOf('titleposition') > -1) {
replace(key, key.replace('titleposition', 'title.position'));
} else if(key.indexOf('titleside') > -1) {
replace(key, key.replace('titleside', 'title.side'));
} else if(key.indexOf('titleoffset') > -1) {
replace(key, key.replace('titleoffset', 'title.offset'));
}
}

function replace(oldAttrStr, newAttrStr) {
aobj[newAttrStr] = aobj[oldAttrStr];
delete aobj[oldAttrStr];
}
}

/**
* relayout: update layout attributes of an existing plot
*
Expand Down Expand Up @@ -1926,7 +1881,6 @@ function _relayout(gd, aobj) {

var arrayStr, i, j;

cleanDeprecatedAttributeKeys(aobj);
keys = Object.keys(aobj);

// look for 'allaxes', split out into all axes
Expand Down
28 changes: 2 additions & 26 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,11 @@ module.exports = {
text: {
valType: 'string',
editType: 'ticks',
description: [
'Sets the title of this axis.',
'Note that before the existence of `title.text`, the title\'s',
'contents used to be defined as the `title` attribute itself.',
'This behavior has been deprecated.'
].join(' ')
description: 'Sets the title of this axis.'
},
font: fontAttrs({
editType: 'ticks',
description: [
'Sets this axis\' title font.',
'Note that the title\'s font used to be customized',
'by the now deprecated `titlefont` attribute.'
].join(' ')
description: 'Sets this axis\' title font.'
}),
standoff: {
valType: 'number',
Expand Down Expand Up @@ -1250,20 +1241,5 @@ module.exports = {
'Set `tickmode` to *linear* for `autotick` *false*.'
].join(' ')
},
title: {
valType: 'string',
editType: 'ticks',
description: [
'Value of `title` is no longer a simple *string* but a set of sub-attributes.',
'To set the axis\' title, please use `title.text` now.'
].join(' ')
},
titlefont: fontAttrs({
editType: 'ticks',
description: [
'Former `titlefont` is now the sub-attribute `font` of `title`.',
'To customize title font properties, please use `title.font` now.'
].join(' ')
})
}
};
2 changes: 1 addition & 1 deletion src/plots/cartesian/tick_label_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function handleTickLabelDefaults(containerIn, containerOut, coe
var position = containerOut.ticklabelposition || '';
var dfltFontColor = position.indexOf('inside') !== -1 ?
contrast(options.bgColor) :
// as with titlefont.color, inherit axis.color only if one was
// as with title.font.color, inherit axis.color only if one was
// explicitly provided
(contColor && contColor !== layoutAttributes.color.dflt) ?
contColor : font.color;
Expand Down
4 changes: 0 additions & 4 deletions src/plots/gl3d/layout/axis_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,4 @@ module.exports = overrideAll({
zeroline: axesAttrs.zeroline,
zerolinecolor: axesAttrs.zerolinecolor,
zerolinewidth: axesAttrs.zerolinewidth,
_deprecated: {
title: axesAttrs._deprecated.title,
titlefont: axesAttrs._deprecated.titlefont
}
}, 'plot', 'from-root');
30 changes: 2 additions & 28 deletions src/plots/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,11 @@ module.exports = {
text: {
valType: 'string',
editType: 'layoutstyle',
description: [
'Sets the plot\'s title.',
'Note that before the existence of `title.text`, the title\'s',
'contents used to be defined as the `title` attribute itself.',
'This behavior has been deprecated.'
].join(' ')
description: 'Sets the plot\'s title.'
},
font: fontAttrs({
editType: 'layoutstyle',
description: [
'Sets the title font.',
'Note that the title\'s font used to be customized',
'by the now deprecated `titlefont` attribute.'
].join(' ')
description: 'Sets the title font.'
}),
subtitle: {
text: {
Expand Down Expand Up @@ -460,21 +451,4 @@ module.exports = {
].join(' '),
editType: 'none'
}),
_deprecated: {
title: {
valType: 'string',
editType: 'layoutstyle',
description: [
'Value of `title` is no longer a simple *string* but a set of sub-attributes.',
'To set the contents of the title, please use `title.text` now.'
].join(' ')
},
titlefont: fontAttrs({
editType: 'layoutstyle',
description: [
'Former `titlefont` is now the sub-attribute `font` of `title`.',
'To customize title font properties, please use `title.font` now.'
].join(' ')
})
}
};
5 changes: 0 additions & 5 deletions src/plots/polar/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@ var radialAxisAttrs = {
},

editType: 'calc',

_deprecated: {
title: axesAttrs._deprecated.title,
titlefont: axesAttrs._deprecated.titlefont
}
};

extendFlat(
Expand Down
4 changes: 0 additions & 4 deletions src/plots/ternary/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ var ternaryAxesAttrs = {
'all the minima set to zero.'
].join(' ')
},
_deprecated: {
title: axesAttrs._deprecated.title,
titlefont: axesAttrs._deprecated.titlefont
}
};

var attrs = module.exports = overrideAll({
Expand Down
Loading

0 comments on commit 7916edf

Please sign in to comment.