Skip to content

Commit

Permalink
Merge branch 'main' of github.com:elastic/kibana into adds-revision-t…
Browse files Browse the repository at this point in the history
…o-alerts-schema
  • Loading branch information
spong committed Mar 28, 2023
2 parents 52013c4 + 8c6e58c commit b7c544f
Show file tree
Hide file tree
Showing 185 changed files with 4,894 additions and 2,396 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ packages/kbn-yarn-lock-validator @elastic/kibana-operations
/x-pack/test/functional/es_archives/uptime @elastic/uptime
/x-pack/test/functional/services/uptime @elastic/uptime
/x-pack/test/api_integration/apis/uptime @elastic/uptime
/x-pack/test/api_integration/apis/synthetics @elastic/uptime
/x-pack/plugins/observability/public/components/shared/exploratory_view @elastic/uptime
/x-pack/plugins/observability/public/components/shared/field_value_suggestions @elastic/uptime
/x-pack/plugins/observability/public/components/shared/core_web_vitals @elastic/uptime
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"@dnd-kit/utilities": "^2.0.0",
"@elastic/apm-rum": "^5.12.0",
"@elastic/apm-rum-react": "^1.4.2",
"@elastic/charts": "53.1.0",
"@elastic/charts": "54.0.0",
"@elastic/datemath": "5.0.3",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@8.6.0-canary.3",
"@elastic/ems-client": "8.4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,46 @@
import { DatatableRow } from '@kbn/expressions-plugin/public';
import { BucketColumns } from '../../common/types';

/**
* All the available categories of a datatable.
*/
export interface DistinctSeries {
allSeries: string[];
parentSeries: string[];
/**
* An array of unique category/bucket available on all the categorical/bucket columns.
* It could be `string` or `RangeKey` but is typed as unknown for now due to the loose nature of the DatatableRow type
*/
allSeries: unknown[];
/**
* An array of unique category/bucket available on the first column of a datatable.
* It could be `string` or `RangeKey` but is typed as unknown for now due to the loose nature of the DatatableRow type
*/
parentSeries: unknown[];
}

