mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Lens] Log data tables properly (#128297)
* log data tables properly * update tests * fix heatmap * fix annotations Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
5e847ac074
commit
028992def3
17 changed files with 154 additions and 100 deletions
|
@ -182,12 +182,16 @@ export const gaugeFunction = (): GaugeExpressionFunctionDefinition => ({
|
|||
}
|
||||
|
||||
if (handlers?.inspectorAdapters?.tables) {
|
||||
const logTable = prepareLogTable(data, [
|
||||
[metric ? [metric] : undefined, strings.getMetricHelp()],
|
||||
[min ? [min] : undefined, strings.getMinHelp()],
|
||||
[max ? [max] : undefined, strings.getMaxHelp()],
|
||||
[goal ? [goal] : undefined, strings.getGoalHelp()],
|
||||
]);
|
||||
const logTable = prepareLogTable(
|
||||
data,
|
||||
[
|
||||
[metric ? [metric] : undefined, strings.getMetricHelp()],
|
||||
[min ? [min] : undefined, strings.getMinHelp()],
|
||||
[max ? [max] : undefined, strings.getMaxHelp()],
|
||||
[goal ? [goal] : undefined, strings.getGoalHelp()],
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ Object {
|
|||
Object {
|
||||
"id": "col-0-1",
|
||||
"meta": Object {
|
||||
"dimensionName": undefined,
|
||||
"dimensionName": "Metric",
|
||||
"type": "number",
|
||||
},
|
||||
"name": "Count",
|
||||
|
@ -14,7 +14,7 @@ Object {
|
|||
Object {
|
||||
"id": "col-1-2",
|
||||
"meta": Object {
|
||||
"dimensionName": undefined,
|
||||
"dimensionName": "X axis",
|
||||
"type": "string",
|
||||
},
|
||||
"name": "Dest",
|
||||
|
|
|
@ -28,7 +28,7 @@ const convertToVisDimension = (
|
|||
const column = columns.find((c) => c.id === accessor);
|
||||
if (!column) return;
|
||||
return {
|
||||
accessor: Number(column.id),
|
||||
accessor: column,
|
||||
format: {
|
||||
id: column.meta.params?.id,
|
||||
params: { ...column.meta.params?.params },
|
||||
|
@ -212,7 +212,7 @@ export const heatmapFunction = (): HeatmapExpressionFunctionDefinition => ({
|
|||
})
|
||||
);
|
||||
}
|
||||
const logTable = prepareLogTable(data, argsTable);
|
||||
const logTable = prepareLogTable(data, argsTable, true);
|
||||
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
|
||||
}
|
||||
return {
|
||||
|
|
|
@ -162,7 +162,7 @@ export const metricVisFunction = (): MetricVisExpressionFunctionDefinition => ({
|
|||
}),
|
||||
]);
|
||||
}
|
||||
const logTable = prepareLogTable(input, argsTable);
|
||||
const logTable = prepareLogTable(input, argsTable, true);
|
||||
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,14 +27,6 @@ Object {
|
|||
},
|
||||
"name": "Field 3",
|
||||
},
|
||||
Object {
|
||||
"id": "col-0-4",
|
||||
"meta": Object {
|
||||
"dimensionName": undefined,
|
||||
"type": "number",
|
||||
},
|
||||
"name": "Field 4",
|
||||
},
|
||||
],
|
||||
"rows": Array [
|
||||
Object {
|
||||
|
|
|
@ -27,14 +27,6 @@ Object {
|
|||
},
|
||||
"name": "Field 3",
|
||||
},
|
||||
Object {
|
||||
"id": "col-0-4",
|
||||
"meta": Object {
|
||||
"dimensionName": undefined,
|
||||
"type": "number",
|
||||
},
|
||||
"name": "Field 4",
|
||||
},
|
||||
],
|
||||
"rows": Array [
|
||||
Object {
|
||||
|
|
|
@ -19,22 +19,6 @@ Object {
|
|||
},
|
||||
"name": "Field 2",
|
||||
},
|
||||
Object {
|
||||
"id": "col-0-3",
|
||||
"meta": Object {
|
||||
"dimensionName": undefined,
|
||||
"type": "number",
|
||||
},
|
||||
"name": "Field 3",
|
||||
},
|
||||
Object {
|
||||
"id": "col-0-4",
|
||||
"meta": Object {
|
||||
"dimensionName": undefined,
|
||||
"type": "number",
|
||||
},
|
||||
"name": "Field 4",
|
||||
},
|
||||
],
|
||||
"rows": Array [
|
||||
Object {
|
||||
|
|
|
@ -134,12 +134,16 @@ export const mosaicVisFunction = (): MosaicVisExpressionFunctionDefinition => ({
|
|||
};
|
||||
|
||||
if (handlers?.inspectorAdapters?.tables) {
|
||||
const logTable = prepareLogTable(context, [
|
||||
[[args.metric], strings.getSliceSizeHelp()],
|
||||
[args.buckets, strings.getSliceHelp()],
|
||||
[args.splitColumn, strings.getColumnSplitHelp()],
|
||||
[args.splitRow, strings.getRowSplitHelp()],
|
||||
]);
|
||||
const logTable = prepareLogTable(
|
||||
context,
|
||||
[
|
||||
[[args.metric], strings.getSliceSizeHelp()],
|
||||
[args.buckets, strings.getSliceHelp()],
|
||||
[args.splitColumn, strings.getColumnSplitHelp()],
|
||||
[args.splitRow, strings.getRowSplitHelp()],
|
||||
],
|
||||
true
|
||||
);
|
||||
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
|
||||
}
|
||||
|
||||
|
|
|
@ -154,12 +154,16 @@ export const pieVisFunction = (): PieVisExpressionFunctionDefinition => ({
|
|||
};
|
||||
|
||||
if (handlers?.inspectorAdapters?.tables) {
|
||||
const logTable = prepareLogTable(context, [
|
||||
[[args.metric], strings.getSliceSizeHelp()],
|
||||
[args.buckets, strings.getSliceHelp()],
|
||||
[args.splitColumn, strings.getColumnSplitHelp()],
|
||||
[args.splitRow, strings.getRowSplitHelp()],
|
||||
]);
|
||||
const logTable = prepareLogTable(
|
||||
context,
|
||||
[
|
||||
[[args.metric], strings.getSliceSizeHelp()],
|
||||
[args.buckets, strings.getSliceHelp()],
|
||||
[args.splitColumn, strings.getColumnSplitHelp()],
|
||||
[args.splitRow, strings.getRowSplitHelp()],
|
||||
],
|
||||
true
|
||||
);
|
||||
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
|
||||
}
|
||||
|
||||
|
|
|
@ -134,12 +134,16 @@ export const treemapVisFunction = (): TreemapVisExpressionFunctionDefinition =>
|
|||
};
|
||||
|
||||
if (handlers?.inspectorAdapters?.tables) {
|
||||
const logTable = prepareLogTable(context, [
|
||||
[[args.metric], strings.getSliceSizeHelp()],
|
||||
[args.buckets, strings.getSliceHelp()],
|
||||
[args.splitColumn, strings.getColumnSplitHelp()],
|
||||
[args.splitRow, strings.getRowSplitHelp()],
|
||||
]);
|
||||
const logTable = prepareLogTable(
|
||||
context,
|
||||
[
|
||||
[[args.metric], strings.getSliceSizeHelp()],
|
||||
[args.buckets, strings.getSliceHelp()],
|
||||
[args.splitColumn, strings.getColumnSplitHelp()],
|
||||
[args.splitRow, strings.getRowSplitHelp()],
|
||||
],
|
||||
true
|
||||
);
|
||||
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
|
||||
}
|
||||
|
||||
|
|
|
@ -129,12 +129,16 @@ export const waffleVisFunction = (): WaffleVisExpressionFunctionDefinition => ({
|
|||
};
|
||||
|
||||
if (handlers?.inspectorAdapters?.tables) {
|
||||
const logTable = prepareLogTable(context, [
|
||||
[[args.metric], strings.getSliceSizeHelp()],
|
||||
[buckets, strings.getSliceHelp()],
|
||||
[args.splitColumn, strings.getColumnSplitHelp()],
|
||||
[args.splitRow, strings.getRowSplitHelp()],
|
||||
]);
|
||||
const logTable = prepareLogTable(
|
||||
context,
|
||||
[
|
||||
[[args.metric], strings.getSliceSizeHelp()],
|
||||
[buckets, strings.getSliceHelp()],
|
||||
[args.splitColumn, strings.getColumnSplitHelp()],
|
||||
[args.splitRow, strings.getRowSplitHelp()],
|
||||
],
|
||||
true
|
||||
);
|
||||
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
|
||||
}
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ export const tagcloudFunction: ExpressionTagcloudFunction = () => {
|
|||
if (args.bucket) {
|
||||
argsTable.push([[args.bucket], dimension.tags]);
|
||||
}
|
||||
const logTable = prepareLogTable(input, argsTable);
|
||||
const logTable = prepareLogTable(input, argsTable, true);
|
||||
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
|
||||
}
|
||||
return {
|
||||
|
|
|
@ -57,17 +57,23 @@ const getDimensionName = (
|
|||
}
|
||||
};
|
||||
|
||||
export const prepareLogTable = (datatable: Datatable, dimensions: Dimension[]) => {
|
||||
export const prepareLogTable = (
|
||||
datatable: Datatable,
|
||||
dimensions: Dimension[],
|
||||
removeUnmappedColumns: boolean = false
|
||||
) => {
|
||||
return {
|
||||
...datatable,
|
||||
columns: datatable.columns.map((column, columnIndex) => {
|
||||
return {
|
||||
...column,
|
||||
meta: {
|
||||
...column.meta,
|
||||
dimensionName: getDimensionName(column, columnIndex, dimensions),
|
||||
},
|
||||
};
|
||||
}),
|
||||
columns: datatable.columns
|
||||
.map((column, columnIndex) => {
|
||||
return {
|
||||
...column,
|
||||
meta: {
|
||||
...column.meta,
|
||||
dimensionName: getDimensionName(column, columnIndex, dimensions),
|
||||
},
|
||||
};
|
||||
})
|
||||
.filter((column) => !removeUnmappedColumns || column.meta.dimensionName),
|
||||
};
|
||||
};
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
|
||||
import { cloneDeep } from 'lodash';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { prepareLogTable } from '../../../../../../src/plugins/visualizations/common/utils';
|
||||
import { FormatFactory, LensMultiTable } from '../../types';
|
||||
import { transposeTable } from './transpose_helpers';
|
||||
import { computeSummaryRowForColumn } from './summary';
|
||||
|
@ -15,7 +17,6 @@ import type {
|
|||
ExecutionContext,
|
||||
} from '../../../../../../src/plugins/expressions';
|
||||
import type { DatatableExpressionFunction } from './types';
|
||||
import { logDataTable } from '../expressions_utils';
|
||||
|
||||
function isRange(meta: { params?: { id?: string } } | undefined) {
|
||||
return meta?.params?.id === 'range';
|
||||
|
@ -26,13 +27,26 @@ export const datatableFn =
|
|||
getFormatFactory: (context: ExecutionContext) => FormatFactory | Promise<FormatFactory>
|
||||
): DatatableExpressionFunction['fn'] =>
|
||||
async (data, args, context) => {
|
||||
const [firstTable] = Object.values(data.tables);
|
||||
if (context?.inspectorAdapters?.tables) {
|
||||
logDataTable(context.inspectorAdapters.tables, data.tables);
|
||||
const logTable = prepareLogTable(
|
||||
Object.values(data.tables)[0],
|
||||
[
|
||||
[
|
||||
args.columns.map((column) => column.columnId),
|
||||
i18n.translate('xpack.lens.datatable.column.help', {
|
||||
defaultMessage: 'Datatable column',
|
||||
}),
|
||||
],
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
context.inspectorAdapters.tables.logDatatable('default', logTable);
|
||||
}
|
||||
|
||||
let untransposedData: LensMultiTable | undefined;
|
||||
// do the sorting at this level to propagate it also at CSV download
|
||||
const [firstTable] = Object.values(data.tables);
|
||||
const [layerId] = Object.keys(context.inspectorAdapters.tables || {});
|
||||
const formatters: Record<string, ReturnType<FormatFactory>> = {};
|
||||
const formatFactory = await getFormatFactory(context);
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
/*
|
||||
* 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; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { TablesAdapter } from '../../../../../src/plugins/expressions';
|
||||
import type { Datatable } from '../../../../../src/plugins/expressions';
|
||||
|
||||
export const logDataTable = (
|
||||
tableAdapter: TablesAdapter,
|
||||
datatables: Record<string, Datatable> = {}
|
||||
) => {
|
||||
Object.entries(datatables).forEach(([key, table]) => tableAdapter.logDatatable(key, table));
|
||||
};
|
|
@ -10,14 +10,33 @@ import type { ExpressionValueSearchContext } from '../../../../../../src/plugins
|
|||
import type { LensMultiTable } from '../../types';
|
||||
import type { XYArgs } from './xy_args';
|
||||
import { fittingFunctionDefinitions } from './fitting_function';
|
||||
import { prepareLogTable } from '../../../../../../src/plugins/visualizations/common/utils';
|
||||
import { endValueDefinitions } from './end_value';
|
||||
import { logDataTable } from '../expressions_utils';
|
||||
|
||||
export interface XYChartProps {
|
||||
data: LensMultiTable;
|
||||
args: XYArgs;
|
||||
}
|
||||
|
||||
const strings = {
|
||||
getMetricHelp: () =>
|
||||
i18n.translate('xpack.lens.xy.logDatatable.metric', {
|
||||
defaultMessage: 'Vertical axis',
|
||||
}),
|
||||
getXAxisHelp: () =>
|
||||
i18n.translate('xpack.lens.xy.logDatatable.x', {
|
||||
defaultMessage: 'Horizontal axis',
|
||||
}),
|
||||
getBreakdownHelp: () =>
|
||||
i18n.translate('xpack.lens.xy.logDatatable.breakDown', {
|
||||
defaultMessage: 'Break down by',
|
||||
}),
|
||||
getReferenceLineHelp: () =>
|
||||
i18n.translate('xpack.lens.xy.logDatatable.breakDown', {
|
||||
defaultMessage: 'Break down by',
|
||||
}),
|
||||
};
|
||||
|
||||
export interface XYRender {
|
||||
type: 'render';
|
||||
as: 'lens_xy_chart_renderer';
|
||||
|
@ -174,7 +193,26 @@ export const xyChart: ExpressionFunctionDefinition<
|
|||
},
|
||||
fn(data: LensMultiTable, args: XYArgs, handlers) {
|
||||
if (handlers?.inspectorAdapters?.tables) {
|
||||
logDataTable(handlers.inspectorAdapters.tables, data.tables);
|
||||
args.layers.forEach((layer) => {
|
||||
if (layer.layerType === 'annotations') {
|
||||
return;
|
||||
}
|
||||
const { layerId, accessors, xAccessor, splitAccessor, layerType } = layer;
|
||||
const logTable = prepareLogTable(
|
||||
data.tables[layerId],
|
||||
[
|
||||
[
|
||||
accessors ? accessors : undefined,
|
||||
layerType === 'data' ? strings.getMetricHelp() : strings.getReferenceLineHelp(),
|
||||
],
|
||||
[xAccessor ? [xAccessor] : undefined, strings.getXAxisHelp()],
|
||||
[splitAccessor ? [splitAccessor] : undefined, strings.getBreakdownHelp()],
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
handlers.inspectorAdapters.tables.logDatatable(layerId, logTable);
|
||||
});
|
||||
}
|
||||
return {
|
||||
type: 'render',
|
||||
|
|
|
@ -6,9 +6,11 @@
|
|||
*/
|
||||
|
||||
import type { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import type { LensMultiTable } from '../../../../lens/common';
|
||||
import type { ChoroplethChartConfig, ChoroplethChartProps } from './types';
|
||||
import { RENDERER_ID } from './expression_renderer';
|
||||
import { prepareLogTable } from '../../../../../../src/plugins/visualizations/common/utils';
|
||||
|
||||
interface ChoroplethChartRender {
|
||||
type: 'render';
|
||||
|
@ -56,7 +58,29 @@ export const getExpressionFunction = (): ExpressionFunctionDefinition<
|
|||
},
|
||||
},
|
||||
inputTypes: ['lens_multitable'],
|
||||
fn(data, args) {
|
||||
fn(data, args, handlers) {
|
||||
if (handlers?.inspectorAdapters?.tables) {
|
||||
const logTable = prepareLogTable(
|
||||
Object.values(data.tables)[0],
|
||||
[
|
||||
[
|
||||
args.valueAccessor ? [args.valueAccessor] : undefined,
|
||||
i18n.translate('xpack.maps.logDatatable.value', {
|
||||
defaultMessage: 'Value',
|
||||
}),
|
||||
],
|
||||
[
|
||||
args.regionAccessor ? [args.regionAccessor] : undefined,
|
||||
i18n.translate('xpack.maps.logDatatable.region', {
|
||||
defaultMessage: 'Region key',
|
||||
}),
|
||||
],
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
|
||||
}
|
||||
return {
|
||||
type: 'render',
|
||||
as: RENDERER_ID,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue