Skip to content

pie/bar textfont-color restyles #3214

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

Merged
merged 2 commits into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/traces/bar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var extendFlat = require('../../lib/extend').extendFlat;
var textFontAttrs = fontAttrs({
editType: 'calc',
arrayOk: true,
colorEditType: 'style',
description: ''
});

Expand Down
2 changes: 1 addition & 1 deletion src/traces/pie/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var extendFlat = require('../../lib/extend').extendFlat;
var textFontAttrs = fontAttrs({
editType: 'calc',
arrayOk: true,
colorEditType: 'style',
colorEditType: 'plot',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, would be nice someday to get style to work but this isn't a real high-traffic pathway (nor a heavy plot type, unless someone's really abusing it!)

description: 'Sets the font used for `textinfo`.'
});

Expand Down
34 changes: 34 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,7 @@ describe('A bar plot', function() {
.catch(failTest)
.then(done);
});

it('should show bar texts (outside case)', function(done) {
var data = [{
y: [10, -20, 30],
Expand Down Expand Up @@ -1736,6 +1737,39 @@ describe('A bar plot', function() {
.catch(failTest)
.then(done);
});

it('should be able to react with new text colors', function(done) {
Plotly.react(gd, [{
type: 'bar',
y: [1, 2, 3],
text: ['A', 'B', 'C'],
textposition: 'inside'
}])
.then(assertTextFontColors(['rgb(255, 255, 255)', 'rgb(255, 255, 255)', 'rgb(255, 255, 255)']))
.then(function() {
gd.data[0].insidetextfont = {color: 'red'};
return Plotly.react(gd, gd.data);
})
.then(assertTextFontColors(['rgb(255, 0, 0)', 'rgb(255, 0, 0)', 'rgb(255, 0, 0)']))
.then(function() {
delete gd.data[0].insidetextfont.color;
gd.data[0].textfont = {color: 'blue'};
return Plotly.react(gd, gd.data);
})
.then(assertTextFontColors(['rgb(0, 0, 255)', 'rgb(0, 0, 255)', 'rgb(0, 0, 255)']))
.then(function() {
gd.data[0].textposition = 'outside';
return Plotly.react(gd, gd.data);
})
.then(assertTextFontColors(['rgb(0, 0, 255)', 'rgb(0, 0, 255)', 'rgb(0, 0, 255)']))
.then(function() {
gd.data[0].outsidetextfont = {color: 'red'};
return Plotly.react(gd, gd.data);
})
.then(assertTextFontColors(['rgb(255, 0, 0)', 'rgb(255, 0, 0)', 'rgb(255, 0, 0)']))
.catch(failTest)
.then(done);
});
});

describe('bar visibility toggling:', function() {
Expand Down
56 changes: 56 additions & 0 deletions test/jasmine/tests/pie_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,62 @@ describe('Pie traces', function() {
.then(done);
});
});

it('should be able to restyle title color', function(done) {
function _assert(msg, exp) {
var title = d3.select('.titletext > text').node();
expect(title.style.fill).toBe(exp.color, msg);
}

Plotly.plot(gd, [{
type: 'pie',
values: [1, 2, 3],
title: 'yo',
titlefont: {color: 'blue'}
}])
.then(function() {
_assert('base', {color: 'rgb(0, 0, 255)'});
return Plotly.restyle(gd, 'titlefont.color', 'red');
})
.then(function() {
_assert('base', {color: 'rgb(255, 0, 0)'});
})
.catch(failTest)
.then(done);
});

it('should be able to react with new text colors', function(done) {
Plotly.plot(gd, [{
type: 'pie',
values: [1, 2, 3],
text: ['A', 'B', 'C'],
textposition: 'inside'
}])
.then(_checkFontColors(['rgb(255, 255, 255)', 'rgb(68, 68, 68)', 'rgb(255, 255, 255)']))
.then(function() {
gd.data[0].insidetextfont = {color: 'red'};
return Plotly.react(gd, gd.data);
})
.then(_checkFontColors(['rgb(255, 0, 0)', 'rgb(255, 0, 0)', 'rgb(255, 0, 0)']))
.then(function() {
delete gd.data[0].insidetextfont.color;
gd.data[0].textfont = {color: 'blue'};
return Plotly.react(gd, gd.data);
})
.then(_checkFontColors(['rgb(0, 0, 255)', 'rgb(0, 0, 255)', 'rgb(0, 0, 255)']))
.then(function() {
gd.data[0].textposition = 'outside';
return Plotly.react(gd, gd.data);
})
.then(_checkFontColors(['rgb(0, 0, 255)', 'rgb(0, 0, 255)', 'rgb(0, 0, 255)']))
.then(function() {
gd.data[0].outsidetextfont = {color: 'red'};
return Plotly.react(gd, gd.data);
})
.then(_checkFontColors(['rgb(255, 0, 0)', 'rgb(255, 0, 0)', 'rgb(255, 0, 0)']))
.catch(failTest)
.then(done);
});
});

describe('pie hovering', function() {
Expand Down