mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
* [Maps] fix unable to pluck style meta from local data for geo_grid vector tiles for any property other then count * use metric instead of field value to be more precise Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Nathan Reese <reese.nathan@gmail.com>
This commit is contained in:
parent
76f374e00e
commit
9b7cdd9920
9 changed files with 197 additions and 17 deletions
|
@ -32,6 +32,13 @@ export type TileMetaFeature = Feature & {
|
|||
properties: {
|
||||
'hits.total.relation': string;
|
||||
'hits.total.value': number;
|
||||
|
||||
// For _mvt requests with "aggs" property in request: aggregation statistics returned in the pattern outined below
|
||||
// aggregations._count.min
|
||||
// aggregations._count.max
|
||||
// aggregations.<agg_name>.min
|
||||
// aggregations.<agg_name>.max
|
||||
[key: string]: number | string;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
import { IndexPattern } from 'src/plugins/data/public';
|
||||
import { AGG_TYPE } from '../../../../common/constants';
|
||||
import { TileMetaFeature } from '../../../../common/descriptor_types';
|
||||
import { CountAggField } from './count_agg_field';
|
||||
import { isMetricCountable } from '../../util/is_metric_countable';
|
||||
import { CountAggFieldParams } from './agg_field_types';
|
||||
|
@ -104,4 +105,17 @@ export class AggField extends CountAggField {
|
|||
async getCategoricalFieldMetaRequest(size: number): Promise<unknown> {
|
||||
return this._esDocField ? await this._esDocField.getCategoricalFieldMetaRequest(size) : null;
|
||||
}
|
||||
|
||||
pluckRangeFromTileMetaFeature(metaFeature: TileMetaFeature) {
|
||||
const minField = `aggregations.${this.getName()}.min`;
|
||||
const maxField = `aggregations.${this.getName()}.max`;
|
||||
return metaFeature.properties &&
|
||||
typeof metaFeature.properties[minField] === 'number' &&
|
||||
typeof metaFeature.properties[maxField] === 'number'
|
||||
? {
|
||||
min: metaFeature.properties[minField] as number,
|
||||
max: metaFeature.properties[maxField] as number,
|
||||
}
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import { IndexPattern } from 'src/plugins/data/public';
|
|||
import { IESAggSource } from '../../sources/es_agg_source';
|
||||
import { IVectorSource } from '../../sources/vector_source';
|
||||
import { AGG_TYPE, FIELD_ORIGIN } from '../../../../common/constants';
|
||||
import { TileMetaFeature } from '../../../../common/descriptor_types';
|
||||
import { ITooltipProperty, TooltipProperty } from '../../tooltips/tooltip_property';
|
||||
import { ESAggTooltipProperty } from '../../tooltips/es_agg_tooltip_property';
|
||||
import { IESAggField, CountAggFieldParams } from './agg_field_types';
|
||||
|
@ -109,4 +110,17 @@ export class CountAggField implements IESAggField {
|
|||
isEqual(field: IESAggField) {
|
||||
return field.getName() === this.getName();
|
||||
}
|
||||
|
||||
pluckRangeFromTileMetaFeature(metaFeature: TileMetaFeature) {
|
||||
const minField = `aggregations._count.min`;
|
||||
const maxField = `aggregations._count.max`;
|
||||
return metaFeature.properties &&
|
||||
typeof metaFeature.properties[minField] === 'number' &&
|
||||
typeof metaFeature.properties[maxField] === 'number'
|
||||
? {
|
||||
min: metaFeature.properties[minField] as number,
|
||||
max: metaFeature.properties[maxField] as number,
|
||||
}
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import { IESAggField } from './agg_field_types';
|
|||
import { IVectorSource } from '../../sources/vector_source';
|
||||
import { ITooltipProperty, TooltipProperty } from '../../tooltips/tooltip_property';
|
||||
import { TOP_TERM_PERCENTAGE_SUFFIX, FIELD_ORIGIN } from '../../../../common/constants';
|
||||
import { TileMetaFeature } from '../../../../common/descriptor_types';
|
||||
|
||||
export class TopTermPercentageField implements IESAggField {
|
||||
private readonly _topTermAggField: IESAggField;
|
||||
|
@ -90,4 +91,8 @@ export class TopTermPercentageField implements IESAggField {
|
|||
isEqual(field: IESAggField) {
|
||||
return field.getName() === this.getName();
|
||||
}
|
||||
|
||||
pluckRangeFromTileMetaFeature(metaFeature: TileMetaFeature) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { TileMetaFeature } from '../../../common/descriptor_types';
|
||||
import { FIELD_ORIGIN } from '../../../common/constants';
|
||||
import { IVectorSource } from '../sources/vector_source';
|
||||
import { ITooltipProperty, TooltipProperty } from '../tooltips/tooltip_property';
|
||||
|
@ -39,6 +40,8 @@ export interface IField {
|
|||
supportsFieldMetaFromEs(): boolean;
|
||||
|
||||
isEqual(field: IField): boolean;
|
||||
|
||||
pluckRangeFromTileMetaFeature(metaFeature: TileMetaFeature): { min: number; max: number } | null;
|
||||
}
|
||||
|
||||
export class AbstractField implements IField {
|
||||
|
@ -114,4 +117,8 @@ export class AbstractField implements IField {
|
|||
isEqual(field: IField) {
|
||||
return this._origin === field.getOrigin() && this._fieldName === field.getName();
|
||||
}
|
||||
|
||||
pluckRangeFromTileMetaFeature(metaFeature: TileMetaFeature) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -309,24 +309,17 @@ export class DynamicStyleProperty<T>
|
|||
pluckOrdinalStyleMetaFromTileMetaFeatures(
|
||||
metaFeatures: TileMetaFeature[]
|
||||
): RangeFieldMeta | null {
|
||||
if (!this.isOrdinal()) {
|
||||
if (!this._field || !this.isOrdinal()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const mbFieldName = this.getMbFieldName();
|
||||
let min = Infinity;
|
||||
let max = -Infinity;
|
||||
for (let i = 0; i < metaFeatures.length; i++) {
|
||||
const fieldMeta = metaFeatures[i].properties;
|
||||
const minField = `aggregations.${mbFieldName}.min`;
|
||||
const maxField = `aggregations.${mbFieldName}.max`;
|
||||
if (
|
||||
fieldMeta &&
|
||||
typeof fieldMeta[minField] === 'number' &&
|
||||
typeof fieldMeta[maxField] === 'number'
|
||||
) {
|
||||
min = Math.min(fieldMeta[minField] as number, min);
|
||||
max = Math.max(fieldMeta[maxField] as number, max);
|
||||
const range = this._field.pluckRangeFromTileMetaFeature(metaFeatures[i]);
|
||||
if (range) {
|
||||
min = Math.min(range.min, min);
|
||||
max = Math.max(range.max, max);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ export default function ({ loadTestFile, getService }) {
|
|||
loadTestFile(require.resolve('./joins'));
|
||||
loadTestFile(require.resolve('./mapbox_styles'));
|
||||
loadTestFile(require.resolve('./mvt_scaling'));
|
||||
loadTestFile(require.resolve('./mvt_super_fine'));
|
||||
loadTestFile(require.resolve('./mvt_geotile_grid'));
|
||||
loadTestFile(require.resolve('./add_layer_panel'));
|
||||
loadTestFile(require.resolve('./import_geojson'));
|
||||
loadTestFile(require.resolve('./layer_errors'));
|
||||
|
|
|
@ -14,13 +14,12 @@ export default function ({ getPageObjects, getService }) {
|
|||
const inspector = getService('inspector');
|
||||
const security = getService('security');
|
||||
|
||||
describe('mvt grid layer', () => {
|
||||
describe('mvt geotile grid layer', () => {
|
||||
before(async () => {
|
||||
await security.testUser.setRoles(
|
||||
['global_maps_all', 'test_logstash_reader', 'geoshape_data_reader'],
|
||||
false
|
||||
);
|
||||
await PageObjects.maps.loadSavedMap('geo grid vector grid example SUPER_FINE resolution');
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
|
@ -28,7 +27,8 @@ export default function ({ getPageObjects, getService }) {
|
|||
await security.testUser.restoreDefaults();
|
||||
});
|
||||
|
||||
it('should render with mvt-source', async () => {
|
||||
it('should render with mvt-source (style meta from ES)', async () => {
|
||||
await PageObjects.maps.loadSavedMap('MVT geotile grid (style meta from ES)');
|
||||
const mapboxStyle = await PageObjects.maps.getMapboxStyle();
|
||||
|
||||
//Source should be correct
|
||||
|
@ -79,5 +79,95 @@ export default function ({ getPageObjects, getService }) {
|
|||
'fill-opacity': 0.75,
|
||||
});
|
||||
});
|
||||
|
||||
it('should render with mvt-source (style meta from local - count)', async () => {
|
||||
await PageObjects.maps.loadSavedMap('MVT geotile grid (style meta from local - count)');
|
||||
const mapboxStyle = await PageObjects.maps.getMapboxStyle();
|
||||
|
||||
const fillLayer = mapboxStyle.layers.find(
|
||||
(layer) => layer.id === MB_VECTOR_SOURCE_ID + '_fill'
|
||||
);
|
||||
|
||||
expect(fillLayer.paint).to.eql({
|
||||
'fill-color': [
|
||||
'interpolate',
|
||||
['linear'],
|
||||
[
|
||||
'coalesce',
|
||||
[
|
||||
'case',
|
||||
['==', ['get', '_count'], null],
|
||||
0,
|
||||
['max', ['min', ['to-number', ['get', '_count']], 10], 1],
|
||||
],
|
||||
0,
|
||||
],
|
||||
0,
|
||||
'rgba(0,0,0,0)',
|
||||
1,
|
||||
'#ecf1f7',
|
||||
2.125,
|
||||
'#d9e3ef',
|
||||
3.25,
|
||||
'#c5d5e7',
|
||||
4.375,
|
||||
'#b2c7df',
|
||||
5.5,
|
||||
'#9eb9d8',
|
||||
6.625,
|
||||
'#8bacd0',
|
||||
7.75,
|
||||
'#769fc8',
|
||||
8.875,
|
||||
'#6092c0',
|
||||
],
|
||||
'fill-opacity': 0.75,
|
||||
});
|
||||
});
|
||||
|
||||
it('should render with mvt-source (style meta from local - metric)', async () => {
|
||||
await PageObjects.maps.loadSavedMap('MVT geotile grid (style meta from local - metric)');
|
||||
const mapboxStyle = await PageObjects.maps.getMapboxStyle();
|
||||
|
||||
const fillLayer = mapboxStyle.layers.find(
|
||||
(layer) => layer.id === MB_VECTOR_SOURCE_ID + '_fill'
|
||||
);
|
||||
|
||||
expect(fillLayer.paint).to.eql({
|
||||
'fill-color': [
|
||||
'interpolate',
|
||||
['linear'],
|
||||
[
|
||||
'coalesce',
|
||||
[
|
||||
'case',
|
||||
['==', ['get', 'sum_of_bytes.value'], null],
|
||||
-1,
|
||||
['max', ['min', ['to-number', ['get', 'sum_of_bytes.value']], 14941], 0],
|
||||
],
|
||||
-1,
|
||||
],
|
||||
-1,
|
||||
'rgba(0,0,0,0)',
|
||||
0,
|
||||
'#ecf1f7',
|
||||
1867.625,
|
||||
'#d9e3ef',
|
||||
3735.25,
|
||||
'#c5d5e7',
|
||||
5602.875,
|
||||
'#b2c7df',
|
||||
7470.5,
|
||||
'#9eb9d8',
|
||||
9338.125,
|
||||
'#8bacd0',
|
||||
11205.75,
|
||||
'#769fc8',
|
||||
13073.375,
|
||||
'#6092c0',
|
||||
],
|
||||
'fill-opacity': 0.75,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
|
@ -725,7 +725,7 @@
|
|||
"description": "",
|
||||
"layerListJSON": "[{\"id\":\"g1xkv\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"sourceDescriptor\":{\"resolution\":\"SUPER_FINE\",\"type\":\"ES_GEO_GRID\",\"id\":\"9305f6ea-4518-4c06-95b9-33321aa38d6a\",\"geoField\":\"geo.coordinates\",\"requestType\":\"grid\",\"metrics\":[{\"type\":\"count\"},{\"type\":\"max\",\"field\":\"bytes\"}],\"indexPatternRefName\":\"layer_0_source_index_pattern\",\"applyGlobalQuery\":true},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"DYNAMIC\",\"options\":{\"field\":{\"label\":\"max of bytes\",\"name\":\"max_of_bytes\",\"origin\":\"source\"},\"color\":\"Blues\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#cccccc\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"DYNAMIC\",\"options\":{\"field\":{\"label\":\"Count\",\"name\":\"doc_count\",\"origin\":\"source\"},\"minSize\":4,\"maxSize\":32}}},\"temporary\":true,\"previousStyle\":null},\"type\":\"TILED_VECTOR\"}]",
|
||||
"mapStateJSON": "{\"zoom\":3.59,\"center\":{\"lon\":-98.05765,\"lat\":38.32288},\"timeFilters\":{\"from\":\"2015-09-20T00:00:00.000Z\",\"to\":\"2015-09-20T01:00:00.000Z\"},\"refreshConfig\":{\"isPaused\":true,\"interval\":1000},\"settings\":{\"autoFitToDataBounds\":false}}",
|
||||
"title": "geo grid vector grid example SUPER_FINE resolution",
|
||||
"title": "MVT geotile grid (style meta from ES)",
|
||||
"uiStateJSON": "{\"isDarkMode\":false}"
|
||||
},
|
||||
"coreMigrationVersion": "8.0.0",
|
||||
|
@ -744,6 +744,56 @@
|
|||
"version": "WzU1LDJd"
|
||||
}
|
||||
|
||||
{
|
||||
"attributes": {
|
||||
"description":"",
|
||||
"layerListJSON":"[{\"id\":\"g1xkv\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"sourceDescriptor\":{\"resolution\":\"SUPER_FINE\",\"type\":\"ES_GEO_GRID\",\"id\":\"9305f6ea-4518-4c06-95b9-33321aa38d6a\",\"geoField\":\"geo.coordinates\",\"requestType\":\"grid\",\"metrics\":[{\"type\":\"count\"},{\"type\":\"max\",\"field\":\"bytes\"}],\"applyGlobalQuery\":true,\"indexPatternRefName\":\"layer_0_source_index_pattern\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"icon\":{\"type\":\"STATIC\",\"options\":{\"value\":\"marker\"}},\"fillColor\":{\"type\":\"DYNAMIC\",\"options\":{\"field\":{\"name\":\"doc_count\",\"origin\":\"source\"},\"color\":\"Blues\",\"type\":\"ORDINAL\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#cccccc\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"DYNAMIC\",\"options\":{\"field\":{\"label\":\"Count\",\"name\":\"doc_count\",\"origin\":\"source\"},\"minSize\":4,\"maxSize\":32}},\"iconOrientation\":{\"type\":\"STATIC\",\"options\":{\"orientation\":0}},\"labelText\":{\"type\":\"STATIC\",\"options\":{\"value\":\"\"}},\"labelColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#000000\"}},\"labelSize\":{\"type\":\"STATIC\",\"options\":{\"size\":14}},\"labelBorderColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"symbolizeAs\":{\"options\":{\"value\":\"circle\"}},\"labelBorderSize\":{\"options\":{\"size\":\"SMALL\"}}},\"isTimeAware\":true},\"type\":\"TILED_VECTOR\"}]",
|
||||
"mapStateJSON":"{\"zoom\":3.59,\"center\":{\"lon\":-98.05765,\"lat\":38.32288},\"timeFilters\":{\"from\":\"2015-09-20T00:00:00.000Z\",\"to\":\"2015-09-21T01:00:00.000Z\"},\"refreshConfig\":{\"isPaused\":true,\"interval\":1000},\"query\":{\"language\":\"kuery\",\"query\":\"\"},\"filters\":[],\"settings\":{\"autoFitToDataBounds\":false,\"backgroundColor\":\"#ffffff\",\"disableInteractive\":false,\"disableTooltipControl\":false,\"hideToolbarOverlay\":false,\"hideLayerControl\":false,\"hideViewControl\":false,\"initialLocation\":\"LAST_SAVED_LOCATION\",\"fixedLocation\":{\"lat\":0,\"lon\":0,\"zoom\":2},\"browserLocation\":{\"zoom\":2},\"maxZoom\":24,\"minZoom\":0,\"showScaleControl\":false,\"showSpatialFilters\":true,\"showTimesliderToggleButton\":true,\"spatialFiltersAlpa\":0.3,\"spatialFiltersFillColor\":\"#DA8B45\",\"spatialFiltersLineColor\":\"#DA8B45\"}}",
|
||||
"title":"MVT geotile grid (style meta from local - count)",
|
||||
"uiStateJSON":"{\"isLayerTOCOpen\":true,\"openTOCDetails\":[\"g1xkv\"]}"
|
||||
},
|
||||
"coreMigrationVersion":"8.1.0",
|
||||
"id":"943443a0-3b48-11ec-8a0d-af01166a5cc3",
|
||||
"migrationVersion": {
|
||||
"map":"8.0.0"
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"id":"c698b940-e149-11e8-a35a-370a8516603a",
|
||||
"name":"layer_0_source_index_pattern",
|
||||
"type":"index-pattern"
|
||||
}
|
||||
],
|
||||
"type":"map",
|
||||
"updated_at":"2021-11-01T19:20:50.287Z",
|
||||
"version":"WzkwLDFd"
|
||||
}
|
||||
|
||||
{
|
||||
"attributes": {
|
||||
"description":"",
|
||||
"layerListJSON":"[{\"id\":\"g1xkv\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"sourceDescriptor\":{\"resolution\":\"SUPER_FINE\",\"type\":\"ES_GEO_GRID\",\"id\":\"9305f6ea-4518-4c06-95b9-33321aa38d6a\",\"geoField\":\"geo.coordinates\",\"requestType\":\"grid\",\"metrics\":[{\"type\":\"count\"},{\"type\":\"sum\",\"field\":\"bytes\"}],\"applyGlobalQuery\":true,\"indexPatternRefName\":\"layer_0_source_index_pattern\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"icon\":{\"type\":\"STATIC\",\"options\":{\"value\":\"marker\"}},\"fillColor\":{\"type\":\"DYNAMIC\",\"options\":{\"field\":{\"origin\":\"source\",\"name\":\"sum_of_bytes\"},\"color\":\"Blues\",\"fieldMetaOptions\":{\"isEnabled\":false}}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#cccccc\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"DYNAMIC\",\"options\":{\"field\":{\"label\":\"Count\",\"name\":\"doc_count\",\"origin\":\"source\"},\"minSize\":4,\"maxSize\":32}},\"iconOrientation\":{\"type\":\"STATIC\",\"options\":{\"orientation\":0}},\"labelText\":{\"type\":\"STATIC\",\"options\":{\"value\":\"\"}},\"labelColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#000000\"}},\"labelSize\":{\"type\":\"STATIC\",\"options\":{\"size\":14}},\"labelBorderColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"symbolizeAs\":{\"options\":{\"value\":\"circle\"}},\"labelBorderSize\":{\"options\":{\"size\":\"SMALL\"}}},\"isTimeAware\":true},\"type\":\"TILED_VECTOR\"}]",
|
||||
"mapStateJSON":"{\"zoom\":3.59,\"center\":{\"lon\":-98.05765,\"lat\":38.32288},\"timeFilters\":{\"from\":\"2015-09-20T00:00:00.000Z\",\"to\":\"2015-09-20T04:00:00.000Z\"},\"refreshConfig\":{\"isPaused\":true,\"interval\":1000},\"query\":{\"language\":\"kuery\",\"query\":\"\"},\"filters\":[],\"settings\":{\"autoFitToDataBounds\":false,\"backgroundColor\":\"#ffffff\",\"disableInteractive\":false,\"disableTooltipControl\":false,\"hideToolbarOverlay\":false,\"hideLayerControl\":false,\"hideViewControl\":false,\"initialLocation\":\"LAST_SAVED_LOCATION\",\"fixedLocation\":{\"lat\":0,\"lon\":0,\"zoom\":2},\"browserLocation\":{\"zoom\":2},\"maxZoom\":24,\"minZoom\":0,\"showScaleControl\":false,\"showSpatialFilters\":true,\"showTimesliderToggleButton\":true,\"spatialFiltersAlpa\":0.3,\"spatialFiltersFillColor\":\"#DA8B45\",\"spatialFiltersLineColor\":\"#DA8B45\"}}",
|
||||
"title":"MVT geotile grid (style meta from local - metric)",
|
||||
"uiStateJSON":"{\"isLayerTOCOpen\":true,\"openTOCDetails\":[\"g1xkv\"]}"
|
||||
},
|
||||
"coreMigrationVersion":"8.1.0",
|
||||
"id":"9ff6f170-3b56-11ec-9cfb-57b0ede90800",
|
||||
"migrationVersion": {
|
||||
"map":"8.0.0"
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"id":"c698b940-e149-11e8-a35a-370a8516603a",
|
||||
"name":"layer_0_source_index_pattern",
|
||||
"type":"index-pattern"
|
||||
}
|
||||
],
|
||||
"type":"map",
|
||||
"updated_at":"2021-11-01T21:01:40.951Z",
|
||||
"version":"WzkyLDFd"
|
||||
}
|
||||
|
||||
{
|
||||
"attributes": {
|
||||
"description": "",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue