Skip to content

Commit

Permalink
adding canvas functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Sep 17, 2018
1 parent 2fe2999 commit 569bf24
Show file tree
Hide file tree
Showing 15 changed files with 843 additions and 6 deletions.
33 changes: 33 additions & 0 deletions src/core_plugins/kibana_canvas_visualize/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.
*/

export default function (kibana) {
return new kibana.Plugin({
require: [
'canvas'
],
name: 'kibana_canvas_visualize',
uiExports: {
hacks: [
// register functions and the like things with canvas
'plugins/kibana_canvas_visualize/lib/load_plugin.js',
]
},
});
}
4 changes: 4 additions & 0 deletions src/core_plugins/kibana_canvas_visualize/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "kibana_canvas_visualize",
"version": "kibana"
}
115 changes: 115 additions & 0 deletions src/core_plugins/kibana_canvas_visualize/public/functions/esaggs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* 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 _ from 'lodash';
import { CourierRequestHandlerProvider } from 'ui/vis/request_handlers/courier';
import { AggConfigs } from 'ui/vis/agg_configs';

// need to get rid of angular from these
import { VisProvider } from 'ui/vis/vis';
import { IndexPatternsProvider } from 'ui/index_patterns';
import { SearchSourceProvider } from 'ui/courier/search_source';

import chrome from 'ui/chrome';

const courierRequestHandlerProvider = CourierRequestHandlerProvider;
const courierRequestHandler = courierRequestHandlerProvider().handler;

export default () => ({
name: 'esaggs',
type: 'kibana_table',
context: {
types: [
'kibana_context',
'null',
],
},
help: 'Run AggConfig aggregation.',
args: {
index: {
types: ['string', 'null'],
default: null,
},
q: {
types: ['string', 'null'],
aliases: ['query'],
help: 'A Lucene query string',
default: null,
},
filters: {
types: ['string', 'null'],
help: 'Filters object',
default: '"[]"',
},
// can this be passed in as object instead of string ?
timeRange: {
types: ['string', 'null'],
help: 'Sets date range to query',
default: null,
},
aggConfigs: {
types: ['string'],
default: '""',
help: 'AggConfig definition',
multi: false,
},
},
fn(context, args) {
return chrome.dangerouslyGetActiveInjector().then(async $injector => {
const Private = $injector.get('Private');
const indexPatterns = Private(IndexPatternsProvider);
const SearchSource = Private(SearchSourceProvider);
const Vis = Private(VisProvider);

const timeRange = JSON.parse(args.timeRange);
const aggConfigsState = JSON.parse(args.aggConfigs);
const filters = JSON.parse(args.filters);
const query = JSON.parse(args.q);

const indexPattern = await indexPatterns.get(args.index);
const aggs = new AggConfigs(indexPattern, aggConfigsState);

// we should move searchSource creation inside courier request handler
const searchSource = new SearchSource();
searchSource.setField('index', indexPattern);
searchSource.setField('filter', filters);
searchSource.setField('query', query);

// we need vis just for the inspector
const vis = new Vis(indexPattern);
vis.aggs = aggs;

const response = await courierRequestHandler(vis, {
searchSource: searchSource,
aggs: aggs,
timeRange: timeRange || _.get(context, 'timeRange', null),
query: _.get(context, 'q', null),
filters: _.get(context, 'filters', null),
forceFetch: true
});

return {
type: 'kibana_table',
index: args.index,
...response,
};

});
},
});
30 changes: 30 additions & 0 deletions src/core_plugins/kibana_canvas_visualize/public/functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 visualization from './visualization';
import esaggs from './esaggs';
import kibana from './kibana';
import vega from './vega';
import timelion from './timelion_vis';
import tsvb from './tsvb';
//import pie from './pie';

export const functions = [
visualization, esaggs, kibana, vega, timelion, tsvb //pie
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.
*/

export default () => ({
name: 'kibana',
type: 'kibana_context',
context: {},
help: 'Gets kibana global context.',
args: {},
fn(context) {
return {
type: 'kibana_context',
query: context.query,
filters: context.filters,
timeRange: context.timeRange,
};
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* 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 _ from 'lodash';

import { TimelionRequestHandlerProvider } from '../../../timelion/public/vis/timelion_request_handler';

// need to get rid of angular from these
import { VisProvider } from 'ui/vis/vis';

import chrome from 'ui/chrome';


export default () => ({
name: 'timelion_vis',
type: 'render',
context: {
types: [
'kibana_context',
'null',
],
},
help: 'Run tsvb request.',
args: {
index: {
types: ['string', 'null'],
default: null,
},
q: {
types: ['string', 'null'],
aliases: ['query'],
help: 'A Lucene query string',
default: null,
},
filters: {
types: ['string', 'null'],
help: 'Filters object',
default: null,
},
// can this be passed in as object instead of string ?
timeRange: {
types: ['string', 'null'],
help: 'Sets date range to query',
default: null,
},
expression: {
types: ['string'],
default: '".es(*)"',
help: 'timelion expression definition',
multi: false,
},
},
fn(context, args) {
return chrome.dangerouslyGetActiveInjector().then(async $injector => {
const Private = $injector.get('Private');
const timelionRequestHandler = Private(TimelionRequestHandlerProvider).handler;
const Vis = Private(VisProvider);

const timeRange = JSON.parse(args.timeRange);

// we need vis just for the inspector
const vis = new Vis(null, { type: 'timelion', params: { expression: args.expression } });

const response = await timelionRequestHandler(vis, {
timeRange: timeRange || _.get(context, 'timeRange', null),
query: JSON.parse(args.q) || _.get(context, 'q', null),
filters: _.get(context, 'filters', null),
forceFetch: true
});

return {
type: 'render',
as: 'visualization',
value: response,
};

});
},
});
Loading

0 comments on commit 569bf24

Please sign in to comment.