diff --git a/src/legacy/core_plugins/tagcloud/index.ts b/src/legacy/core_plugins/tagcloud/index.ts new file mode 100644 index 0000000000000..57641b9014261 --- /dev/null +++ b/src/legacy/core_plugins/tagcloud/index.ts @@ -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; diff --git a/src/legacy/core_plugins/tagcloud/public/__snapshots__/tag_cloud_fn.test.js.snap b/src/legacy/core_plugins/tagcloud/public/__snapshots__/tag_cloud_fn.test.ts.snap similarity index 100% rename from src/legacy/core_plugins/tagcloud/public/__snapshots__/tag_cloud_fn.test.js.snap rename to src/legacy/core_plugins/tagcloud/public/__snapshots__/tag_cloud_fn.test.ts.snap diff --git a/src/legacy/core_plugins/tagcloud/public/__tests__/afterparamchange.png b/src/legacy/core_plugins/tagcloud/public/components/__tests__/afterparamchange.png similarity index 100% rename from src/legacy/core_plugins/tagcloud/public/__tests__/afterparamchange.png rename to src/legacy/core_plugins/tagcloud/public/components/__tests__/afterparamchange.png diff --git a/src/legacy/core_plugins/tagcloud/public/__tests__/afterresize.png b/src/legacy/core_plugins/tagcloud/public/components/__tests__/afterresize.png similarity index 100% rename from src/legacy/core_plugins/tagcloud/public/__tests__/afterresize.png rename to src/legacy/core_plugins/tagcloud/public/components/__tests__/afterresize.png diff --git a/src/legacy/core_plugins/tagcloud/public/__tests__/basicdraw.png b/src/legacy/core_plugins/tagcloud/public/components/__tests__/basicdraw.png similarity index 100% rename from src/legacy/core_plugins/tagcloud/public/__tests__/basicdraw.png rename to src/legacy/core_plugins/tagcloud/public/components/__tests__/basicdraw.png diff --git a/src/legacy/core_plugins/tagcloud/public/__tests__/simpleload.png b/src/legacy/core_plugins/tagcloud/public/components/__tests__/simpleload.png similarity index 100% rename from src/legacy/core_plugins/tagcloud/public/__tests__/simpleload.png rename to src/legacy/core_plugins/tagcloud/public/components/__tests__/simpleload.png diff --git a/src/legacy/core_plugins/tagcloud/public/__tests__/tag_cloud.js b/src/legacy/core_plugins/tagcloud/public/components/__tests__/tag_cloud.js similarity index 99% rename from src/legacy/core_plugins/tagcloud/public/__tests__/tag_cloud.js rename to src/legacy/core_plugins/tagcloud/public/components/__tests__/tag_cloud.js index f6736b5d3d116..bddd18e5138cb 100644 --- a/src/legacy/core_plugins/tagcloud/public/__tests__/tag_cloud.js +++ b/src/legacy/core_plugins/tagcloud/public/components/__tests__/tag_cloud.js @@ -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'; diff --git a/src/legacy/core_plugins/tagcloud/public/__tests__/tag_cloud_visualization.js b/src/legacy/core_plugins/tagcloud/public/components/__tests__/tag_cloud_visualization.js similarity index 100% rename from src/legacy/core_plugins/tagcloud/public/__tests__/tag_cloud_visualization.js rename to src/legacy/core_plugins/tagcloud/public/components/__tests__/tag_cloud_visualization.js diff --git a/src/legacy/core_plugins/tagcloud/public/feedback_message.js b/src/legacy/core_plugins/tagcloud/public/components/feedback_message.js similarity index 100% rename from src/legacy/core_plugins/tagcloud/public/feedback_message.js rename to src/legacy/core_plugins/tagcloud/public/components/feedback_message.js diff --git a/src/legacy/core_plugins/tagcloud/public/label.js b/src/legacy/core_plugins/tagcloud/public/components/label.js similarity index 100% rename from src/legacy/core_plugins/tagcloud/public/label.js rename to src/legacy/core_plugins/tagcloud/public/components/label.js diff --git a/src/legacy/core_plugins/tagcloud/public/tag_cloud.js b/src/legacy/core_plugins/tagcloud/public/components/tag_cloud.js similarity index 99% rename from src/legacy/core_plugins/tagcloud/public/tag_cloud.js rename to src/legacy/core_plugins/tagcloud/public/components/tag_cloud.js index ab5b9e8a23f6d..92277df8680e8 100644 --- a/src/legacy/core_plugins/tagcloud/public/tag_cloud.js +++ b/src/legacy/core_plugins/tagcloud/public/components/tag_cloud.js @@ -37,7 +37,7 @@ const D3_SCALING_FUNCTIONS = { 'square root': () => d3.scale.sqrt() }; -class TagCloud extends EventEmitter { +export class TagCloud extends EventEmitter { constructor(domNode) { @@ -424,5 +424,3 @@ function hashWithinRange(str, max) { } return Math.abs(hash) % max; } - -export default TagCloud; diff --git a/src/legacy/core_plugins/tagcloud/public/tag_cloud_visualization.js b/src/legacy/core_plugins/tagcloud/public/components/tag_cloud_visualization.js similarity index 99% rename from src/legacy/core_plugins/tagcloud/public/tag_cloud_visualization.js rename to src/legacy/core_plugins/tagcloud/public/components/tag_cloud_visualization.js index e13efaf8b14a9..64c5d96a26955 100644 --- a/src/legacy/core_plugins/tagcloud/public/tag_cloud_visualization.js +++ b/src/legacy/core_plugins/tagcloud/public/components/tag_cloud_visualization.js @@ -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; @@ -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(); @@ -79,7 +79,6 @@ export class TagCloudVisualization { this._updateData(data); } - if (status.resize) { this._resize(); } @@ -104,7 +103,6 @@ export class TagCloudVisualization { }); } - destroy() { this._tagCloud.destroy(); unmountComponentAtNode(this._feedbackNode); @@ -136,7 +134,6 @@ export class TagCloudVisualization { }; }); - if (tags.length > MAX_TAG_COUNT) { tags.length = MAX_TAG_COUNT; this._truncated = true; @@ -145,7 +142,6 @@ export class TagCloudVisualization { } this._tagCloud.setData(tags); - } _updateParams(visParams) { @@ -156,5 +152,4 @@ export class TagCloudVisualization { _resize() { this._tagCloud.resize(); } - } diff --git a/src/legacy/core_plugins/tagcloud/index.js b/src/legacy/core_plugins/tagcloud/public/index.ts similarity index 73% rename from src/legacy/core_plugins/tagcloud/index.js rename to src/legacy/core_plugins/tagcloud/public/index.ts index 6ae53f745f82a..90e6305262caa 100644 --- a/src/legacy/core_plugins/tagcloud/index.js +++ b/src/legacy/core_plugins/tagcloud/public/index.ts @@ -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); } diff --git a/src/legacy/core_plugins/tagcloud/public/legacy.ts b/src/legacy/core_plugins/tagcloud/public/legacy.ts new file mode 100644 index 0000000000000..01b2d99ce509c --- /dev/null +++ b/src/legacy/core_plugins/tagcloud/public/legacy.ts @@ -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 = { + 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); diff --git a/src/legacy/core_plugins/tagcloud/public/plugin.ts b/src/legacy/core_plugins/tagcloud/public/plugin.ts new file mode 100644 index 0000000000000..e7f633b4af377 --- /dev/null +++ b/src/legacy/core_plugins/tagcloud/public/plugin.ts @@ -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; + visualizations: VisualizationsSetup; +} + +/** @internal */ +export class TagCloudPlugin implements Plugin { + 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 + } +} diff --git a/src/legacy/core_plugins/tagcloud/public/tag_cloud_fn.test.js b/src/legacy/core_plugins/tagcloud/public/tag_cloud_fn.test.ts similarity index 92% rename from src/legacy/core_plugins/tagcloud/public/tag_cloud_fn.test.js rename to src/legacy/core_plugins/tagcloud/public/tag_cloud_fn.test.ts index 01f3ba0a99af7..d14871c6bd337 100644 --- a/src/legacy/core_plugins/tagcloud/public/tag_cloud_fn.test.js +++ b/src/legacy/core_plugins/tagcloud/public/tag_cloud_fn.test.ts @@ -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 }], diff --git a/src/legacy/core_plugins/tagcloud/public/tag_cloud_fn.js b/src/legacy/core_plugins/tagcloud/public/tag_cloud_fn.ts similarity index 68% rename from src/legacy/core_plugins/tagcloud/public/tag_cloud_fn.js rename to src/legacy/core_plugins/tagcloud/public/tag_cloud_fn.ts index e49e31fe4741d..6c035a61986a5 100644 --- a/src/legacy/core_plugins/tagcloud/public/tag_cloud_fn.js +++ b/src/legacy/core_plugins/tagcloud/public/tag_cloud_fn.ts @@ -17,19 +17,48 @@ * 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; + +interface RenderValue { + visType: typeof name; + visData: Context; + visConfig: VisParams; + params: any; +} + +type Return = Render; + +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: { @@ -37,7 +66,7 @@ export const tagcloud = () => ({ 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: { @@ -45,36 +74,39 @@ export const tagcloud = () => ({ 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, @@ -82,7 +114,7 @@ export const tagcloud = () => ({ maxFontSize: args.maxFontSize, showLabel: args.showLabel, metric: args.metric, - }; + } as Arguments; if (args.bucket !== undefined) { visConfig.bucket = args.bucket; @@ -93,14 +125,12 @@ export const tagcloud = () => ({ as: 'visualization', value: { visData: context, - visType: 'tagcloud', + visType: name, visConfig, params: { listenOnChange: true, - } + }, }, }; }, }); - -functionsRegistry.register(tagcloud); diff --git a/src/legacy/core_plugins/tagcloud/public/tag_cloud_vis.js b/src/legacy/core_plugins/tagcloud/public/tag_cloud_type.ts similarity index 72% rename from src/legacy/core_plugins/tagcloud/public/tag_cloud_vis.js rename to src/legacy/core_plugins/tagcloud/public/tag_cloud_type.ts index ddb3a722333ef..94cd362bccbf7 100644 --- a/src/legacy/core_plugins/tagcloud/public/tag_cloud_vis.js +++ b/src/legacy/core_plugins/tagcloud/public/tag_cloud_type.ts @@ -18,23 +18,23 @@ */ import { i18n } from '@kbn/i18n'; -import { VisFactoryProvider } from 'ui/vis/vis_factory'; -import { Schemas } from 'ui/vis/editors/default/schemas'; -import { TagCloudVisualization } from './tag_cloud_visualization'; -import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; import { Status } from 'ui/vis/update_status'; -import { TagCloudOptions } from './components/tag_cloud_options'; +// @ts-ignore +import { Schemas } from 'ui/vis/editors/default/schemas'; -VisTypesRegistryProvider.register(function (Private) { +import { TagCloudOptions } from './components/tag_cloud_options'; +import { visFactory } from '../../visualizations/public'; - const VisFactory = Private(VisFactoryProvider); +// @ts-ignore +import { TagCloudVisualization } from './components/tag_cloud_visualization'; - return VisFactory.createBaseVisualization({ +export const createTagCloudTypeDefinition = () => { + return visFactory.createBaseVisualization({ name: 'tagcloud', title: i18n.translate('tagCloud.vis.tagCloudTitle', { defaultMessage: 'Tag Cloud' }), icon: 'visTagCloud', description: i18n.translate('tagCloud.vis.tagCloudDescription', { - defaultMessage: 'A group of words, sized according to their importance' + defaultMessage: 'A group of words, sized according to their importance', }), visConfig: { defaults: { @@ -42,8 +42,8 @@ VisTypesRegistryProvider.register(function (Private) { orientation: 'single', minFontSize: 18, maxFontSize: 72, - showLabel: true - } + showLabel: true, + }, }, requiresUpdateStatus: [Status.PARAMS, Status.RESIZE, Status.DATA], visualization: TagCloudVisualization, @@ -52,41 +52,41 @@ VisTypesRegistryProvider.register(function (Private) { scales: [ { text: i18n.translate('tagCloud.vis.editorConfig.scales.linearText', { - defaultMessage: 'Linear' + defaultMessage: 'Linear', }), - value: 'linear' + value: 'linear', }, { text: i18n.translate('tagCloud.vis.editorConfig.scales.logText', { - defaultMessage: 'Log' + defaultMessage: 'Log', }), - value: 'log' + value: 'log', }, { text: i18n.translate('tagCloud.vis.editorConfig.scales.squareRootText', { - defaultMessage: 'Square root' + defaultMessage: 'Square root', }), - value: 'square root' + value: 'square root', }, ], orientations: [ { text: i18n.translate('tagCloud.vis.editorConfig.orientations.singleText', { - defaultMessage: 'Single' + defaultMessage: 'Single', }), - value: 'single' + value: 'single', }, { text: i18n.translate('tagCloud.vis.editorConfig.orientations.rightAngledText', { - defaultMessage: 'Right angled' + defaultMessage: 'Right angled', }), - value: 'right angled' + value: 'right angled', }, { text: i18n.translate('tagCloud.vis.editorConfig.orientations.multipleText', { - defaultMessage: 'Multiple' + defaultMessage: 'Multiple', }), - value: 'multiple' + value: 'multiple', }, ], }, @@ -98,10 +98,15 @@ VisTypesRegistryProvider.register(function (Private) { title: i18n.translate('tagCloud.vis.schemas.metricTitle', { defaultMessage: 'Tag size' }), min: 1, max: 1, - aggFilter: ['!std_dev', '!percentiles', '!percentile_ranks', '!derivative', '!geo_bounds', '!geo_centroid'], - defaults: [ - { schema: 'metric', type: 'count' } - ] + aggFilter: [ + '!std_dev', + '!percentiles', + '!percentile_ranks', + '!derivative', + '!geo_bounds', + '!geo_centroid', + ], + defaults: [{ schema: 'metric', type: 'count' }], }, { group: 'buckets', @@ -109,10 +114,10 @@ VisTypesRegistryProvider.register(function (Private) { title: i18n.translate('tagCloud.vis.schemas.segmentTitle', { defaultMessage: 'Tags' }), min: 1, max: 1, - aggFilter: ['terms', 'significant_terms'] - } - ]) + aggFilter: ['terms', 'significant_terms'], + }, + ]), }, - useCustomNoDataScreen: true + useCustomNoDataScreen: true, }); -}); +};