Skip to content

Commit d022f4f

Browse files
Alex VinoberAlex Vinober
Alex Vinober
authored and
Alex Vinober
committed
Chart Title Alignment
1 parent 599dff9 commit d022f4f

File tree

8 files changed

+43
-24
lines changed

8 files changed

+43
-24
lines changed

src/components/colorbar/draw.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ module.exports = function draw(gd, id) {
172172
tickprefix: opts.tickprefix,
173173
showticksuffix: opts.showticksuffix,
174174
ticksuffix: opts.ticksuffix,
175-
title: opts.title,
176-
titlefont: opts.titlefont,
175+
title: opts.title.text,
176+
titlefont: opts.title.font,
177177
showline: true,
178178
anchor: 'free',
179179
position: 1

src/components/titles/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,18 @@ Titles.draw = function(gd, titleClass, options) {
6363
var group = options.containerGroup;
6464

6565
var fullLayout = gd._fullLayout;
66-
var font = cont.titlefont.family;
67-
var fontSize = cont.titlefont.size;
68-
var fontColor = cont.titlefont.color;
66+
var font = typeof cont.title.text !== 'undefined' ? cont.title.font.family : cont.titlefont.family;
67+
var fontSize = typeof cont.title.text !== 'undefined' ? cont.title.font.size : cont.titlefont.size;
68+
var fontColor = typeof cont.title.text !== 'undefined' ? cont.title.font.color : cont.titlefont.color;
6969

7070
var opacity = 1;
7171
var isplaceholder = false;
72-
var txt = cont.title.trim();
72+
var txt = typeof cont.title.text !== 'undefined' ? cont.title.text.trim() : cont.title.trim();
7373

7474
// only make this title editable if we positively identify its property
7575
// as one that has editing enabled.
7676
var editAttr;
77-
if(prop === 'title') editAttr = 'titleText';
77+
if(prop === 'title.text') editAttr = 'titleText';
7878
else if(prop.indexOf('axis') !== -1) editAttr = 'axisTitleText';
7979
else if(prop.indexOf('colorbar' !== -1)) editAttr = 'colorbarTitleText';
8080
var editable = gd._context.edits[editAttr];

src/plot_api/plot_api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ function plotPolar(gd, data, layout) {
563563

564564
// editable title
565565
var opacity = 1;
566-
var txt = gd._fullLayout.title;
566+
var txt = gd._fullLayout.title.text;
567567
if(txt === '' || !txt) opacity = 0;
568568

569569
var titleLayout = function() {
@@ -597,7 +597,7 @@ function plotPolar(gd, data, layout) {
597597
var setContenteditable = function() {
598598
this.call(svgTextUtils.makeEditable, {gd: gd})
599599
.on('edit', function(text) {
600-
gd.framework({layout: {title: text}});
600+
gd.framework({layout: {title: {text: text}}});
601601
this.text(text)
602602
.call(titleLayout);
603603
this.call(setContenteditable);

src/snapshot/cloneplot.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ function cloneLayoutOverride(tileClass) {
2525
autosize: true,
2626
width: 150,
2727
height: 150,
28-
title: '',
28+
title: {
29+
text: ''
30+
},
2931
showlegend: false,
3032
margin: {l: 5, r: 5, t: 5, b: 5, pad: 0},
3133
annotations: []
@@ -34,7 +36,9 @@ function cloneLayoutOverride(tileClass) {
3436

3537
case 'thumbnail':
3638
override = {
37-
title: '',
39+
title: {
40+
text: ''
41+
},
3842
hidesources: true,
3943
showlegend: false,
4044
borderwidth: 0,

test/image/mocks/14.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,15 @@
9797
}
9898
],
9999
"layout": {
100-
"title": "Silicon Photovoltaics Learning Curve",
101-
"titlefont": {
102-
"color": "",
103-
"family": "",
104-
"size": 0
105-
},
100+
"title": {
101+
"text": "test",
102+
"alignment": "left",
103+
"font": {
104+
"color": "",
105+
"family": "",
106+
"size": 0
107+
}
108+
},
106109
"font": {
107110
"family": "Arial, sans-serif",
108111
"size": 12,

test/jasmine/tests/snapshot_test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ describe('Plotly.Snapshot', function() {
3535

3636
data = [dummyTrace1, dummyTrace2];
3737
layout = {
38-
title: 'Chart Title',
38+
title: {
39+
text: 'Chart Title'
40+
},
3941
showlegend: true,
4042
autosize: true,
4143
width: 688,
@@ -69,7 +71,9 @@ describe('Plotly.Snapshot', function() {
6971
autosize: true,
7072
width: 150,
7173
height: 150,
72-
title: '',
74+
title: {
75+
text: ''
76+
},
7377
showlegend: false,
7478
margin: {'l': 5, 'r': 5, 't': 5, 'b': 5, 'pad': 0},
7579
annotations: []

test/jasmine/tests/titles_test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ describe('editable titles', function() {
8383
Plotly.plot(gd, data, {
8484
xaxis: {title: ''},
8585
yaxis: {title: ''},
86-
title: ''
86+
title: {
87+
text: ''
88+
}
8789
}, {editable: true})
8890
.then(function() {
8991
return Promise.all([
@@ -99,7 +101,9 @@ describe('editable titles', function() {
99101
Plotly.plot(gd, data, {
100102
xaxis: {title: ''},
101103
yaxis: {title: ''},
102-
title: ''
104+
title: {
105+
text: ''
106+
}
103107
}, {editable: true})
104108
.then(function() {
105109
return editTitle('x', 'xaxis.title', 'XXX');
@@ -108,7 +112,7 @@ describe('editable titles', function() {
108112
return editTitle('y', 'yaxis.title', 'YYY');
109113
})
110114
.then(function() {
111-
return editTitle('g', 'title', 'TTT');
115+
return editTitle('g', 'title.text', 'TTT');
112116
})
113117
.then(function() {
114118
return Promise.all([

test/jasmine/tests/validate_test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ describe('Plotly.validate', function() {
1818
type: 'scatter',
1919
x: [1, 2, 3]
2020
}], {
21-
title: 'my simple graph'
21+
title: {
22+
text: 'my simple graph'
23+
}
2224
});
2325

2426
expect(out).toBeUndefined();
@@ -362,7 +364,9 @@ describe('Plotly.validate', function() {
362364
}]
363365
}),
364366
], {
365-
title: 'my transformed graph'
367+
title: {
368+
text: 'my transformed graph'
369+
}
366370
});
367371

368372
expect(out.length).toEqual(5);

0 commit comments

Comments
 (0)