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

[XY] Order by metric/custom metric doesn't work well for split chart #128185

Merged
merged 5 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
import React from 'react';
import { Accessor, AccessorFn, GroupBy, SmallMultiples } from '@elastic/charts';
import { Predicate } from '@elastic/charts/dist/common/predicate';
import { DatatableColumn } from '../../../../expressions/public';

interface ChartSplitProps {
splitColumnAccessor?: Accessor | AccessorFn;
splitRowAccessor?: Accessor | AccessorFn;
splitDimension?: DatatableColumn;
}

const CHART_SPLIT_ID = '__pie_chart_split__';
Expand Down
44 changes: 44 additions & 0 deletions src/plugins/vis_types/xy/public/chart_split.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 React from 'react';
import { Accessor, AccessorFn, GroupBy, SmallMultiples } from '@elastic/charts';
import { Predicate } from '@elastic/charts/dist/common/predicate';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure that it's a correct import.


interface ChartSplitProps {
splitColumnAccessor?: Accessor | AccessorFn;
splitRowAccessor?: Accessor | AccessorFn;
}

const CHART_SPLIT_ID = '__chart_split__';

export const ChartSplit = ({ splitColumnAccessor, splitRowAccessor }: ChartSplitProps) => {
if (!splitColumnAccessor && !splitRowAccessor) return null;

return (
<>
<GroupBy
id={CHART_SPLIT_ID}
by={(spec, datum) => {
const splitTypeAccessor = splitColumnAccessor || splitRowAccessor;
if (splitTypeAccessor) {
return typeof splitTypeAccessor === 'function'
? splitTypeAccessor(datum)
: datum[splitTypeAccessor];
}
return spec.id;
}}
sort={Predicate.DataIndex}
/>
<SmallMultiples
splitVertically={splitRowAccessor ? CHART_SPLIT_ID : undefined}
splitHorizontally={splitColumnAccessor ? CHART_SPLIT_ID : undefined}
/>
</>
);
};
57 changes: 0 additions & 57 deletions src/plugins/vis_types/xy/public/chart_splitter.tsx

This file was deleted.

11 changes: 2 additions & 9 deletions src/plugins/vis_types/xy/public/vis_component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
getComplexAccessor,
getSplitSeriesAccessorFnMap,
} from './utils/accessors';
import { ChartSplitter } from './chart_splitter';
import { ChartSplit } from './chart_split';

export interface VisComponentProps {
visParams: VisParams;
Expand Down Expand Up @@ -338,12 +338,6 @@ const VisComponent = (props: VisComponentProps) => {
[getSeriesName, legendPosition, props.uiState, setColor, visParams.palette.name]
);

const splitChartDimension = visParams.dimensions.splitColumn
? visData.columns[visParams.dimensions.splitColumn[0].accessor]
: visParams.dimensions.splitRow
? visData.columns[visParams.dimensions.splitRow[0].accessor]
: undefined;

return (
<div className="xyChart__container" data-test-subj="visTypeXyChart">
<LegendToggle
Expand All @@ -352,10 +346,9 @@ const VisComponent = (props: VisComponentProps) => {
legendPosition={legendPosition}
/>
<Chart size="100%" ref={chartRef}>
<ChartSplitter
<ChartSplit
splitColumnAccessor={splitChartColumnAccessor}
splitRowAccessor={splitChartRowAccessor}
splitDimension={splitChartDimension}
/>
<XYSettings
{...config}
Expand Down