Skip to content

Commit

Permalink
Replace euiThemeVars in maps
Browse files Browse the repository at this point in the history
  • Loading branch information
cqliu1 committed Jan 2, 2025
1 parent 2ee9cbf commit 8de78d4
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@
*/

import React from 'react';
import { euiThemeVars } from '@kbn/ui-theme';
import { EuiFormRow, EuiToolTip } from '@elastic/eui';
import { EuiFormRow, EuiToolTip, useEuiTheme } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { MbValidatedColorPicker } from './mb_validated_color_picker';
import { OTHER_CATEGORY_LABEL, OTHER_CATEGORY_DEFAULT_COLOR } from '../../style_util';

const OTHER_CATEGORY_SWATCHES = [
euiThemeVars.euiColorLightestShade,
euiThemeVars.euiColorLightShade,
euiThemeVars.euiColorMediumShade,
euiThemeVars.euiColorDarkShade,
euiThemeVars.euiColorDarkestShade,
];
import { OTHER_CATEGORY_DEFAULT_COLOR_TOKEN, OTHER_CATEGORY_LABEL } from '../../style_util';

interface Props {
onChange: (color: string) => void;
color?: string;
}

export function OtherCategoryColorPicker(props: Props) {
const { euiTheme } = useEuiTheme();

const OTHER_CATEGORY_SWATCHES = [
euiTheme.colors.backgroundBasePlain,
euiTheme.colors.backgroundBaseSubdued,
euiTheme.colors.backgroundBaseSkeletonMiddle,
];

return (
<EuiFormRow>
<EuiToolTip
Expand All @@ -39,7 +38,7 @@ export function OtherCategoryColorPicker(props: Props) {
swatches={OTHER_CATEGORY_SWATCHES}
prepend={OTHER_CATEGORY_LABEL}
onChange={props.onChange}
color={props.color ? props.color : OTHER_CATEGORY_DEFAULT_COLOR}
color={props.color ? props.color : euiTheme.colors[OTHER_CATEGORY_DEFAULT_COLOR_TOKEN]}
/>
</EuiToolTip>
</EuiFormRow>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React, { FC, CSSProperties } from 'react';
import { useEuiTheme } from '@elastic/eui';
import { RightAlignedText } from '../right_aligned_text';

const FONT_SIZE = 10;

interface Props {
radius: number;
circleCenterX: number;
circleTopY: number;
textOffset: number;
textY: number;
formattedValue: string | number;
circleCenterY: number;
circleStyle: CSSProperties;
onWidthChange: (width: number) => void;
}

export const MapMarker: FC<Props> = ({
circleCenterX,
circleCenterY,
circleTopY,
formattedValue,
radius,
textOffset,
textY,
onWidthChange,
}) => {
const { euiTheme } = useEuiTheme();
const circleStyle = {
fillOpacity: 0,
stroke: euiTheme.colors.textParagraph,
strokeWidth: 1,
};

return (
<g key={radius}>
<line
style={{ stroke: euiTheme.border.color }}
x1={circleCenterX}
y1={circleTopY}
x2={circleCenterX * 2.25}
y2={circleTopY}
/>
<RightAlignedText
setWidth={onWidthChange}
style={{ fontSize: FONT_SIZE, fill: euiTheme.colors.textParagraph }}
x={circleCenterX * 2.25 + textOffset}
y={textY}
value={formattedValue}
/>
<circle
style={{ ...circleStyle, stroke: euiTheme.colors.textParagraph }}
cx={circleCenterX}
cy={circleCenterY}
r={radius}
/>
</g>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

import React, { Component } from 'react';
import _ from 'lodash';
import { euiThemeVars } from '@kbn/ui-theme';
import { EuiFlexGroup, EuiFlexItem, EuiText, EuiToolTip } from '@elastic/eui';
import { RangeFieldMeta } from '../../../../../../../common/descriptor_types';
import { DynamicSizeProperty } from '../../../properties/dynamic_size_property';
import { RightAlignedText } from '../right_aligned_text';
import { getMaxLabel, getMinLabel } from './get_ordinal_label';
import { type Marker, MarkerList } from './marker_list';
import { MapMarker } from './map_marker';

const FONT_SIZE = 10;
const HALF_FONT_SIZE = FONT_SIZE / 2;
Expand Down Expand Up @@ -96,7 +95,6 @@ export class MarkerSizeLegend extends Component<Props, State> {

const circleStyle = {
fillOpacity: 0,
stroke: euiThemeVars.euiTextColor,
strokeWidth: 1,
};

Expand All @@ -112,23 +110,17 @@ export class MarkerSizeLegend extends Component<Props, State> {
const textY = rawTextY > svgHeight ? svgHeight : rawTextY;
return {
svg: (
<g key={radius}>
<line
style={{ stroke: euiThemeVars.euiBorderColor }}
x1={circleCenterX}
y1={circleTopY}
x2={circleCenterX * 2.25}
y2={circleTopY}
/>
<RightAlignedText
setWidth={this._onRightAlignedWidthChange}
style={{ fontSize: FONT_SIZE, fill: euiThemeVars.euiTextColor }}
x={circleCenterX * 2.25 + textOffset}
y={textY}
value={formattedValue}
/>
<circle style={circleStyle} cx={circleCenterX} cy={circleCenterY} r={radius} />
</g>
<MapMarker
circleCenterX={circleCenterX}
circleCenterY={circleCenterY}
circleTopY={circleTopY}
circleStyle={circleStyle}
radius={radius}
textOffset={textOffset}
textY={textY}
formattedValue={formattedValue}
onWidthChange={this._onRightAlignedWidthChange}
/>
),
textY,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/

import React from 'react';
import { EuiText } from '@elastic/eui';
import { euiThemeVars } from '@kbn/ui-theme';
import { EuiText, useEuiTheme } from '@elastic/eui';
import { StyleError } from './style_error';
import {
DynamicStyleProperty,
Expand Down Expand Up @@ -62,7 +61,8 @@ export function VectorStyleLegend({
);
}

function renderMasksByFieldOrigin(fieldOrigin: FIELD_ORIGIN) {
function MasksByFieldOrigin({ fieldOrigin }: { fieldOrigin: FIELD_ORIGIN }) {
const { euiTheme } = useEuiTheme();
const masksByFieldOrigin = masks.filter(
(mask) => mask.getEsAggField().getOrigin() === fieldOrigin
);
Expand All @@ -89,10 +89,7 @@ export function VectorStyleLegend({
</EuiText>
<ul>
{masksByFieldOrigin.map((mask) => (
<li
key={mask.getEsAggField().getMbFieldName()}
style={{ marginLeft: euiThemeVars.euiSizeS }}
>
<li key={mask.getEsAggField().getMbFieldName()} style={{ marginLeft: euiTheme.size.s }}>
<MaskLegend
esAggField={mask.getEsAggField()}
onlyShowLabelAndValue={true}
Expand All @@ -108,8 +105,8 @@ export function VectorStyleLegend({

return (
<>
{renderMasksByFieldOrigin(FIELD_ORIGIN.SOURCE)}
{renderMasksByFieldOrigin(FIELD_ORIGIN.JOIN)}
<MasksByFieldOrigin fieldOrigin={FIELD_ORIGIN.SOURCE} />
<MasksByFieldOrigin fieldOrigin={FIELD_ORIGIN.JOIN} />
{legendRows}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
VECTOR_STYLES,
} from '../../../../../common/constants';
import { isCategoricalStopsInvalid } from '../components/color/color_stops_utils';
import { OTHER_CATEGORY_LABEL, OTHER_CATEGORY_DEFAULT_COLOR } from '../style_util';
import { OTHER_CATEGORY_LABEL, OTHER_CATEGORY_DEFAULT_COLOR_TOKEN } from '../style_util';
import { Break, BreakedLegend } from '../components/legend/breaked_legend';
import { ColorDynamicOptions, OrdinalColorStop } from '../../../../../common/descriptor_types';
import { LegendProps } from './style_property';
Expand Down Expand Up @@ -246,9 +246,11 @@ export class DynamicColorProperty extends DynamicStyleProperty<ColorDynamicOptio
return this._chartsPaletteServiceGetColor('__other__');
}

const { euiTheme } = useEuiTheme();

return this._options.otherCategoryColor
? this._options.otherCategoryColor
: OTHER_CATEGORY_DEFAULT_COLOR;
: OTHER_CATEGORY_DEFAULT_COLOR_TOKEN;
}

_getColorPaletteStops() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { euiThemeVars } from '@kbn/ui-theme';
import { i18n } from '@kbn/i18n';
import { ICON_SOURCE, MB_LOOKUP_FUNCTION, VECTOR_STYLES } from '../../../../common/constants';
import { Category } from '../../../../common/descriptor_types';
Expand All @@ -19,7 +18,7 @@ export const OTHER_CATEGORY_LABEL = i18n.translate(
}
);

export const OTHER_CATEGORY_DEFAULT_COLOR = euiThemeVars.euiColorLightShade;
export const OTHER_CATEGORY_DEFAULT_COLOR_TOKEN = 'textSubdued';

export function getComputedFieldName(styleName: VECTOR_STYLES, fieldName: string) {
return `${getComputedFieldNamePrefix(fieldName)}__${styleName as string}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
* 2.0.
*/

import { euiThemeVars } from '@kbn/ui-theme';
import { INITIAL_LOCATION, MAX_ZOOM, MIN_ZOOM } from '../../../common/constants';
import { MapSettings } from '../../../common/descriptor_types';

export function getDefaultMapSettings(): MapSettings {
return {
autoFitToDataBounds: false,
backgroundColor: euiThemeVars.euiColorEmptyShade,
backgroundColor: '#FFFFFF', // TODO: use eui theme
customIcons: [],
disableInteractive: false,
disableTooltipControl: false,
Expand Down

0 comments on commit 8de78d4

Please sign in to comment.