Skip to content

Commit

Permalink
[TSVB][Lens] Navigate to Lens context converting improvement. (#139719)
Browse files Browse the repository at this point in the history
* Added NavigateToLens types.

* Removed math/overall* columns to be replaced by Formula.

* Removed Lens specific columns/fields.

* Added percentile column convertion.

* Fixed labels.

* Add percentile_rank converter

* Added math formula and timeScale support.

* Added MovingAverage and Derivative support.

* Updated formula and supported metrics.

* Fixed pipeline aggs.

* CumulativeSum added.

* Fixed formula, timeScale and etc.

* Removed console.log.

* Other aggs to formula convertion added.

* Filter ratio added.

* Add XY Configuration

* Added last_value convertion.

* Updated ColumnWithMeta types.

* Fixed for loop.

* Added StaticValue convertion.

* Added default agg convertion.

* Add filters column

* Refactored filter part.

* Added meta to all the cols.

* Fixed problem with columns.

* Added date_histogram column, fixed layer configuration

* Added terms support.

* Refactored for consistancy.

* Removed `getVisualizationSuggestionFromContext` fn.

* Added references.

* Fixed percentile and percentile ranks.

* removed unused return statement.

* Refactoring 'getEmptyLayersSuggestionsForVisualizeCharts' method

* TimeScaleUnit fix.

* Fixed references.

* Fixed types.

* Fixed terms column

* Fixed count custom label.

* Fix multi series

* Fixed custom labels.

* Fixed 'insertReferences' method

* Revert "Fixed custom labels."

This reverts commit 9bd61fb.

* Fixed custom labels.

* Fixed filter ratio and derivative metrics

* fix last_value and series agg

* Added CounterRate formula support.

* Replaced usage of timeseries.

* Added window everywhere.

* Add std_deviation and value_count, fix some issues

* Fix interval for date_histogram and fix getting filter for metrics and difference

* Fix tests for 'getDatasourceSuggestionsForVisualizeCharts' except test for 'format'

* Refactored code.

* Refactoring 'createNewLayerWithMetricAggregationFromVizEditor'

* Removed not used code.

* Removed unused import.

* Fixed types.

* Removed tests with type troubles.

* Some code refactoring + formatter.

* Removed not used comment.

* Added formatter validation.

* Added tests for getFormat.

* Fix `getFormat` method

* createColumn test added.

* Added tests for `excludeMetaFromColumn` and `isColumnWithMeta`.

* Added tests for counter_rate.

* Added tests for cumulative_sum.

* Updated cumulative_sum tests.

* Added date_histogram tests.

* Added filter ratio tests.

* Filters test added.

* createFormulaColumn test added.

* convertMathToFormulaColumn test added.

* Added one more case to check.

* Added test for convertOtherAggsToFormulaColumn

* added more tests for formula.

* Added last_value tests.

* Added tests for moving average.

* Style fix.

* Added test for convertMetricAggregationColumnWithoutSpecialParams

* Add tests for metrics_helper. Update tests for filter ratio and counter rate formulas

* Added tests for convertMetricAggregationToColumn

* Added tests for computeParentPipelineColumns

* Added tests for convertParentPipelineAggToColumns

* Add tests for getParentPipelineSeriesFormula

* Added tests for createParentPipelineAggregationColumn

* Added tests for isPercentileRanksColumnWithMeta

* Added tests for convertToPercentileRankParams

* Update and add tests for getSiblingPipelineSeriesFormula

* Fixed tests.

* Added tests for convertToPercentileRankColumn.

* Added tests for convertToPercentileRankColumns.

* Added tests for percentile.

* Added tests for static_value.

* Add tests for isValidMetrics

* Added std_deviation tests.

* Added tests for terms.

* Added tests.

* Add tests for getLayers in xy configuration

* Rename window to reducedTimeRange

* Added test for getBucketsColumns

* Fixed tests for parent_pipeline.

* Added tests for getValidColumns

* Added tests for getMetricsColumns

* Removed empty new.index.ts of top_n.

* Configuration refactored.

* Added tests for getConfigurationForTimeseries and getConfigurationForTopN

* Added tests for timeseries/index.ts

* Added test for top_n.

* Refactored getSuggestionFromConvertToLensContext at suggestion_helpers.

* Fix format

* Fix types

* Remove unused code

* Fix tests

* Fix bucket columns test

* Fix counter rate metric and remove unused comments

* Fixed pipeline and terms aggs. Added timeShift arg.

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

* Fixed tests

* Fixed cumulative sum by value count.

* Fixed percentile and percentile ranks.

* Fixed tests.

* One more fix.

* Fixed timeShift

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

* Fixed getDataSourceInfo method

Co-authored-by: Uladzislau Lasitsa <vlad.lasitsa@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
  • Loading branch information
4 people committed Sep 15, 2022
1 parent 929cdc0 commit 4d3e76c
Show file tree
Hide file tree
Showing 120 changed files with 8,106 additions and 4,029 deletions.
1 change: 1 addition & 0 deletions src/plugins/field_formats/common/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const fieldFormatsMock: IFieldFormatsRegistry = {
getByFieldType: jest.fn(),
getDefaultConfig: jest.fn(),
getDefaultInstance: jest.fn().mockImplementation(() => ({
type: { id: 'bytes' },
convert: jest.fn().mockImplementation((t: string) => t),
getConverterFor: jest.fn().mockImplementation(() => (t: string) => t),
})),
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_types/timeseries/common/agg_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export const aggs: Agg[] = [
},
},
{
id: TSVB_METRIC_TYPES.VALUE_COUNT,
id: METRIC_TYPES.VALUE_COUNT,
meta: {
...aggDefaultMeta,
isFilterRatioSupported: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export enum TSVB_METRIC_TYPES {
STD_DEVIATION = 'std_deviation',
SUM_OF_SQUARES = 'sum_of_squares',
TOP_HIT = 'top_hit',
VALUE_COUNT = 'value_count',
VARIANCE = 'variance',
CALCULATION = 'calculation',
MOVING_AVERAGE = 'moving_average',
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_types/timeseries/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { KBN_FIELD_TYPES, Query } from '@kbn/data-plugin/common';
import type { DataView } from '@kbn/data-views-plugin/public';
import { Panel } from './panel_model';

export type { Metric, Series, Panel, MetricType } from './panel_model';
export type { Metric, Series, Panel, MetricType, Percentile } from './panel_model';
export type {
TimeseriesVisData,
PanelData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface MetricVariable {
name?: string;
}

interface Percentile {
export interface Percentile {
id: string;
mode: 'line' | 'band';
field?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

import { KBN_FIELD_TYPES } from '@kbn/data-plugin/public';
import { METRIC_TYPES } from '@kbn/data-plugin/common';
import { TSVB_METRIC_TYPES } from '../../../../common/enums';

export function getSupportedFieldsByMetricType(type) {
switch (type) {
case METRIC_TYPES.CARDINALITY:
return Object.values(KBN_FIELD_TYPES).filter((t) => t !== KBN_FIELD_TYPES.HISTOGRAM);
case TSVB_METRIC_TYPES.VALUE_COUNT:
case METRIC_TYPES.VALUE_COUNT:
return Object.values(KBN_FIELD_TYPES);
case METRIC_TYPES.AVG:
case METRIC_TYPES.SUM:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import type { Panel } from '../../common/types';
import { PANEL_TYPES } from '../../common/enums';
import { ConvertTsvbToLensVisualization } from './types';

const getConvertFnByType = (
type: PANEL_TYPES
): Promise<ConvertTsvbToLensVisualization> | undefined => {
const getConvertFnByType = (type: PANEL_TYPES) => {
const convertionFns: { [key in PANEL_TYPES]?: () => Promise<ConvertTsvbToLensVisualization> } = {
[PANEL_TYPES.TIMESERIES]: async () => {
const { convertToLens } = await import('./timeseries');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { PANEL_TYPES } from '../../../../common/enums';
import { Panel, Series } from '../../../../common/types';

export const createSeries = (partialSeries?: Partial<Series>): Series => ({
axis_position: 'right',
chart_type: 'line',
color: '#68BC00',
fill: '0.5',
formatter: '',
id: '3bb3c1d2-5af8-44cc-9759-86725e34b157',
label: '',
line_width: 1,
metrics: [],
override_index_pattern: 0,
palette: { name: 'default', type: 'palette' },
point_size: 1,
separate_axis: 0,
series_drop_last_bucket: 0,
split_mode: 'everything',
stacked: 'none',
time_range_mode: 'entire_time_range',
value_template: '{{value}}',
seperate_axis: 0,
series_index_pattern: { id: 'test' },
series_max_bars: 0,
steps: 0,
...partialSeries,
});

export const createPanel = (parialPanel?: Partial<Panel>): Panel => ({
annotations: [],
axis_formatter: '',
axis_max: 100,
axis_min: 0,
axis_position: 'right',
axis_scale: '',
bar_color_rules: [],
drop_last_bucket: 0,
hide_last_value_indicator: false,
id: 'some-id',
ignore_daylight_time: true,
index_pattern: { id: 'test' },
interval: '',
// eslint-disable-next-line @typescript-eslint/naming-convention
markdown_openLinksInNewTab: 0,
markdown_scrollbars: 0,
max_bars: 0,
series: [createSeries()],
show_grid: 0,
show_legend: 0,
type: PANEL_TYPES.TIMESERIES,
...parialPanel,
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* Side Public License, v 1.
*/

export * from './get_layer';
export * from './xy';
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { SeriesType, SeriesTypes } from '@kbn/visualizations-plugin/common/convert_to_lens';
import { Series } from '../../../../../common/types';
import { PANEL_TYPES } from '../../../../../common/enums';

export const getChartType = (series: Series, type: PANEL_TYPES): SeriesType => {
let layerChartType: SeriesType = SeriesTypes.LINE;
switch (series.chart_type) {
case SeriesTypes.LINE:
layerChartType = Number(series.fill) > 0 ? SeriesTypes.AREA : SeriesTypes.LINE;
break;
case SeriesTypes.AREA:
layerChartType = SeriesTypes.AREA;
break;
case SeriesTypes.BAR:
layerChartType = SeriesTypes.BAR;
break;
}

if (type === PANEL_TYPES.TOP_N) {
return SeriesTypes.BAR_HORIZONTAL;
}

if (series.stacked !== 'none' && series.stacked !== 'percent') {
return layerChartType !== SeriesTypes.LINE ? `${layerChartType}_stacked` : SeriesTypes.LINE;
}
if (series.stacked === 'percent') {
return layerChartType !== SeriesTypes.LINE
? `${layerChartType}_percentage_stacked`
: SeriesTypes.LINE;
}

return layerChartType;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { createPanel } from '../../__mocks__';
import { getConfigurationForTopN, getConfigurationForTimeseries } from './configuration';

describe('getConfigurationForTimeseries', () => {
test('should return correct configuration for timeseries', () => {
expect(getConfigurationForTimeseries(createPanel(), [])).toEqual({
layers: [],
fillOpacity: 0.5,
legend: {
isVisible: false,
showSingleSeries: false,
position: 'right',
shouldTruncate: false,
maxLines: 1,
},
gridlinesVisibilitySettings: {
x: false,
yLeft: false,
yRight: false,
},
yLeftExtent: { mode: 'full' },
yRightExtent: { mode: 'full' },
yLeftScale: 'linear',
yRightScale: 'linear',
});
});
});

describe('getConfigurationForTopN', () => {
test('should return correct configuration for top n', () => {
expect(getConfigurationForTopN(createPanel(), [])).toEqual({
layers: [],
fillOpacity: 0.5,
legend: {
isVisible: false,
showSingleSeries: false,
position: 'right',
shouldTruncate: false,
maxLines: 1,
},
gridlinesVisibilitySettings: {
x: false,
yLeft: false,
yRight: false,
},
tickLabelsVisibilitySettings: {
x: true,
yLeft: false,
yRight: false,
},
axisTitlesVisibilitySettings: {
x: false,
yLeft: false,
yRight: false,
},
valueLabels: 'show',
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { Position } from '@elastic/charts';
import { XYConfiguration, XYLayerConfig } from '@kbn/visualizations-plugin/common';
import { Panel } from '../../../../../common/types';
import { getYExtents } from './extents';

export const getConfigurationForTimeseries = (
model: Panel,
layers: XYLayerConfig[]
): XYConfiguration => {
const extents = getYExtents(model);
return {
layers,
fillOpacity: Number(model.series[0].fill) ?? 0.3,
legend: {
isVisible: Boolean(model.show_legend),
showSingleSeries: Boolean(model.show_legend),
position: (model.legend_position as Position) ?? Position.Right,
shouldTruncate: Boolean(model.truncate_legend),
maxLines: model.max_lines_legend ?? 1,
},
gridlinesVisibilitySettings: {
x: Boolean(model.show_grid),
yLeft: Boolean(model.show_grid),
yRight: Boolean(model.show_grid),
},
yLeftExtent: extents.yLeftExtent,
yRightExtent: extents.yRightExtent,
yLeftScale: model.axis_scale === 'log' ? 'log' : 'linear',
yRightScale: model.axis_scale === 'log' ? 'log' : 'linear',
};
};

export const getConfigurationForTopN = (
model: Panel,
layers: XYLayerConfig[]
): XYConfiguration => ({
layers,
fillOpacity: Number(model.series[0].fill) ?? 0.3,
legend: {
isVisible: Boolean(model.show_legend),
showSingleSeries: Boolean(model.show_legend),
position: (model.legend_position as Position) ?? Position.Right,
shouldTruncate: Boolean(model.truncate_legend),
maxLines: model.max_lines_legend ?? 1,
},
gridlinesVisibilitySettings: {
x: false,
yLeft: false,
yRight: false,
},
tickLabelsVisibilitySettings: {
x: true,
yLeft: false,
yRight: false,
},
axisTitlesVisibilitySettings: {
x: false,
yLeft: false,
yRight: false,
},
valueLabels: 'show',
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import type { Panel } from '../../../../common/types';
import type { Panel } from '../../../../../common/types';
import { getYExtents } from './extents';

const model = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* Side Public License, v 1.
*/

import type { Panel, Series } from '../../../../common/types';
import { AxisExtentConfig } from '@kbn/visualizations-plugin/common/convert_to_lens';
import type { Panel, Series } from '../../../../../common/types';

const lowerBoundShouldBeZero = (
lowerBound: number | null,
Expand Down Expand Up @@ -45,7 +46,12 @@ const getLowerValue = (
* In Lens, we only allow 2 axis, one left and one right. We need an assumption here.
* We will transfer in Lens the "collapsed" axes with both bounds.
*/
export const getYExtents = (model: Panel) => {
export const getYExtents = (
model: Panel
): {
yLeftExtent?: AxisExtentConfig;
yRightExtent?: AxisExtentConfig;
} => {
let lowerBoundLeft: number | null = null;
let upperBoundLeft: number | null = null;
let lowerBoundRight: number | null = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
* Side Public License, v 1.
*/

export * from './layers';
export * from './extents';
export * from './chart_type';
export * from './configuration';

0 comments on commit 4d3e76c

Please sign in to comment.