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] Support vis_dimension type for accessors #128063

Closed
Show file tree
Hide file tree
Changes from 97 commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
9388bba
added xy plugin.
Kuznietsov Mar 8, 2022
8df9659
Merge branch 'main' into chart_expressions-xy
kibanamachine Mar 9, 2022
ab72728
Added expressionXY limits.
Kuznietsov Mar 9, 2022
5747322
Merge branch 'chart_expressions-xy' of github.com:Kunzetsov/kibana in…
Kuznietsov Mar 9, 2022
b4ee9c1
Added xy expression functions to the expression_xy plugin.
Kuznietsov Mar 10, 2022
400845d
Moved xy to a separate plugin.
Kuznietsov Mar 11, 2022
b2090f3
Small refactoring.
Kuznietsov Mar 11, 2022
33a06fa
Fixed types.
Kuznietsov Mar 14, 2022
d94fa4f
Merge branch 'main' into chart_expressions-xy
Kuznietsov Mar 14, 2022
663e093
Fixed import of scss.
Kuznietsov Mar 14, 2022
cbffe77
Fixed imports.
Kuznietsov Mar 14, 2022
389f933
Added required plugins.
Kuznietsov Mar 14, 2022
90aa97a
Fixed import
Kuznietsov Mar 14, 2022
1d3a264
Fixed types.
Kuznietsov Mar 14, 2022
a78d45d
Changed expression names.
Kuznietsov Mar 14, 2022
35cab91
Fixed bugs, caused by the refactoring process.
Kuznietsov Mar 14, 2022
847b3c4
Merge branch 'main' into chart_expressions-xy
kibanamachine Mar 15, 2022
ed7f8ea
Fixed lens snapshots.
Kuznietsov Mar 15, 2022
b6daa5d
Removed new line.
Kuznietsov Mar 15, 2022
bda6524
Merge branch 'chart_expressions-xy' of github.com:Kunzetsov/kibana in…
Kuznietsov Mar 15, 2022
c8d40fe
Fixed xy_chart tests.
Kuznietsov Mar 15, 2022
5fed60c
Added lazy loading for xy chart.
Kuznietsov Mar 15, 2022
dc195b2
Fixed xy chart test.
Kuznietsov Mar 15, 2022
d39681f
Fixed broken chart selectors.
Kuznietsov Mar 16, 2022
b901d68
Fixed dashboard tests.
Kuznietsov Mar 16, 2022
d327dfe
dashboard test fixed.
Kuznietsov Mar 16, 2022
b500961
Fixed heatmap vis.
Kuznietsov Mar 16, 2022
7a25b74
Smokescreen test fixed.
Kuznietsov Mar 16, 2022
0004794
more fixes.
Kuznietsov Mar 16, 2022
fc8c0b3
async dashboard tests fixed.
Kuznietsov Mar 16, 2022
98454ad
Fixed xy smokescreen tests selectors.
Kuznietsov Mar 16, 2022
05cccac
fixed show_underlying_data tests.
Kuznietsov Mar 16, 2022
bcf5201
Updated snapshots.
Kuznietsov Mar 16, 2022
99dc773
updated limits.
Kuznietsov Mar 16, 2022
94a5850
Fixed more selectors
Kuznietsov Mar 16, 2022
bfea6f1
Fixed persistent context test.
Kuznietsov Mar 16, 2022
7cb4db4
Fixed some more test at ml.
Kuznietsov Mar 16, 2022
98e8661
Merge branch 'main' into chart_expressions-xy
Kuznietsov Mar 16, 2022
5ea9cc5
Fixed types and imports
Kuznietsov Mar 16, 2022
4f72658
Fixed handlers.inspectorAdapters.tables.logDatatable
Kuznietsov Mar 16, 2022
ee4ec20
Fixed logDatatable
Kuznietsov Mar 17, 2022
e72005c
Translations fixed.
Kuznietsov Mar 17, 2022
902972d
Fixed "Visualize App ... cleans filters and query" test.
Kuznietsov Mar 17, 2022
05b0f8d
Fixed "lens disable auto-apply tests" test.
Kuznietsov Mar 17, 2022
cae1e75
Updated dashboard tests.
Kuznietsov Mar 17, 2022
00c7e28
Fixed translations.
Kuznietsov Mar 17, 2022
0ad3793
Expression tests fixed.
Kuznietsov Mar 17, 2022
2fbe81f
Cleaned up expression_xy.
Kuznietsov Mar 17, 2022
e9c497f
cleaned up lens xy_visualization.
Kuznietsov Mar 17, 2022
ea299ec
fixed more tests.
Kuznietsov Mar 17, 2022
9ea2cbb
Fix of tsvb.
Kuznietsov Mar 17, 2022
46edc6b
Fixed more tests.
Kuznietsov Mar 17, 2022
672885c
Merge branch 'main' into chart_expressions-xy
Kuznietsov Mar 17, 2022
f109200
Merge branch 'main' into chart_expressions-xy
Kuznietsov Mar 17, 2022
498b34e
Fixed xy chart limits.
Kuznietsov Mar 18, 2022
eeefc8b
Merge branch 'chart_expressions-xy' of github.com:Kunzetsov/kibana in…
Kuznietsov Mar 18, 2022
e00f089
Merge branch 'main' into chart_expressions-xy
Kuznietsov Mar 18, 2022
b06f00f
Add support of vis_dimension type for accessors
VladLasitsa Mar 18, 2022
fa43335
Merge remote-tracking branch 'Kunzetsov/chart_expressions-xy' into ch…
VladLasitsa Mar 18, 2022
0024b0f
Remove unused import
VladLasitsa Mar 18, 2022
4996ea6
Fixed new tests.
Kuznietsov Mar 18, 2022
97bb678
Fixed types.
Kuznietsov Mar 18, 2022
0709192
Merge remote-tracking branch 'Kunzetsov/chart_expressions-xy' into ch…
VladLasitsa Mar 18, 2022
6d83b2e
Fix types
VladLasitsa Mar 18, 2022
c1833c6
Fix types
VladLasitsa Mar 18, 2022
f91c8d5
Merge branch 'main' into chart_expressions-xy
kibanamachine Mar 20, 2022
208d1d9
Fix CI
VladLasitsa Mar 21, 2022
0b6db50
Merge branch 'main' into chart_expressions-xy
kibanamachine Mar 21, 2022
1cc2ff7
Merge remote-tracking branch 'Kunzetsov/chart_expressions-xy' into ch…
VladLasitsa Mar 21, 2022
75b2e91
Merge branch 'main' into chart_expressions-xy
Kuznietsov Mar 23, 2022
902dae6
Merge branch 'main' into chart_expressions-xy
Kuznietsov Mar 24, 2022
21e34b4
First try to fix merge conflicts.
Kuznietsov Mar 24, 2022
9cc22c8
Fixed annotatations.
Kuznietsov Mar 25, 2022
a99a223
Fixed types.
Kuznietsov Mar 25, 2022
b553456
Updated snapshots
Kuznietsov Mar 25, 2022
60f5645
Merge branch 'main' into chart_expressions-xy
Kuznietsov Mar 25, 2022
dec0d18
Fixed tests.
Kuznietsov Mar 25, 2022
628ade6
Fixed dependencies.
Kuznietsov Mar 25, 2022
cc63956
Fixed i18n.
Kuznietsov Mar 25, 2022
0e4092d
Moved XY state types to lens.
Kuznietsov Mar 25, 2022
ef30205
Fixed more types.
Kuznietsov Mar 25, 2022
f29bdcf
Merge branch 'main' into chart_expressions-xy
Kuznietsov Mar 28, 2022
8139986
Update src/plugins/chart_expressions/expression_xy/README.md
Kuznietsov Mar 28, 2022
8307b73
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine Mar 28, 2022
500fb78
Removed yConfig from *Layers types
Kuznietsov Mar 28, 2022
839b023
Fixed styles.
Kuznietsov Mar 28, 2022
b61e59a
Fixed types.
Kuznietsov Mar 28, 2022
53a6659
Removed not used utils and styles.
Kuznietsov Mar 28, 2022
490159a
Merge branch 'main' into chart_expressions-xy
Kuznietsov Mar 28, 2022
0039dc4
Merge remote-tracking branch 'Kunzetsov/chart_expressions-xy' into ch…
VladLasitsa Mar 28, 2022
c8b86b3
Fix types
VladLasitsa Mar 28, 2022
62fbde1
Merge remote-tracking branch 'upstream/main' into chart_expressions-x…
VladLasitsa Mar 29, 2022
484d897
Some fixes
VladLasitsa Mar 29, 2022
35caaa9
Remove unneeded changes
VladLasitsa Mar 29, 2022
284a56d
Fix types
VladLasitsa Mar 29, 2022
4c16eb3
Update limits
VladLasitsa Mar 29, 2022
79de4d7
Merge commit 'c11a44eb3b19a662e34a58aface197f0418fe6c6' into chart_ex…
mbondyra Mar 29, 2022
147d59d
Fix checks
VladLasitsa Mar 30, 2022
f0b1f16
Merge branch 'main' into chart_expressions-xy-support-visdimension-type
kibanamachine Apr 1, 2022
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 @@ -46,7 +46,7 @@ export const dataLayerConfigFunction: ExpressionFunctionDefinition<
}),
},
xAccessor: {
types: ['string'],
types: ['string', 'vis_dimension'],
help: i18n.translate('expressionXY.dataLayer.xAccessor.help', {
defaultMessage: 'X-axis',
}),
Expand Down Expand Up @@ -80,13 +80,13 @@ export const dataLayerConfigFunction: ExpressionFunctionDefinition<
default: YScaleTypes.LINEAR,
},
splitAccessor: {
types: ['string'],
types: ['string', 'vis_dimension'],
help: i18n.translate('expressionXY.dataLayer.splitAccessor.help', {
defaultMessage: 'The column to split by',
}),
},
accessors: {
types: ['string'],
types: ['string', 'vis_dimension'],
help: i18n.translate('expressionXY.dataLayer.accessors.help', {
defaultMessage: 'The columns to display on the y axis.',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const referenceLineLayerConfigFunction: ExpressionFunctionDefinition<
}),
},
accessors: {
types: ['string'],
types: ['string', 'vis_dimension'],
help: i18n.translate('expressionXY.referenceLineLayer.accessors.help', {
defaultMessage: 'The columns to display on the y axis.',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const yAxisConfigFunction: ExpressionFunctionDefinition<
inputTypes: ['null'],
args: {
forAccessor: {
types: ['string'],
types: ['string', 'vis_dimension'],
help: i18n.translate('expressionXY.yConfig.forAccessor.help', {
defaultMessage: 'The accessor this configuration is for',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { HorizontalAlignment, Position, VerticalAlignment } from '@elastic/charts';
import { $Values } from '@kbn/utility-types';
import type { ExpressionValueVisDimension } from '../../../../visualizations/public';
import { Datatable } from '../../../../expressions';
import { PaletteOutput } from '../../../../charts/common';
import { EventAnnotationOutput } from '../../../../event_annotation/common';
Expand Down Expand Up @@ -70,7 +71,7 @@ export interface AxisConfig {
}

export interface YConfig {
forAccessor: string;
forAccessor: string | ExpressionValueVisDimension;
axisMode?: YAxisMode;
color?: string;
icon?: string;
Expand All @@ -87,11 +88,11 @@ export interface ValidLayer extends DataLayerConfigResult {

export interface DataLayerArgs {
layerId: string;
accessors: string[];
accessors: Array<string | ExpressionValueVisDimension>;
seriesType: SeriesType;
xAccessor?: string;
xAccessor?: string | ExpressionValueVisDimension;
hide?: boolean;
splitAccessor?: string;
splitAccessor?: string | ExpressionValueVisDimension;
columnToLabel?: string; // Actually a JSON key-value pair
yScaleType: YScaleType;
xScaleType: XScaleType;
Expand Down Expand Up @@ -192,7 +193,7 @@ export type AnnotationLayerConfigResult = AnnotationLayerArgs & {

export interface ReferenceLineLayerArgs {
layerId: string;
accessors: string[];
accessors: Array<string | ExpressionValueVisDimension>;
columnToLabel?: string;
yConfig?: YConfigResult[];
}
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/chart_expressions/expression_xy/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"ui": true,
"requiredPlugins": ["expressions", "charts", "data", "fieldFormats", "uiActions", "eventAnnotation", "visualizations"],
"requiredBundles": ["kibanaReact"],
"optionalPlugins": []
"optionalPlugins": [],
"extraPublicDirs": ["common"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

import React from 'react';
import type { LegendAction, XYChartSeriesIdentifier } from '@elastic/charts';
import {
getAccessorByDimension,
getFormatByAccessor,
} from '../../../../../plugins/visualizations/common/utils';
import type { FilterEvent } from '../types';
import type { LensMultiTable, DataLayerArgs } from '../../common';
import type { FormatFactory } from '../types';
Expand All @@ -23,19 +27,23 @@ export const getLegendAction = (
React.memo(({ series: [xySeries] }) => {
const series = xySeries as XYChartSeriesIdentifier;
const layer = filteredLayers.find((l) =>
series.seriesKeys.some((key: string | number) => l.accessors.includes(key.toString()))
series.seriesKeys.some((key: string | number) =>
l.accessors.some(
(accessor) =>
getAccessorByDimension(accessor, tables[l.layerId].columns) === key.toString()
)
)
);

if (!layer || !layer.splitAccessor) {
return null;
}

const splitLabel = series.seriesKeys[0] as string;
const accessor = layer.splitAccessor;

const table = tables[layer.layerId];
const splitColumn = table.columns.find(({ id }) => id === layer.splitAccessor);
const formatter = formatFactory(splitColumn && splitColumn.meta?.params);
const accessor = getAccessorByDimension(layer.splitAccessor, table.columns);
const formatter = formatFactory(getFormatByAccessor(layer.splitAccessor, table.columns));

const rowIndex = table.rows.findIndex((row) => {
if (layersAlreadyFormatted[accessor]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import React from 'react';
import { groupBy } from 'lodash';
import { RectAnnotation, AnnotationDomainType, LineAnnotation, Position } from '@elastic/charts';
import { euiLightVars } from '@kbn/ui-theme';
import { getAccessorByDimension } from '../../../../../plugins/visualizations/common/utils';
mbondyra marked this conversation as resolved.
Show resolved Hide resolved
import type { FieldFormat } from '../../../../field_formats/common';
import type { IconPosition, ReferenceLineLayerArgs, YAxisMode } from '../../common/types';
import type { LensMultiTable } from '../../common/types';
Expand Down Expand Up @@ -120,7 +121,9 @@ export const ReferenceLineAnnotations = ({
const row = table.rows[0];

const yConfigByValue = yConfigs.sort(
({ forAccessor: idA }, { forAccessor: idB }) => row[idA] - row[idB]
({ forAccessor: idA }, { forAccessor: idB }) =>
row[getAccessorByDimension(idA, table.columns)] -
row[getAccessorByDimension(idB, table.columns)]
);

const groupedByDirection = groupBy(yConfigByValue, 'fill');
Expand All @@ -137,6 +140,8 @@ export const ReferenceLineAnnotations = ({
? 'right'
: 'left';

const forAccessor = getAccessorByDimension(yConfig.forAccessor, table.columns);

const formatter = formatters[groupId || 'bottom'];

const defaultColor = euiLightVars.euiColorDarkShade;
Expand Down Expand Up @@ -194,12 +199,12 @@ export const ReferenceLineAnnotations = ({
annotations.push(
<LineAnnotation
{...props}
id={`${layerId}-${yConfig.forAccessor}-line`}
key={`${layerId}-${yConfig.forAccessor}-line`}
id={`${layerId}-${forAccessor}-line`}
key={`${layerId}-${forAccessor}-line`}
dataValues={table.rows.map(() => ({
dataValue: row[yConfig.forAccessor],
header: columnToLabelMap[yConfig.forAccessor],
details: formatter?.convert(row[yConfig.forAccessor]) || row[yConfig.forAccessor],
dataValue: row[forAccessor],
header: columnToLabelMap[forAccessor],
details: formatter?.convert(row[forAccessor]) || row[forAccessor],
}))}
domainType={
yConfig.axisMode === 'bottom'
Expand All @@ -218,42 +223,46 @@ export const ReferenceLineAnnotations = ({
if (yConfig.fill && yConfig.fill !== 'none') {
const isFillAbove = yConfig.fill === 'above';
const indexFromSameType = groupedByDirection[yConfig.fill].findIndex(
({ forAccessor }) => forAccessor === yConfig.forAccessor
(yConfigResult) =>
getAccessorByDimension(yConfigResult.forAccessor, table.columns) === forAccessor
);
const shouldCheckNextReferenceLine =
indexFromSameType < groupedByDirection[yConfig.fill].length - 1;
annotations.push(
<RectAnnotation
{...props}
id={`${layerId}-${yConfig.forAccessor}-rect`}
key={`${layerId}-${yConfig.forAccessor}-rect`}
id={`${layerId}-${forAccessor}-rect`}
key={`${layerId}-${forAccessor}-rect`}
dataValues={table.rows.map(() => {
const nextValue = shouldCheckNextReferenceLine
? row[groupedByDirection[yConfig.fill!][indexFromSameType + 1].forAccessor]
? row[
getAccessorByDimension(
groupedByDirection[yConfig.fill!][indexFromSameType + 1].forAccessor,
table.columns
)
]
: undefined;
if (yConfig.axisMode === 'bottom') {
return {
coordinates: {
x0: isFillAbove ? row[yConfig.forAccessor] : nextValue,
x0: isFillAbove ? row[forAccessor] : nextValue,
y0: undefined,
x1: isFillAbove ? nextValue : row[yConfig.forAccessor],
x1: isFillAbove ? nextValue : row[forAccessor],
y1: undefined,
},
header: columnToLabelMap[yConfig.forAccessor],
details:
formatter?.convert(row[yConfig.forAccessor]) || row[yConfig.forAccessor],
header: columnToLabelMap[forAccessor],
details: formatter?.convert(row[forAccessor]) || row[forAccessor],
};
}
return {
coordinates: {
x0: undefined,
y0: isFillAbove ? row[yConfig.forAccessor] : nextValue,
y0: isFillAbove ? row[forAccessor] : nextValue,
x1: undefined,
y1: isFillAbove ? nextValue : row[yConfig.forAccessor],
y1: isFillAbove ? nextValue : row[forAccessor],
},
header: columnToLabelMap[yConfig.forAccessor],
details:
formatter?.convert(row[yConfig.forAccessor]) || row[yConfig.forAccessor],
header: columnToLabelMap[forAccessor],
details: formatter?.convert(row[forAccessor]) || row[forAccessor],
};
})}
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import moment from 'moment';
import { Endzones } from '../../../../../plugins/charts/public';
import type { LensMultiTable, DataLayerArgs } from '../../common';
import { search } from '../../../../../plugins/data/public';
import {
getColumnByAccessor,
getAccessorByDimension,
} from '../../../../../plugins/visualizations/common/utils';

export interface XDomain {
min?: number;
Expand All @@ -23,7 +27,9 @@ export const getAppliedTimeRange = (layers: DataLayerArgs[], data: LensMultiTabl
return Object.entries(data.tables)
.map(([tableId, table]) => {
const layer = layers.find((l) => l.layerId === tableId);
const xColumn = table.columns.find((col) => col.id === layer?.xAccessor);
const xColumn = layer?.xAccessor
? getColumnByAccessor(layer?.xAccessor, table.columns)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: you can use layer.xAccessor here.

: null;
const timeRange =
xColumn && search.aggs.getDateHistogramMetaDataByDatatableColumn(xColumn)?.timeRange;
if (timeRange) {
Expand Down Expand Up @@ -59,9 +65,12 @@ export const getXDomain = (
if (isHistogram && isFullyQualified(baseDomain)) {
const xValues = uniq(
layers
.flatMap((layer) =>
data.tables[layer.layerId].rows.map((row) => row[layer.xAccessor!].valueOf() as number)
)
.flatMap((layer) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: instead of using as number, you could use flatMap<number> here.
PS: I know, you are not the author of this code.

const xAccessor =
layer.xAccessor &&
getAccessorByDimension(layer.xAccessor, data.tables[layer.layerId].columns);
return data.tables[layer.layerId].rows.map((row) => row[xAccessor!].valueOf() as number);
})
.sort()
);

Expand Down
Loading