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

Mask timeslider #102046

Merged
merged 20 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
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 @@ -65,6 +65,7 @@ export type VectorSourceRequestMeta = MapFilters & {
applyGlobalTime: boolean;
fieldNames: string[];
geogridPrecision?: number;
timesiceMaskField?: string;
sourceQuery?: MapQuery;
sourceMeta: VectorSourceSyncMeta;
};
Expand All @@ -83,6 +84,9 @@ export type VectorStyleRequestMeta = MapFilters & {
export type ESSearchSourceResponseMeta = {
areResultsTrimmed?: boolean;
resultsCount?: number;
// results time extent, either Kibana time range or timeslider time slice
timeExtent?: Timeslice;
isTimeExtentForTimeslice?: boolean;

// top hits meta
areEntitiesTrimmed?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
LAYER_STYLE_TYPE,
FIELD_ORIGIN,
} from '../../../../common/constants';
import { isTotalHitsGreaterThan, TotalHits } from '../../../../common/elasticsearch_util';
import { ESGeoGridSource } from '../../sources/es_geo_grid_source/es_geo_grid_source';
import { canSkipSourceUpdate } from '../../util/can_skip_fetch';
import { IESSource } from '../../sources/es_source';
Expand All @@ -46,10 +45,6 @@ import { isSearchSourceAbortError } from '../../sources/es_source/es_source';

const ACTIVE_COUNT_DATA_ID = 'ACTIVE_COUNT_DATA_ID';

interface CountData {
isSyncClustered: boolean;
}

function getAggType(
dynamicProperty: IDynamicStyleProperty<DynamicStylePropertyOptions>
): AGG_TYPE.AVG | AGG_TYPE.TERMS {
Expand Down Expand Up @@ -216,7 +211,7 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
let isClustered = false;
const countDataRequest = this.getDataRequest(ACTIVE_COUNT_DATA_ID);
if (countDataRequest) {
const requestData = countDataRequest.getData() as CountData;
const requestData = countDataRequest.getData() as { isSyncClustered: boolean };
if (requestData && requestData.isSyncClustered) {
isClustered = true;
}
Expand Down Expand Up @@ -294,7 +289,7 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
async syncData(syncContext: DataRequestContext) {
const dataRequestId = ACTIVE_COUNT_DATA_ID;
const requestToken = Symbol(`layer-active-count:${this.getId()}`);
const searchFilters: VectorSourceRequestMeta = this._getSearchFilters(
const searchFilters: VectorSourceRequestMeta = await this._getSearchFilters(
syncContext.dataFilters,
this.getSource(),
this.getCurrentStyle()
Expand Down Expand Up @@ -322,22 +317,11 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
let isSyncClustered;
try {
syncContext.startLoading(dataRequestId, requestToken, searchFilters);
const abortController = new AbortController();
syncContext.registerCancelCallback(requestToken, () => abortController.abort());
const maxResultWindow = await this._documentSource.getMaxResultWindow();
const searchSource = await this._documentSource.makeSearchSource(searchFilters, 0);
searchSource.setField('trackTotalHits', maxResultWindow + 1);
const resp = await searchSource.fetch({
abortSignal: abortController.signal,
sessionId: syncContext.dataFilters.searchSessionId,
legacyHitsTotal: false,
});
isSyncClustered = isTotalHitsGreaterThan(
(resp.hits.total as unknown) as TotalHits,
maxResultWindow
);
const countData = { isSyncClustered } as CountData;
syncContext.stopLoading(dataRequestId, requestToken, countData, searchFilters);
isSyncClustered = !(await this._documentSource.canLoadAllDocuments(
searchFilters,
syncContext.registerCancelCallback.bind(null, requestToken)
));
syncContext.stopLoading(dataRequestId, requestToken, { isSyncClustered }, searchFilters);
} catch (error) {
if (!(error instanceof DataRequestAbortError) || !isSearchSourceAbortError(error)) {
syncContext.onLoadError(dataRequestId, requestToken, error.message);
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/maps/public/classes/layers/layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
LayerDescriptor,
MapExtent,
StyleDescriptor,
Timeslice,
} from '../../../common/descriptor_types';
import { ImmutableSourceProperty, ISource, SourceEditorArgs } from '../sources/source';
import { DataRequestContext } from '../../actions';
Expand Down Expand Up @@ -78,7 +79,7 @@ export interface ILayer {
getMbLayerIds(): string[];
ownsMbLayerId(mbLayerId: string): boolean;
ownsMbSourceId(mbSourceId: string): boolean;
syncLayerWithMB(mbMap: MbMap): void;
syncLayerWithMB(mbMap: MbMap, timeslice?: Timeslice): void;
getLayerTypeIconName(): string;
isInitialDataLoadComplete(): boolean;
getIndexPatternIds(): string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class TiledVectorLayer extends VectorLayer {
dataFilters,
}: DataRequestContext) {
const requestToken: symbol = Symbol(`layer-${this.getId()}-${SOURCE_DATA_REQUEST_ID}`);
const searchFilters: VectorSourceRequestMeta = this._getSearchFilters(
const searchFilters: VectorSourceRequestMeta = await this._getSearchFilters(
dataFilters,
this.getSource(),
this._style as IVectorStyle
Expand Down
16 changes: 14 additions & 2 deletions x-pack/plugins/maps/public/classes/layers/vector_layer/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import {
SOURCE_DATA_REQUEST_ID,
VECTOR_SHAPE_TYPE,
} from '../../../../common/constants';
import { MapExtent, MapQuery, VectorSourceRequestMeta } from '../../../../common/descriptor_types';
import {
DataMeta,
MapExtent,
MapQuery,
VectorSourceRequestMeta,
} from '../../../../common/descriptor_types';
import { DataRequestContext } from '../../../actions';
import { IVectorSource } from '../../sources/vector_source';
import { DataRequestAbortError } from '../../util/data_request';
Expand Down Expand Up @@ -102,7 +107,14 @@ export async function syncVectorSource({
) {
layerFeatureCollection.features.push(...getCentroidFeatures(layerFeatureCollection));
}
stopLoading(dataRequestId, requestToken, layerFeatureCollection, meta);
const responseMeta: DataMeta = meta ? { ...meta } : {};
if (requestMeta.applyGlobalTime && (await source.isTimeAware())) {
const timesiceMaskField = await source.getTimesliceMaskFieldName();
if (timesiceMaskField) {
responseMeta.timesiceMaskField = timesiceMaskField;
}
}
stopLoading(dataRequestId, requestToken, layerFeatureCollection, responseMeta);
return {
refreshed: true,
featureCollection: layerFeatureCollection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ import {
getFillFilterExpression,
getLineFilterExpression,
getPointFilterExpression,
TimesliceMaskConfig,
} from '../../util/mb_filter_expressions';

import {
DynamicStylePropertyOptions,
MapFilters,
MapQuery,
Timeslice,
VectorJoinSourceRequestMeta,
VectorLayerDescriptor,
VectorSourceRequestMeta,
Expand Down Expand Up @@ -381,17 +383,22 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
return await Promise.all(joinSyncs);
}

_getSearchFilters(
async _getSearchFilters(
dataFilters: MapFilters,
source: IVectorSource,
style: IVectorStyle
): VectorSourceRequestMeta {
): Promise<VectorSourceRequestMeta> {
const fieldNames = [
...source.getFieldNames(),
...style.getSourceFieldNames(),
...this.getValidJoins().map((join) => join.getLeftField().getName()),
];

const timesliceMaskFieldName = await source.getTimesliceMaskFieldName();
if (timesliceMaskFieldName) {
fieldNames.push(timesliceMaskFieldName);
}

const sourceQuery = this.getQuery() as MapQuery;
return {
...dataFilters,
Expand Down Expand Up @@ -666,7 +673,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
layerId: this.getId(),
layerName: await this.getDisplayName(source),
prevDataRequest: this.getSourceDataRequest(),
requestMeta: this._getSearchFilters(syncContext.dataFilters, source, style),
requestMeta: await this._getSearchFilters(syncContext.dataFilters, source, style),
syncContext,
source,
});
Expand Down Expand Up @@ -718,7 +725,11 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
}
}

_setMbPointsProperties(mbMap: MbMap, mvtSourceLayer?: string) {
_setMbPointsProperties(
mbMap: MbMap,
mvtSourceLayer?: string,
timesliceMaskConfig?: TimesliceMaskConfig
) {
const pointLayerId = this._getMbPointLayerId();
const symbolLayerId = this._getMbSymbolLayerId();
const pointLayer = mbMap.getLayer(pointLayerId);
Expand All @@ -735,15 +746,15 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
if (symbolLayer) {
mbMap.setLayoutProperty(symbolLayerId, 'visibility', 'none');
}
this._setMbCircleProperties(mbMap, mvtSourceLayer);
this._setMbCircleProperties(mbMap, mvtSourceLayer, timesliceMaskConfig);
} else {
markerLayerId = symbolLayerId;
textLayerId = symbolLayerId;
if (pointLayer) {
mbMap.setLayoutProperty(pointLayerId, 'visibility', 'none');
mbMap.setLayoutProperty(this._getMbTextLayerId(), 'visibility', 'none');
}
this._setMbSymbolProperties(mbMap, mvtSourceLayer);
this._setMbSymbolProperties(mbMap, mvtSourceLayer, timesliceMaskConfig);
}

this.syncVisibilityWithMb(mbMap, markerLayerId);
Expand All @@ -754,7 +765,11 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
}
}

_setMbCircleProperties(mbMap: MbMap, mvtSourceLayer?: string) {
_setMbCircleProperties(
mbMap: MbMap,
mvtSourceLayer?: string,
timesliceMaskConfig?: TimesliceMaskConfig
) {
const sourceId = this.getId();
const pointLayerId = this._getMbPointLayerId();
const pointLayer = mbMap.getLayer(pointLayerId);
Expand Down Expand Up @@ -786,7 +801,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
mbMap.addLayer(mbLayer);
}

const filterExpr = getPointFilterExpression(this.hasJoins());
const filterExpr = getPointFilterExpression(this.hasJoins(), timesliceMaskConfig);
if (!_.isEqual(filterExpr, mbMap.getFilter(pointLayerId))) {
mbMap.setFilter(pointLayerId, filterExpr);
mbMap.setFilter(textLayerId, filterExpr);
Expand All @@ -805,7 +820,11 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
});
}

_setMbSymbolProperties(mbMap: MbMap, mvtSourceLayer?: string) {
_setMbSymbolProperties(
mbMap: MbMap,
mvtSourceLayer?: string,
timesliceMaskConfig?: TimesliceMaskConfig
) {
const sourceId = this.getId();
const symbolLayerId = this._getMbSymbolLayerId();
const symbolLayer = mbMap.getLayer(symbolLayerId);
Expand All @@ -822,7 +841,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
mbMap.addLayer(mbLayer);
}

const filterExpr = getPointFilterExpression(this.hasJoins());
const filterExpr = getPointFilterExpression(this.hasJoins(), timesliceMaskConfig);
if (!_.isEqual(filterExpr, mbMap.getFilter(symbolLayerId))) {
mbMap.setFilter(symbolLayerId, filterExpr);
}
Expand All @@ -840,7 +859,11 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
});
}

_setMbLinePolygonProperties(mbMap: MbMap, mvtSourceLayer?: string) {
_setMbLinePolygonProperties(
mbMap: MbMap,
mvtSourceLayer?: string,
timesliceMaskConfig?: TimesliceMaskConfig
) {
const sourceId = this.getId();
const fillLayerId = this._getMbPolygonLayerId();
const lineLayerId = this._getMbLineLayerId();
Expand Down Expand Up @@ -904,14 +927,14 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {

this.syncVisibilityWithMb(mbMap, fillLayerId);
mbMap.setLayerZoomRange(fillLayerId, this.getMinZoom(), this.getMaxZoom());
const fillFilterExpr = getFillFilterExpression(hasJoins);
const fillFilterExpr = getFillFilterExpression(hasJoins, timesliceMaskConfig);
if (!_.isEqual(fillFilterExpr, mbMap.getFilter(fillLayerId))) {
mbMap.setFilter(fillLayerId, fillFilterExpr);
}

this.syncVisibilityWithMb(mbMap, lineLayerId);
mbMap.setLayerZoomRange(lineLayerId, this.getMinZoom(), this.getMaxZoom());
const lineFilterExpr = getLineFilterExpression(hasJoins);
const lineFilterExpr = getLineFilterExpression(hasJoins, timesliceMaskConfig);
if (!_.isEqual(lineFilterExpr, mbMap.getFilter(lineLayerId))) {
mbMap.setFilter(lineLayerId, lineFilterExpr);
}
Expand All @@ -920,7 +943,11 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
mbMap.setLayerZoomRange(tooManyFeaturesLayerId, this.getMinZoom(), this.getMaxZoom());
}

_setMbCentroidProperties(mbMap: MbMap, mvtSourceLayer?: string) {
_setMbCentroidProperties(
mbMap: MbMap,
mvtSourceLayer?: string,
timesliceMaskConfig?: TimesliceMaskConfig
) {
const centroidLayerId = this._getMbCentroidLayerId();
const centroidLayer = mbMap.getLayer(centroidLayerId);
if (!centroidLayer) {
Expand All @@ -935,7 +962,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
mbMap.addLayer(mbLayer);
}

const filterExpr = getCentroidFilterExpression(this.hasJoins());
const filterExpr = getCentroidFilterExpression(this.hasJoins(), timesliceMaskConfig);
if (!_.isEqual(filterExpr, mbMap.getFilter(centroidLayerId))) {
mbMap.setFilter(centroidLayerId, filterExpr);
}
Expand All @@ -950,17 +977,32 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
mbMap.setLayerZoomRange(centroidLayerId, this.getMinZoom(), this.getMaxZoom());
}

_syncStylePropertiesWithMb(mbMap: MbMap) {
this._setMbPointsProperties(mbMap);
this._setMbLinePolygonProperties(mbMap);
_syncStylePropertiesWithMb(mbMap: MbMap, timeslice?: Timeslice) {
const timesliceMaskConfig = this._getTimesliceMaskConfig(timeslice);
this._setMbPointsProperties(mbMap, undefined, timesliceMaskConfig);
this._setMbLinePolygonProperties(mbMap, undefined, timesliceMaskConfig);
// centroid layers added after polygon layers to ensure they are on top of polygon layers
this._setMbCentroidProperties(mbMap);
this._setMbCentroidProperties(mbMap, undefined, timesliceMaskConfig);
}

_getTimesliceMaskConfig(timeslice?: Timeslice): TimesliceMaskConfig | undefined {
if (!timeslice || this.hasJoins()) {
return;
}

const prevMeta = this.getSourceDataRequest()?.getMeta();
return prevMeta !== undefined && prevMeta.timesiceMaskField !== undefined
? {
timesiceMaskField: prevMeta.timesiceMaskField,
timeslice,
}
: undefined;
}

syncLayerWithMB(mbMap: MbMap) {
syncLayerWithMB(mbMap: MbMap, timeslice?: Timeslice) {
addGeoJsonMbSource(this._getMbSourceId(), this.getMbLayerIds(), mbMap);
this._syncFeatureCollectionWithMb(mbMap);
this._syncStylePropertiesWithMb(mbMap);
this._syncStylePropertiesWithMb(mbMap, timeslice);
}

_getMbPointLayerId() {
Expand Down
Loading