Skip to content

Commit e4dbc5d

Browse files
committed
Transition carpet to new title attr structure [882]
- Also remove unnecessary code in carpet implementation.
1 parent a4e43a6 commit e4dbc5d

File tree

5 files changed

+76
-32
lines changed

5 files changed

+76
-32
lines changed

src/plot_api/helpers.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ function cleanTitle(titleContainer) {
241241
};
242242
}
243243

244+
// TODO 882 DRY UP?
244245
// titlefont -> title.font
245246
var oldFontAttrSet = Lib.isPlainObject(titleContainer.titlefont);
246247
var newFontAttrSet = titleContainer.title && Lib.isPlainObject(titleContainer.title.font);
@@ -261,6 +262,13 @@ function cleanTitle(titleContainer) {
261262
if(oldSideAttrSet && !newSideAttrSet) {
262263
nestTitleAttr('titleside', 'side');
263264
}
265+
266+
// titleoffset -> title.offset
267+
var oldOffsetAttrSet = titleContainer.titleoffset;
268+
var newOffsetAttrSet = titleContainer.title && titleContainer.title.offset;
269+
if(oldOffsetAttrSet && !newOffsetAttrSet) {
270+
nestTitleAttr('titleoffset', 'offset');
271+
}
264272
}
265273

266274
function nestTitleAttr(oldAttrName, newAttrName) {
@@ -483,6 +491,8 @@ exports.cleanData = function(data) {
483491
if(trace.colorbar) cleanTitle(trace.colorbar);
484492
if(trace.marker && trace.marker.colorbar) cleanTitle(trace.marker.colorbar);
485493
if(trace.line && trace.line.colorbar) cleanTitle(trace.line.colorbar);
494+
if(trace.aaxis) cleanTitle(trace.aaxis);
495+
if(trace.baxis) cleanTitle(trace.baxis);
486496
}
487497
};
488498

src/plot_api/plot_api.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,8 @@ function cleanDeprecatedAttributeKeys(aobj) {
17301730
replace(key, key.replace('titleposition', 'title.position'));
17311731
} else if(key.indexOf('titleside') > -1) {
17321732
replace(key, key.replace('titleside', 'title.side'));
1733+
} else if(key.indexOf('titleoffset') > -1) {
1734+
replace(key, key.replace('titleoffset', 'title.offset'));
17331735
}
17341736
}
17351737

src/traces/carpet/axis_attributes.js

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,38 @@ module.exports = {
3434
editType: 'calc'
3535
},
3636
title: {
37-
valType: 'string',
38-
role: 'info',
37+
text: {
38+
valType: 'string',
39+
role: 'info',
40+
editType: 'calc',
41+
description: [
42+
'Sets the title of this axis.',
43+
'Note that before the existence of `title.text`, the title\'s',
44+
'contents used to be defined as the `title` attribute itself.',
45+
'This behavior has been deprecated.'
46+
].join(' ')
47+
},
48+
font: fontAttrs({
49+
editType: 'calc',
50+
description: [
51+
'Sets this axis\' title font.',
52+
'Note that the title\'s font used to be set',
53+
'by the now deprecated `titlefont` attribute.'
54+
].join(' ')
55+
}),
56+
offset: {
57+
valType: 'number',
58+
role: 'info',
59+
dflt: 10,
60+
editType: 'calc',
61+
description: [
62+
'An additional amount by which to offset the title from the tick',
63+
'labels, given in pixels.',
64+
'Note that this used to be set',
65+
'by the now deprecated `titleoffset` attribute.'
66+
].join(' '),
67+
},
3968
editType: 'calc',
40-
description: 'Sets the title of this axis.'
41-
},
42-
titlefont: fontAttrs({
43-
editType: 'calc',
44-
description: [
45-
'Sets this axis\' title font.'
46-
].join(' ')
47-
}),
48-
titleoffset: {
49-
valType: 'number',
50-
role: 'info',
51-
dflt: 10,
52-
editType: 'calc',
53-
description: [
54-
'An additional amount by which to offset the title from the tick',
55-
'labels, given in pixels'
56-
].join(' '),
5769
},
5870
type: {
5971
valType: 'enumerated',
@@ -494,5 +506,30 @@ module.exports = {
494506
editType: 'calc',
495507
description: 'The stride between grid lines along the axis'
496508
},
509+
510+
_deprecated: {
511+
title: {
512+
valType: 'string',
513+
role: 'info',
514+
editType: 'calc',
515+
description: [
516+
'Deprecated in favor of `title.text`.',
517+
'Note that value of `title` is no longer a simple',
518+
'*string* but a set of sub-attributes.'
519+
].join(' ')
520+
},
521+
titlefont: fontAttrs({
522+
editType: 'calc',
523+
description: 'Deprecated in favor of `title.font`.'
524+
}),
525+
titleoffset: {
526+
valType: 'number',
527+
role: 'info',
528+
dflt: 10,
529+
editType: 'calc',
530+
description: 'Deprecated in favor of `title.offset`.'
531+
}
532+
},
533+
497534
editType: 'calc'
498535
};