/**
* This method returns all the categories available in a datatable.
* Here, categorical values are described as `bucket`, following the Elasticsearch bucket aggregation naming.
* It describes as `parentSeries` all the categories available on the `first` available column.
* It describes as `allSeries` each unique category/bucket available on all the categorical/bucket columns.
* The output order depends on the original datatable configuration.
*/
export const getDistinctSeries = (
rows: DatatableRow[],
buckets: Array<Partial<BucketColumns>>
bucketColumns: Array<Partial<BucketColumns>>
): DistinctSeries => {
const parentBucketId = buckets[0].id;
const parentSeries: string[] = [];
const allSeries: string[] = [];
buckets.forEach(({ id }) => {
const parentBucketId = bucketColumns[0].id;
// using unknown here because there the DatatableRow is just a plain Record<string, any>
// At least we can prevent some issues, see https://github.com/elastic/kibana/issues/153437
const parentSeries: Set<unknown> = new Set();
const allSeries: Set<unknown> = new Set();
bucketColumns.forEach(({ id }) => {
if (!id) return;
rows.forEach((row) => {
const name = row[id];
if (!allSeries.includes(name)) {
allSeries.push(name);
}
if (id === parentBucketId && !parentSeries.includes(row[parentBucketId])) {
parentSeries.push(row[parentBucketId]);
allSeries.add(row[id]);
if (id === parentBucketId) {
parentSeries.add(row[parentBucketId]);
}
});
});
return { allSeries, parentSeries };
return { allSeries: [...allSeries], parentSeries: [...parentSeries] };
};
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const getLegendActions = (
visData,
columnIndex,
formatter.deserialize,
// FIXME key could be a RangeKey see https://github.com/elastic/kibana/issues/153437
pieSeries.key
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import type { PaletteOutput, PaletteDefinition } from '@kbn/coloring';
import { chartPluginMock } from '@kbn/charts-plugin/public/mocks';
import { Datatable } from '@kbn/expressions-plugin/common';
import { byDataColorPaletteMap } from './get_color';
import { ShapeTreeNode } from '@elastic/charts';
import { byDataColorPaletteMap, SimplifiedArrayNode } from './get_color';
import type { SeriesLayer } from '@kbn/coloring';
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import { fieldFormatsMock } from '@kbn/field-formats-plugin/common/mocks';
Expand All @@ -19,6 +18,7 @@ import { getColor } from './get_color';
import { createMockVisData, createMockBucketColumns, createMockPieParams } from '../../mocks';
import { generateFormatters } from '../formatters';
import { ChartTypes } from '../../../common/types';
import { getDistinctSeries } from '..';

describe('#byDataColorPaletteMap', () => {
let datatable: Datatable;
Expand Down Expand Up @@ -110,6 +110,8 @@ describe('getColor', () => {
}
const defaultFormatter = jest.fn((...args) => fieldFormatsMock.deserialize(...args));
const formatters = generateFormatters(visData, defaultFormatter);
const distinctSeries = getDistinctSeries(visData.rows, buckets);
const dataLength = { columnsLength: buckets.length, rowsLength: visData.rows.length };

dataMock.fieldFormats = {
deserialize: jest.fn(() => ({
Expand Down Expand Up @@ -145,24 +147,29 @@ describe('getColor', () => {
};
};
it('should return the correct color based on the parent sortIndex', () => {
const d = {
dataName: 'ES-Air',
const d: SimplifiedArrayNode = {
depth: 1,
sortIndex: 0,
parent: {
children: [['ES-Air'], ['Kibana Airlines']],
children: [
['ES-Air', undefined],
['Kibana Airlines', undefined],
],
depth: 0,
sortIndex: 0,
},
} as unknown as ShapeTreeNode;
children: [],
};

const color = getColor(
ChartTypes.PIE,
'ES-Air',
d,
0,
false,
{},
buckets,
visData.rows,
distinctSeries,
dataLength,
visParams,
getPaletteRegistry(),
{ getColor: () => undefined },
Expand All @@ -176,24 +183,28 @@ describe('getColor', () => {
});

it('slices with the same label should have the same color for small multiples', () => {
const d = {
dataName: 'ES-Air',
const d: SimplifiedArrayNode = {
depth: 1,
sortIndex: 0,
parent: {
children: [['ES-Air'], ['Kibana Airlines']],
children: [
['ES-Air', undefined],
['Kibana Airlines', undefined],
],
depth: 0,
sortIndex: 0,
},
} as unknown as ShapeTreeNode;
children: [],
};
const color = getColor(
ChartTypes.PIE,
'ES-Air',
d,
0,
true,
{},
buckets,
visData.rows,
distinctSeries,
dataLength,
visParams,
getPaletteRegistry(),
{ getColor: () => undefined },
Expand All @@ -206,24 +217,28 @@ describe('getColor', () => {
expect(color).toEqual('color3');
});
it('returns the overwriteColor if exists', () => {
const d = {
dataName: 'ES-Air',
const d: SimplifiedArrayNode = {
depth: 1,
sortIndex: 0,
parent: {
children: [['ES-Air'], ['Kibana Airlines']],
children: [
['ES-Air', undefined],
['Kibana Airlines', undefined],
],
depth: 0,
sortIndex: 0,
},
} as unknown as ShapeTreeNode;
children: [],
};
const color = getColor(
ChartTypes.PIE,
'ES-Air',
d,
0,
true,
{ 'ES-Air': '#000028' },
buckets,
visData.rows,
distinctSeries,
dataLength,
visParams,
getPaletteRegistry(),
{ getColor: () => undefined },
Expand All @@ -237,11 +252,7 @@ describe('getColor', () => {
});

it('returns the overwriteColor for older visualizations with formatted values', () => {
const d = {
dataName: {
gte: 1000,
lt: 2000,
},
const d: SimplifiedArrayNode = {
depth: 1,
sortIndex: 0,
parent: {
Expand All @@ -250,19 +261,22 @@ describe('getColor', () => {
{
gte: 1000,
lt: 2000,
},
}.toString(),
undefined,
],
[
{
gte: 2000,
lt: 3000,
},
}.toString(),
undefined,
],
],
depth: 0,
sortIndex: 0,
},
} as unknown as ShapeTreeNode;
children: [],
};
const visParamsNew = {
...visParams,
distinctColors: true,
Expand All @@ -278,12 +292,17 @@ describe('getColor', () => {
};
const color = getColor(
ChartTypes.PIE,
// There is the unhandled situation that the categoricalName passed is not a plain string but a RangeKey
// In this case, the internal code, thankfully, requires the stringified version of it and/or the formatted one
// handling also this badly configured type
// FIXME when getColor could handle both strings and RangeKey
{ gte: 1000, lt: 2000 } as unknown as string,
d,
0,
true,
{ '≥ 1000 and < 2000': '#3F6833' },
buckets,
visData.rows,
distinctSeries,
dataLength,
visParamsNew,
getPaletteRegistry(),
{ getColor: () => undefined },
Expand All @@ -297,30 +316,34 @@ describe('getColor', () => {
});

it('should only pass the second layer for mosaic', () => {
const d = {
dataName: 'Second level 1',
const d: SimplifiedArrayNode = {
depth: 2,
sortIndex: 0,
parent: {
children: [['Second level 1'], ['Second level 2']],
children: [
['Second level 1', undefined],
['Second level 2', undefined],
],
depth: 1,
sortIndex: 0,
parent: {
children: [['First level']],
children: [['First level', undefined]],
depth: 0,
sortIndex: 0,
},
},
} as unknown as ShapeTreeNode;
children: [],
};
const registry = getPaletteRegistry();
getColor(
ChartTypes.MOSAIC,
'Second level 1',
d,
1,
true,
{},
buckets,
visData.rows,
distinctSeries,
dataLength,
visParams,
registry,
undefined,
Expand All @@ -338,30 +361,34 @@ describe('getColor', () => {
});

it('should only pass the first layer for treemap', () => {
const d = {
dataName: 'Second level 1',
const d: SimplifiedArrayNode = {
depth: 2,
sortIndex: 0,
parent: {
children: [['Second level 1'], ['Second level 2']],
children: [
['Second level 1', undefined],
['Second level 2', undefined],
],
depth: 1,
sortIndex: 0,
parent: {
children: [['First level']],
children: [['First level', undefined]],
depth: 0,
sortIndex: 0,
},
},
} as unknown as ShapeTreeNode;
children: [],
};
const registry = getPaletteRegistry();
getColor(
ChartTypes.TREEMAP,
'Second level 1',
d,
1,
true,
{},
buckets,
visData.rows,
distinctSeries,
dataLength,
visParams,
registry,
undefined,
Expand Down
Loading

0 comments on commit b7c544f

Please sign in to comment.