Skip to content

Commit

Permalink
[XY] Order by metric/custom metric doesn't work well for split chart (#…
Browse files Browse the repository at this point in the history
…128185)

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

* Update Predicate import paths

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
DianaDerevyankina and kibanamachine authored Apr 5, 2022
1 parent 3e2761d commit 0a4f0fc
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
*/

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';
import { Accessor, AccessorFn, GroupBy, SmallMultiples, Predicate } from '@elastic/charts';

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

const CHART_SPLIT_ID = '__pie_chart_split__';
Expand Down
43 changes: 43 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,43 @@
/*
* 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, Predicate } from '@elastic/charts';

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

0 comments on commit 0a4f0fc

Please sign in to comment.