Skip to content

Commit

Permalink
[Tag Cloud] Shim new platform (elastic#42348)
Browse files Browse the repository at this point in the history
* [Tag Cloud] Shim new platform

* fix PR comments
  • Loading branch information
alexwizp committed Aug 5, 2019
1 parent 8697967 commit c14f91a
Show file tree
Hide file tree
Showing 18 changed files with 228 additions and 77 deletions.
44 changes: 44 additions & 0 deletions src/legacy/core_plugins/tagcloud/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 { resolve } from 'path';
import { Legacy } from 'kibana';

import { LegacyPluginApi, LegacyPluginInitializer } from '../../../../src/legacy/types';

const tagCloudPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPluginApi) =>
new Plugin({
id: 'tagcloud',
require: ['kibana', 'elasticsearch', 'visualizations', 'interpreter', 'data'],
publicDir: resolve(__dirname, 'public'),
uiExports: {
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
hacks: [resolve(__dirname, 'public/legacy')],
injectDefaultVars: server => ({}),
},
init: (server: Legacy.Server) => ({}),
config(Joi: any) {
return Joi.object({
enabled: Joi.boolean().default(true),
}).default();
},
} as Legacy.PluginSpecOptions);

// eslint-disable-next-line import/no-default-export
export default tagCloudPluginInitializer;
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

import expect from '@kbn/expect';
import _ from 'lodash';
import TagCloud from '../tag_cloud';
import d3 from 'd3';

import { TagCloud } from '../tag_cloud';
import { fromNode, delay } from 'bluebird';
import { ImageComparator } from 'test_utils/image_comparator';
import simpleloadPng from './simpleload.png';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const D3_SCALING_FUNCTIONS = {
'square root': () => d3.scale.sqrt()
};

class TagCloud extends EventEmitter {
export class TagCloud extends EventEmitter {

constructor(domNode) {

Expand Down Expand Up @@ -424,5 +424,3 @@ function hashWithinRange(str, max) {
}
return Math.abs(hash) % max;
}

export default TagCloud;
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
* under the License.
*/

import TagCloud from './tag_cloud';
import React from 'react';
import * as Rx from 'rxjs';
import { take } from 'rxjs/operators';
import { render, unmountComponentAtNode } from 'react-dom';
import React from 'react';
import { getFormat } from 'ui/visualize/loader/pipeline_helpers/utilities';

import { getFormat } from 'ui/visualize/loader/pipeline_helpers/utilities';
import { I18nContext } from 'ui/i18n';

import { Label } from './label';
import { TagCloud } from './tag_cloud';
import { FeedbackMessage } from './feedback_message';

const MAX_TAG_COUNT = 200;
Expand Down Expand Up @@ -58,7 +59,6 @@ export class TagCloudVisualization {
});
this._renderComplete$ = Rx.fromEvent(this._tagCloud, 'renderComplete');


this._feedbackNode = document.createElement('div');
this._containerNode.appendChild(this._feedbackNode);
this._feedbackMessage = React.createRef();
Expand All @@ -79,7 +79,6 @@ export class TagCloudVisualization {
this._updateData(data);
}


if (status.resize) {
this._resize();
}
Expand All @@ -104,7 +103,6 @@ export class TagCloudVisualization {
});
}


destroy() {
this._tagCloud.destroy();
unmountComponentAtNode(this._feedbackNode);
Expand Down Expand Up @@ -136,7 +134,6 @@ export class TagCloudVisualization {
};
});


if (tags.length > MAX_TAG_COUNT) {
tags.length = MAX_TAG_COUNT;
this._truncated = true;
Expand All @@ -145,7 +142,6 @@ export class TagCloudVisualization {
}

this._tagCloud.setData(tags);

}