src/traces/carpet/axis_defaults.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
113113
// inherit from global font color in case that was provided.
114114
var dfltFontColor = (dfltColor === containerIn.color) ? dfltColor : font.color;
115115

116-
coerce('title');
117-
Lib.coerceFont(coerce, 'titlefont', {
116+
coerce('title.text');
117+
Lib.coerceFont(coerce, 'title.font', {
118118
family: font.family,
119119
size: Math.round(font.size * 1.2),
120120
color: dfltFontColor
121121
});
122122

123-
coerce('titleoffset');
123+
coerce('title.offset');
124124

125125
coerce('tickangle');
126126

@@ -203,11 +203,6 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
203203
// but no, we *actually* want to coerce this.
204204
coerce('tickmode');
205205

206-
if(!containerOut.title || (containerOut.title && containerOut.title.length === 0)) {
207-
delete containerOut.titlefont;
208-
delete containerOut.titleoffset;
209-
}
210-
211206
return containerOut;
212207
};
213208

src/traces/carpet/plot.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ var midShift = ((1 - alignmentConstants.MID_SHIFT) / lineSpacing) + 1;
197197

198198
function drawAxisTitle(gd, layer, trace, t, xy, dxy, axis, xa, ya, labelOrientation, labelClass) {
199199
var data = [];
200-
if(axis.title) data.push(axis.title);
200+
if(axis.title.text) data.push(axis.title.text);
201201
var titleJoin = layer.selectAll('text.' + labelClass).data(data);
202202
var offset = labelOrientation.maxExtent;
203203

@@ -213,16 +213,16 @@ function drawAxisTitle(gd, layer, trace, t, xy, dxy, axis, xa, ya, labelOrientat
213213
}
214214

215215
// In addition to the size of the labels, add on some extra padding:
216-
var titleSize = axis.titlefont.size;
217-
offset += titleSize + axis.titleoffset;
216+
var titleSize = axis.title.font.size;
217+
offset += titleSize + axis.title.offset;
218218

219219
var labelNorm = labelOrientation.angle + (labelOrientation.flip < 0 ? 180 : 0);
220220
var angleDiff = (labelNorm - orientation.angle + 450) % 360;
221221
var reverseTitle = angleDiff > 90 && angleDiff < 270;
222222

223223
var el = d3.select(this);
224224

225-
el.text(axis.title || '')
225+
el.text(axis.title.text)
226226
.call(svgTextUtils.convertToTspans, gd);
227227

228228
if(reverseTitle) {
@@ -236,7 +236,7 @@ function drawAxisTitle(gd, layer, trace, t, xy, dxy, axis, xa, ya, labelOrientat
236236
)
237237
.classed('user-select-none', true)
238238
.attr('text-anchor', 'middle')
239-
.call(Drawing.font, axis.titlefont);
239+
.call(Drawing.font, axis.title.font);
240240
});
241241

242242
titleJoin.exit().remove();

0 commit comments

Comments
 (0)