Skip to content

Commit

Permalink
Fix bug with plot sorting (#98084) (#98149)
Browse files Browse the repository at this point in the history
Co-authored-by: Corey Robertson <[email protected]>
  • Loading branch information
kibanamachine and Corey Robertson authored Apr 23, 2021
1 parent ead4081 commit c375a0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
26 changes: 11 additions & 15 deletions x-pack/plugins/canvas/public/functions/plot/get_tick_hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { get, sortBy } from 'lodash';
import { get } from 'lodash';
import { PointSeriesColumns, DatatableRow, Ticks } from '../../../types';

export const getTickHash = (columns: PointSeriesColumns, rows: DatatableRow[]) => {
Expand All @@ -21,23 +21,19 @@ export const getTickHash = (columns: PointSeriesColumns, rows: DatatableRow[]) =
};

if (get(columns, 'x.type') === 'string') {
sortBy(rows, ['x'])
.reverse()
.forEach((row) => {
if (!ticks.x.hash[row.x]) {
ticks.x.hash[row.x] = ticks.x.counter++;
}
});
rows.forEach((row) => {
if (!ticks.x.hash[row.x]) {
ticks.x.hash[row.x] = ticks.x.counter++;
}
});
}

if (get(columns, 'y.type') === 'string') {
sortBy(rows, ['y'])
.reverse()
.forEach((row) => {
if (!ticks.y.hash[row.y]) {
ticks.y.hash[row.y] = ticks.y.counter++;
}
});
rows.reverse().forEach((row) => {
if (!ticks.y.hash[row.y]) {
ticks.y.hash[row.y] = ticks.y.counter++;
}
});
}

return ticks;
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/canvas/public/functions/plot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ export function plotFunctionFactory(
fn: (input, args) => {
const seriesStyles: { [key: string]: SeriesStyle } =
keyBy(args.seriesStyle || [], 'label') || {};

const sortedRows = sortBy(input.rows, ['x', 'y', 'color', 'size', 'text']);
const sortedRows = input.rows;
const ticks = getTickHash(input.columns, sortedRows);
const font = args.font ? getFontSpec(args.font) : {};

Expand Down

0 comments on commit c375a0d

Please sign in to comment.