Skip to content

Commit df9ac56

Browse files
authored
Merge pull request #3214 from plotly/pie-bar-textcolor-restyle
pie/bar textfont-color restyles
2 parents 03a12e0 + 840623d commit df9ac56

File tree

4 files changed

+92
-1
lines changed

4 files changed

+92
-1
lines changed

src/traces/bar/attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var extendFlat = require('../../lib/extend').extendFlat;
1818
var textFontAttrs = fontAttrs({
1919
editType: 'calc',
2020
arrayOk: true,
21+
colorEditType: 'style',
2122
description: ''
2223
});
2324

src/traces/pie/attributes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var extendFlat = require('../../lib/extend').extendFlat;
1818
var textFontAttrs = fontAttrs({
1919
editType: 'calc',
2020
arrayOk: true,
21-
colorEditType: 'style',
21+
colorEditType: 'plot',
2222
description: 'Sets the font used for `textinfo`.'
2323
});
2424

test/jasmine/tests/bar_test.js

+34
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,7 @@ describe('A bar plot', function() {
10831083
.catch(failTest)
10841084
.then(done);
10851085
});
1086+
10861087
it('should show bar texts (outside case)', function(done) {
10871088
var data = [{
10881089
y: [10, -20, 30],
@@ -1736,6 +1737,39 @@ describe('A bar plot', function() {
17361737
.catch(failTest)
17371738
.then(done);
17381739
});
1740+
1741+
it('should be able to react with new text colors', function(done) {
1742+
Plotly.react(gd, [{
1743+
type: 'bar',
1744+
y: [1, 2, 3],
1745+
text: ['A', 'B', 'C'],
1746+
textposition: 'inside'
1747+
}])
1748+
.then(assertTextFontColors(['rgb(255, 255, 255)', 'rgb(255, 255, 255)', 'rgb(255, 255, 255)']))
1749+
.then(function() {
1750+
gd.data[0].insidetextfont = {color: 'red'};
1751+
return Plotly.react(gd, gd.data);
1752+
})
1753+
.then(assertTextFontColors(['rgb(255, 0, 0)', 'rgb(255, 0, 0)', 'rgb(255, 0, 0)']))
1754+
.then(function() {
1755+
delete gd.data[0].insidetextfont.color;
1756+
gd.data[0].textfont = {color: 'blue'};
1757+
return Plotly.react(gd, gd.data);
1758+
})
1759+
.then(assertTextFontColors(['rgb(0, 0, 255)', 'rgb(0, 0, 255)', 'rgb(0, 0, 255)']))
1760+
.then(function() {
1761+
gd.data[0].textposition = 'outside';
1762+
return Plotly.react(gd, gd.data);
1763+
})
1764+
.then(assertTextFontColors(['rgb(0, 0, 255)', 'rgb(0, 0, 255)', 'rgb(0, 0, 255)']))
1765+
.then(function() {
1766+
gd.data[0].outsidetextfont = {color: 'red'};
1767+
return Plotly.react(gd, gd.data);
1768+
})
1769+
.then(assertTextFontColors(['rgb(255, 0, 0)', 'rgb(255, 0, 0)', 'rgb(255, 0, 0)']))
1770+
.catch(failTest)
1771+
.then(done);
1772+
});
17391773
});
17401774

17411775
describe('bar visibility toggling:', function() {

test/jasmine/tests/pie_test.js

+56
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,62 @@ describe('Pie traces', function() {
691691
.then(done);
692692
});
693693
});
694+
695+
it('should be able to restyle title color', function(done) {
696+
function _assert(msg, exp) {
697+
var title = d3.select('.titletext > text').node();
698+
expect(title.style.fill).toBe(exp.color, msg);
699+
}
700+
701+
Plotly.plot(gd, [{
702+
type: 'pie',
703+
values: [1, 2, 3],
704+
title: 'yo',
705+
titlefont: {color: 'blue'}
706+
}])
707+
.then(function() {
708+
_assert('base', {color: 'rgb(0, 0, 255)'});
709+
return Plotly.restyle(gd, 'titlefont.color', 'red');
710+
})
711+
.then(function() {
712+
_assert('base', {color: 'rgb(255, 0, 0)'});
713+
})
714+
.catch(failTest)
715+
.then(done);
716+
});
717+
718+
it('should be able to react with new text colors', function(done) {
719+
Plotly.plot(gd, [{
720+
type: 'pie',
721+
values: [1, 2, 3],
722+
text: ['A', 'B', 'C'],
723+
textposition: 'inside'
724+
}])
725+
.then(_checkFontColors(['rgb(255, 255, 255)', 'rgb(68, 68, 68)', 'rgb(255, 255, 255)']))
726+
.then(function() {
727+
gd.data[0].insidetextfont = {color: 'red'};
728+
return Plotly.react(gd, gd.data);
729+
})
730+
.then(_checkFontColors(['rgb(255, 0, 0)', 'rgb(255, 0, 0)', 'rgb(255, 0, 0)']))
731+
.then(function() {
732+
delete gd.data[0].insidetextfont.color;
733+
gd.data[0].textfont = {color: 'blue'};
734+
return Plotly.react(gd, gd.data);
735+
})
736+
.then(_checkFontColors(['rgb(0, 0, 255)', 'rgb(0, 0, 255)', 'rgb(0, 0, 255)']))
737+
.then(function() {
738+
gd.data[0].textposition = 'outside';
739+
return Plotly.react(gd, gd.data);
740+
})
741+
.then(_checkFontColors(['rgb(0, 0, 255)', 'rgb(0, 0, 255)', 'rgb(0, 0, 255)']))
742+
.then(function() {
743+
gd.data[0].outsidetextfont = {color: 'red'};
744+
return Plotly.react(gd, gd.data);
745+
})
746+
.then(_checkFontColors(['rgb(255, 0, 0)', 'rgb(255, 0, 0)', 'rgb(255, 0, 0)']))
747+
.catch(failTest)
748+
.then(done);
749+
});
694750
});
695751

696752
describe('pie hovering', function() {

0 commit comments

Comments
 (0)