Skip to content

Commit

Permalink
test: layer sorting (#1483)
Browse files Browse the repository at this point in the history
  • Loading branch information
monfera authored Nov 18, 2021
1 parent ff4e910 commit 832eab8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions integration/tests/partition_stories.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { common } from '../page_objects';

describe('Axis stories', () => {
it('should sort the first layer too', async () => {
await common.expectChartAtUrlToMatchScreenshot(
'http://localhost:9001/?path=/story/mosaic-alpha--other-slices&globals=background:white;theme:light&knob-"Other" on bottom even if not the smallest=true&knob-Alphabetical outer group sorting=true',
);
});
it('should sort just the first layer', async () => {
await common.expectChartAtUrlToMatchScreenshot(
'http://localhost:9001/?path=/story/mosaic-alpha--other-slices&globals=background:white;theme:light&knob-"Other" on bottom even if not the smallest=false&knob-Alphabetical outer group sorting=true',
);
});
});
26 changes: 20 additions & 6 deletions storybook/stories/mosaic/20_mosaic_with_other.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

import { boolean } from '@storybook/addon-knobs';
import React from 'react';

import {
Expand Down Expand Up @@ -40,6 +41,8 @@ const data = [
];

export const Example = () => {
const alphabetical = boolean('Alphabetical outer group sorting', false);
const otherOnBottom = boolean('"Other" on bottom even if not the smallest', true);
return (
<Chart>
<Settings baseTheme={useBaseTheme()} />
Expand All @@ -52,6 +55,15 @@ export const Example = () => {
{
groupByRollup: (d: Datum) => d.region,
nodeLabel: (d) => String(d).toUpperCase(),
sortPredicate: alphabetical
? ([name1, node1]: ArrayEntry, [name2, node2]: ArrayEntry) => {
if (name1 < name2) return -1;
if (name2 < name1) return 1;

// otherwise, use the increasing value order
return node1.value - node2.value;
}
: undefined,
fillLabel: {
valueFormatter: () => ``,
fontWeight: 600,
Expand All @@ -63,13 +75,15 @@ export const Example = () => {
{
groupByRollup: (d: Datum) => d.dest,
nodeLabel: (d: any) => countryLookup[d]?.name ?? d,
sortPredicate: ([name1, node1]: ArrayEntry, [name2, node2]: ArrayEntry) => {
if (name1 === 'Other' && name2 !== 'Other') return -1;
if (name2 === 'Other' && name1 !== 'Other') return 1;
sortPredicate: otherOnBottom
? ([name1, node1]: ArrayEntry, [name2, node2]: ArrayEntry) => {
if (name1 === 'Other' && name2 !== 'Other') return 1;
if (name2 === 'Other' && name1 !== 'Other') return -1;

// otherwise, use the increasing value order
return node1.value - node2.value;
},
// otherwise, use the increasing value order
return node1.value - node2.value;
}
: undefined,
fillLabel: {
fontWeight: 100,
maxFontSize: 16,
Expand Down

0 comments on commit 832eab8

Please sign in to comment.