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

Small multiples in vis_type_xy plugin #86880

Merged
merged 30 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f6b51c5
Small multiples in vis_type_xy plugin
DianaDerevyankina Dec 22, 2020
645933f
Fix tooltip and formatted split chart values
nickofthyme Dec 23, 2020
f9ddb84
update advanced settings wording
nickofthyme Dec 23, 2020
353b3ae
Merge branch 'master' into Diana/82496
DianaDerevyankina Dec 23, 2020
8f600af
Remove React import in files with no JSX and change the extension to .ts
DianaDerevyankina Dec 23, 2020
a967804
Merge branch 'master' into Diana/82496
kibanamachine Jan 7, 2021
0afd9d5
Merge branch 'master' into Diana/82496
DianaDerevyankina Jan 13, 2021
7ba9cea
Simplify conditions
DianaDerevyankina Jan 13, 2021
a7287b9
fix bar interval on split charts in vislib
nickofthyme Jan 13, 2021
842034b
Merge branch 'master' into Diana/82496
DianaDerevyankina Jan 14, 2021
ad44d9f
Fix charts not splitting for terms boolean fields
DianaDerevyankina Jan 14, 2021
30d0055
Merge pull request #1 from nickofthyme/nick-sm-fixes
DianaDerevyankina Jan 14, 2021
e51c5b0
fix filtering for small multiples
nickofthyme Jan 14, 2021
fceee26
Merge pull request #2 from nickofthyme/fix-filtering
DianaDerevyankina Jan 15, 2021
b6ab151
Merge branch 'master' into Diana/82496
kibanamachine Jan 15, 2021
870a728
Merge branch 'master' into Diana/82496
DianaDerevyankina Jan 18, 2021
92f9d1b
Change tests interval values from 100 to 1000000
DianaDerevyankina Jan 18, 2021
dc181eb
Merge branch 'master' into Diana/82496
DianaDerevyankina Jan 19, 2021
4ab6368
Revert "Change tests interval values from 100 to 1000000"
DianaDerevyankina Jan 19, 2021
9152287
Fix tests for interval issue in vislib
DianaDerevyankina Jan 16, 2021
e752837
Merge branch 'master' into Diana/82496
DianaDerevyankina Jan 20, 2021
ba53abd
Revert axis_scale changes related to interval
DianaDerevyankina Jan 20, 2021
282b571
Merge branch 'master' into Diana/82496
kibanamachine Jan 20, 2021
e2f602f
Merge branch 'master' into Diana/82496
kibanamachine Jan 21, 2021
cad1e20
Merge branch 'master' into Diana/82496
DianaDerevyankina Jan 22, 2021
965824b
Enable _line_chart_split_chart test for new charts library
DianaDerevyankina Jan 22, 2021
91d5df6
Merge branch 'master' into Diana/82496
kibanamachine Jan 25, 2021
4cf3bc9
Merge branch 'master' into Diana/82496
kibanamachine Jan 25, 2021
48780a0
Merge branch 'master' into Diana/82496
DianaDerevyankina Jan 25, 2021
4436b62
Move chart splitter id to const
DianaDerevyankina Jan 25, 2021
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
2 changes: 1 addition & 1 deletion docs/management/advanced-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ of buckets to try to represent.

[horizontal]
[[visualization-visualize-chartslibrary]]`visualization:visualize:legacyChartsLibrary`::
Enables legacy charts library for area, line and bar charts in visualize. Currently, only legacy charts library supports split chart aggregation.
Enables legacy charts library for area, line and bar charts in visualize.

[[visualization-colormapping]]`visualization:colorMapping`::
**This setting is deprecated and will not be supported as of 8.0.**
Expand Down
54 changes: 54 additions & 0 deletions src/plugins/vis_type_xy/public/chart_splitter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React from 'react';
import { Accessor, AccessorFn, GroupBy, GroupBySort, SmallMultiples } from '@elastic/charts';

interface ChartSplitterProps {
splitColumnAccessor?: Accessor | AccessorFn;
splitRowAccessor?: Accessor | AccessorFn;
sort?: GroupBySort;
}

export const ChartSplitter = ({
splitColumnAccessor,
splitRowAccessor,
sort,
}: ChartSplitterProps) =>
splitColumnAccessor || splitRowAccessor ? (
<>
<GroupBy
id="__chart_splitter__"
alexwizp marked this conversation as resolved.
Show resolved Hide resolved
by={(spec, datum) => {
const splitTypeAccessor = splitColumnAccessor || splitRowAccessor;
if (splitTypeAccessor) {
return typeof splitTypeAccessor === 'function'
? splitTypeAccessor(datum)
: datum[splitTypeAccessor];
}
return spec.id;
}}
sort={sort || 'dataIndex'}
/>
<SmallMultiples
splitVertically={splitRowAccessor ? '__chart_splitter__' : undefined}
splitHorizontally={splitColumnAccessor ? '__chart_splitter__' : undefined}
/>
</>
) : null;
34 changes: 27 additions & 7 deletions src/plugins/vis_type_xy/public/components/detailed_tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@ import {
XYChartSeriesIdentifier,
} from '@elastic/charts';

