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

test(partiton): demo first layer sorting #1483

Merged
merged 1 commit into from
Nov 18, 2021
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
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