Skip to content
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

882 - Chart Title Alignment #3276

Merged
merged 50 commits into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
6687034
Add test of current plot title alignment [882]
rmoestl Oct 30, 2018
a7e3a9d
Transition layout titles from being strings to be objects [882]
rmoestl Oct 30, 2018
50a1e9b
Support updating titles through `relayout` and `update` [882]
rmoestl Oct 31, 2018
4d21886
Deprecate `*.titlefont` attributes in favor of `*.title.font` [882]
rmoestl Nov 5, 2018
66a8154
Implement basic chart title alignment options [882]
rmoestl Nov 7, 2018
6f583a4
Add test to ensure current chart title position is still supported [882]
rmoestl Nov 8, 2018
185772b
Implement 'auto' values for title's `xanchor` and `yanchor` [882]
rmoestl Nov 12, 2018
ac3649b
Support deprecated axes titles syntax for multiple axes [882]
rmoestl Nov 13, 2018
493b6ec
Adapt axes tests to new `title` structure [882]
rmoestl Nov 14, 2018
4d7c4b3
Adapt axes auto-margin code to new `title` structure [882]
rmoestl Nov 14, 2018
96df782
Adapt `axes.swap` to new `title` attr structure [882]
rmoestl Nov 14, 2018
43da557
Adapt colorbar to new title attr structure [882]
rmoestl Nov 13, 2018
9e2cbfe
Adapt rangeslider to new title attr structure [882]
rmoestl Nov 14, 2018
f632a7d
Transition polar plot type to new title attr structure [882]
rmoestl Nov 15, 2018
b3367f1
Adapt legacy polar chart to new title attr structure [882]
rmoestl Nov 15, 2018
cf7f493
Transition ternary plot type to new title attr structure [882]
rmoestl Nov 15, 2018
573c90d
Deduplicate transitioning to new title structure in `cleanLayout` [882]
rmoestl Nov 15, 2018
ddf9c0b
Transition gl3d plot type to new title attr structure [882]
rmoestl Nov 15, 2018
0e144b6
Transition gl2d plot type to new title attr structure [882]
rmoestl Nov 15, 2018
984aa46
Expect new title syntax in legend, lib and further tests [882]
rmoestl Nov 15, 2018
58f402a
Reactivating editing plot title [882]
rmoestl Nov 15, 2018
5e16b02
Also call cleanLayout on `layout.template.layout` [882]
rmoestl Nov 16, 2018
7a81f27
Adjust hover template test to new title structure [882]
rmoestl Nov 20, 2018
e53e546
Adapt clonePlot function to new title attr structure [882]
rmoestl Nov 20, 2018
ca920ab
Implement padding for chart title alignment [882]
rmoestl Nov 20, 2018
37bb68c
Restrict title.y (and x) to a number between 0 and 1 [882]
rmoestl Nov 20, 2018
e438a3f
Edit attribute descriptions for new title attr structure [882]
rmoestl Nov 21, 2018
b37950d
Minor clean up in subroutines.js [882]
rmoestl Nov 21, 2018
0c2bfd7
Fix cleaning deprecated title structure on relayout/update [882]
rmoestl Nov 21, 2018
eda4f72
Fix `cleanLayout` bug [882]
rmoestl Nov 21, 2018
53ea94d
Remove small piece of obsolete code in gl3d's convert module [882]
rmoestl Nov 21, 2018
f896273
Still accept numbers as titles when defined in deprecated notation [882]
rmoestl Nov 22, 2018
f7b652b
Improve and simplify title compatibility code for relayout [882]
rmoestl Nov 22, 2018
1288121
Clear TODOs in gl3d axis_defaults.js and cloneplot.js [882]
rmoestl Nov 22, 2018
ee613bb
Streamline variable names in subroutines.js [882]
rmoestl Nov 23, 2018
678c2d9
Deprecate old title structure properly [882]
rmoestl Nov 23, 2018
598fc5f
Fix plotschema_test.js to embrace deprecated attribute containers [882]
rmoestl Nov 23, 2018
4efb546
Make explanatory comment in polar.js more clear [882]
rmoestl Nov 23, 2018
014548c
Skip overriding deprecated title attributes in polar [882]
rmoestl Nov 26, 2018
1117113
Reuse Lib.counterRegex to match deprecated title string attributes [882]
rmoestl Nov 26, 2018
c2b4c10
Pass back update data unmodified to plotly_relayout event handlers [882]
rmoestl Nov 26, 2018
86a88e2
Move legend's anchor_utils to Lib and use them in title alignment [882]
rmoestl Nov 23, 2018
5fb7b8f
Redeclare valType of title.y to be a 'number' [882]
rmoestl Nov 26, 2018
d600bbd
Merge branch 'master' into 882-chart-title-alignment
rmoestl Nov 27, 2018
a2f0543
Transition pie trace type to new title attr structure [882]
rmoestl Nov 27, 2018
a4e43a6
Transition color bar to new title attr structure [882]
rmoestl Nov 27, 2018
e4dbc5d
Transition carpet to new title attr structure [882]
rmoestl Nov 28, 2018
ef9e078
Refactor code to clean up deprecated title attr structure [882]
rmoestl Nov 28, 2018
e3bcf7c
Let '' be the default carpet axes title [882]
rmoestl Nov 28, 2018
2b26746
Reverse coerce logic for carpet axes titles [882]
rmoestl Nov 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/plot_api/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ function cleanTitle(titleContainer) {
};
}

