-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/140204-ui
- Loading branch information
Showing
227 changed files
with
6,187 additions
and
680 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/plugins/vis_types/timeseries/public/convert_to_lens/lib/configurations/metric/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { MetricVisConfiguration } from '@kbn/visualizations-plugin/common'; | ||
import { Metric, Panel, Series } from '../../../../../common/types'; | ||
import { Column, Layer } from '../../convert'; | ||
import { getSeriesAgg } from '../../series'; | ||
import { getPalette } from './palette'; | ||
|
||
const getMetricWithCollapseFn = (series: Series | undefined) => { | ||
if (!series) { | ||
return; | ||
} | ||
const { metrics, seriesAgg } = getSeriesAgg(series.metrics); | ||
const visibleMetric = metrics[metrics.length - 1]; | ||
return { metric: visibleMetric, collapseFn: seriesAgg }; | ||
}; | ||
|
||
const findMetricColumn = (metric: Metric | undefined, columns: Column[]) => { | ||
if (!metric) { | ||
return; | ||
} | ||
|
||
return columns.find((column) => 'meta' in column && column.meta.metricId === metric.id); | ||
}; | ||
|
||
export const getConfigurationForMetric = ( | ||
model: Panel, | ||
layer: Layer, | ||
bucket?: Column | ||
): MetricVisConfiguration | null => { | ||
const [primarySeries, secondarySeries] = model.series.filter(({ hidden }) => !hidden); | ||
|
||
const primaryMetricWithCollapseFn = getMetricWithCollapseFn(primarySeries); | ||
|
||
if (!primaryMetricWithCollapseFn || !primaryMetricWithCollapseFn.metric) { | ||
return null; | ||
} | ||
|
||
const secondaryMetricWithCollapseFn = getMetricWithCollapseFn(secondarySeries); | ||
const primaryColumn = findMetricColumn(primaryMetricWithCollapseFn.metric, layer.columns); | ||
const secondaryColumn = findMetricColumn(secondaryMetricWithCollapseFn?.metric, layer.columns); | ||
|
||
if (primaryMetricWithCollapseFn.collapseFn && secondaryMetricWithCollapseFn?.collapseFn) { | ||
return null; | ||
} | ||
|
||
const palette = getPalette(model.background_color_rules ?? []); | ||
if (palette === null) { | ||
return null; | ||
} | ||
|
||
return { | ||
layerId: layer.layerId, | ||
layerType: 'data', | ||
metricAccessor: primaryColumn?.columnId, | ||
secondaryMetricAccessor: secondaryColumn?.columnId, | ||
breakdownByAccessor: bucket?.columnId, | ||
palette, | ||
collapseFn: primaryMetricWithCollapseFn.collapseFn ?? secondaryMetricWithCollapseFn?.collapseFn, | ||
}; | ||
}; |
177 changes: 177 additions & 0 deletions
177
...ins/vis_types/timeseries/public/convert_to_lens/lib/configurations/metric/palette.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
/* | ||
* 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 { getPalette } from './palette'; | ||
|
||
describe('getPalette', () => { | ||
const invalidRules = [ | ||
{ id: 'some-id-0' }, | ||
{ id: 'some-id-1', value: 10 }, | ||
{ id: 'some-id-2', operator: 'gte' }, | ||
{ id: 'some-id-3', color: '#000' }, | ||
{ id: 'some-id-4', background_color: '#000' }, | ||
]; | ||
test('should return undefined if no filled rules was provided', () => { | ||
expect(getPalette([])).toBeUndefined(); | ||
expect(getPalette(invalidRules)).toBeUndefined(); | ||
}); | ||
|
||
test('should return undefined if only one valid rule is provided and it is not lte', () => { | ||
expect(getPalette([])).toBeUndefined(); | ||
expect( | ||
getPalette([ | ||
...invalidRules, | ||
{ id: 'some-id-5', operator: 'gt', value: 100, background_color: '#000' }, | ||
]) | ||
).toBeUndefined(); | ||
}); | ||
|
||
test('should return custom palette if only one valid rule is provided and it is lte', () => { | ||
expect(getPalette([])).toBeUndefined(); | ||
expect( | ||
getPalette([ | ||
...invalidRules, | ||
{ id: 'some-id-5', operator: 'lte', value: 100, background_color: '#000' }, | ||
]) | ||
).toEqual({ | ||
name: 'custom', | ||
params: { | ||
colorStops: [{ color: '#000000', stop: 100 }], | ||
continuity: 'below', | ||
maxSteps: 5, | ||
name: 'custom', | ||
progression: 'fixed', | ||
rangeMax: 100, | ||
rangeMin: -Infinity, | ||
rangeType: 'number', | ||
reverse: false, | ||
steps: 1, | ||
stops: [{ color: '#000000', stop: 100 }], | ||
}, | ||
type: 'palette', | ||
}); | ||
}); | ||
|
||
test('should return undefined if more than two types of rules', () => { | ||
expect(getPalette([])).toBeUndefined(); | ||
expect( | ||
getPalette([ | ||
...invalidRules, | ||
{ id: 'some-id-5', operator: 'lte', value: 100, background_color: '#000' }, | ||
{ id: 'some-id-6', operator: 'gte', value: 150, background_color: '#000' }, | ||
{ id: 'some-id-7', operator: 'lt', value: 200, background_color: '#000' }, | ||
]) | ||
).toBeUndefined(); | ||
}); | ||
|
||
test('should return undefined if two types of rules and last rule is not lte', () => { | ||
expect(getPalette([])).toBeUndefined(); | ||
expect( | ||
getPalette([ | ||
...invalidRules, | ||
{ id: 'some-id-5', operator: 'gte', value: 100, background_color: '#000' }, | ||
{ id: 'some-id-7', operator: 'lt', value: 200, background_color: '#000' }, | ||
{ id: 'some-id-6', operator: 'gte', value: 150, background_color: '#000' }, | ||
]) | ||
).toBeUndefined(); | ||
}); | ||
|
||
test('should return undefined if all rules are lte', () => { | ||
expect(getPalette([])).toBeUndefined(); | ||
expect( | ||
getPalette([ | ||
...invalidRules, | ||
{ id: 'some-id-5', operator: 'lte', value: 100, background_color: '#000' }, | ||
{ id: 'some-id-7', operator: 'lte', value: 200, background_color: '#000' }, | ||
{ id: 'some-id-6', operator: 'lte', value: 150, background_color: '#000' }, | ||
]) | ||
).toBeUndefined(); | ||
}); | ||
|
||
test('should return undefined if two types of rules and all except last one are lt and last one is not lte', () => { | ||
expect(getPalette([])).toBeUndefined(); | ||
expect( | ||
getPalette([ | ||
...invalidRules, | ||
{ id: 'some-id-5', operator: 'lt', value: 100, background_color: '#000' }, | ||
{ id: 'some-id-7', operator: 'gte', value: 200, background_color: '#000' }, | ||
{ id: 'some-id-6', operator: 'lt', value: 150, background_color: '#000' }, | ||
]) | ||
).toBeUndefined(); | ||
}); | ||
|
||
test('should return custom palette if two types of rules and all except last one is lt and last one is lte', () => { | ||
expect(getPalette([])).toBeUndefined(); | ||
expect( | ||
getPalette([ | ||
...invalidRules, | ||
{ id: 'some-id-5', operator: 'lt', value: 100, background_color: '#000' }, | ||
{ id: 'some-id-7', operator: 'lte', value: 200, background_color: '#000' }, | ||
{ id: 'some-id-6', operator: 'lt', value: 150, background_color: '#000' }, | ||
]) | ||
).toEqual({ | ||
name: 'custom', | ||
params: { | ||
colorStops: [ | ||
{ color: '#000000', stop: -Infinity }, | ||
{ color: '#000000', stop: 100 }, | ||
{ color: '#000000', stop: 150 }, | ||
], | ||
continuity: 'below', | ||
maxSteps: 5, | ||
name: 'custom', | ||
progression: 'fixed', | ||
rangeMax: 200, | ||
rangeMin: -Infinity, | ||
rangeType: 'number', | ||
reverse: false, | ||
steps: 4, | ||
stops: [ | ||
{ color: '#000000', stop: 100 }, | ||
{ color: '#000000', stop: 150 }, | ||
{ color: '#000000', stop: 200 }, | ||
], | ||
}, | ||
type: 'palette', | ||
}); | ||
}); | ||
|
||
test('should return custom palette if last one is lte and all previous are gte', () => { | ||
expect(getPalette([])).toBeUndefined(); | ||
expect( | ||
getPalette([ | ||
...invalidRules, | ||
{ id: 'some-id-5', operator: 'gte', value: 100, background_color: '#000' }, | ||
{ id: 'some-id-7', operator: 'lte', value: 200, background_color: '#000' }, | ||
{ id: 'some-id-6', operator: 'gte', value: 150, background_color: '#000' }, | ||
]) | ||
).toEqual({ | ||
name: 'custom', | ||
params: { | ||
colorStops: [ | ||
{ color: '#000000', stop: 100 }, | ||
{ color: '#000000', stop: 150 }, | ||
], | ||
continuity: 'none', | ||
maxSteps: 5, | ||
name: 'custom', | ||
progression: 'fixed', | ||
rangeMax: 200, | ||
rangeMin: 100, | ||
rangeType: 'number', | ||
reverse: false, | ||
steps: 2, | ||
stops: [ | ||
{ color: '#000000', stop: 150 }, | ||
{ color: '#000000', stop: 200 }, | ||
], | ||
}, | ||
type: 'palette', | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.