import { BUCKET_TYPES } from '../../../data/public';

import { Aspects } from '../types';

import './_detailed_tooltip.scss';
import { fillEmptyValue } from '../utils/get_series_name_fn';
import { COMPLEX_SPLIT_ACCESSOR } from '../utils/accessors';
import { COMPLEX_SPLIT_ACCESSOR, isRangeAggType } from '../utils/accessors';

interface TooltipData {
label: string;
value: string;
}

// TODO: replace when exported from elastic/charts
const DEFAULT_SINGLE_PANEL_SM_VALUE = '__ECH_DEFAULT_SINGLE_PANEL_SM_VALUE__';

const getTooltipData = (
aspects: Aspects,
header: TooltipValue | null,
Expand All @@ -48,10 +49,7 @@ const getTooltipData = (
const data: TooltipData[] = [];

if (header) {
const xFormatter =
aspects.x.aggType === BUCKET_TYPES.DATE_RANGE || aspects.x.aggType === BUCKET_TYPES.RANGE
? null
: aspects.x.formatter;
const xFormatter = isRangeAggType(aspects.x.aggType) ? null : aspects.x.formatter;
data.push({
label: aspects.x.title,
value: xFormatter ? xFormatter(header.value) : `${header.value}`,
Expand Down Expand Up @@ -91,6 +89,28 @@ const getTooltipData = (
}
});

if (
aspects.splitColumn &&
valueSeries.smHorizontalAccessorValue !== undefined &&
valueSeries.smHorizontalAccessorValue !== DEFAULT_SINGLE_PANEL_SM_VALUE
) {
data.push({
label: aspects.splitColumn.title,
value: `${valueSeries.smHorizontalAccessorValue}`,
});
}

if (
aspects.splitRow &&
valueSeries.smVerticalAccessorValue !== undefined &&
valueSeries.smVerticalAccessorValue !== DEFAULT_SINGLE_PANEL_SM_VALUE
) {
data.push({
label: aspects.splitRow.title,
value: `${valueSeries.smVerticalAccessorValue}`,
});
}

return data;
};

Expand Down
1 change: 0 additions & 1 deletion src/plugins/vis_type_xy/public/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ export { XYEndzones } from './xy_endzones';
export { XYCurrentTime } from './xy_current_time';
export { XYSettings } from './xy_settings';
export { XYThresholdLine } from './xy_threshold_line';
export { SplitChartWarning } from './split_chart_warning';
55 changes: 0 additions & 55 deletions src/plugins/vis_type_xy/public/components/split_chart_warning.tsx

This file was deleted.

11 changes: 10 additions & 1 deletion src/plugins/vis_type_xy/public/config/get_aspects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,23 @@ export function getEmptyAspect(): Aspect {
},
};
}
export function getAspects(columns: DatatableColumn[], { x, y, z, series }: Dimensions): Aspects {
export function getAspects(
columns: DatatableColumn[],
{ x, y, z, series, splitColumn, splitRow }: Dimensions
): Aspects {
const seriesDimensions = Array.isArray(series) || series === undefined ? series : [series];

return {
x: getAspectsFromDimension(columns, x) ?? getEmptyAspect(),
y: getAspectsFromDimension(columns, y) ?? [],
z: z && z?.length > 0 ? getAspectsFromDimension(columns, z[0]) : undefined,
series: getAspectsFromDimension(columns, seriesDimensions),
splitColumn:
splitColumn && splitColumn?.length > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: splitColumn && splitColumn?.length > 0 === splitColumn?.length

? getAspectsFromDimension(columns, splitColumn[0])
: undefined,
splitRow:
splitRow && splitRow?.length > 0 ? getAspectsFromDimension(columns, splitRow[0]) : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: splitRow && splitRow?.length > 0 -> splitRow?.length

};
}

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/vis_type_xy/public/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export interface Aspects {
y: Aspect[];
z?: Aspect;
series?: Aspect[];
splitColumn?: Aspect;
splitRow?: Aspect;
}

export interface AxisGrid {
Expand Down
13 changes: 6 additions & 7 deletions src/plugins/vis_type_xy/public/utils/accessors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,23 @@ const getFieldName = (fieldName: string, index?: number) => {
return `${fieldName}${indexStr}`;
};

export const isRangeAggType = (type: string | null) =>
type === BUCKET_TYPES.DATE_RANGE || type === BUCKET_TYPES.RANGE;

/**
* Returns accessor function for complex accessor types
* @param aspect
* @param isComplex - forces to be functional/complex accessor
*/
export const getComplexAccessor = (fieldName: string) => (
export const getComplexAccessor = (fieldName: string, isComplex: boolean = false) => (
aspect: Aspect,
index?: number
): Accessor | AccessorFn | undefined => {
if (!aspect.accessor) {
return;
}

if (
!(
(aspect.aggType === BUCKET_TYPES.DATE_RANGE || aspect.aggType === BUCKET_TYPES.RANGE) &&
aspect.formatter
)
) {
if (!((isComplex || isRangeAggType(aspect.aggType)) && aspect.formatter)) {
return aspect.accessor;
}

Expand Down
11 changes: 11 additions & 0 deletions src/plugins/vis_type_xy/public/vis_component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {
getComplexAccessor,
getSplitSeriesAccessorFnMap,
} from './utils/accessors';
import { ChartSplitter } from './chart_splitter';

export interface VisComponentProps {
visParams: VisParams;
Expand Down Expand Up @@ -265,6 +266,12 @@ const VisComponent = (props: VisComponentProps) => {
const splitSeriesAccessors = config.aspects.series
? compact(config.aspects.series.map(getComplexAccessor(COMPLEX_SPLIT_ACCESSOR)))
: [];
const splitChartColumnAccessor = config.aspects.splitColumn
? getComplexAccessor(COMPLEX_SPLIT_ACCESSOR, true)(config.aspects.splitColumn)
: undefined;
const splitChartRowAccessor = config.aspects.splitRow
? getComplexAccessor(COMPLEX_SPLIT_ACCESSOR, true)(config.aspects.splitRow)
: undefined;

return (
<div className="xyChart__container" data-test-subj="visTypeXyChart">
Expand All @@ -274,6 +281,10 @@ const VisComponent = (props: VisComponentProps) => {
legendPosition={legendPosition}
/>
<Chart size="100%">
<ChartSplitter
splitColumnAccessor={splitChartColumnAccessor}
splitRowAccessor={splitChartRowAccessor}
/>
<XYSettings
{...config}
showLegend={showLegend}
Expand Down
23 changes: 9 additions & 14 deletions src/plugins/vis_type_xy/public/vis_renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { VisualizationContainer } from '../../visualizations/public';
import type { PersistedState } from '../../visualizations/public';

import { XyVisType } from '../common';
import { SplitChartWarning } from './components/split_chart_warning';
import { VisComponentType } from './vis_component';
import { RenderValue, visName } from './xy_vis_fn';

Expand All @@ -47,23 +46,19 @@ export const xyVisRenderer: ExpressionRenderDefinition<RenderValue> = {
reuseDomNode: true,
render: (domNode, { visData, visConfig, visType }, handlers) => {
const showNoResult = shouldShowNoResultsMessage(visData, visType);
const isSplitChart = Boolean(visConfig.dimensions.splitRow || visConfig.dimensions.splitRow);

handlers.onDestroy(() => unmountComponentAtNode(domNode));
render(
<I18nProvider>
<>
{isSplitChart && <SplitChartWarning />}
<VisualizationContainer handlers={handlers} showNoResult={showNoResult || isSplitChart}>
<VisComponent
visParams={visConfig}
visData={visData}
renderComplete={handlers.done}
fireEvent={handlers.event}
uiState={handlers.uiState as PersistedState}
/>
</VisualizationContainer>
</>
<VisualizationContainer handlers={handlers} showNoResult={showNoResult}>
<VisComponent
visParams={visConfig}
visData={visData}
renderComplete={handlers.done}
fireEvent={handlers.event}
uiState={handlers.uiState as PersistedState}
/>
</VisualizationContainer>
</I18nProvider>,
domNode
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

import React from 'react';

import { i18n } from '@kbn/i18n';
// @ts-ignore
import { euiPaletteColorBlind } from '@elastic/eui/lib/services';
Expand All @@ -42,7 +40,6 @@ import { toExpressionAst } from '../to_ast';
import { ChartType } from '../../common';
import { getConfigCollections } from '../editor/collections';
import { getOptionTabs } from '../editor/common_config';
import { SplitTooltip } from './split_tooltip';

export const getAreaVisTypeDefinition = (
showElasticChartsOptions = false
Expand Down Expand Up @@ -189,12 +186,6 @@ export const getAreaVisTypeDefinition = (
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter'],
// TODO: Remove when split chart aggs are supported
// https://github.com/elastic/kibana/issues/82496
...(showElasticChartsOptions && {
disabled: true,
tooltip: <SplitTooltip />,
}),
},
]),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

import React from 'react';

import { i18n } from '@kbn/i18n';
// @ts-ignore
import { euiPaletteColorBlind } from '@elastic/eui/lib/services';
Expand All @@ -42,7 +40,6 @@ import { ChartType } from '../../common';
import { getConfigCollections } from '../editor/collections';
import { getOptionTabs } from '../editor/common_config';
import { defaultCountLabel, LabelRotation } from '../../../charts/public';
import { SplitTooltip } from './split_tooltip';

export const getHistogramVisTypeDefinition = (
showElasticChartsOptions = false
Expand Down Expand Up @@ -192,12 +189,6 @@ export const getHistogramVisTypeDefinition = (
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter'],
// TODO: Remove when split chart aggs are supported
// https://github.com/elastic/kibana/issues/82496
...(showElasticChartsOptions && {
disabled: true,
tooltip: <SplitTooltip />,
}),
},
]),
},
Expand Down
Loading