Skip to content
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

<Pie /> Allow null sort callbacks #327

Merged
merged 1 commit into from
Jul 25, 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
6 changes: 3 additions & 3 deletions packages/vx-shape/src/shapes/Pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export default function Pie({
if (cornerRadius) path.cornerRadius(cornerRadius);
if (padRadius) path.padRadius(padRadius);
const pie = d3Pie();
if (pieSort) pie.sort(pieSort);
if (pieSortValues) pie.sortValues(pieSortValues);
if (pieSort !== undefined) pie.sort(pieSort);
if (pieSortValues !== undefined) pie.sortValues(pieSortValues);
if (pieValue) pie.value(pieValue);
if (padAngle != null) pie.padAngle(padAngle);
if (startAngle != null) pie.startAngle(startAngle);
Expand All @@ -50,7 +50,7 @@ export default function Pie({
generateCentroid: arc => centroid && centroid(path.centroid(arc), arc)
};
return (
<Group className='vx-pie-arcs-group' top={top} left={left}>
<Group className="vx-pie-arcs-group" top={top} left={left}>
{children
? children(renderFunctionArg)
: arcs.map((arc, i) => {
Expand Down
21 changes: 21 additions & 0 deletions packages/vx-shape/test/Pie.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ describe('<Pie />', () => {
}).not.toThrow();
});

test('it should accept null sort callbacks', () => {
expect.assertions(3);

expect(() => {
PieWrapper({ pieSort: null, pieSortValues: null });
}).not.toThrow();

// Should sort the arcs the same order as the input data
// The default pieSortValues sorts data by descending values
const A = 1;
const B = 20;
shallow(
<Pie data={[A, B]} pieSortValues={null}>
{({ arcs }) => {
expect(arcs[0]).toMatchObject({ value: A, index: 0 });
expect(arcs[1]).toMatchObject({ value: B, index: 1 });
}}
</Pie>
);
});

test('it should break on invalid sort callbacks', () => {
expect(() => PieWrapper({ pieSort: 12 })).toThrow();
expect(() => PieWrapper({ pieSortValues: 12 })).toThrow();
Expand Down