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

Pipeline field formatting #28746

Merged
merged 15 commits into from
Jan 18, 2019
18 changes: 9 additions & 9 deletions src/fixtures/vislib/mock_data/terms/_seriesMultiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,44 @@ export default {
'yScale': null,
'series': [{
'label': 'ios',
'aggLabel': 'Count',
'aggId': '1',
'id': '1',
'yAxisFormatter': _.identity,
'values': [{
'x': '_all',
'y': 2820,
'series': 'ios'
}]
}, {
'label': 'win 7',
'aggLabel': 'Count',
'aggId': '1',
'yAxisFormatter': _.identity,
'values': [{
'x': '_all',
'y': 2319,
'series': 'win 7'
}]
}, {
'label': 'win 8',
'aggLabel': 'Count',
'aggId': '1',
'id': '1',
'yAxisFormatter': _.identity,
'values': [{
'x': '_all',
'y': 1835,
'series': 'win 8'
}]
}, {
'label': 'windows xp service pack 2 version 20123452',
'aggLabel': 'Count',
'aggId': '1',
'id': '1',
'yAxisFormatter': _.identity,
'values': [{
'x': '_all',
'y': 734,
'series': 'win xp'
}]
}, {
'label': 'osx',
'aggLabel': 'Count',
'aggId': '1',
'id': '1',
'yAxisFormatter': _.identity,
'values': [{
'x': '_all',
'y': 1352,
Expand Down
19 changes: 0 additions & 19 deletions src/legacy/core_plugins/interpreter/public/functions/metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,13 @@ export const metric = () => ({
defaultMessage: 'Metric visualization'
}),
args: {
bucket: {
types: ['string', 'null'],
default: null,
},
metric: {
types: ['string'],
default: '1',
},
visConfig: {
types: ['string', 'null'],
default: '"{}"',
},
},
fn(context, args) {
const visConfigParams = JSON.parse(args.visConfig);
const metrics = args.metric.split(',');
metrics.forEach(metric => {
const metricColumn = context.columns.find((column, i) =>
column.id === metric || column.name === metric || i === parseInt(metric));
metricColumn.aggConfig.schema = 'metric';
});
if (args.bucket) {
const bucketColumn = context.columns.find((column, i) =>
column.id === args.bucket || column.name === args.bucket || i === parseInt(args.bucket));
bucketColumn.aggConfig.schema = 'segment';
}

return {
type: 'render',
Expand Down
22 changes: 1 addition & 21 deletions src/legacy/core_plugins/interpreter/public/functions/pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/

import { VisTypesRegistryProvider } from 'ui/registry/vis_types';
import { VislibSlicesResponseHandlerProvider } from 'ui/vis/response_handlers/vislib';
import chrome from 'ui/chrome';
import { i18n } from '@kbn/i18n';
Expand All @@ -34,10 +33,6 @@ export const kibanaPie = () => ({
defaultMessage: 'Pie visualization'
}),
args: {
schemas: {
types: ['string'],
default: '"{}"',
},
visConfig: {
types: ['string', 'null'],
default: '"{}"',
Expand All @@ -47,24 +42,9 @@ export const kibanaPie = () => ({
const $injector = await chrome.dangerouslyGetActiveInjector();
const Private = $injector.get('Private');
const responseHandler = Private(VislibSlicesResponseHandlerProvider).handler;
const visTypes = Private(VisTypesRegistryProvider);
const visConfigParams = JSON.parse(args.visConfig);
const visType = visTypes.byName.pie;
const schemas = JSON.parse(args.schemas);

if (context.columns) {
context.columns.forEach(column => {
column.aggConfig.aggConfigs.schemas = visType.schemas.all;
});

Object.keys(schemas).forEach(key => {
schemas[key].forEach(i => {
context.columns[i].aggConfig.schema = key;
});
});
}

const convertedData = await responseHandler(context);
const convertedData = await responseHandler(context, visConfigParams.dimensions);

return {
type: 'render',
Expand Down
17 changes: 0 additions & 17 deletions src/legacy/core_plugins/interpreter/public/functions/regionmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,13 @@ export const regionmap = () => ({
defaultMessage: 'Regionmap visualization'
}),
args: {
bucket: {
types: ['string'],
default: '0',
},
metric: {
types: ['string'],
default: '1',
},
visConfig: {
types: ['string', 'null'],
default: '"{}"',
},
},
fn(context, args) {
const visConfigParams = JSON.parse(args.visConfig);
const metricColumn = context.columns.find((column, i) =>
column.id === args.metric || column.name === args.metric || i === parseInt(args.metric)
);
const bucketColumn = context.columns.find((column, i) =>
column.id === args.bucket || column.name === args.bucket || i === parseInt(args.bucket)
);

metricColumn.aggConfig.schema = 'metric';
bucketColumn.aggConfig.schema = 'segment';

return {
type: 'render',
Expand Down
42 changes: 1 addition & 41 deletions src/legacy/core_plugins/interpreter/public/functions/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,55 +35,15 @@ export const kibanaTable = () => ({
defaultMessage: 'Table visualization'
}),
args: {
bucket: {
types: ['string'],
},
splitRow: {
types: ['string'],
},
splitColumn: {
types: ['string'],
},
metric: {
types: ['string'],
default: '1',
},
visConfig: {
types: ['string', 'null'],
default: '"{}"',
},
},
async fn(context, args) {
const visConfigParams = JSON.parse(args.visConfig);
args.metric.split(',').forEach(metric => {
const metricColumn = context.columns.find((column, i) =>
column.id === metric || column.name === metric || i === parseInt(metric));
metricColumn.aggConfig.schema = 'metric';
});
if (args.bucket) {
args.bucket.split(',').forEach(bucket => {
const bucketColumn = context.columns.find((column, i) =>
column.id === bucket || column.name === bucket || i === parseInt(bucket));
bucketColumn.aggConfig.schema = 'bucket';
});
}
if (args.splitColumn) {
args.splitColumn.split(',').forEach(split => {
const splitColumn = context.columns.find((column, i) =>
column.id === split || column.name === split || i === parseInt(split));
splitColumn.aggConfig.schema = 'split';
});
}
if (args.splitRow) {
args.splitRow.split(',').forEach(split => {
const splitColumn = context.columns.find((column, i) =>
column.id === split || column.name === split || i === parseInt(split));
splitColumn.aggConfig.schema = 'split';
splitColumn.aggConfig.params.row = true;
});
}

const convertedData = await responseHandler(context);
const convertedData = await responseHandler(context, visConfigParams.dimensions);

return {
type: 'render',
Expand Down
17 changes: 0 additions & 17 deletions src/legacy/core_plugins/interpreter/public/functions/tagcloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,13 @@ export const tagcloud = () => ({
defaultMessage: 'Tagcloud visualization'
}),
args: {
bucket: {
types: ['string'],
default: '0',
},
metric: {
types: ['string'],
default: '1',
},
visConfig: {
types: ['string', 'null'],
default: '"{}"',
},
},
fn(context, args) {
const visConfigParams = JSON.parse(args.visConfig);
const metricColumn = context.columns.find((column, i) =>
column.id === args.metric || column.name === args.metric || i === parseInt(args.metric)
);
const bucketColumn = context.columns.find((column, i) =>
column.id === args.bucket || column.name === args.bucket || i === parseInt(args.bucket)
);

metricColumn.aggConfig.schema = 'metric';
bucketColumn.aggConfig.schema = 'segment';

return {
type: 'render',
Expand Down
27 changes: 6 additions & 21 deletions src/legacy/core_plugins/interpreter/public/functions/tilemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
* under the License.
*/

import { makeGeoJsonResponseHandler } from 'plugins/tile_map/coordinatemap_response_handler';
import { convertToGeoJson } from 'ui/vis/map/convert_to_geojson';
import { i18n } from '@kbn/i18n';

const responseHandler = makeGeoJsonResponseHandler();

export const tilemap = () => ({
name: 'tilemap',
type: 'render',
Expand All @@ -34,32 +32,19 @@ export const tilemap = () => ({
defaultMessage: 'Tilemap visualization'
}),
args: {
bucket: {
types: ['string'],
default: '0',
},
metric: {
types: ['string'],
default: '1',
},
visConfig: {
types: ['string', 'null'],
default: '"{}"',
},
},
fn(context, args) {
const visConfigParams = JSON.parse(args.visConfig);
const metricColumn = context.columns.find((column, i) =>
column.id === args.metric || column.name === args.metric || i === parseInt(args.metric)
);
const bucketColumn = context.columns.find((column, i) =>
column.id === args.bucket || column.name === args.bucket || i === parseInt(args.bucket)
);

metricColumn.aggConfig.schema = 'metric';
bucketColumn.aggConfig.schema = 'segment';

const convertedData = responseHandler(context);
const convertedData = convertToGeoJson(context, {
geohash: visConfigParams.geohash,
metric: visConfigParams.metric,
geocentroid: visConfigParams.geocentroid,
});

return {
type: 'render',
Expand Down
31 changes: 1 addition & 30 deletions src/legacy/core_plugins/interpreter/public/functions/vislib.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import { i18n } from '@kbn/i18n';
import { VisTypesRegistryProvider } from 'ui/registry/vis_types';
import { VislibSeriesResponseHandlerProvider } from 'ui/vis/response_handlers/vislib';
import chrome from 'ui/chrome';

Expand All @@ -34,14 +33,6 @@ export const vislib = () => ({
defaultMessage: 'Vislib visualization'
}),
args: {
type: {
types: ['string'],
default: 'metric',
},
schemas: {
types: ['string'],
default: '"{}"',
},
visConfig: {
types: ['string', 'null'],
default: '"{}"',
Expand All @@ -51,29 +42,9 @@ export const vislib = () => ({
const $injector = await chrome.dangerouslyGetActiveInjector();
const Private = $injector.get('Private');
const responseHandler = Private(VislibSeriesResponseHandlerProvider).handler;
const visTypes = Private(VisTypesRegistryProvider);
const visConfigParams = JSON.parse(args.visConfig);
const schemas = JSON.parse(args.schemas);
const visType = visTypes.byName[args.type || 'histogram'];

if (context.columns) {
// assign schemas to aggConfigs
context.columns.forEach(column => {
column.aggConfig.aggConfigs.schemas = visType.schemas.all;
});

Object.keys(schemas).forEach(key => {
schemas[key].forEach(i => {
const schema = key.split('_');
context.columns[i].aggConfig.schema = schema[0];
if (schema[1] === 'row') {
context.columns[i].aggConfig.params.row = true;
}
});
});
}

const convertedData = await responseHandler(context);
const convertedData = await responseHandler(context, visConfigParams.dimensions);

return {
type: 'render',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import { tabifyAggResponse } from 'ui/agg_response/tabify';
import { showSaveModal } from 'ui/saved_objects/show_saved_object_save_modal';
import { SavedObjectSaveModal } from 'ui/saved_objects/components/saved_object_save_modal';
import { getRootBreadcrumbs, getSavedSearchBreadcrumbs } from '../breadcrumbs';
import { buildVislibDimensions } from 'ui/visualize/loader/pipeline_helpers/build_pipeline';

const app = uiModules.get('apps/discover', [
'kibana/notify',
Expand Down Expand Up @@ -760,7 +761,7 @@ function discoverController(
const tabifiedData = tabifyAggResponse($scope.vis.aggs, merged);
$scope.searchSource.rawResponse = merged;
Promise
.resolve(responseHandler(tabifiedData))
.resolve(responseHandler(tabifiedData, buildVislibDimensions($scope.vis, $scope.timeRange)))
.then(resp => {
visualizeHandler.render({ value: resp });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ describe('metric vis', () => {
aggs: [{ id: '1', type: 'top_hits', schema: 'metric', params: { field: 'ip' } }],
});

vis.params.metric.metrics = [{ accessor: 0, format: { id: 'url', params: {
urlTemplate: 'http://ip.info?address={{value}}',
labelTemplate: 'ip[{{value}}]'
} } }];

const el = document.createElement('div');
const Controller = metricVisType.visualization;
const controller = new Controller(el, vis);
Expand All @@ -62,7 +67,7 @@ describe('metric vis', () => {

const ip = '235.195.237.208';
render({
columns: [{ id: 'col-0', title: 'ip', aggConfig: vis.aggs[0] }],
columns: [{ id: 'col-0', name: 'ip' }],
rows: [{ 'col-0': ip }]
});

Expand Down
Loading