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

[Visualizations] Adds dimensionName in datatable meta info #107265

Merged
merged 12 commits into from
Aug 3, 2021

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/plugins/vis_type_metric/public/metric_vis_fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { createMetricVisFn } from './metric_vis_fn';
import { functionWrapper } from '../../expressions/common/expression_functions/specs/tests/utils';
import { Datatable } from '../../expressions/common/expression_types/specs';

describe('interpreter/functions#metric', () => {
const fn = functionWrapper(createMetricVisFn());
Expand Down Expand Up @@ -56,4 +57,20 @@ describe('interpreter/functions#metric', () => {

expect(actual).toMatchSnapshot();
});

it('logs correct datatable to inspector', async () => {
let loggedTable: Datatable;
const handlers = {
inspectorAdapters: {
tables: {
logDatatable: (name: string, datatable: Datatable) => {
loggedTable = datatable;
},
},
},
};
await fn(context, args, handlers as any);

expect(loggedTable!).toMatchSnapshot();
});
});
20 changes: 19 additions & 1 deletion src/plugins/vis_type_metric/public/metric_vis_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Style,
} from '../../expressions/public';
import { visType, DimensionsVisParam, VisParams } from './types';
import { prepareLogTable, Dimension } from '../../visualizations/public';
import { ColorSchemas, vislibColorMaps, ColorMode } from '../../charts/public';

