Skip to content

Commit

Permalink
[Maps] Introduce typed styles (#49803)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck authored Oct 31, 2019
1 parent 559ac84 commit 479177a
Show file tree
Hide file tree
Showing 61 changed files with 504 additions and 250 deletions.
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import _ from 'lodash';
import { AbstractLayer } from './layer';
import { VectorLayer } from './vector_layer';
import { HeatmapStyle } from './styles/heatmap_style';
import { HeatmapStyle } from './styles/heatmap/heatmap_style';
import { EMPTY_FEATURE_COLLECTION, LAYER_TYPE } from '../../common/constants';

const SCALED_PROPERTY_NAME = '__kbn_heatmap_weight__';//unique name to store scaled value for weighting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


import { ESTermSource } from '../sources/es_term_source';
import { VectorStyle } from '../styles/vector_style';
import { VectorStyle } from '../styles/vector/vector_style';

export class InnerJoin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { Schemas } from 'ui/vis/editors/default/schemas';
import { AggConfigs } from 'ui/agg_types';
import { tabifyAggResponse } from 'ui/agg_response/tabify';
import { convertToGeoJson } from './convert_to_geojson';
import { VectorStyle } from '../../styles/vector_style';
import { vectorStyles } from '../../styles/vector_style_defaults';
import { VectorStyle } from '../../styles/vector/vector_style';
import { vectorStyles } from '../../styles/vector/vector_style_defaults';
import { RENDER_AS } from './render_as';
import { CreateSourceEditor } from './create_source_editor';
import { UpdateSourceEditor } from './update_source_editor';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { VECTOR_SHAPE_TYPES } from '../vector_feature_types';
import { VectorLayer } from '../../vector_layer';
import { CreateSourceEditor } from './create_source_editor';
import { UpdateSourceEditor } from './update_source_editor';
import { VectorStyle } from '../../styles/vector_style';
import { vectorStyles } from '../../styles/vector_style_defaults';
import { VectorStyle } from '../../styles/vector/vector_style';
import { vectorStyles } from '../../styles/vector/vector_style_defaults';
import { i18n } from '@kbn/i18n';
import { SOURCE_DATA_ID_ORIGIN, ES_PEW_PEW } from '../../../../common/constants';
import { getDataSourceLabel } from '../../../../common/i18n_getters';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { VectorLayer } from '../vector_layer';
import { TooltipProperty } from '../tooltips/tooltip_property';
import { VectorStyle } from '../styles/vector_style';
import { VectorStyle } from '../styles/vector/vector_style';
import { AbstractSource } from './source';
import * as topojson from 'topojson-client';
import _ from 'lodash';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@import './components/color_gradient';
@import './components/static_dynamic_style_row';
@import './components/vector/color/color_stops';
@import './vector/components/color/color_stops';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React from 'react';
import { VectorStyle } from '../vector_style';
import { VectorStyle } from '../vector/vector_style';
import _ from 'lodash';
import { i18n } from '@kbn/i18n';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React from 'react';

import { EuiFormRow, EuiSuperSelect } from '@elastic/eui';
import { COLOR_GRADIENTS } from '../../color_utils';
import { ColorGradient } from '../color_gradient';
import { ColorGradient } from '../../components/color_gradient';
import {
DEFAULT_RGB_HEATMAP_COLOR_RAMP,
DEFAULT_HEATMAP_COLOR_RAMP_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import React from 'react';

import { i18n } from '@kbn/i18n';
import { ColorGradient } from '../../color_gradient';
import { StyleLegendRow } from '../../style_legend_row';
import { ColorGradient } from '../../../components/color_gradient';
import { StyleLegendRow } from '../../../components/style_legend_row';
import {
DEFAULT_RGB_HEATMAP_COLOR_RAMP,
DEFAULT_HEATMAP_COLOR_RAMP_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/

import React from 'react';
import { GRID_RESOLUTION } from '../grid_resolution';
import { AbstractStyle } from './abstract_style';
import { HeatmapStyleEditor } from './components/heatmap/heatmap_style_editor';
import { HeatmapLegend } from './components/heatmap/legend/heatmap_legend';
import { DEFAULT_HEATMAP_COLOR_RAMP_NAME } from './components/heatmap/heatmap_constants';
import { getColorRampStops } from './color_utils';
import { GRID_RESOLUTION } from '../../grid_resolution';
import { AbstractStyle } from '../abstract_style';
import { HeatmapStyleEditor } from './components/heatmap_style_editor';
import { HeatmapLegend } from './components/legend/heatmap_legend';
import { DEFAULT_HEATMAP_COLOR_RAMP_NAME } from './components/heatmap_constants';
import { getColorRampStops } from '../color_utils';
import { i18n } from '@kbn/i18n';
import { EuiIcon } from '@elastic/eui';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React from 'react';

import { StaticDynamicStyleRow } from '../../static_dynamic_style_row';
import { StaticDynamicStyleRow } from '../../../components/static_dynamic_style_row';
import { DynamicColorSelection } from './dynamic_color_selection';
import { StaticColorSelection } from './static_color_selection';
import { getVectorStyleLabel } from '../get_vector_style_label';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { i18n } from '@kbn/i18n';

import { vectorStyles } from '../../vector_style_defaults';
import { vectorStyles } from '../vector_style_defaults';

export function getVectorStyleLabel(styleName) {
switch (styleName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';

import { styleOptionShapes, rangeShape } from '../style_option_shapes';
import { VectorStyle } from '../../../vector_style';
import { ColorGradient } from '../../color_gradient';
import { VectorStyle } from '../../vector_style';
import { ColorGradient } from '../../../components/color_gradient';
import { CircleIcon } from './circle_icon';
import { getVectorStyleLabel } from '../get_vector_style_label';
import { EuiFlexGroup, EuiFlexItem, EuiHorizontalRule } from '@elastic/eui';
import { StyleLegendRow } from '../../style_legend_row';
import { StyleLegendRow } from '../../../components/style_legend_row';

function getLineWidthIcons() {
const defaultStyle = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';

import { getMakiSymbolSvg, styleSvg, buildSrcUrl } from '../../../symbol_utils';
import { getMakiSymbolSvg, styleSvg, buildSrcUrl } from '../../symbol_utils';

export class SymbolIcon extends Component {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CircleIcon } from './circle_icon';
import { LineIcon } from './line_icon';
import { PolygonIcon } from './polygon_icon';
import { SymbolIcon } from './symbol_icon';
import { VectorStyle } from '../../../vector_style';
import { VectorStyle } from '../../vector_style';
import { getColorRampCenterColor } from '../../../color_utils';

export class VectorIcon extends Component {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React from 'react';
import { shallow } from 'enzyme';

import { VectorIcon } from './vector_icon';
import { VectorStyle } from '../../../vector_style';
import { VectorStyle } from '../../vector_style';

let isPointsOnly = false;
let isLinesOnly = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React from 'react';

import { StaticDynamicStyleRow } from '../../static_dynamic_style_row';
import { StaticDynamicStyleRow } from '../../../components/static_dynamic_style_row';
import { DynamicOrientationSelection } from './dynamic_orientation_selection';
import { StaticOrientationSelection } from './static_orientation_selection';
import { i18n } from '@kbn/i18n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { ValidatedDualRange } from 'ui/validated_range';
import { DEFAULT_MIN_SIZE, DEFAULT_MAX_SIZE } from '../../../vector_style_defaults';
import { DEFAULT_MIN_SIZE, DEFAULT_MAX_SIZE } from '../../vector_style_defaults';
import { i18n } from '@kbn/i18n';

export function SizeRangeSelector({ minSize, maxSize, onChange, ...rest }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React from 'react';

import { StaticDynamicStyleRow } from '../../static_dynamic_style_row';
import { StaticDynamicStyleRow } from '../../../components/static_dynamic_style_row';
import { DynamicSizeSelection } from './dynamic_size_selection';
import { StaticSizeSelection } from './static_size_selection';
import { getVectorStyleLabel } from '../get_vector_style_label';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import {
getDefaultDynamicProperties,
getDefaultStaticProperties,
vectorStyles,
} from '../../vector_style_defaults';
} from '../vector_style_defaults';
import { DEFAULT_FILL_COLORS, DEFAULT_LINE_COLORS } from '../../color_utils';
import { VECTOR_SHAPE_TYPES } from '../../../sources/vector_feature_types';
import { SYMBOLIZE_AS_ICON } from '../../vector_constants';
import { SYMBOLIZE_AS_ICON } from '../vector_constants';
import { i18n } from '@kbn/i18n';
import { SYMBOL_OPTIONS } from '../../symbol_utils';
import { SYMBOL_OPTIONS } from '../symbol_utils';

import { EuiSpacer, EuiButtonGroup } from '@elastic/eui';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@elastic/eui';

import { i18n } from '@kbn/i18n';
import { SYMBOLIZE_AS_CIRCLE, SYMBOLIZE_AS_ICON } from '../../vector_constants';
import { SYMBOLIZE_AS_CIRCLE, SYMBOLIZE_AS_ICON } from '../vector_constants';
import { SymbolIcon } from './legend/symbol_icon';

const SYMBOLIZE_AS_OPTIONS = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react';
import { shallow } from 'enzyme';

import { SYMBOLIZE_AS_CIRCLE, SYMBOLIZE_AS_ICON } from '../../vector_constants';
import { SYMBOLIZE_AS_CIRCLE, SYMBOLIZE_AS_ICON } from '../vector_constants';
import { VectorStyleSymbolEditor } from './vector_style_symbol_editor';

const symbolOptions = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* 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 { DynamicStyleProperty } from './dynamic_style_property';
import _ from 'lodash';
import { getComputedFieldName } from '../style_util';
import { getColorRampStops } from '../../color_utils';


export class DynamicColorProperty extends DynamicStyleProperty {


syncCircleColorWithMb(mbLayerId, mbMap, alpha) {
const color = this._getMbColor();
mbMap.setPaintProperty(mbLayerId, 'circle-color', color);
mbMap.setPaintProperty(mbLayerId, 'circle-opacity', alpha);
}

syncIconColorWithMb(mbLayerId, mbMap) {
const color = this._getMbColor();
mbMap.setPaintProperty(mbLayerId, 'icon-color', color);
}

syncHaloBorderColorWithMb(mbLayerId, mbMap) {
const color = this._getMbColor();
mbMap.setPaintProperty(mbLayerId, 'icon-halo-color', color);
}

syncCircleStrokeWithMb(pointLayerId, mbMap, alpha) {
const color = this._getMbColor();
mbMap.setPaintProperty(pointLayerId, 'circle-stroke-color', color);
mbMap.setPaintProperty(pointLayerId, 'circle-stroke-opacity', alpha);
}

syncFillColorWithMb(mbLayerId, mbMap, alpha) {
const color = this._getMbColor();
mbMap.setPaintProperty(mbLayerId, 'fill-color', color);
mbMap.setPaintProperty(mbLayerId, 'fill-opacity', alpha);
}

syncLineColorWithMb(mbLayerId, mbMap, alpha) {
const color = this._getMbColor();
mbMap.setPaintProperty(mbLayerId, 'line-color', color);
mbMap.setPaintProperty(mbLayerId, 'line-opacity', alpha);
}

_getMbColor() {
const isDynamicConfigComplete = _.has(this._options, 'field.name') && _.has(this._options, 'color');
if (!isDynamicConfigComplete) {
return null;
}

if (this._options.useCustomColorRamp && (!this._options.customColorRamp || !this._options.customColorRamp.length)) {
return null;
}

return this._getMBDataDrivenColor({
targetName: getComputedFieldName(this._styleName, this._options.field.name),
colorStops: this._getMBColorStops(),
isSteps: this._options.useCustomColorRamp,
});
}

_getMBDataDrivenColor({ targetName, colorStops, isSteps }) {
if (isSteps) {
const firstStopValue = colorStops[0];
const lessThenFirstStopValue = firstStopValue - 1;
return [
'step',
['coalesce', ['feature-state', targetName], lessThenFirstStopValue],
'rgba(0,0,0,0)', // MB will assign the base value to any features that is below the first stop value
...colorStops
];
}

return [
'interpolate',
['linear'],
['coalesce', ['feature-state', targetName], -1],
-1, 'rgba(0,0,0,0)',
...colorStops
];
}


_getMBColorStops() {

if (this._options.useCustomColorRamp) {
return this._options.customColorRamp.reduce((accumulatedStops, nextStop) => {
return [...accumulatedStops, nextStop.stop, nextStop.color];
}, []);
}

return getColorRampStops(this._options.color);
}

}




Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 { DynamicStyleProperty } from './dynamic_style_property';
import { getComputedFieldName } from '../style_util';
import { vectorStyles } from '../vector_style_defaults';


export class DynamicOrientationProperty extends DynamicStyleProperty {

syncIconRotationWithMb(symbolLayerId, mbMap) {
if (this._options.field && this._options.field.name) {
const targetName = getComputedFieldName(vectorStyles.ICON_ORIENTATION, this._options.field.name);
// Using property state instead of feature-state because layout properties do not support feature-state
mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', ['coalesce', ['get', targetName], 0]);
} else {
mbMap.setLayoutProperty(symbolLayerId, 'icon-rotate', 0);
}
}

}




Loading

0 comments on commit 479177a

Please sign in to comment.