Skip to content

Commit

Permalink
fix: don't sort in pie function (#27076) (#29444)
Browse files Browse the repository at this point in the history
  • Loading branch information
w33ble authored Jan 28, 2019
1 parent 8da5482 commit 979ae76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,23 @@ describe('pie', () => {

describe('data', () => {
const result = fn(testPie).value.data;
it('is sorted by the series labels', () => {
expect(result.every((val, i) => (!!i ? val.label >= result[i - 1].label : true))).to.be(true);
});

it('has one series per unique label', () => {
const uniqueLabels = testPie.rows
.reduce(
(unique, series) =>
!unique.includes(series.color) ? unique.concat([series.color]) : unique,
[]
)
.sort();
const uniqueLabels = testPie.rows.reduce(
(unique, series) =>
!unique.includes(series.color) ? unique.concat([series.color]) : unique,
[]
);

expect(result).to.have.length(uniqueLabels.length);
expect(result.every((series, i) => series.label === uniqueLabels[i])).to.be(true);
});

it('populates the data of the plot with points from the pointseries', () => {
expect(result[0].data).to.eql([536]);
expect(result[1].data).to.eql([202]);
expect(result[2].data).to.eql([67]);
expect(result[3].data).to.eql([311]);
expect(result[0].data).to.eql([202]);
expect(result[1].data).to.eql([67]);
expect(result[2].data).to.eql([311]);
expect(result[3].data).to.eql([536]);
expect(result[4].data).to.eql([288]);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import keyBy from 'lodash.keyby';
import { get, map, groupBy, sortBy } from 'lodash';
import { get, map, groupBy } from 'lodash';
import { getColorsFromPalette } from '../../../common/lib/get_colors_from_palette';
import { getLegendConfig } from '../../../common/lib/get_legend_config';

Expand Down Expand Up @@ -67,10 +67,9 @@ export const pie = () => ({
},
},
fn: (context, args) => {
const rows = sortBy(context.rows, ['color', 'size']);
const seriesStyles = keyBy(args.seriesStyle || [], 'label') || {};

const data = map(groupBy(rows, 'color'), (series, label) => {
const data = map(groupBy(context.rows, 'color'), (series, label) => {
const item = {
label: label,
data: series.map(point => point.size || 1),
Expand All @@ -91,7 +90,7 @@ export const pie = () => ({
as: 'pie',
value: {
font: args.font,
data: sortBy(data, 'label'),
data,
options: {
canvas: false,
colors: getColorsFromPalette(args.palette, data.length),
Expand Down

0 comments on commit 979ae76

Please sign in to comment.