Skip to content

Fix pie's support for individual stroke width values [2989] #3030

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 1 commit into from
Sep 22, 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
3 changes: 2 additions & 1 deletion src/components/legend/get_legend_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ module.exports = function getLegendData(calcdata, opts) {
label: labelj,
color: cd[j].color,
i: cd[j].i,
trace: trace
trace: trace,
pts: cd[j].pts
});

slicesShown[lgroup][labelj] = true;
Expand Down
44 changes: 40 additions & 4 deletions test/jasmine/tests/pie_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var customAssertions = require('../assets/custom_assertions');
var assertHoverLabelStyle = customAssertions.assertHoverLabelStyle;
var assertHoverLabelContent = customAssertions.assertHoverLabelContent;

var SLICES_SELECTOR = '.slice path';
var LEGEND_ENTRIES_SELECTOR = '.legendpoints path';

describe('Pie defaults', function() {
function _supply(trace) {
Expand Down Expand Up @@ -100,11 +102,11 @@ describe('Pie traces:', function() {
expect(this.style.stroke.replace(/\s/g, '')).toBe('rgb(100,100,100)');
expect(this.style.strokeOpacity).toBe('0.7');
}
var slices = d3.selectAll('.slice path');
var slices = d3.selectAll(SLICES_SELECTOR);
slices.each(checkPath);
expect(slices.size()).toBe(5);

var legendEntries = d3.selectAll('.legendpoints path');
var legendEntries = d3.selectAll(LEGEND_ENTRIES_SELECTOR);
legendEntries.each(checkPath);
expect(legendEntries.size()).toBe(5);
})
Expand Down Expand Up @@ -141,7 +143,7 @@ describe('Pie traces:', function() {

function _checkSliceColors(colors) {
return function() {
d3.select(gd).selectAll('.slice path').each(function(d, i) {
d3.select(gd).selectAll(SLICES_SELECTOR).each(function(d, i) {
expect(this.style.fill.replace(/(\s|rgb\(|\))/g, '')).toBe(colors[i], i);
});
};
Expand Down Expand Up @@ -182,6 +184,40 @@ describe('Pie traces:', function() {
.catch(failTest)
.then(done);
});

it('supports separate stroke width values per slice', function(done) {
var data = [
{
values: [20, 26, 55],
labels: ['Residential', 'Non-Residential', 'Utility'],
type: 'pie',
pull: [0.1, 0, 0],
marker: {
colors: ['rebeccapurple', 'purple', 'mediumpurple'],
line: {
width: [3, 0, 0]
}
}
}
];
var layout = {
showlegend: true
};

Plotly.plot(gd, data, layout)
.then(function() {
var expWidths = ['3', '0', '0'];

d3.selectAll(SLICES_SELECTOR).each(function(d) {
expect(this.style.strokeWidth).toBe(expWidths[d.pointNumber]);
});
d3.selectAll(LEGEND_ENTRIES_SELECTOR).each(function(d) {
expect(this.style.strokeWidth).toBe(expWidths[d[0].i]);
});
})
.catch(failTest)
.then(done);
});
});

describe('pie hovering', function() {
Expand Down Expand Up @@ -677,7 +713,7 @@ describe('pie relayout', function() {
return Plotly.relayout(gd, 'colorway', relayoutColors);
})
.then(function() {
var slices = d3.selectAll('.slice path');
var slices = d3.selectAll(SLICES_SELECTOR);
slices.each(checkRelayoutColor);
})
.then(done);
Expand Down