export type Input = Datatable;
Expand Down Expand Up @@ -164,7 +165,24 @@ export const createMetricVisFn = (): MetricVisExpressionFunctionDefinition => ({
const fontSize = Number.parseInt(args.font.spec.fontSize || '', 10);

if (handlers?.inspectorAdapters?.tables) {
handlers.inspectorAdapters.tables.logDatatable('default', input);
const argsTable: Dimension[] = [
[
args.metric,
i18n.translate('visTypeMetric.function.dimension.metric', {
defaultMessage: 'Metric',
}),
],
];
if (args.bucket) {
argsTable.push([
[args.bucket],
i18n.translate('visTypeMetric.function.adimension.splitGroup', {
defaultMessage: 'Split group',
}),
]);
}
const logTable = prepareLogTable(input, argsTable);
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
}
return {
type: 'render',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/plugins/vis_type_table/public/table_vis_fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { createTableVisFn } from './table_vis_fn';
import { tableVisResponseHandler } from './utils';

import { functionWrapper } from '../../expressions/common/expression_functions/specs/tests/utils';
import { Datatable } from '../../expressions/common/expression_types/specs';

jest.mock('./utils', () => ({
tableVisResponseHandler: jest.fn().mockReturnValue({
Expand Down Expand Up @@ -67,4 +68,20 @@ describe('interpreter/functions#table', () => {
expect(tableVisResponseHandler).toHaveBeenCalledTimes(1);
expect(tableVisResponseHandler).toHaveBeenCalledWith(context, visConfig);
});

it('logs correct datatable to inspector', async () => {
let loggedTable: Datatable;
const handlers = {
inspectorAdapters: {
tables: {
logDatatable: (name: string, datatable: Datatable) => {
loggedTable = datatable;
},
},
},
};
await fn(context, visConfig, handlers as any);

expect(loggedTable!).toMatchSnapshot();
});
});
34 changes: 33 additions & 1 deletion src/plugins/vis_type_table/public/table_vis_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { i18n } from '@kbn/i18n';
import { ExpressionFunctionDefinition, Datatable, Render } from '../../expressions/public';
import { prepareLogTable, Dimension } from '../../visualizations/public';
import { TableVisData, TableVisConfig } from './types';
import { VIS_TYPE_TABLE } from '../common';
import { tableVisResponseHandler } from './utils';
Expand Down Expand Up @@ -122,7 +123,38 @@ export const createTableVisFn = (): TableExpressionFunctionDefinition => ({
const convertedData = tableVisResponseHandler(input, args);

if (handlers?.inspectorAdapters?.tables) {
handlers.inspectorAdapters.tables.logDatatable('default', input);
const argsTable: Dimension[] = [
[
args.metrics,
i18n.translate('visTypeTable.function.dimension.metrics', {
defaultMessage: 'Metrics',
}),
],
[
args.buckets,
i18n.translate('visTypeTable.function.adimension.buckets', {
defaultMessage: 'Buckets',
}),
],
];
if (args.splitColumn) {
argsTable.push([
[args.splitColumn],
i18n.translate('visTypeTable.function.dimension.splitColumn', {
defaultMessage: 'Split by column',
}),
]);
}
if (args.splitRow) {
argsTable.push([
[args.splitRow],
i18n.translate('visTypeTable.function.dimension.splitRow', {
defaultMessage: 'Split by row',
}),
]);
}
const logTable = prepareLogTable(input, argsTable);
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
}
return {
type: 'render',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/plugins/vis_type_tagcloud/public/tag_cloud_fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { createTagCloudFn } from './tag_cloud_fn';

import { functionWrapper } from '../../expressions/common/expression_functions/specs/tests/utils';
import { Datatable } from '../../expressions/common/expression_types/specs';

describe('interpreter/functions#tagcloud', () => {
const fn = functionWrapper(createTagCloudFn());
Expand All @@ -31,4 +32,20 @@ describe('interpreter/functions#tagcloud', () => {
const actual = fn(context, visConfig, undefined);
expect(actual).toMatchSnapshot();
});

it('logs correct datatable to inspector', async () => {
let loggedTable: Datatable;
const handlers = {
inspectorAdapters: {
tables: {
logDatatable: (name: string, datatable: Datatable) => {
loggedTable = datatable;
},
},
},
};
await fn(context, visConfig, handlers as any);

expect(loggedTable!).toMatchSnapshot();
});
});
20 changes: 19 additions & 1 deletion src/plugins/vis_type_tagcloud/public/tag_cloud_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { i18n } from '@kbn/i18n';

import { ExpressionFunctionDefinition, Datatable, Render } from '../../expressions/public';
import { prepareLogTable, Dimension } from '../../visualizations/public';
import { TagCloudVisParams, TagCloudVisConfig } from './types';

const name = 'tagcloud';
Expand Down Expand Up @@ -109,7 +110,24 @@ export const createTagCloudFn = (): TagcloudExpressionFunctionDefinition => ({
} as TagCloudVisParams;

if (handlers?.inspectorAdapters?.tables) {
handlers.inspectorAdapters.tables.logDatatable('default', input);
const argsTable: Dimension[] = [
[
[args.metric],
i18n.translate('visTypeTagCloud.function.dimension.tagSize', {
defaultMessage: 'Tag size',
}),
],
];
if (args.bucket) {
argsTable.push([
[args.bucket],
i18n.translate('visTypeTagCloud.function.adimension.tags', {
defaultMessage: 'Tags',
}),
]);
}
const logTable = prepareLogTable(input, argsTable);
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
}
return {
type: 'render',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ export { seriesParam, ExpressionValueSeriesParam } from './series_param';
export { thresholdLine, ExpressionValueThresholdLine } from './threshold_line';
export { label, ExpressionValueLabel } from './label';
export { visScale, ExpressionValueScale } from './vis_scale';
export { xyDimension, ExpressionValueXYDimension } from './xy_dimension';
42 changes: 40 additions & 2 deletions src/plugins/vis_type_xy/public/expression_functions/xy_vis_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import { i18n } from '@kbn/i18n';

import type { ExpressionFunctionDefinition, Datatable, Render } from '../../../expressions/public';
import type { ExpressionFunctionDefinition, Datatable, Render } from '../../../expressions/common';
import { prepareLogTable, Dimension } from '../../../visualizations/public';
import type { ChartType } from '../../common';
import type { VisParams, XYVisConfig } from '../types';

Expand Down Expand Up @@ -262,7 +263,44 @@ export const visTypeXyVisFn = (): VisTypeXyExpressionFunctionDefinition => ({
} as VisParams;

if (handlers?.inspectorAdapters?.tables) {
handlers.inspectorAdapters.tables.logDatatable('default', context);
const argsTable: Dimension[] = [
[
args.yDimension,
i18n.translate('visTypeXy.function.dimension.metric', {
defaultMessage: 'Metric',
}),
],
[
args.zDimension,
i18n.translate('visTypeXy.function.adimension.dotSize', {
defaultMessage: 'Dot size',
}),
],
[
args.splitColumnDimension,
i18n.translate('visTypeXy.function.dimension.splitcolumn', {
defaultMessage: 'Column split',
}),
],
[
args.splitRowDimension,
i18n.translate('visTypeXy.function.dimension.splitrow', {
defaultMessage: 'Row split',
}),
],
];

if (args.xDimension) {
argsTable.push([
[args.xDimension],
i18n.translate('visTypeXy.function.adimension.bucket', {
defaultMessage: 'Bucket',
}),
]);
}

const logTable = prepareLogTable(context, argsTable);
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
}

return {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/vis_type_xy/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export class VisTypeXyPlugin
expressions.registerFunction(expressionFunctions.thresholdLine);
expressions.registerFunction(expressionFunctions.label);
expressions.registerFunction(expressionFunctions.visScale);
expressions.registerFunction(expressionFunctions.xyDimension);

visTypesDefinitions.forEach(visualizations.createBaseVisualization);
}
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/vis_type_xy/public/types/param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import type { Fit, Position } from '@elastic/charts';
import type { Style, Labels, PaletteOutput } from '../../../charts/public';
import type { SchemaConfig } from '../../../visualizations/public';
import type { SchemaConfig, ExpressionValueXYDimension } from '../../../visualizations/public';
import type { ChartType, XyVisType } from '../../common';
import type {
ExpressionValueCategoryAxis,
Expand All @@ -17,7 +17,6 @@ import type {
ExpressionValueLabel,
ExpressionValueThresholdLine,
ExpressionValueTimeMarker,
ExpressionValueXYDimension,
} from '../expression_functions';

import type {
Expand Down
Loading