Skip to content

Commit 97cc9bb

Browse files
committed
Remove default option for titleposition.
If it is undefined, titleposition is set to 'middle center', if hole > 0, and to 'top center' otherwise. _verifyTitle now returns a promise.
1 parent 96e3afd commit 97cc9bb

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

src/traces/pie/attributes.js

-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ module.exports = {
197197
'middle center',
198198
'bottom left', 'bottom center', 'bottom right'
199199
],
200-
dflt: 'top center',
201200
role: 'info',
202201
editType: 'calc',
203202
description: [

src/traces/pie/defaults.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
7070
var hole = coerce('hole');
7171
var title = coerce('title');
7272
if(title) {
73-
var titlePosition = coerce('titleposition');
74-
73+
var titlePosition = coerce('titleposition', hole ? 'middle center' : 'top center');
7574
if(!hole && titlePosition === 'middle center') traceOut.titleposition = 'top center';
7675
coerceFont(coerce, 'titlefont', layout.font);
7776
}

src/traces/pie/plot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ function positionTitleOutside(cd0, plotSize) {
582582
function getTitleSpace(cd0, plotSize) {
583583
var trace = cd0.trace;
584584
var pieBoxHeight = plotSize.h * (trace.domain.y[1] - trace.domain.y[0]);
585-
// use at most half of the plot for the pie
585+
// use at most half of the plot for the title
586586
return Math.min(cd0.titleBox.height, pieBoxHeight / 2);
587587
}
588588

test/jasmine/tests/pie_test.js

+31-15
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ describe('Pie traces:', function() {
187187
Plotly.newPlot(gd, [{
188188
values: [2, 2, 2, 2],
189189
title: 'Test<br>Title',
190-
titleposition: 'middle center',
191190
hole: 0.5,
192191
type: 'pie',
193192
textinfo: 'none'
@@ -243,22 +242,24 @@ describe('Pie traces:', function() {
243242
});
244243

245244
function _verifyTitle(checkLeft, checkRight, checkTop, checkBottom, checkMiddleX) {
246-
var title = d3.selectAll('.titletext text');
247-
expect(title.size()).toBe(1);
248-
var titleBox = d3.select('g.titletext').node().getBoundingClientRect();
249-
var pieBox = d3.select('g.trace').node().getBoundingClientRect();
250-
// check that margins agree. we leave an error margin of 2.
251-
if(checkLeft) expect(Math.abs(titleBox.left - pieBox.left)).toBeLessThan(2);
252-
if(checkRight) expect(Math.abs(titleBox.right - pieBox.right)).toBeLessThan(2);
253-
if(checkTop) expect(Math.abs(titleBox.top - pieBox.top)).toBeLessThan(2);
254-
if(checkBottom) expect(Math.abs(titleBox.bottom - pieBox.bottom)).toBeLessThan(2);
255-
if(checkMiddleX) {
256-
expect(Math.abs(titleBox.left + titleBox.right - pieBox.left - pieBox.right))
257-
.toBeLessThan(2);
258-
}
245+
return function() {
246+
var title = d3.selectAll('.titletext text');
247+
expect(title.size()).toBe(1);
248+
var titleBox = d3.select('g.titletext').node().getBoundingClientRect();
249+
var pieBox = d3.select('g.trace').node().getBoundingClientRect();
250+
// check that margins agree. we leave an error margin of 2.
251+
if(checkLeft) expect(Math.abs(titleBox.left - pieBox.left)).toBeLessThan(2);
252+
if(checkRight) expect(Math.abs(titleBox.right - pieBox.right)).toBeLessThan(2);
253+
if(checkTop) expect(Math.abs(titleBox.top - pieBox.top)).toBeLessThan(2);
254+
if(checkBottom) expect(Math.abs(titleBox.bottom - pieBox.bottom)).toBeLessThan(2);
255+
if(checkMiddleX) {
256+
expect(Math.abs(titleBox.left + titleBox.right - pieBox.left - pieBox.right))
257+
.toBeLessThan(2);
258+
}
259+
};
259260
}
260261

261-
it('shows title top center if there is no hole', function(done) {
262+
it('shows title top center if hole is zero', function(done) {
262263
Plotly.newPlot(gd, [{
263264
values: [2, 2, 2, 2],
264265
title: 'Test<BR>Title',
@@ -275,6 +276,21 @@ describe('Pie traces:', function() {
275276
.then(done);
276277
});
277278

279+
it('shows title top center if titleposition is undefined and no hole', function(done) {
280+
Plotly.newPlot(gd, [{
281+
values: [2, 2, 2, 2],
282+
title: 'Test<BR>Title',
283+
titlefont: {
284+
size: 12
285+
},
286+
type: 'pie',
287+
textinfo: 'none'
288+
}], {height: 300, width: 300})
289+
.then(_verifyTitle(false, false, true, false, true))
290+
.catch(failTest)
291+
.then(done);
292+
});
293+
278294
it('shows title top center', function(done) {
279295
Plotly.newPlot(gd, [{
280296
values: [1, 1, 1, 1, 2],

0 commit comments

Comments
 (0)