Skip to content

Commit 7714aa6

Browse files
authored
Merge pull request #3030 from plotly/2928-pie-bugs
Fix pie's support for individual stroke width values [2989]
2 parents 2f0d56e + 206c00c commit 7714aa6

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

Diff for: src/components/legend/get_legend_data.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ module.exports = function getLegendData(calcdata, opts) {
5959
label: labelj,
6060
color: cd[j].color,
6161
i: cd[j].i,
62-
trace: trace
62+
trace: trace,
63+
pts: cd[j].pts
6364
});
6465

6566
slicesShown[lgroup][labelj] = true;

Diff for: test/jasmine/tests/pie_test.js

+40-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ var customAssertions = require('../assets/custom_assertions');
1414
var assertHoverLabelStyle = customAssertions.assertHoverLabelStyle;
1515
var assertHoverLabelContent = customAssertions.assertHoverLabelContent;
1616

17+
var SLICES_SELECTOR = '.slice path';
18+
var LEGEND_ENTRIES_SELECTOR = '.legendpoints path';
1719

1820
describe('Pie defaults', function() {
1921
function _supply(trace) {
@@ -100,11 +102,11 @@ describe('Pie traces:', function() {
100102
expect(this.style.stroke.replace(/\s/g, '')).toBe('rgb(100,100,100)');
101103
expect(this.style.strokeOpacity).toBe('0.7');
102104
}
103-
var slices = d3.selectAll('.slice path');
105+
var slices = d3.selectAll(SLICES_SELECTOR);
104106
slices.each(checkPath);
105107
expect(slices.size()).toBe(5);
106108

107-
var legendEntries = d3.selectAll('.legendpoints path');
109+
var legendEntries = d3.selectAll(LEGEND_ENTRIES_SELECTOR);
108110
legendEntries.each(checkPath);
109111
expect(legendEntries.size()).toBe(5);
110112
})
@@ -141,7 +143,7 @@ describe('Pie traces:', function() {
141143

142144
function _checkSliceColors(colors) {
143145
return function() {
144-
d3.select(gd).selectAll('.slice path').each(function(d, i) {
146+
d3.select(gd).selectAll(SLICES_SELECTOR).each(function(d, i) {
145147
expect(this.style.fill.replace(/(\s|rgb\(|\))/g, '')).toBe(colors[i], i);
146148
});
147149
};
@@ -182,6 +184,40 @@ describe('Pie traces:', function() {
182184
.catch(failTest)
183185
.then(done);
184186
});
187+
188+
it('supports separate stroke width values per slice', function(done) {
189+
var data = [
190+
{
191+
values: [20, 26, 55],
192+
labels: ['Residential', 'Non-Residential', 'Utility'],
193+
type: 'pie',
194+
pull: [0.1, 0, 0],
195+
marker: {
196+
colors: ['rebeccapurple', 'purple', 'mediumpurple'],
197+
line: {
198+
width: [3, 0, 0]
199+
}
200+
}
201+
}
202+
];
203+
var layout = {
204+
showlegend: true
205+
};
206+
207+
Plotly.plot(gd, data, layout)
208+
.then(function() {
209+
var expWidths = ['3', '0', '0'];
210+
211+
d3.selectAll(SLICES_SELECTOR).each(function(d) {
212+
expect(this.style.strokeWidth).toBe(expWidths[d.pointNumber]);
213+
});
214+
d3.selectAll(LEGEND_ENTRIES_SELECTOR).each(function(d) {
215+
expect(this.style.strokeWidth).toBe(expWidths[d[0].i]);
216+
});
217+
})
218+
.catch(failTest)
219+
.then(done);
220+
});
185221
});
186222

187223
describe('pie hovering', function() {
@@ -677,7 +713,7 @@ describe('pie relayout', function() {
677713
return Plotly.relayout(gd, 'colorway', relayoutColors);
678714
})
679715
.then(function() {
680-
var slices = d3.selectAll('.slice path');
716+
var slices = d3.selectAll(SLICES_SELECTOR);
681717
slices.each(checkRelayoutColor);
682718
})
683719
.then(done);

0 commit comments

Comments
 (0)