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

[Vega] Shim new platform - vega_fn.js -> vega_fn.js , use ExpressionFunction #42582

Merged
merged 6 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/legacy/core_plugins/vis_type_vega/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ import { LegacyDependenciesPlugin, LegacyDependenciesPluginSetup } from './shim'
import { Plugin as DataPublicPlugin } from '../../../../plugins/data/public';
import { VisualizationsSetup } from '../../visualizations/public';

// @ts-ignore
import { createVegaFn } from './vega_fn';
// @ts-ignore
import { createVegaTypeDefinition } from './vega_type';

/** @private */
interface VegaVisualizationDependencies extends LegacyDependenciesPluginSetup {
/** @internal */
export interface VegaVisualizationDependencies extends LegacyDependenciesPluginSetup {
uiSettings: UiSettingsClientContract;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,35 @@

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

import { ExpressionFunction, KibanaContext, Render } from '../../interpreter/types';
import { VegaVisualizationDependencies } from './plugin';
import { createVegaRequestHandler } from './vega_request_handler';

export const createVegaFn = (dependencies) => ({
name: 'vega',
const name = 'vega';
type Context = KibanaContext | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukeelmers talked to @alexwizp
Were unclear about the meaning of the Context type, in the scope of ExpressionFunction?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lizozom @alexwizp Context is the output of one function that gets passed to the next. For example, in this expression:

esaggs aggConfig="blah blah" | vega spec="hi"

The value returned by the esaggs function and piped into the vega function is called "Context".

Each expression function defines which context types it accepts as context...

context: {
types: ['kibana_context', 'null'],
},

...And which context type it returns (Return interface) as type:


interface Arguments {
spec: string;
}

type VisParams = Required<Arguments>;

interface RenderValue {
visData: Context;
visType: typeof name;
visConfig: VisParams;
}

type Return = Promise<Render<RenderValue>>;

export const createVegaFn = (
dependencies: VegaVisualizationDependencies
): ExpressionFunction<typeof name, Context, Arguments, Return> => ({
name,
type: 'render',
context: {
types: [
'kibana_context',
'null',
],
types: ['kibana_context', 'null'],
},
help: i18n.translate('visTypeVega.function.help', {
defaultMessage: 'Vega visualization',
Expand All @@ -37,6 +56,7 @@ export const createVegaFn = (dependencies) => ({
spec: {
types: ['string'],
default: '',
help: '',
},
},
async fn(context, args) {
Expand All @@ -55,7 +75,7 @@ export const createVegaFn = (dependencies) => ({
as: 'visualization',
value: {
visData: response,
visType: 'vega',
visType: name,
visConfig: {
spec: args.spec,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,27 @@
* under the License.
*/
import { timefilter } from 'ui/timefilter';
import { buildEsQuery, getEsQueryConfig } from '@kbn/es-query';

// @ts-ignore
import { buildEsQuery, getEsQueryConfig } from '@kbn/es-query';
// @ts-ignore
import { VegaParser } from './data_model/vega_parser';
// @ts-ignore
import { SearchCache } from './data_model/search_cache';
// @ts-ignore
import { TimeCache } from './data_model/time_cache';

export function createVegaRequestHandler({ uiSettings, es, serviceSettings }) {
import { VegaVisualizationDependencies } from './plugin';

export function createVegaRequestHandler({
uiSettings,
es,
serviceSettings,
}: VegaVisualizationDependencies) {
const searchCache = new SearchCache(es, { max: 10, maxAge: 4 * 1000 });
const timeCache = new TimeCache(timefilter, 3 * 1000);

return ({ timeRange, filters, query, visParams }) => {
return ({ timeRange, filters, query, visParams }: any) => {
alexwizp marked this conversation as resolved.
Show resolved Hide resolved
timeCache.setTimeRange(timeRange);

const esQueryConfigs = getEsQueryConfig(uiSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@
*/

import { i18n } from '@kbn/i18n';
import { DefaultEditorSize } from 'ui/vis/editor_size';
import { Status } from 'ui/vis/update_status';
// @ts-ignore
import { DefaultEditorSize } from 'ui/vis/editor_size';
// @ts-ignore
import { defaultFeedbackMessage } from 'ui/vis/default_feedback_message';

import vegaEditorTemplate from './vega_editor_template.html';
import { visFactory } from '../../visualizations/public';
import { VegaVisualizationDependencies } from './plugin';

import { createVegaRequestHandler } from './vega_request_handler';
// @ts-ignore
import { createVegaVisualization } from './vega_visualization';

import vegaEditorTemplate from './vega_editor_template.html';
// @ts-ignore
import defaultSpec from '!!raw-loader!./default.spec.hjson';

import { visFactory } from '../../visualizations/public';

export const createVegaTypeDefinition = (dependencies) => {
export const createVegaTypeDefinition = (dependencies: VegaVisualizationDependencies) => {
const requestHandler = createVegaRequestHandler(dependencies);
const visualization = createVegaVisualization(dependencies);

Expand Down