fix(pie): align slices and legend orders

This commit is contained in:
Reda Al Sulais
2023-08-25 16:07:28 +03:00
parent 8ef5f38861
commit 267935713c

View File

@@ -12,14 +12,16 @@ import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
const createPieArcs = (sections: Sections): d3.PieArcDatum<D3Sections>[] => { const createPieArcs = (sections: Sections): d3.PieArcDatum<D3Sections>[] => {
// Compute the position of each group on the pie: // Compute the position of each group on the pie:
const pieData: D3Sections[] = Object.entries(sections).map( const pieData: D3Sections[] = Object.entries(sections)
(element: [string, number]): D3Sections => { .map((element: [string, number]): D3Sections => {
return { return {
label: element[0], label: element[0],
value: element[1], value: element[1],
}; };
} })
); .sort((a: D3Sections, b: D3Sections): number => {
return b.value - a.value;
});
const pie: d3.Pie<unknown, D3Sections> = d3pie<D3Sections>().value( const pie: d3.Pie<unknown, D3Sections> = d3pie<D3Sections>().value(
(d3Section: D3Sections): number => d3Section.value (d3Section: D3Sections): number => d3Section.value
); );