Skip to content

Commit 3437e28

Browse files
authored
Merge pull request #1615 from plotly/pie-fill-opacity
Split up fill and fill-opacity for pies
2 parents efa5edb + 9aa726a commit 3437e28

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

src/traces/pie/style_one.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ module.exports = function styleOne(s, pt, trace) {
1717
var lineWidth = trace.marker.line.width || 0;
1818
if(Array.isArray(lineWidth)) lineWidth = lineWidth[pt.i] || 0;
1919

20-
s.style({
21-
'stroke-width': lineWidth,
22-
fill: pt.color
23-
})
20+
s.style({'stroke-width': lineWidth})
21+
.call(Color.fill, pt.color)
2422
.call(Color.stroke, lineColor);
2523
};

test/jasmine/tests/pie_test.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
var d3 = require('d3');
2+
3+
var Plotly = require('@lib/index');
4+
5+
var createGraphDiv = require('../assets/create_graph_div');
6+
var destroyGraphDiv = require('../assets/destroy_graph_div');
7+
var failTest = require('../assets/fail_test');
8+
9+
describe('Pies', function() {
10+
'use strict';
11+
12+
var gd;
13+
14+
beforeEach(function() { gd = createGraphDiv(); });
15+
16+
afterEach(destroyGraphDiv);
17+
18+
it('should separate colors and opacities', function(done) {
19+
Plotly.newPlot(gd, [{
20+
values: [1, 2, 3, 4, 5],
21+
type: 'pie',
22+
sort: false,
23+
marker: {
24+
line: {width: 3, color: 'rgba(100,100,100,0.7)'},
25+
colors: [
26+
'rgba(0,0,0,0.2)',
27+
'rgba(255,0,0,0.3)',
28+
'rgba(0,255,0,0.4)',
29+
'rgba(0,0,255,0.5)',
30+
'rgba(255,255,0,0.6)'
31+
]
32+
}
33+
}], {height: 300, width: 400}).then(function() {
34+
var colors = [
35+
'rgb(0,0,0)',
36+
'rgb(255,0,0)',
37+
'rgb(0,255,0)',
38+
'rgb(0,0,255)',
39+
'rgb(255,255,0)'
40+
];
41+
var opacities = [0.2, 0.3, 0.4, 0.5, 0.6];
42+
43+
function checkPath(d, i) {
44+
var path = d3.select(this);
45+
// strip spaces (ie 'rgb(0, 0, 0)') so we're not dependent on browser specifics
46+
expect(path.style('fill').replace(/\s/g, '')).toBe(colors[i]);
47+
expect(path.style('fill-opacity')).toBe(String(opacities[i]));
48+
expect(path.style('stroke').replace(/\s/g, '')).toBe('rgb(100,100,100)');
49+
expect(path.style('stroke-opacity')).toBe('0.7');
50+
}
51+
var slices = d3.selectAll('.slice path');
52+
slices.each(checkPath);
53+
expect(slices.size()).toBe(5);
54+
55+
var legendEntries = d3.selectAll('.legendpoints path');
56+
legendEntries.each(checkPath);
57+
expect(legendEntries.size()).toBe(5);
58+
})
59+
.catch(failTest)
60+
.then(done);
61+
});
62+
});

0 commit comments

Comments
 (0)