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] choropleth layer wizard #69699

Merged
merged 22 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 16 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
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { i18n } from '@kbn/i18n';
import { LAYER_WIZARD_CATEGORY } from '../../../../common/constants';
import { LayerWizard, RenderWizardArguments } from '../layer_wizard_registry';
import { LayerTemplate } from './layer_template';

export const choroplethLayerWizardConfig: LayerWizard = {
categories: [LAYER_WIZARD_CATEGORY.ELASTICSEARCH],
description: i18n.translate('xpack.maps.choropleth.desc', {
defaultMessage: 'Shaded areas to compare statistics across boundaries',
}),
icon: 'logoElasticsearch',
renderWizard: (renderWizardArguments: RenderWizardArguments) => {
return <LayerTemplate {...renderWizardArguments} />;
},
title: i18n.translate('xpack.maps.choropleth.title', {
defaultMessage: 'Choropleth',
}),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import uuid from 'uuid/v4';
import {
AGG_TYPE,
COLOR_MAP_TYPE,
FIELD_ORIGIN,
SCALING_TYPES,
SOURCE_TYPES,
STYLE_TYPE,
VECTOR_STYLES,
} from '../../../../common/constants';
import { getJoinAggKey } from '../../../../common/get_agg_key';
import {
AggDescriptor,
ColorDynamicOptions,
EMSFileSourceDescriptor,
ESSearchSourceDescriptor,
} from '../../../../common/descriptor_types';
import { VectorStyle } from '../../styles/vector/vector_style';
import { VectorLayer } from '../vector_layer/vector_layer';
import { EMSFileSource } from '../../sources/ems_file_source';
// @ts-ignore
import { ESSearchSource } from '../../sources/es_search_source';
import { getDefaultDynamicProperties } from '../../styles/vector/vector_style_defaults';

const defaultDynamicProperties = getDefaultDynamicProperties();

function createChoroplethLayerDescriptor({
sourceDescriptor,
leftField,
rightIndexPatternId,
rightIndexPatternTitle,
rightTermField,
}: {
sourceDescriptor: EMSFileSourceDescriptor | ESSearchSourceDescriptor;
leftField: string;
rightIndexPatternId: string;
rightIndexPatternTitle: string;
rightTermField: string;
}) {
const metricsDescriptor: AggDescriptor = { type: AGG_TYPE.COUNT };
const joinId = uuid();
const joinKey = getJoinAggKey({
aggType: metricsDescriptor.type,
aggFieldName: metricsDescriptor.field ? metricsDescriptor.field : '',
rightSourceId: joinId,
});
return VectorLayer.createDescriptor({
thomasneirynck marked this conversation as resolved.
Show resolved Hide resolved
joins: [
nreese marked this conversation as resolved.
Show resolved Hide resolved
{
leftField,
right: {
type: SOURCE_TYPES.ES_TERM_SOURCE,
id: joinId,
indexPatternId: rightIndexPatternId,
indexPatternTitle: rightIndexPatternTitle,
term: rightTermField,
metrics: [metricsDescriptor],
},
},
],
sourceDescriptor,
style: VectorStyle.createDescriptor({
[VECTOR_STYLES.FILL_COLOR]: {
type: STYLE_TYPE.DYNAMIC,
options: {
...(defaultDynamicProperties[VECTOR_STYLES.FILL_COLOR]!.options as ColorDynamicOptions),
field: {
name: joinKey,
origin: FIELD_ORIGIN.JOIN,
},
color: 'Yellow to Red',
type: COLOR_MAP_TYPE.ORDINAL,
},
},
[VECTOR_STYLES.LINE_COLOR]: {
type: STYLE_TYPE.STATIC,
options: {
color: '#3d3d3d',
},
},
}),
});
}

export function createEmsChoroplethLayerDescriptor({
leftEmsFileId,
leftEmsField,
rightIndexPatternId,
rightIndexPatternTitle,
rightTermField,
}: {
leftEmsFileId: string;
leftEmsField: string;
rightIndexPatternId: string;
rightIndexPatternTitle: string;
rightTermField: string;
}) {
return createChoroplethLayerDescriptor({
sourceDescriptor: EMSFileSource.createDescriptor({
id: leftEmsFileId,
tooltipProperties: [leftEmsField],
}),
leftField: leftEmsField,
rightIndexPatternId,
rightIndexPatternTitle,
rightTermField,
});
}

export function createEsChoroplethLayerDescriptor({
leftIndexPatternId,
leftGeoField,
leftJoinField,
rightIndexPatternId,
rightIndexPatternTitle,
rightTermField,
}: {
leftIndexPatternId: string;
leftGeoField: string;
leftJoinField: string;
rightIndexPatternId: string;
rightIndexPatternTitle: string;
rightTermField: string;
}) {
return createChoroplethLayerDescriptor({
sourceDescriptor: ESSearchSource.createDescriptor({
indexPatternId: leftIndexPatternId,
geoField: leftGeoField,
scalingType: SCALING_TYPES.LIMIT,
tooltipProperties: [leftJoinField],
}),
leftField: leftJoinField,
rightIndexPatternId,
rightIndexPatternTitle,
rightTermField,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export { choroplethLayerWizardConfig } from './choropleth_layer_wizard';
Loading