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 2 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
elizabetdev 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
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 @@ -6,9 +6,7 @@

import { AbstractESAggSource } from '../es_agg_source';
import { ESGeoGridSourceDescriptor } from '../../../../common/descriptor_types';
import { IESAggField } from '../../fields/es_agg_field';

export class ESGeoGridSource extends AbstractESAggSource {
constructor(sourceDescriptor: ESGeoGridSourceDescriptor, inspectorAdapters: unknown);
getMetricFields(): IESAggField[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,49 @@ import { AGG_TYPE, ES_GEO_GRID, GRID_RESOLUTION, RENDER_AS } from '../../../../c
import { IField } from '../../fields/field';

describe('ESGeoGridSource', () => {
it('metrics and fields should match', async () => {
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 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 geogridSource = new ESGeoGridSource(
{
id: 'foobar',
indexPatternId: 'fooIp',
geoField: 'bar',
metrics: metricExamples,
resolution: GRID_RESOLUTION.COARSE,
type: ES_GEO_GRID,
requestType: RENDER_AS.HEATMAP,
},
{}
);

const fields = await geogridSource.getFields();
const metrics = await geogridSource.getMetricFields();

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

const fm = await Promise.all(fields.map(getFieldMeta));
const mm = await Promise.all(metrics.map(getFieldMeta));

expect(_.isEqual(fm, mm)).toEqual(true);

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(fm, [
_.isEqual(fieldsMeta, [
{
type: 'number',
field: 'sum_of_myFieldGettingSummed',
Expand All @@ -73,4 +67,13 @@ describe('ESGeoGridSource', () => {
])
).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 @@ -130,12 +130,9 @@ export class ColorMapSelect extends Component {
: '';
}

let toggle;
if (this.props.showColorMapTypeToggle) {
toggle = <EuiFlexItem grow={false}>{this._renderColorMapToggle()}</EuiFlexItem>;
} else {
toggle = <Fragment />;
}
const toggle = this.props.showColorMapTypeToggle ? (
<EuiFlexItem grow={false}>{this._renderColorMapToggle()}</EuiFlexItem>
) : null;

return (
<EuiFlexGroup gutterSize={'none'}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ import { CATEGORICAL_DATA_TYPES, COLOR_MAP_TYPE } from '../../../../../../common
import { COLOR_GRADIENTS, COLOR_PALETTES } from '../../../color_utils';
import { i18n } from '@kbn/i18n';

function getDefaultColorMapType(fieldType) {
return CATEGORICAL_DATA_TYPES.includes(fieldType)
? COLOR_MAP_TYPE.CATEGORICAL
: COLOR_MAP_TYPE.ORDINAL;
}

export function DynamicColorForm({
fields,
onDynamicStyleChange,
Expand Down Expand Up @@ -47,7 +41,9 @@ export function DynamicColorForm({

const onFieldChange = async ({ field }) => {
const { name, origin, type: fieldType } = field;
const defaultColorMapType = getDefaultColorMapType(fieldType);
const defaultColorMapType = CATEGORICAL_DATA_TYPES.includes(fieldType)
? COLOR_MAP_TYPE.CATEGORICAL
: COLOR_MAP_TYPE.ORDINAL;
onDynamicStyleChange(styleProperty.getStyleName(), {
...styleOptions,
field: { name, origin },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class VectorStyleEditor extends Component {
dateFields: [],
numberFields: [],
fields: [],
styleableFields: [],
ordinalAndCategoricalFields: [],
defaultDynamicProperties: getDefaultDynamicProperties(),
defaultStaticProperties: getDefaultStaticProperties(),
supportedFeatures: undefined,
Expand Down Expand Up @@ -70,25 +70,19 @@ export class VectorStyleEditor extends Component {
const fieldPromises = fields.map(getFieldMeta);
const fieldsArrayAll = await Promise.all(fieldPromises);
if (this._isMounted && !_.isEqual(fieldsArrayAll, this.state.fields)) {
thomasneirynck marked this conversation as resolved.
Show resolved Hide resolved
thomasneirynck marked this conversation as resolved.
Show resolved Hide resolved
this.setState({ fields: fieldsArrayAll });
return;
}

const styleableFields = fieldsArrayAll.filter(field => {
return CATEGORICAL_DATA_TYPES.includes(field.type) || ORDINAL_DATA_TYPES.includes(field.type);
this.setState({
fields: fieldsArrayAll,
ordinalAndCategoricalFields: fieldsArrayAll.filter(field => {
return (
CATEGORICAL_DATA_TYPES.includes(field.type) || ORDINAL_DATA_TYPES.includes(field.type)
);
}),
dateFields: fieldsArrayAll.filter(field => field.type === 'date'),
numberFields: fieldsArrayAll.filter(field => field.type === 'number'),
});
if (this._isMounted && !_.isEqual(styleableFields, this.state.styleableFields)) {
this.setState({ styleableFields: styleableFields });
}

const dateFieldsArray = styleableFields.filter(field => field.type === 'date');
if (this._isMounted && !_.isEqual(dateFieldsArray, this.state.dateFields)) {
this.setState({ dateFields: dateFieldsArray });
}

const numberFieldsArray = styleableFields.filter(field => field.type === 'number');
if (this._isMounted && !_.isEqual(numberFieldsArray, this.state.numberFields)) {
this.setState({ numberFields: numberFieldsArray });
}
}

async _loadSupportedFeatures() {
Expand Down Expand Up @@ -166,7 +160,7 @@ export class VectorStyleEditor extends Component {
onStaticStyleChange={this._onStaticStyleChange}
onDynamicStyleChange={this._onDynamicStyleChange}
styleProperty={this.props.styleProperties[VECTOR_STYLES.FILL_COLOR]}
fields={this.state.styleableFields}
fields={this.state.ordinalAndCategoricalFields}
defaultStaticStyleOptions={
this.state.defaultStaticProperties[VECTOR_STYLES.FILL_COLOR].options
}
Expand All @@ -187,7 +181,7 @@ export class VectorStyleEditor extends Component {
onStaticStyleChange={this._onStaticStyleChange}
onDynamicStyleChange={this._onDynamicStyleChange}
styleProperty={this.props.styleProperties[VECTOR_STYLES.LINE_COLOR]}
fields={this.state.styleableFields}
fields={this.state.ordinalAndCategoricalFields}
defaultStaticStyleOptions={
this.state.defaultStaticProperties[VECTOR_STYLES.LINE_COLOR].options
}
Expand Down Expand Up @@ -243,7 +237,7 @@ export class VectorStyleEditor extends Component {
onStaticStyleChange={this._onStaticStyleChange}
onDynamicStyleChange={this._onDynamicStyleChange}
styleProperty={this.props.styleProperties[VECTOR_STYLES.LABEL_COLOR]}
fields={this.state.styleableFields}
fields={this.state.ordinalAndCategoricalFields}
defaultStaticStyleOptions={
this.state.defaultStaticProperties[VECTOR_STYLES.LABEL_COLOR].options
}
Expand Down Expand Up @@ -276,7 +270,7 @@ export class VectorStyleEditor extends Component {
onStaticStyleChange={this._onStaticStyleChange}
onDynamicStyleChange={this._onDynamicStyleChange}
styleProperty={this.props.styleProperties[VECTOR_STYLES.LABEL_BORDER_COLOR]}
fields={this.state.styleableFields}
fields={this.state.ordinalAndCategoricalFields}
defaultStaticStyleOptions={
this.state.defaultStaticProperties[VECTOR_STYLES.LABEL_BORDER_COLOR].options
}
Expand Down Expand Up @@ -329,7 +323,7 @@ export class VectorStyleEditor extends Component {
onStaticStyleChange={this._onStaticStyleChange}
onDynamicStyleChange={this._onDynamicStyleChange}
styleProperty={this.props.styleProperties[VECTOR_STYLES.ICON]}
fields={this.state.styleableFields}
fields={this.state.ordinalAndCategoricalFields}
defaultStaticStyleOptions={
this.state.defaultStaticProperties[VECTOR_STYLES.ICON].options
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ test('Should pluck the categorical style-meta from fieldmeta', async () => {
});
});

test('Should read out categorical type correctly', async () => {
test('isCategorical should return true when type is categorical', async () => {
const categoricalColorStyle = makeProperty({
type: COLOR_MAP_TYPE.CATEGORICAL,
colorCategory: 'palette_0',
Expand All @@ -247,7 +247,7 @@ test('Should read out categorical type correctly', async () => {
expect(categoricalColorStyle.isCategorical()).toEqual(true);
});

test('Should read out ordinal correctly when type===undefined', async () => {
test('isOrdinal should return true when type is ordinal', async () => {
const ordinalColorStyle = makeProperty({
type: undefined,
color: 'Blues',
Expand Down