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 all 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 @@ -66,6 +66,7 @@ export type VectorSourceRequestMeta = MapFilters & {
applyGlobalTime: boolean;
fieldNames: string[];
geogridPrecision?: number;
timesiceMaskField?: string;
sourceQuery?: MapQuery;
sourceMeta: VectorSourceSyncMeta;
};
Expand All @@ -84,6 +85,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 @@ -35,6 +34,7 @@ import {
DynamicStylePropertyOptions,
StylePropertyOptions,
LayerDescriptor,
Timeslice,
VectorLayerDescriptor,
VectorSourceRequestMeta,
VectorStylePropertiesDescriptor,
Expand All @@ -46,10 +46,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 +212,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 +290,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 All @@ -305,6 +301,9 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
prevDataRequest: this.getDataRequest(dataRequestId),
nextMeta: searchFilters,
extentAware: source.isFilterByMapBounds(),
getUpdateDueToTimeslice: (timeslice?: Timeslice) => {
return this._getUpdateDueToTimesliceFromSourceRequestMeta(source, timeslice);
},
});

let activeSource;
Expand All @@ -322,22 +321,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
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ export class HeatmapLayer extends AbstractLayer {
},
syncContext,
source: this.getSource(),
getUpdateDueToTimeslice: () => {
return true;
},
});
} catch (error) {
if (!(error instanceof DataRequestAbortError)) {
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 @@ -21,6 +21,7 @@ import { VectorLayer, VectorLayerArguments } from '../vector_layer';
import { ITiledSingleLayerVectorSource } from '../../sources/tiled_single_layer_vector_source';
import { DataRequestContext } from '../../../actions';
import {
Timeslice,
VectorLayerDescriptor,
VectorSourceRequestMeta,
} from '../../../../common/descriptor_types';
Expand Down Expand Up @@ -66,7 +67,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 All @@ -84,6 +85,10 @@ export class TiledVectorLayer extends VectorLayer {
source: this.getSource(),
prevDataRequest,
nextMeta: searchFilters,
getUpdateDueToTimeslice: (timeslice?: Timeslice) => {
// TODO use meta features to determine if tiles already contain features for timeslice.
return true;
},
});
const canSkip = noChangesInSourceState && noChangesInSearchState;
if (canSkip) {
Expand Down
20 changes: 18 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,13 @@ import {
SOURCE_DATA_REQUEST_ID,
VECTOR_SHAPE_TYPE,
} from '../../../../common/constants';
import { MapExtent, MapQuery, VectorSourceRequestMeta } from '../../../../common/descriptor_types';
import {
DataMeta,
MapExtent,
MapQuery,
Timeslice,
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 @@ -52,13 +58,15 @@ export async function syncVectorSource({
requestMeta,
syncContext,
source,
getUpdateDueToTimeslice,
}: {
layerId: string;
layerName: string;
prevDataRequest: DataRequest | undefined;
requestMeta: VectorSourceRequestMeta;
syncContext: DataRequestContext;
source: IVectorSource;
getUpdateDueToTimeslice: (timeslice?: Timeslice) => boolean;
}): Promise<{ refreshed: boolean; featureCollection: FeatureCollection }> {
const {
startLoading,
Expand All @@ -76,6 +84,7 @@ export async function syncVectorSource({
prevDataRequest,
nextMeta: requestMeta,
extentAware: source.isFilterByMapBounds(),
getUpdateDueToTimeslice,
});
if (canSkipFetch) {
return {
Expand Down Expand Up @@ -104,7 +113,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
Loading