_updateParams(visParams) {
Expand All @@ -156,5 +152,4 @@ export class TagCloudVisualization {
_resize() {
this._tagCloud.resize();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@
* under the License.
*/

import { resolve } from 'path';
import { PluginInitializerContext } from '../../../../core/public';
import { TagCloudPlugin as Plugin } from './plugin';

export default function (kibana) {

return new kibana.Plugin({
uiExports: {
visTypes: ['plugins/tagcloud/tag_cloud_vis'],
interpreter: ['plugins/tagcloud/tag_cloud_fn'],
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
}
});
export function plugin(initializerContext: PluginInitializerContext) {
return new Plugin(initializerContext);
}
35 changes: 35 additions & 0 deletions src/legacy/core_plugins/tagcloud/public/legacy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 { PluginInitializerContext } from 'kibana/public';
import { npSetup, npStart } from 'ui/new_platform';

import { visualizations } from '../../visualizations/public';
import { TagCloudPluginSetupDependencies } from './plugin';
import { plugin } from '.';

const plugins: Readonly<TagCloudPluginSetupDependencies> = {
visualizations,
data: npSetup.plugins.data,
};

const pluginInstance = plugin({} as PluginInitializerContext);

export const setup = pluginInstance.setup(npSetup.core, plugins);
export const start = pluginInstance.start(npStart.core);
49 changes: 49 additions & 0 deletions src/legacy/core_plugins/tagcloud/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../../core/public';
import { Plugin as DataPublicPlugin } from '../../../../plugins/data/public';
import { VisualizationsSetup } from '../../visualizations/public';

import { createTagCloudFn } from './tag_cloud_fn';
import { createTagCloudTypeDefinition } from './tag_cloud_type';

/** @internal */
export interface TagCloudPluginSetupDependencies {
data: ReturnType<DataPublicPlugin['setup']>;
visualizations: VisualizationsSetup;
}

/** @internal */
export class TagCloudPlugin implements Plugin<void, void> {
initializerContext: PluginInitializerContext;

constructor(initializerContext: PluginInitializerContext) {
this.initializerContext = initializerContext;
}

public setup(core: CoreSetup, { data, visualizations }: TagCloudPluginSetupDependencies) {
data.expressions.registerFunction(createTagCloudFn);
visualizations.types.VisTypesRegistryProvider.register(createTagCloudTypeDefinition);
}

public start(core: CoreStart) {
// nothing to do here yet
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* under the License.
*/

import { functionWrapper } from '../../interpreter/test_helpers';
import { tagcloud } from './tag_cloud_fn';
import { createTagCloudFn } from './tag_cloud_fn';

jest.mock('ui/new_platform');
// @ts-ignore
import { functionWrapper } from '../../interpreter/test_helpers';

describe('interpreter/functions#tagcloud', () => {
const fn = functionWrapper(tagcloud);
const fn = functionWrapper(createTagCloudFn);
const context = {
type: 'kibana_datatable',
rows: [{ 'col-0-1': 0 }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,72 +17,104 @@
* under the License.
*/

import { functionsRegistry } from 'plugins/interpreter/registries';
import { i18n } from '@kbn/i18n';

export const tagcloud = () => ({
name: 'tagcloud',
import { ExpressionFunction, KibanaDatatable, Render } from '../../interpreter/types';

const name = 'tagcloud';

type Context = KibanaDatatable;

interface Arguments {
scale: string;
orientation: string;
minFontSize: number;
maxFontSize: number;
showLabel: boolean;
metric: any; // these aren't typed yet
bucket: any; // these aren't typed yet
}

type VisParams = Omit<Arguments, 'bucket'>;

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

type Return = Render<RenderValue>;

export const createTagCloudFn = (): ExpressionFunction<
typeof name,
Context,
Arguments,
Return
> => ({
name,
type: 'render',
context: {
types: [
'kibana_datatable'
],
types: ['kibana_datatable'],
},
help: i18n.translate('tagCloud.function.help', {
defaultMessage: 'Tagcloud visualization'
defaultMessage: 'Tagcloud visualization',
}),
args: {
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'
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'
defaultMessage: 'Orientation of words inside tagcloud',
}),
},
minFontSize: {
types: ['number'],
default: 18,
help: '',
},
maxFontSize: {
types: ['number'],
default: 72
default: 72,
help: '',
},
showLabel: {
types: ['boolean'],
default: true,
help: '',
},
metric: {
types: ['vis_dimension'],
help: i18n.translate('tagCloud.function.metric.help', {
defaultMessage: 'metric dimension configuration'
defaultMessage: 'metric dimension configuration',
}),
required: true,
},
bucket: {
types: ['vis_dimension'],
help: i18n.translate('tagCloud.function.bucket.help', {
defaultMessage: 'bucket dimension configuration'
defaultMessage: 'bucket dimension configuration',
}),
},
},
fn(context, args) {
fn(context: Context, args: Arguments) {
const visConfig = {
scale: args.scale,
orientation: args.orientation,
minFontSize: args.minFontSize,
maxFontSize: args.maxFontSize,
showLabel: args.showLabel,
metric: args.metric,
};
} as Arguments;

if (args.bucket !== undefined) {
visConfig.bucket = args.bucket;
Expand All @@ -93,14 +125,12 @@ export const tagcloud = () => ({
as: 'visualization',
value: {
visData: context,
visType: 'tagcloud',
visType: name,
visConfig,
params: {
listenOnChange: true,
}
},
},
};
},
});

functionsRegistry.register(tagcloud);
Loading

0 comments on commit c14f91a

Please sign in to comment.