// TODO 882 DRY UP?
// titlefont -> title.font
var oldFontAttrSet = Lib.isPlainObject(titleContainer.titlefont);
var newFontAttrSet = titleContainer.title && Lib.isPlainObject(titleContainer.title.font);
Expand All @@ -261,6 +262,13 @@ function cleanTitle(titleContainer) {
if(oldSideAttrSet && !newSideAttrSet) {
nestTitleAttr('titleside', 'side');
}

// titleoffset -> title.offset
var oldOffsetAttrSet = titleContainer.titleoffset;
var newOffsetAttrSet = titleContainer.title && titleContainer.title.offset;
if(oldOffsetAttrSet && !newOffsetAttrSet) {
nestTitleAttr('titleoffset', 'offset');
}
}

function nestTitleAttr(oldAttrName, newAttrName) {
Expand Down Expand Up @@ -483,6 +491,8 @@ exports.cleanData = function(data) {
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
2 changes: 2 additions & 0 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,8 @@ function cleanDeprecatedAttributeKeys(aobj) {
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'));
}
}

Expand Down
75 changes: 56 additions & 19 deletions src/traces/carpet/axis_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,38 @@ module.exports = {
editType: 'calc'
},
title: {
valType: 'string',
role: 'info',
text: {
valType: 'string',
role: 'info',
editType: 'calc',
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(' ')
},
font: fontAttrs({
editType: 'calc',
description: [
'Sets this axis\' title font.',
'Note that the title\'s font used to be set',
'by the now deprecated `titlefont` attribute.'
].join(' ')
}),
offset: {
valType: 'number',
role: 'info',
dflt: 10,
editType: 'calc',
description: [
'An additional amount by which to offset the title from the tick',
'labels, given in pixels.',
'Note that this used to be set',
'by the now deprecated `titleoffset` attribute.'
].join(' '),
},
editType: 'calc',
description: 'Sets the title of this axis.'
},
titlefont: fontAttrs({
editType: 'calc',
description: [
'Sets this axis\' title font.'
].join(' ')
}),
titleoffset: {
valType: 'number',
role: 'info',
dflt: 10,
editType: 'calc',
description: [
'An additional amount by which to offset the title from the tick',
'labels, given in pixels'
].join(' '),
},
type: {
valType: 'enumerated',
Expand Down Expand Up @@ -494,5 +506,30 @@ module.exports = {
editType: 'calc',
description: 'The stride between grid lines along the axis'
},

_deprecated: {
title: {
valType: 'string',
role: 'info',
editType: 'calc',
description: [
'Deprecated in favor of `title.text`.',
'Note that value of `title` is no longer a simple',
'*string* but a set of sub-attributes.'
].join(' ')
},
titlefont: fontAttrs({
editType: 'calc',
description: 'Deprecated in favor of `title.font`.'
}),
titleoffset: {
valType: 'number',
role: 'info',
dflt: 10,
editType: 'calc',
description: 'Deprecated in favor of `title.offset`.'
}
},

editType: 'calc'
};
11 changes: 3 additions & 8 deletions src/traces/carpet/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
// inherit from global font color in case that was provided.
var dfltFontColor = (dfltColor === containerIn.color) ? dfltColor : font.color;

coerce('title');
Lib.coerceFont(coerce, 'titlefont', {
coerce('title.text');
Lib.coerceFont(coerce, 'title.font', {
family: font.family,
size: Math.round(font.size * 1.2),
color: dfltFontColor
});

coerce('titleoffset');
coerce('title.offset');

coerce('tickangle');

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

if(!containerOut.title || (containerOut.title && containerOut.title.length === 0)) {
rmoestl marked this conversation as resolved.
Show resolved Hide resolved
delete containerOut.titlefont;
delete containerOut.titleoffset;
}

return containerOut;
};

Expand Down
10 changes: 5 additions & 5 deletions src/traces/carpet/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ var midShift = ((1 - alignmentConstants.MID_SHIFT) / lineSpacing) + 1;

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

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

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

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

var el = d3.select(this);

el.text(axis.title || '')
el.text(axis.title.text)
rmoestl marked this conversation as resolved.
Show resolved Hide resolved
.call(svgTextUtils.convertToTspans, gd);

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

titleJoin.exit().remove();
Expand Down