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

[Maps] Support categorical styling for numbers and dates #57908

Merged
merged 41 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f544734
boilerplate
thomasneirynck Feb 18, 2020
4be903f
styling
thomasneirynck Feb 18, 2020
894a5ba
fix
thomasneirynck Feb 18, 2020
3f798be
remove cruft
thomasneirynck Feb 20, 2020
cc0738d
Improving color map select styles
miukimiu Feb 20, 2020
67fa1b8
enable for icon-fields
thomasneirynck Feb 23, 2020
09af833
remove unused
thomasneirynck Feb 23, 2020
42d7cd3
only include styleable fields
thomasneirynck Feb 23, 2020
6cf2e34
remove number fields
thomasneirynck Feb 23, 2020
42b1d88
remove date fields
thomasneirynck Feb 23, 2020
f927b75
add tooltip
thomasneirynck Feb 23, 2020
567c36b
change text
thomasneirynck Feb 23, 2020
1a8e11a
Merge branch 'master' into number_ordinals
elasticmachine Feb 24, 2020
417c44a
Merge branch 'master' into number_ordinals
thomasneirynck Feb 26, 2020
988b567
feedback
thomasneirynck Feb 26, 2020
5d09375
remove restriction
thomasneirynck Feb 26, 2020
fa3898d
Merge branch 'master' of github.com:elastic/kibana into number_ordinals
thomasneirynck Feb 26, 2020
d6565ff
add unit test
thomasneirynck Feb 26, 2020
444cbbf
more typing
thomasneirynck Feb 26, 2020
d029094
add style ts boilerplate
thomasneirynck Feb 27, 2020
970aeda
lint
thomasneirynck Feb 27, 2020
fbad9fe
Merge branch 'master' into maps/numbers_ordinals
thomasneirynck Mar 5, 2020
c6e2535
split tests
thomasneirynck Mar 5, 2020
6067fcd
Merge branch 'master' into maps/numbers_ordinals
thomasneirynck Mar 6, 2020
ef9e742
tslint fixes
thomasneirynck Mar 6, 2020
b6764d8
lint fix
thomasneirynck Mar 6, 2020
cb0e37a
fix name
thomasneirynck Mar 6, 2020
fee6793
fix faulty merge
thomasneirynck Mar 6, 2020
89d461d
init feedback
thomasneirynck Mar 6, 2020
fae5e84
more edits
thomasneirynck Mar 6, 2020
2958ba7
test
thomasneirynck Mar 7, 2020
cc08409
language
thomasneirynck Mar 7, 2020
3c4cd9b
add dummy test
thomasneirynck Mar 8, 2020
9180698
Merge branch 'master' into maps/numbers_ordinals
thomasneirynck Mar 9, 2020
6a3b99a
remove agg type
thomasneirynck Mar 9, 2020
7813255
remove getAggType
thomasneirynck Mar 9, 2020
1c7391d
add more boilerplate
thomasneirynck Mar 9, 2020
02c725e
remove cruft
thomasneirynck Mar 9, 2020
4756563
remove aggtype
thomasneirynck Mar 9, 2020
e7153db
formatting
thomasneirynck Mar 9, 2020
a66bb34
remove from constants
thomasneirynck Mar 9, 2020
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 x-pack/legacy/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export const COLOR_MAP_TYPE = {
export const COLOR_PALETTE_MAX_SIZE = 10;

export const CATEGORICAL_DATA_TYPES = ['string', 'ip', 'boolean'];
export const ORDINAL_DATA_TYPES = ['number', 'date'];

export const SYMBOLIZE_AS_TYPES = {
CIRCLE: 'circle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ export class ESDocField extends AbstractField {

async getCategoricalFieldMetaRequest() {
const field = await this._getField();
if (field.type !== 'string') {
//UX does not support categorical styling for number/date fields
return null;
}

const topTerms = {
size: COLOR_PALETTE_MAX_SIZE - 1, //need additional color for the "other"-value
};
Expand Down
12 changes: 0 additions & 12 deletions x-pack/legacy/plugins/maps/public/layers/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,6 @@ export class AbstractLayer {
return [];
}

async getDateFields() {
return [];
}

async getNumberFields() {
return [];
}

async getCategoricalFields() {
return [];
}

async getFields() {
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import { IESSource } from './es_source';
import { AbstractESSource } from './es_source';
import { AGG_TYPE } from '../../../common/constants';
import { IESAggField } from '../fields/es_agg_field';

export interface IESAggSource extends IESSource {
getAggKey(aggType: AGG_TYPE, fieldName: string): string;
getAggLabel(aggType: AGG_TYPE, fieldName: string): string;
getMetricFields(): IESAggField[];
}

export class AbstractESAggSource extends AbstractESSource implements IESAggSource {
getAggKey(aggType: AGG_TYPE, fieldName: string): string;
getAggLabel(aggType: AGG_TYPE, fieldName: string): string;
getMetricFields(): IESAggField[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export class AbstractESAggSource extends AbstractESSource {
}
}

async getFields() {
return this.getMetricFields();
}

getValueAggsDsl(indexPattern) {
const valueAggsDsl = {};
this.getMetricFields().forEach(esAggMetric => {
Expand All @@ -89,10 +93,6 @@ export class AbstractESAggSource extends AbstractESSource {
return valueAggsDsl;
}

async getNumberFields() {
return this.getMetricFields();
}

async filterAndFormatPropertiesToHtmlForMetricFields(properties) {
const metricFields = this.getMetricFields();
const tooltipPropertiesPromises = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
jest.mock('../../../kibana_services', () => {});
jest.mock('ui/new_platform');

import { ESGeoGridSource } from './es_geo_grid_source';
import { AGG_TYPE, ES_GEO_GRID, GRID_RESOLUTION, RENDER_AS } from '../../../../common/constants';
import { IField } from '../../fields/field';

describe('ESGeoGridSource', () => {
const metricExamples = [
{
type: AGG_TYPE.SUM,
field: 'myFieldGettingSummed',
label: 'my custom label',
},
{
// metric config is invalid beause field is missing
type: AGG_TYPE.MAX,
},
{
// metric config is valid because "count" metric does not need to provide field
type: AGG_TYPE.COUNT,
label: '', // should ignore empty label fields
},
];

const geogridSource = new ESGeoGridSource(
{
id: 'foobar',
indexPatternId: 'fooIp',
geoField: 'bar',
metrics: metricExamples,
resolution: GRID_RESOLUTION.COARSE,
type: ES_GEO_GRID,
requestType: RENDER_AS.HEATMAP,
},
{}
);

const getFieldMeta = async (field: IField) => {
return {
field: field.getName(),
label: await field.getLabel(),
type: await field.getDataType(),
};
};

it('getMetricFields should remove incomplete metric aggregations. Smaller tests t', async () => {
thomasneirynck marked this conversation as resolved.
Show resolved Hide resolved
const fields = await geogridSource.getFields();
const fieldsMeta = await Promise.all(fields.map(getFieldMeta));
expect(
thomasneirynck marked this conversation as resolved.
Show resolved Hide resolved
_.isEqual(fieldsMeta, [
{
type: 'number',
field: 'sum_of_myFieldGettingSummed',
label: 'my custom label',
},
{
type: 'number',
label: 'count',
field: 'doc_count',
},
])
).toEqual(true);
});

it('getFields should return getMetricFields', async () => {
const fields = await geogridSource.getFields();
const metrics = await geogridSource.getMetricFields();
const fieldsMeta = await Promise.all(fields.map(getFieldMeta));
const metricFieldsMeta = await Promise.all(metrics.map(getFieldMeta));

expect(_.isEqual(fieldsMeta, metricFieldsMeta)).toEqual(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
ES_GEO_FIELD_TYPE,
DEFAULT_MAX_BUCKETS_LIMIT,
SORT_ORDER,
CATEGORICAL_DATA_TYPES,
} from '../../../../common/constants';
import { i18n } from '@kbn/i18n';
import { getDataSourceLabel } from '../../../../common/i18n_getters';
Expand Down Expand Up @@ -135,49 +134,6 @@ export class ESSearchSource extends AbstractESSource {
);
}

async getNumberFields() {
try {
const indexPattern = await this.getIndexPattern();
return indexPattern.fields.getByType('number').map(field => {
return this.createField({ fieldName: field.name });
});
} catch (error) {
return [];
}
}

async getDateFields() {
try {
const indexPattern = await this.getIndexPattern();
return indexPattern.fields.getByType('date').map(field => {
return this.createField({ fieldName: field.name });
});
} catch (error) {
return [];
}
}

async getCategoricalFields() {
try {
const indexPattern = await this.getIndexPattern();

const aggFields = [];
CATEGORICAL_DATA_TYPES.forEach(dataType => {
indexPattern.fields.getByType(dataType).forEach(field => {
if (field.aggregatable) {
aggFields.push(field);
}
});
});
return aggFields.map(field => {
return this.createField({ fieldName: field.name });
});
} catch (error) {
//error surfaces in the LayerTOC UI
return [];
}
}

async getFields() {
try {
const indexPattern = await this.getIndexPattern();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { ESTermSource, extractPropertiesMap } from './es_term_source';
import _ from 'lodash';

jest.mock('ui/new_platform');
jest.mock('../vector_layer', () => {});
Expand Down Expand Up @@ -64,6 +65,30 @@ describe('getMetricFields', () => {
expect(metrics[1].getName()).toEqual('__kbnjoin__count_groupby_myIndex.myTermField');
expect(await metrics[1].getLabel()).toEqual('Count of myIndex');
});

it('should match getFields since term_source is agg_source', async () => {
thomasneirynck marked this conversation as resolved.
Show resolved Hide resolved
const source = new ESTermSource({
indexPatternTitle: indexPatternTitle,
term: termFieldName,
metrics: metricExamples,
});
const metrics = source.getMetricFields();
const fields = await source.getFields();

const getFieldMeta = async field => {
return {
aggType: field.getAggType(),
name: field.getName(),
label: await field.getLabel(),
esDoc: field.getRootName(),
};
};

const metricsFieldMeta = await Promise.all(metrics.map(getFieldMeta));
const fieldsFieldMeta = await Promise.all(fields.map(getFieldMeta));

expect(_.isEqual(metricsFieldMeta, fieldsFieldMeta)).toEqual(true);
});
});

describe('extractPropertiesMap', () => {
Expand Down
12 changes: 0 additions & 12 deletions x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,7 @@ export class AbstractVectorSource extends AbstractSource {
return null;
}

async getDateFields() {
return [];
}

async getNumberFields() {
return [];
}

async getFields() {
return [...(await this.getDateFields()), ...(await this.getNumberFields())];
}

async getCategoricalFields() {
return [];
}

Expand Down
Loading