Skip to content

Commit

Permalink
log data tables properly
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Mar 22, 2022
1 parent b0c3aab commit 7d03a66
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 16 additions & 10 deletions src/plugins/visualizations/common/utils/prepare_log_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
};
20 changes: 17 additions & 3 deletions x-pack/plugins/lens/common/expressions/datatable/datatable_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -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);
Expand Down
16 changes: 0 additions & 16 deletions x-pack/plugins/lens/common/expressions/expressions_utils.ts

This file was deleted.

38 changes: 36 additions & 2 deletions x-pack/plugins/lens/common/expressions/xy_chart/xy_chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,32 @@ import type { ExpressionValueSearchContext } from '../../../../../../src/plugins
import type { LensMultiTable } from '../../types';
import type { XYArgs } from './xy_args';
import { fittingFunctionDefinitions } from './fitting_function';
import { logDataTable } from '../expressions_utils';
import { prepareLogTable } from '../../../../../../src/plugins/visualizations/common/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';
Expand Down Expand Up @@ -159,7 +178,22 @@ export const xyChart: ExpressionFunctionDefinition<
},
fn(data: LensMultiTable, args: XYArgs, handlers) {
if (handlers?.inspectorAdapters?.tables) {
logDataTable(handlers.inspectorAdapters.tables, data.tables);
args.layers.forEach(({ layerId, accessors, xAccessor, splitAccessor, layerType }) => {
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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7d03a66

Please sign in to comment.