Skip to content

Commit bcf38e7

Browse files
[Maps] fix color-style disappears when mapping by percentiles when breaks are identical (#85654) (#85813)
* [Maps] fix color-style disappears when mapping by percentiles when breaks are identical * tslint Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent e28dd2a commit bcf38e7

2 files changed

Lines changed: 68 additions & 9 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { percentilesValuesToFieldMeta } from './dynamic_style_property';
8+
9+
describe('percentilesValuesToFieldMeta', () => {
10+
test('should return null when values is not defined', () => {
11+
expect(percentilesValuesToFieldMeta(undefined)).toBeNull();
12+
expect(percentilesValuesToFieldMeta({})).toBeNull();
13+
});
14+
15+
test('should convert values to percentiles field meta', () => {
16+
expect(percentilesValuesToFieldMeta(undefined)).toBeNull();
17+
expect(
18+
percentilesValuesToFieldMeta({
19+
values: {
20+
'25.0': 375.0,
21+
'50.0': 400.0,
22+
'75.0': 550.0,
23+
},
24+
})
25+
).toEqual([
26+
{ percentile: '25.0', value: 375.0 },
27+
{ percentile: '50.0', value: 400.0 },
28+
{ percentile: '75.0', value: 550.0 },
29+
]);
30+
});
31+
32+
test('should remove duplicated percentile percentilesValuesToFieldMeta', () => {
33+
expect(percentilesValuesToFieldMeta(undefined)).toBeNull();
34+
expect(
35+
percentilesValuesToFieldMeta({
36+
values: {
37+
'25.0': 375.0,
38+
'50.0': 375.0,
39+
'75.0': 550.0,
40+
},
41+
})
42+
).toEqual([
43+
{ percentile: '25.0', value: 375.0 },
44+
{ percentile: '75.0', value: 550.0 },
45+
]);
46+
});
47+
});

x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import {
2929
CategoryFieldMeta,
3030
FieldMetaOptions,
31+
PercentilesFieldMeta,
3132
RangeFieldMeta,
3233
StyleMetaData,
3334
} from '../../../../../common/descriptor_types';
@@ -144,15 +145,8 @@ export class DynamicStyleProperty<T>
144145
const styleMetaData = styleMetaDataRequest.getData() as StyleMetaData;
145146
const percentiles = styleMetaData[`${this._field.getRootName()}_percentiles`] as
146147
| undefined
147-
| { values?: { [key: string]: number } };
148-
return percentiles !== undefined && percentiles.values !== undefined
149-
? Object.keys(percentiles.values).map((key) => {
150-
return {
151-
percentile: key,
152-
value: percentiles.values![key],
153-
};
154-
})
155-
: null;
148+
| PercentilesValues;
149+
return percentilesValuesToFieldMeta(percentiles);
156150
}
157151

158152
getCategoryFieldMeta() {
@@ -499,3 +493,21 @@ export function getNumericalMbFeatureStateValue(value: RawValue) {
499493
const valueAsFloat = parseFloat(value);
500494
return isNaN(valueAsFloat) ? null : valueAsFloat;
501495
}
496+
497+
interface PercentilesValues {
498+
values?: { [key: string]: number };
499+
}
500+
export function percentilesValuesToFieldMeta(
501+
percentiles?: PercentilesValues | undefined
502+
): PercentilesFieldMeta | null {
503+
if (percentiles === undefined || percentiles.values === undefined) {
504+
return null;
505+
}
506+
const percentilesFieldMeta = Object.keys(percentiles.values).map((key) => {
507+
return {
508+
percentile: key,
509+
value: percentiles.values![key],
510+
};
511+
});
512+
return _.uniqBy(percentilesFieldMeta, 'value');
513+
}

0 commit comments

Comments
 (0)