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

Timelion visualization renderer #78540

Merged
merged 19 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ A user friendly name of the renderer as will be displayed to user in UI.
<b>Signature:</b>

```typescript
displayName: string;
displayName?: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ A user friendly name of the renderer as will be displayed to user in UI.
<b>Signature:</b>

```typescript
displayName: string;
displayName?: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface ExpressionRenderDefinition<Config = unknown> {
/**
* A user friendly name of the renderer as will be displayed to user in UI.
*/
displayName: string;
displayName?: string;

/**
* Help text as will be displayed to user. A sentence or few about what this
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/expressions/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export interface ExpressionImage {
//
// @public (undocumented)
export interface ExpressionRenderDefinition<Config = unknown> {
displayName: string;
displayName?: string;
help?: string;
name: string;
render: (domNode: HTMLElement, config: Config, handlers: IInterpreterRenderHandlers) => void | Promise<void>;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/expressions/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export interface ExpressionImage {
//
// @public (undocumented)
export interface ExpressionRenderDefinition<Config = unknown> {
displayName: string;
displayName?: string;
help?: string;
name: string;
render: (domNode: HTMLElement, config: Config, handlers: IInterpreterRenderHandlers) => void | Promise<void>;
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/timelion/public/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
@import './app';
@import './base';
@import './directives/index';

// these styles is needed to be loaded here explicitly if the timelion visualization was not opened in browser
// styles for timelion visualization are lazy loaded only while a vis is opened
// this will duplicate styles only if both Timelion app and timelion visualization are loaded
// could be left here as it is since the Timelion app is deprecated
@import '../../vis_type_timelion/public/components/index.scss';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions src/plugins/vis_type_timelion/public/_timelion_editor.scss

This file was deleted.

12 changes: 0 additions & 12 deletions src/plugins/vis_type_timelion/public/_timelion_vis.scss

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@
white-space: nowrap;
font-weight: $euiFontWeightBold;
}

.visEditor--timelion {
.visEditorSidebar__timelionOptions {
flex: 1 1 auto;
display: flex;
flex-direction: column;
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@import 'panel';
@import 'timelion_vis';
@import 'timelion_expression_input';
1 change: 0 additions & 1 deletion src/plugins/vis_type_timelion/public/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@

export * from './timelion_expression_input';
export * from './timelion_interval';
export * from './timelion_vis';
50 changes: 0 additions & 50 deletions src/plugins/vis_type_timelion/public/components/timelion_vis.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import React, { useState, useEffect, useMemo, useCallback } from 'react';
import $ from 'jquery';
import moment from 'moment-timezone';
import { debounce, compact, get, each, cloneDeep, last, map } from 'lodash';
import { useResizeObserver } from '@elastic/eui';

import { IInterpreterRenderHandlers } from 'src/plugins/expressions';
import { useKibana } from '../../../kibana_react/public';
import '../flot';
import { DEFAULT_TIME_FORMAT } from '../../common/lib';
Expand All @@ -38,18 +40,19 @@ import { Series, Sheet } from '../helpers/timelion_request_handler';
import { tickFormatters } from '../helpers/tick_formatters';
import { generateTicksProvider } from '../helpers/tick_generator';
import { TimelionVisDependencies } from '../plugin';
import { ExprVisAPIEvents } from '../../../visualizations/public';

import './index.scss';

interface CrosshairPlot extends jquery.flot.plot {
setCrosshair: (pos: Position) => void;
clearCrosshair: () => void;
}

interface PanelProps {
applyFilter: ExprVisAPIEvents['applyFilter'];
interface TimelionVisComponentProps {
fireEvent: IInterpreterRenderHandlers['event'];
interval: string;
seriesList: Sheet;
renderComplete(): void;
renderComplete: IInterpreterRenderHandlers['done'];
}

interface Position {
Expand All @@ -75,11 +78,16 @@ const DEBOUNCE_DELAY = 50;
// ensure legend is the same height with or without a caption so legend items do not move around
const emptyCaption = '<br>';

function Panel({ interval, seriesList, renderComplete, applyFilter }: PanelProps) {
function TimelionVisComponent({
interval,
seriesList,
renderComplete,
fireEvent,
}: TimelionVisComponentProps) {
const kibana = useKibana<TimelionVisDependencies>();
const [chart, setChart] = useState(() => cloneDeep(seriesList.list));
const [canvasElem, setCanvasElem] = useState<HTMLDivElement>();
const [chartElem, setChartElem] = useState<HTMLDivElement>();
const [chartElem, setChartElem] = useState<HTMLDivElement | null>(null);

const [originalColorMap, setOriginalColorMap] = useState(() => new Map<Series, string>());

Expand Down Expand Up @@ -191,7 +199,7 @@ function Panel({ interval, seriesList, renderComplete, applyFilter }: PanelProps
interval,
kibana.services.timefilter,
kibana.services.uiSettings,
chartElem && chartElem.clientWidth,
chartElem?.clientWidth,
grid
);
const updatedSeries = buildSeriesData(chartValue, options);
Expand All @@ -216,12 +224,14 @@ function Panel({ interval, seriesList, renderComplete, applyFilter }: PanelProps
updateCaption(newPlot.getData());
}
},
[canvasElem, chartElem, renderComplete, kibana.services, interval, updateCaption]
[canvasElem, chartElem?.clientWidth, renderComplete, kibana.services, interval, updateCaption]
);

const dimensions = useResizeObserver(chartElem);

useEffect(() => {
updatePlot(chart, seriesList.render && seriesList.render.grid);
}, [chart, updatePlot, seriesList.render]);
}, [chart, updatePlot, seriesList.render, dimensions]);

useEffect(() => {
const colorsSet: Array<[Series, string]> = [];
Expand Down Expand Up @@ -349,21 +359,24 @@ function Panel({ interval, seriesList, renderComplete, applyFilter }: PanelProps

const plotSelectedHandler = useCallback(
(event: JQuery.TriggeredEvent, ranges: Ranges) => {
applyFilter({
timeFieldName: '*',
filters: [
{
range: {
'*': {
gte: ranges.xaxis.from,
lte: ranges.xaxis.to,
fireEvent({
name: 'applyFilter',
data: {
timeFieldName: '*',
filters: [
{
range: {
'*': {
gte: ranges.xaxis.from,
lte: ranges.xaxis.to,
},
},
},
},
],
],
},
});
},
[applyFilter]
[fireEvent]
);

useEffect(() => {
Expand Down Expand Up @@ -396,4 +409,6 @@ function Panel({ interval, seriesList, renderComplete, applyFilter }: PanelProps
);
}

export { Panel };
// default export required for React.Lazy
// eslint-disable-next-line import/no-default-export
export { TimelionVisComponent as default };
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

import { i18n } from '@kbn/i18n';
import { KIBANA_CONTEXT_NAME } from 'src/plugins/expressions/public';
import { VisParams } from '../../../visualizations/public';
import { TimeRange, Filter, esQuery, Query } from '../../../data/public';
import { TimelionVisDependencies } from '../plugin';
import { getTimezone } from './get_timezone';
import { TimelionVisParams } from '../timelion_vis_fn';

interface Stats {
cacheCount: number;
Expand Down Expand Up @@ -77,7 +77,7 @@ export function getTimelionRequestHandler({
timeRange: TimeRange;
filters: Filter[];
query: Query;
visParams: VisParams;
visParams: TimelionVisParams;
}): Promise<TimelionSuccessResponse> {
const expression = visParams.expression;

Expand Down
3 changes: 0 additions & 3 deletions src/plugins/vis_type_timelion/public/index.scss

This file was deleted.

5 changes: 3 additions & 2 deletions src/plugins/vis_type_timelion/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import { getTimelionVisDefinition } from './timelion_vis_type';
import { setIndexPatterns, setSavedObjectsClient } from './helpers/plugin_services';
import { ConfigSchema } from '../config';

import './index.scss';
import { getArgValueSuggestions } from './helpers/arg_value_suggestions';
import { getTimelionVisRenderer } from './timelion_vis_renderer';

/** @internal */
export interface TimelionVisDependencies extends Partial<CoreStart> {
Expand Down Expand Up @@ -93,7 +93,8 @@ export class TimelionVisPlugin
};

expressions.registerFunction(() => getTimelionVisualizationConfig(dependencies));
visualizations.createReactVisualization(getTimelionVisDefinition(dependencies));
expressions.registerRenderer(getTimelionVisRenderer(dependencies));
visualizations.createBaseVisualization(getTimelionVisDefinition(dependencies));

return {
isUiEnabled: this.initializerContext.config.get().ui.enabled,
Expand Down
13 changes: 7 additions & 6 deletions src/plugins/vis_type_timelion/public/timelion_options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ import React, { useCallback } from 'react';
import { EuiPanel } from '@elastic/eui';

import { VisOptionsProps } from 'src/plugins/vis_default_editor/public';
import { VisParams } from './timelion_vis_fn';
import { TimelionVisParams } from './timelion_vis_fn';
import { TimelionInterval, TimelionExpressionInput } from './components';

export type TimelionOptionsProps = VisOptionsProps<VisParams>;
export type TimelionOptionsProps = VisOptionsProps<TimelionVisParams>;

function TimelionOptions({ stateParams, setValue, setValidity }: TimelionOptionsProps) {
const setInterval = useCallback((value: VisParams['interval']) => setValue('interval', value), [
setValue,
]);
const setInterval = useCallback(
(value: TimelionVisParams['interval']) => setValue('interval', value),
[setValue]
);
const setExpressionInput = useCallback(
(value: VisParams['expression']) => setValue('expression', value),
(value: TimelionVisParams['expression']) => setValue('expression', value),
[setValue]
);

Expand Down