import { capitalize } from 'lodash'; import React, { FC } from 'react'; import { useObservable } from 'react-use'; import { Observable, of } from 'rxjs'; import { FieldConfigPropertyItem, StandardEditorProps, StandardEditorsRegistryItem } from '@grafana/data'; import { ColorPicker, Field, HorizontalGroup, InlineField, InlineFieldRow, InlineLabel, RadioButtonGroup, } from '@grafana/ui'; import { NumberValueEditor } from 'app/core/components/OptionsUI/number'; import { SliderValueEditor } from 'app/core/components/OptionsUI/slider'; import { ColorDimensionEditor, ResourceDimensionEditor, ScaleDimensionEditor, ScalarDimensionEditor, TextDimensionEditor, } from 'app/features/dimensions/editors'; import { ScaleDimensionConfig, ResourceDimensionConfig, ColorDimensionConfig, ResourceFolderName, TextDimensionConfig, defaultTextConfig, ScalarDimensionConfig, } from 'app/features/dimensions/types'; import { defaultStyleConfig, GeometryTypeId, StyleConfig, TextAlignment, TextBaseline } from '../style/types'; import { styleUsesText } from '../style/utils'; import { LayerContentInfo } from '../utils/getFeatures'; export interface StyleEditorOptions { layerInfo?: Observable; simpleFixedValues?: boolean; displayRotation?: boolean; } export const StyleEditor: FC> = ({ value, context, onChange, item, }) => { const settings = item.settings; const onSizeChange = (sizeValue: ScaleDimensionConfig | undefined) => { onChange({ ...value, size: sizeValue }); }; const onSymbolChange = (symbolValue: ResourceDimensionConfig | undefined) => { onChange({ ...value, symbol: symbolValue }); }; const onColorChange = (colorValue: ColorDimensionConfig | undefined) => { onChange({ ...value, color: colorValue }); }; const onOpacityChange = (opacityValue: number | undefined) => { onChange({ ...value, opacity: opacityValue }); }; const onRotationChange = (rotationValue: ScalarDimensionConfig | undefined) => { onChange({ ...value, rotation: rotationValue }); }; const onTextChange = (textValue: TextDimensionConfig | undefined) => { onChange({ ...value, text: textValue }); }; const onTextFontSizeChange = (fontSize: number | undefined) => { onChange({ ...value, textConfig: { ...value.textConfig, fontSize } }); }; const onTextOffsetXChange = (offsetX: number | undefined) => { onChange({ ...value, textConfig: { ...value.textConfig, offsetX } }); }; const onTextOffsetYChange = (offsetY: number | undefined) => { onChange({ ...value, textConfig: { ...value.textConfig, offsetY } }); }; const onTextAlignChange = (textAlign: TextAlignment) => { onChange({ ...value, textConfig: { ...value.textConfig, textAlign: textAlign } }); }; const onTextBaselineChange = (textBaseline: TextBaseline) => { onChange({ ...value, textConfig: { ...value.textConfig, textBaseline: textBaseline } }); }; const propertyOptions = useObservable(settings?.layerInfo ?? of()); const featuresHavePoints = propertyOptions?.geometryType === GeometryTypeId.Point; const hasTextLabel = styleUsesText(value); // Simple fixed value display if (settings?.simpleFixedValues) { return ( <> {featuresHavePoints && ( <> )} { onColorChange({ fixed: v }); }} /> ); } return ( <> {settings?.displayRotation && ( )} {hasTextLabel && ( <> )} ); };