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

[TSVB][Lens] Navigate to Lens context converting improvement. #139719

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
c698e75
Added NavigateToLens types.
Kuznietsov Aug 15, 2022
de2b27b
Removed math/overall* columns to be replaced by Formula.
Kuznietsov Aug 16, 2022
f1a628a
Removed Lens specific columns/fields.
Kuznietsov Aug 16, 2022
0733449
Added percentile column convertion.
Kuznietsov Aug 16, 2022
1749b10
Fixed labels.
Kuznietsov Aug 16, 2022
15ab59a
Add percentile_rank converter
VladLasitsa Aug 17, 2022
8f1ca40
Added math formula and timeScale support.
Kuznietsov Aug 17, 2022
6e3cfb9
Added MovingAverage and Derivative support.
Kuznietsov Aug 18, 2022
d0e7722
Updated formula and supported metrics.
Kuznietsov Aug 18, 2022
e982ac7
Fixed pipeline aggs.
Kuznietsov Aug 18, 2022
471f91a
Another fix.
Kuznietsov Aug 18, 2022
537d33a
One more fix.
Kuznietsov Aug 18, 2022
59db553
CumulativeSum added.
Kuznietsov Aug 18, 2022
c19acc7
Fixed formula, timeScale and etc.
Kuznietsov Aug 19, 2022
a2d51eb
Removed console.log.
Kuznietsov Aug 19, 2022
78b715d
Other aggs to formula convertion added.
Kuznietsov Aug 19, 2022
0549bdd
Filter ratio added.
Kuznietsov Aug 19, 2022
9d1b9c9
Add XY Configuration
VladLasitsa Aug 19, 2022
7b8786f
Added last_value convertion.
Kuznietsov Aug 19, 2022
8b57f8d
Merge branch 'navigate-to-lens-context-converting-imporvement' of git…
Kuznietsov Aug 19, 2022
6766d81
Updated ColumnWithMeta types.
Kuznietsov Aug 19, 2022
edbeea0
Fixed for loop.
Kuznietsov Aug 19, 2022
5221a01
Added StaticValue convertion.
Kuznietsov Aug 19, 2022
ecdf3e2
Added default agg convertion.
Kuznietsov Aug 19, 2022
faab810
Add filters column
VladLasitsa Aug 19, 2022
08a0539
Refactored filter part.
Kuznietsov Aug 19, 2022
defc3a0
Added meta to all the cols.
Kuznietsov Aug 22, 2022
0da77f1
Fixed problem with columns.
Kuznietsov Aug 22, 2022
fcdcb41
Added date_histogram column, fixed layer configuration
VladLasitsa Aug 22, 2022
bfd1dff
Added terms support.
Kuznietsov Aug 22, 2022
8f4c8d5
Refactored.
Kuznietsov Aug 22, 2022
a21b64e
Refactored for consistancy.
Kuznietsov Aug 22, 2022
6b0f939
Removed `getVisualizationSuggestionFromContext` fn.
Kuznietsov Aug 22, 2022
a36fabc
Added references.
Kuznietsov Aug 23, 2022
a9d19b7
Fixed percentile and percentile ranks.
Kuznietsov Aug 23, 2022
f1b8303
removed unused return statement.
Kuznietsov Aug 23, 2022
00dc472
Refactoring 'getEmptyLayersSuggestionsForVisualizeCharts' method
VladLasitsa Aug 23, 2022
b146838
TimeScaleUnit fix.
Kuznietsov Aug 23, 2022
97187d6
Fixed references.
Kuznietsov Aug 23, 2022
b2817cc
Fixed types.
Kuznietsov Aug 23, 2022
798998b
Fixed terms column
VladLasitsa Aug 23, 2022
b26ca08
Fixed count custom label.
Kuznietsov Aug 23, 2022
28e20f7
Merge branch 'navigate-to-lens-context-converting-imporvement' of git…
Kuznietsov Aug 23, 2022
ac20b5a
Fix multi series
VladLasitsa Aug 23, 2022
235ac24
Merge branch 'navigate-to-lens-context-converting-imporvement' of htt…
VladLasitsa Aug 23, 2022
9bd61fb
Fixed custom labels.
Kuznietsov Aug 23, 2022
7073b79
Merge branch 'navigate-to-lens-context-converting-imporvement' of git…
Kuznietsov Aug 23, 2022
9d45e79
Fixed 'insertReferences' method
VladLasitsa Aug 23, 2022
0556994
Revert "Fixed custom labels."
Kuznietsov Aug 24, 2022
09973a2
Merge branch 'navigate-to-lens-context-converting-imporvement' of git…
Kuznietsov Aug 24, 2022
83060ad
Fixed custom labels.
Kuznietsov Aug 24, 2022
fac12ff
Fixed filter ratio and derivative metrics
VladLasitsa Aug 24, 2022
6070dec
fix last_value and series agg
VladLasitsa Aug 24, 2022
8e045ea
Added CounterRate formula support.
Kuznietsov Aug 24, 2022
f804cab
Merge branch 'navigate-to-lens-context-converting-imporvement' of git…
Kuznietsov Aug 24, 2022
8cbb4ad
Merge remote-tracking branch 'upstream/main' into navigate-to-lens-co…
VladLasitsa Aug 24, 2022
2c0c001
Fix types
VladLasitsa Aug 24, 2022
3e2d943
Replaced usage of timeseries.
Kuznietsov Aug 24, 2022
0bc07fd
Merge branch 'navigate-to-lens-context-converting-imporvement' of git…
Kuznietsov Aug 24, 2022
12669a3
Added window everywhere.
Kuznietsov Aug 24, 2022
9e9593c
Add std_deviation and value_count, fix some issues
VladLasitsa Aug 25, 2022
7fae45e
Fix interval for date_histogram and fix getting filter for metrics an…
VladLasitsa Aug 25, 2022
afe393d
Fix tests for 'getDatasourceSuggestionsForVisualizeCharts' except tes…
VladLasitsa Aug 25, 2022
421c39b
Refactored code.
Kuznietsov Aug 26, 2022
ca82caf
Refactoring 'createNewLayerWithMetricAggregationFromVizEditor'
VladLasitsa Aug 26, 2022
0e847fa
Removed not used code.
Kuznietsov Aug 26, 2022
3f36734
Merge branch 'navigate-to-lens-context-converting-imporvement' of git…
Kuznietsov Aug 26, 2022
8ddaed9
Removed unused import.
Kuznietsov Aug 26, 2022
f49d11a
Fixed types.
Kuznietsov Aug 26, 2022
f472b42
Removed tests with type troubles.
Kuznietsov Aug 26, 2022
3ffa2c6
Some code refactoring + formatter.
Kuznietsov Aug 26, 2022
1380bb8
Removed not used comment.
Kuznietsov Aug 26, 2022
51ef491
Added formatter validation.
Kuznietsov Aug 26, 2022
0105536
Added tests for getFormat.
Kuznietsov Aug 26, 2022
26bf0a4
Fix `getFormat` method
VladLasitsa Aug 26, 2022
8576a9b
createColumn test added.
Kuznietsov Aug 26, 2022
309a861
Merge branch 'navigate-to-lens-context-converting-imporvement' of git…
Kuznietsov Aug 26, 2022
dcbf498
Added tests for `excludeMetaFromColumn` and `isColumnWithMeta`.
Kuznietsov Aug 26, 2022
ab7ed74
Added tests for counter_rate.
Kuznietsov Aug 27, 2022
3233c51
Added tests for cumulative_sum.
Kuznietsov Aug 27, 2022
3bce624
Updated cumulative_sum tests.
Kuznietsov Aug 27, 2022
a7a6e8f
Added date_histogram tests.
Kuznietsov Aug 27, 2022
74ed9d6
Added filter ratio tests.
Kuznietsov Aug 27, 2022
2e1cafa
Filters test added.
Kuznietsov Aug 27, 2022
b653473
createFormulaColumn test added.
Kuznietsov Aug 27, 2022
299033f
convertMathToFormulaColumn test added.
Kuznietsov Aug 27, 2022
6594b8f
Added one more case to check.
Kuznietsov Aug 27, 2022
c9d089c
Added test for convertOtherAggsToFormulaColumn
Kuznietsov Aug 27, 2022
875e6ed
added more tests for formula.
Kuznietsov Aug 29, 2022
133cd0b
Added last_value tests.
Kuznietsov Aug 29, 2022
fcf9711
Added tests for moving average.
Kuznietsov Aug 29, 2022
6947132
Style fix.
Kuznietsov Aug 29, 2022
00e3fb6
Added test for convertMetricAggregationColumnWithoutSpecialParams
Kuznietsov Aug 29, 2022
4d45e3f
Add tests for metrics_helper. Update tests for filter ratio and count…
VladLasitsa Aug 29, 2022
2c9662c
Added tests for convertMetricAggregationToColumn
Kuznietsov Aug 29, 2022
85e25ed
Merge branch 'navigate-to-lens-context-converting-imporvement' of git…
Kuznietsov Aug 29, 2022
7401851
Added tests for computeParentPipelineColumns
Kuznietsov Aug 29, 2022
4608467
Added tests for convertParentPipelineAggToColumns
Kuznietsov Aug 29, 2022
588d983
Add tests for getParentPipelineSeriesFormula
VladLasitsa Aug 29, 2022
dd6cbda
Merge branch 'navigate-to-lens-context-converting-imporvement' of htt…
VladLasitsa Aug 29, 2022
538bb05
Added tests for createParentPipelineAggregationColumn
Kuznietsov Aug 29, 2022
1fdba4a
Merge branch 'navigate-to-lens-context-converting-imporvement' of git…
Kuznietsov Aug 29, 2022
28022a6
Added tests for isPercentileRanksColumnWithMeta
Kuznietsov Aug 29, 2022
615eb74
Added tests for convertToPercentileRankParams
Kuznietsov Aug 29, 2022
7335202
Update and add tests for getSiblingPipelineSeriesFormula
VladLasitsa Aug 29, 2022
70504fd
Fixed tests.
Kuznietsov Aug 29, 2022
e396964
Merge branch 'navigate-to-lens-context-converting-imporvement' of git…
Kuznietsov Aug 29, 2022
fedee6d
Added tests for convertToPercentileRankColumn.
Kuznietsov Aug 29, 2022
1fd32b8
Added tests for convertToPercentileRankColumns.
Kuznietsov Aug 29, 2022
a99a96c
Added tests for percentile.
Kuznietsov Aug 29, 2022
3a850e1
Added tests for static_value.
Kuznietsov Aug 29, 2022
eb9fabf
Add tests for isValidMetrics
VladLasitsa Aug 29, 2022
55e5794
Added std_deviation tests.
Kuznietsov Aug 29, 2022
d8e24a0
Merge branch 'navigate-to-lens-context-converting-imporvement' of git…
Kuznietsov Aug 29, 2022
eb6e245
Added tests for terms.
Kuznietsov Aug 29, 2022
69b2499
Added tests.
Kuznietsov Aug 30, 2022
2a4e0fa
Merge branch 'main' into navigate-to-lens-context-converting-imporvement
Kuznietsov Aug 30, 2022
99f86e2
Add tests for getLayers in xy configuration
VladLasitsa Aug 30, 2022
c65115a
Rename window to reducedTimeRange
VladLasitsa Aug 30, 2022
f47e4cf
Added test for getBucketsColumns
Kuznietsov Aug 30, 2022
5442fed
Merge branch 'navigate-to-lens-context-converting-imporvement' of git…
Kuznietsov Aug 30, 2022
d041782
Fixed tests for parent_pipeline.
Kuznietsov Aug 30, 2022
42ab033
Added tests for getValidColumns
Kuznietsov Aug 30, 2022
b5f55f2
Added tests for getMetricsColumns
VladLasitsa Aug 30, 2022
d63061f
Removed empty new.index.ts of top_n.
Kuznietsov Aug 30, 2022
d57f02a
Merge branch 'navigate-to-lens-context-converting-imporvement' of git…
Kuznietsov Aug 30, 2022
689b52b
Configuration refactored.
Kuznietsov Aug 30, 2022
6c7fbbd
Added tests for getConfigurationForTimeseries and getConfigurationFor…
VladLasitsa Aug 30, 2022
0fe7efc
Added tests for timeseries/index.ts
Kuznietsov Aug 30, 2022
2a24a95
Merge branch 'navigate-to-lens-context-converting-imporvement' of git…
Kuznietsov Aug 30, 2022
da89591
Added test for top_n.
Kuznietsov Aug 30, 2022
2a04190
Refactored getSuggestionFromConvertToLensContext at suggestion_helpers.
Kuznietsov Aug 30, 2022
703f03d
Merge branch 'main' into navigate-to-lens-context-converting-imporvement
kibanamachine Sep 1, 2022
873eac7
Fix format
VladLasitsa Sep 1, 2022
e3b98a2
Fix types
VladLasitsa Sep 1, 2022
144a7a2
Remove unused code
VladLasitsa Sep 1, 2022
c0b43ba
Fix tests
VladLasitsa Sep 1, 2022
7e28d79
Fix bucket columns test
VladLasitsa Sep 1, 2022
b4c214b
Merge branch 'main' into navigate-to-lens-context-converting-imporvement
kibanamachine Sep 7, 2022
ac69c8a
Fix counter rate metric and remove unused comments
VladLasitsa Sep 7, 2022
a08ef9d
Merge remote-tracking branch 'upstream/main' into navigate-to-lens-co…
VladLasitsa Sep 9, 2022
f98f3c9
Merge branch 'main' into navigate-to-lens-context-converting-imporvement
flash1293 Sep 12, 2022
3e39342
Fixed pipeline and terms aggs. Added timeShift arg.
VladLasitsa Sep 12, 2022
1e8ef4b
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Sep 12, 2022
9ca095b
Fixed tests
VladLasitsa Sep 12, 2022
9908612
Merge branch 'main' into navigate-to-lens-context-converting-imporvement
Kuznietsov Sep 13, 2022
c3a443c
Fixed cumulative sum by value count.
Kuznietsov Sep 13, 2022
89f6945
Fixed percentile and percentile ranks.
Kuznietsov Sep 13, 2022
cc3fcd8
Fixed tests.
Kuznietsov Sep 13, 2022
018ea3c
One more fix.
Kuznietsov Sep 13, 2022
3743c4d
Fixed timeShift
VladLasitsa Sep 13, 2022
a23795c
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Sep 13, 2022
1625b30
Fixed getDataSourceInfo method
VladLasitsa Sep 13, 2022
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
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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Not for this PR, but I noticed we don't convert the axis scale (setting it to log doesn't carry that over to Lens but it could). I will open an issue for it

Copy link
Contributor

Choose a reason for hiding this comment

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

I added support of it here

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';
Loading