updating tagcloud interpreter func arguments (#33773)
|
@ -23,11 +23,15 @@ export const kibanaDatatable = () => ({
|
|||
name: 'kibana_datatable',
|
||||
from: {
|
||||
datatable: context => {
|
||||
context.columns.forEach(c => c.id = c.name);
|
||||
return {
|
||||
type: 'kibana_datatable',
|
||||
rows: context.rows,
|
||||
columns: context.columns,
|
||||
columns: context.columns.map(column => {
|
||||
return {
|
||||
id: column.name,
|
||||
name: column.name,
|
||||
};
|
||||
}),
|
||||
};
|
||||
},
|
||||
pointseries: context => {
|
||||
|
|
|
@ -22,7 +22,8 @@ import { esaggs } from './esaggs';
|
|||
import { kibana } from './kibana';
|
||||
import { kibanaContext } from './kibana_context';
|
||||
import { visualization } from './visualization';
|
||||
import { visDimension } from './vis_dimension';
|
||||
|
||||
export const functions = [
|
||||
clog, esaggs, kibana, kibanaContext, visualization
|
||||
clog, esaggs, kibana, kibanaContext, visualization, visDimension,
|
||||
];
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
export const visDimension = () => ({
|
||||
name: 'visdimension',
|
||||
help: i18n.translate('interpreter.function.visDimension.help', {
|
||||
defaultMessage: 'Generates visConfig dimension object'
|
||||
}),
|
||||
type: 'vis_dimension',
|
||||
context: {
|
||||
types: [
|
||||
'kibana_datatable'
|
||||
],
|
||||
},
|
||||
args: {
|
||||
accessor: {
|
||||
types: ['string', 'number'],
|
||||
aliases: ['_'],
|
||||
help: i18n.translate('interpreter.function.visDimension.accessor.help', {
|
||||
defaultMessage: 'Column in your dataset to use (either column index or column name)'
|
||||
}),
|
||||
},
|
||||
format: {
|
||||
types: ['string'],
|
||||
default: 'string'
|
||||
},
|
||||
formatParams: {
|
||||
types: ['string'],
|
||||
default: '"{}"',
|
||||
}
|
||||
},
|
||||
fn: (context, args) => {
|
||||
const accessor = Number.isInteger(args.accessor) ?
|
||||
args.accessor :
|
||||
context.columns.find(c => c.id === args.accessor);
|
||||
if (accessor === undefined) {
|
||||
throw new Error(i18n.translate('interpreter.function.visDimension.error.accessor', {
|
||||
defaultMessage: 'Column name provided is invalid'
|
||||
}));
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'vis_dimension',
|
||||
accessor: accessor,
|
||||
format: {
|
||||
id: args.format,
|
||||
params: JSON.parse(args.formatParams),
|
||||
}
|
||||
};
|
||||
},
|
||||
});
|
|
@ -12,11 +12,9 @@ Object {
|
|||
"maxFontSize": 72,
|
||||
"metric": Object {
|
||||
"accessor": 0,
|
||||
"aggType": "count",
|
||||
"format": Object {
|
||||
"id": "number",
|
||||
},
|
||||
"params": Object {},
|
||||
},
|
||||
"minFontSize": 18,
|
||||
"orientation": "single",
|
||||
|
|
|
@ -32,13 +32,61 @@ export const tagcloud = () => ({
|
|||
defaultMessage: 'Tagcloud visualization'
|
||||
}),
|
||||
args: {
|
||||
visConfig: {
|
||||
types: ['string', 'null'],
|
||||
default: '"{}"',
|
||||
scale: {
|
||||
types: ['string'],
|
||||
default: 'linear',
|
||||
options: ['linear', 'log', 'square root'],
|
||||
help: i18n.translate('tagCloud.function.scale.help', {
|
||||
defaultMessage: 'Scale to determine font size of a word'
|
||||
}),
|
||||
},
|
||||
orientation: {
|
||||
types: ['string'],
|
||||
default: 'single',
|
||||
options: ['single', 'right angled', 'multiple'],
|
||||
help: i18n.translate('tagCloud.function.orientation.help', {
|
||||
defaultMessage: 'Orientation of words inside tagcloud'
|
||||
}),
|
||||
},
|
||||
minFontSize: {
|
||||
types: ['number'],
|
||||
default: 18,
|
||||
},
|
||||
maxFontSize: {
|
||||
types: ['number'],
|
||||
default: 72
|
||||
},
|
||||
showLabel: {
|
||||
types: ['boolean'],
|
||||
default: true,
|
||||
},
|
||||
metric: {
|
||||
types: ['vis_dimension'],
|
||||
help: i18n.translate('tagCloud.function.metric.help', {
|
||||
defaultMessage: 'metric dimension configuration'
|
||||
}),
|
||||
required: true,
|
||||
},
|
||||
bucket: {
|
||||
types: ['vis_dimension'],
|
||||
help: i18n.translate('tagCloud.function.bucket.help', {
|
||||
defaultMessage: 'bucket dimension configuration'
|
||||
}),
|
||||
},
|
||||
},
|
||||
fn(context, args) {
|
||||
const visConfig = JSON.parse(args.visConfig);
|
||||
const visConfig = {
|
||||
scale: args.scale,
|
||||
orientation: args.orientation,
|
||||
minFontSize: args.minFontSize,
|
||||
maxFontSize: args.maxFontSize,
|
||||
showLabel: args.showLabel,
|
||||
metric: args.metric,
|
||||
};
|
||||
|
||||
if (args.bucket !== undefined) {
|
||||
visConfig.bucket = args.bucket;
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'render',
|
||||
|
|
|
@ -33,18 +33,11 @@ describe('interpreter/functions#tagcloud', () => {
|
|||
minFontSize: 18,
|
||||
maxFontSize: 72,
|
||||
showLabel: true,
|
||||
metric: {
|
||||
accessor: 0,
|
||||
format: {
|
||||
id: 'number',
|
||||
},
|
||||
params: {},
|
||||
aggType: 'count',
|
||||
},
|
||||
metric: { accessor: 0, format: { id: 'number' } },
|
||||
};
|
||||
|
||||
it('returns an object with the correct structure', () => {
|
||||
const actual = fn(context, { visConfig: JSON.stringify(visConfig) });
|
||||
const actual = fn(context, visConfig);
|
||||
expect(actual).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -26,9 +26,9 @@ exports[`visualize loader pipeline helpers: build pipeline buildPipelineVisFunct
|
|||
|
||||
exports[`visualize loader pipeline helpers: build pipeline buildPipelineVisFunction handles table function without splits or buckets 1`] = `"kibana_table visConfig='{\\"foo\\":\\"bar\\",\\"dimensions\\":{\\"metrics\\":[0,1],\\"buckets\\":[]}}' "`;
|
||||
|
||||
exports[`visualize loader pipeline helpers: build pipeline buildPipelineVisFunction handles tagcloud function with buckets 1`] = `"tagcloud visConfig='{\\"metric\\":0,\\"bucket\\":1}' "`;
|
||||
exports[`visualize loader pipeline helpers: build pipeline buildPipelineVisFunction handles tagcloud function with buckets 1`] = `"tagcloud metric={visdimension 0} bucket={visdimension 1 } "`;
|
||||
|
||||
exports[`visualize loader pipeline helpers: build pipeline buildPipelineVisFunction handles tagcloud function without buckets 1`] = `"tagcloud visConfig='{\\"metric\\":0}' "`;
|
||||
exports[`visualize loader pipeline helpers: build pipeline buildPipelineVisFunction handles tagcloud function without buckets 1`] = `"tagcloud metric={visdimension 0} "`;
|
||||
|
||||
exports[`visualize loader pipeline helpers: build pipeline buildPipelineVisFunction handles tile_map function 1`] = `"tilemap visConfig='{\\"metric\\":{},\\"dimensions\\":{\\"metric\\":0,\\"geohash\\":1,\\"geocentroid\\":3}}' "`;
|
||||
|
||||
|
|
|
@ -170,15 +170,15 @@ describe('visualize loader pipeline helpers: build pipeline', () => {
|
|||
const params = {};
|
||||
|
||||
it('without buckets', () => {
|
||||
const schemas = { metric: [0] };
|
||||
const schemas = { metric: [{ accessor: 0 }] };
|
||||
const actual = buildPipelineVisFunction.tagcloud({ params }, schemas);
|
||||
expect(actual).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('with buckets', () => {
|
||||
const schemas = {
|
||||
metric: [0],
|
||||
segment: [1, 2]
|
||||
metric: [{ accessor: 0 }],
|
||||
segment: [{ accessor: 1 }]
|
||||
};
|
||||
const actual = buildPipelineVisFunction.tagcloud({ params }, schemas);
|
||||
expect(actual).toMatchSnapshot();
|
||||
|
|
|
@ -238,11 +238,35 @@ export const buildPipelineVisFunction: BuildPipelineVisFunction = {
|
|||
return `kibana_metric ${prepareJson('visConfig', visConfig)}`;
|
||||
},
|
||||
tagcloud: (visState, schemas) => {
|
||||
const visConfig = {
|
||||
...visState.params,
|
||||
...buildVisConfig.tagcloud(schemas),
|
||||
};
|
||||
return `tagcloud ${prepareJson('visConfig', visConfig)}`;
|
||||
const { scale, orientation, minFontSize, maxFontSize, showLabel } = visState.params;
|
||||
const { metric, bucket } = buildVisConfig.tagcloud(schemas);
|
||||
let expr = `tagcloud metric={visdimension ${metric.accessor}} `;
|
||||
|
||||
if (scale) {
|
||||
expr += `scale='${scale}' `;
|
||||
}
|
||||
if (orientation) {
|
||||
expr += `orientation='${orientation}' `;
|
||||
}
|
||||
if (minFontSize) {
|
||||
expr += `minFontSize=${minFontSize} `;
|
||||
}
|
||||
if (maxFontSize) {
|
||||
expr += `maxFontSize=${maxFontSize} `;
|
||||
}
|
||||
if (showLabel) {
|
||||
expr += `showLabel=${showLabel} `;
|
||||
}
|
||||
|
||||
if (bucket) {
|
||||
expr += ` bucket={visdimension ${bucket.accessor} `;
|
||||
if (bucket.format) {
|
||||
expr += `format=${bucket.format.id} `;
|
||||
expr += prepareJson('formatParams', bucket.format.params);
|
||||
}
|
||||
expr += '} ';
|
||||
}
|
||||
return expr;
|
||||
},
|
||||
region_map: (visState, schemas) => {
|
||||
const visConfig = {
|
||||
|
|
|
@ -12,10 +12,16 @@ To run these tests during development you can use the following commands:
|
|||
```
|
||||
# Start the test server (can continue running)
|
||||
node scripts/functional_tests_server.js --config test/interpreter_functional/config.js
|
||||
|
||||
# Start a test run
|
||||
node scripts/functional_test_runner.js --config test/interpreter_functional/config.js
|
||||
```
|
||||
|
||||
# Writing tests
|
||||
|
||||
Look into test_suites/run_pipeline/basic.js for examples
|
||||
Look into test_suites/run_pipeline/basic.js for examples
|
||||
|
||||
to update baseline screenshots and snapshots run with:
|
||||
```
|
||||
node scripts/functional_test_runner.js --config test/interpreter_functional/config.js --updateBaselines
|
||||
```
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1 @@
|
|||
{"as":"visualization","type":"render","value":{"params":{"listenOnChange":true},"visConfig":{"bucket":{"accessor":1,"format":{"id":"string","params":{}},"type":"vis_dimension"},"maxFontSize":72,"metric":{"accessor":0,"format":{"id":"string","params":{}},"type":"vis_dimension"},"minFontSize":18,"orientation":"single","scale":"linear","showLabel":true},"visData":{"columns":[{"id":"col-0-2","name":"response.raw: Descending"},{"id":"col-1-1","name":"Count"}],"rows":[{"col-0-2":"200","col-1-1":12891},{"col-0-2":"404","col-1-1":696},{"col-0-2":"503","col-1-1":417}],"type":"kibana_datatable"},"visType":"tagcloud"}}
|
|
@ -0,0 +1 @@
|
|||
{"as":"visualization","type":"render","value":{"params":{"listenOnChange":true},"visConfig":{"bucket":{"accessor":1,"format":{"id":"string","params":{}},"type":"vis_dimension"},"maxFontSize":40,"metric":{"accessor":0,"format":{"id":"string","params":{}},"type":"vis_dimension"},"minFontSize":20,"orientation":"single","scale":"linear","showLabel":true},"visData":{"columns":[{"id":"col-0-2","name":"response.raw: Descending"},{"id":"col-1-1","name":"Count"}],"rows":[{"col-0-2":"200","col-1-1":12891},{"col-0-2":"404","col-1-1":696},{"col-0-2":"503","col-1-1":417}],"type":"kibana_datatable"},"visType":"tagcloud"}}
|
|
@ -0,0 +1 @@
|
|||
{"error":{"message":"[tagcloud] > [vis_dimension] > Objects must have a type property","stack":"Error: [vis_dimension] > Objects must have a type property\n at getType (http://localhost:5620/bundles/commons.bundle.js:15876:27)\n at cast (http://localhost:5620/bundles/commons.bundle.js:15683:46)\n at _callee3$ (http://localhost:5620/bundles/commons.bundle.js:31552:35)\n at tryCatch (webpack://%5Bname%5D/./node_modules/regenerator-runtime/runtime.js?:62:40)\n at Generator.invoke [as _invoke] (webpack://%5Bname%5D/./node_modules/regenerator-runtime/runtime.js?:288:22)\n at Generator.prototype.(anonymous function) [as next] (webpack://%5Bname%5D/./node_modules/regenerator-runtime/runtime.js?:114:21)\n at asyncGeneratorStep (http://localhost:5620/bundles/commons.bundle.js:31397:103)\n at _next (http://localhost:5620/bundles/commons.bundle.js:31399:194)\n at http://localhost:5620/bundles/commons.bundle.js:31399:364\n at new Promise (<anonymous>)"},"type":"error"}
|
|
@ -0,0 +1 @@
|
|||
{"as":"visualization","type":"render","value":{"params":{"listenOnChange":true},"visConfig":{"maxFontSize":72,"metric":{"accessor":0,"format":{"id":"string","params":{}},"type":"vis_dimension"},"minFontSize":18,"orientation":"single","scale":"linear","showLabel":true},"visData":{"columns":[{"id":"col-0-2","name":"response.raw: Descending"},{"id":"col-1-1","name":"Count"}],"rows":[{"col-0-2":"200","col-1-1":12891},{"col-0-2":"404","col-1-1":696},{"col-0-2":"503","col-1-1":417}],"type":"kibana_datatable"},"visType":"tagcloud"}}
|
|
@ -0,0 +1 @@
|
|||
{"as":"visualization","type":"render","value":{"params":{"listenOnChange":true},"visConfig":{"bucket":{"accessor":1,"format":{"id":"string","params":{}},"type":"vis_dimension"},"maxFontSize":72,"metric":{"accessor":0,"format":{"id":"string","params":{}},"type":"vis_dimension"},"minFontSize":18,"orientation":"multiple","scale":"log","showLabel":true},"visData":{"columns":[{"id":"col-0-2","name":"response.raw: Descending"},{"id":"col-1-1","name":"Count"}],"rows":[{"col-0-2":"200","col-1-1":12891},{"col-0-2":"404","col-1-1":696},{"col-0-2":"503","col-1-1":417}],"type":"kibana_datatable"},"visType":"tagcloud"}}
|
|
@ -37,5 +37,6 @@ export default function ({ getService, getPageObjects, loadTestFile }) {
|
|||
});
|
||||
|
||||
loadTestFile(require.resolve('./basic'));
|
||||
loadTestFile(require.resolve('./tag_cloud'));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { expectExpressionProvider } from './helpers';
|
||||
|
||||
// this file showcases how to use testing utilities defined in helpers.js together with the kbn_tp_run_pipeline
|
||||
// test plugin to write autmated tests for interprete
|
||||
export default function ({ getService, updateBaselines }) {
|
||||
|
||||
let expectExpression;
|
||||
describe('tag cloud pipeline expression tests', () => {
|
||||
before(() => {
|
||||
expectExpression = expectExpressionProvider({ getService, updateBaselines });
|
||||
});
|
||||
|
||||
// we should not use this for tests like the ones below. this should be unit tested.
|
||||
// - tests against a single function could easily be written as unit tests (and should be)
|
||||
describe('correctly renders tagcloud', () => {
|
||||
let dataContext;
|
||||
before(async () => {
|
||||
const expression = `kibana | kibana_context | esaggs index='logstash-*' aggConfigs='[
|
||||
{"id":"1","enabled":true,"type":"count","schema":"metric","params":{}},
|
||||
{"id":"2","enabled":true,"type":"terms","schema":"segment","params":
|
||||
{"field":"response.raw","size":4,"order":"desc","orderBy":"1"}
|
||||
}]'`;
|
||||
// we execute the part of expression that fetches the data and store its response
|
||||
dataContext = await expectExpression('partial_tagcloud_test', expression).getResponse();
|
||||
});
|
||||
|
||||
it.skip('with invalid data', async () => {
|
||||
const expression = 'tagcloud metric={visdimension 0}';
|
||||
await (await expectExpression('tagcloud_invalid_data', expression).toMatchSnapshot()).toMatchScreenshot();
|
||||
});
|
||||
|
||||
it('with just metric data', async () => {
|
||||
const expression = 'tagcloud metric={visdimension 0}';
|
||||
await (await expectExpression('tagcloud_metric_data', expression, dataContext).toMatchSnapshot()).toMatchScreenshot();
|
||||
});
|
||||
|
||||
it('with metric and bucket data', async () => {
|
||||
const expression = 'tagcloud metric={visdimension 0} bucket={visdimension 1}';
|
||||
await (await expectExpression('tagcloud_all_data', expression, dataContext).toMatchSnapshot()).toMatchScreenshot();
|
||||
});
|
||||
|
||||
it('with font size options', async () => {
|
||||
const expression = 'tagcloud metric={visdimension 0} bucket={visdimension 1} minFontSize=20 maxFontSize=40';
|
||||
await (await expectExpression('tagcloud_fontsize', expression, dataContext).toMatchSnapshot()).toMatchScreenshot();
|
||||
});
|
||||
|
||||
it('with scale and orientation options', async () => {
|
||||
const expression = 'tagcloud metric={visdimension 0} bucket={visdimension 1} scale="log" orientation="multiple"';
|
||||
await (await expectExpression('tagcloud_options', expression, dataContext).toMatchSnapshot()).toMatchScreenshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|