Skip to content

Commit d3d1872

Browse files
committed
fix #1614 - split up fill and fill-opacity for pies
1 parent ef0946c commit d3d1872

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-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

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

0 commit comments

Comments
 (0)