From 6b39375c7ba7f14e4cc2c78254cf3816e9d0ba55 Mon Sep 17 00:00:00 2001 From: simplexiao <81275881+simplexiao@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:46:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9B=BE=E5=B1=82=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF=E6=94=AF=E6=8C=81=20scale=20=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=8C=BA=E9=97=B4=20(#50)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: yxh01132861 --- .../src/widgets/LegendWidget/helper.ts | 12 +- .../H3HexagonLayer/register-form/index.ts | 39 +++- .../layers/MVTLayer/register-form/index.ts | 39 +++- .../LayerAttribute/LayerForm/index.tsx | 18 +- .../LayerAttribute/BubbleLayerStyle/helper.ts | 41 +++- .../ChoroplethLayerStyle/helper.ts | 40 +++- .../LayerAttribute/GridLayerStyle/helper.ts | 40 +++- .../LayerAttribute/HexbinLayerStyle/helper.ts | 39 +++- .../LayerAttribute/LineLayerStyle/helper.ts | 40 +++- .../LayerAttribute/LineLayerStyle/schema.ts | 17 +- .../common-schema/fill-color-collapse.ts | 11 +- .../CustomItem/Item/index.tsx | 129 +++++++++++ .../CustomItem/Item/style.ts | 24 ++ .../CustomMappingColors/CustomItem/index.tsx | 89 ++++++++ .../CustomMappingColors/CustomItem/style.ts | 63 ++++++ .../CustomMappingColors/contants.ts | 4 + .../CustomMappingColors/index.tsx | 212 ++++++++++++++++++ .../CustomMappingColors/style.ts | 52 +++++ .../components/ScaleSelector/constants.ts | 20 +- .../ScaleSelector/demos/default.tsx | 60 +++++ .../components/ScaleSelector/helper.ts | 147 ++++++++++++ .../components/ScaleSelector/index.md | 22 ++ .../components/ScaleSelector/index.tsx | 151 +++++++++++-- .../components/ScaleSelector/style.ts | 41 ++++ .../components/ScaleSelector/type.ts | 21 ++ .../ColorRangeSelector/Internal/index.tsx | 5 + 26 files changed, 1274 insertions(+), 102 deletions(-) create mode 100644 packages/li-p2/src/LayerAttribute/components/ScaleSelector/CustomMappingColors/CustomItem/Item/index.tsx create mode 100644 packages/li-p2/src/LayerAttribute/components/ScaleSelector/CustomMappingColors/CustomItem/Item/style.ts create mode 100644 packages/li-p2/src/LayerAttribute/components/ScaleSelector/CustomMappingColors/CustomItem/index.tsx create mode 100644 packages/li-p2/src/LayerAttribute/components/ScaleSelector/CustomMappingColors/CustomItem/style.ts create mode 100644 packages/li-p2/src/LayerAttribute/components/ScaleSelector/CustomMappingColors/contants.ts create mode 100644 packages/li-p2/src/LayerAttribute/components/ScaleSelector/CustomMappingColors/index.tsx create mode 100644 packages/li-p2/src/LayerAttribute/components/ScaleSelector/CustomMappingColors/style.ts create mode 100644 packages/li-p2/src/LayerAttribute/components/ScaleSelector/demos/default.tsx create mode 100644 packages/li-p2/src/LayerAttribute/components/ScaleSelector/helper.ts create mode 100644 packages/li-p2/src/LayerAttribute/components/ScaleSelector/index.md create mode 100644 packages/li-p2/src/LayerAttribute/components/ScaleSelector/style.ts create mode 100644 packages/li-p2/src/LayerAttribute/components/ScaleSelector/type.ts diff --git a/packages/li-analysis-assets/src/widgets/LegendWidget/helper.ts b/packages/li-analysis-assets/src/widgets/LegendWidget/helper.ts index 8084fb94..3ed2efb7 100644 --- a/packages/li-analysis-assets/src/widgets/LegendWidget/helper.ts +++ b/packages/li-analysis-assets/src/widgets/LegendWidget/helper.ts @@ -72,6 +72,7 @@ export const parserLegendData = (layer: Layer) => { } const { items, type, field } = legendData; + items.forEach((item, index) => { if (Array.isArray(item.value)) { if (index === items.length - 1) { @@ -85,6 +86,15 @@ export const parserLegendData = (layer: Layer) => { colors.push(item.color); }); + if (type === 'threshold') { + if (labels[0] === undefined) { + labels.splice(0, 1, '<'); + } + if (labels[labels.length - 1] === undefined) { + labels.splice(labels.length - 1, 1, '<'); + } + } + if (type === 'cat') { // 分类图例 // 对标签进行排序 @@ -105,7 +115,7 @@ export const parserLegendData = (layer: Layer) => { }; return data; - } else if (['linear', 'quantile', 'quantize'].includes(type as string)) { + } else if (['linear', 'quantile', 'quantize', 'threshold'].includes(type as string)) { const data: LegendRampData = { type: 'LegendRamp', field: field, diff --git a/packages/li-core-assets/src/layers/H3HexagonLayer/register-form/index.ts b/packages/li-core-assets/src/layers/H3HexagonLayer/register-form/index.ts index d562193d..8147f618 100644 --- a/packages/li-core-assets/src/layers/H3HexagonLayer/register-form/index.ts +++ b/packages/li-core-assets/src/layers/H3HexagonLayer/register-form/index.ts @@ -10,6 +10,18 @@ const toValues = (config: LayerRegisterFormResultType): LayerRegisterFormResultType): LayerRegisterFormResultType = ({ className, config, onChange }) => const datasetFields = useMemo(() => getDatasetFields(columns), [columns]); + const datasetFieldList = useMemo(() => { + return datasetFields.map((item) => { + // @ts-ignore + const itemValue = dataset.data.map((_item: Record) => _item[item.value]); + const domain = item.type === 'number' ? [min(itemValue), max(itemValue)] : [...new Set(itemValue)]; + + return { + ...item, + domain, + }; + }); + // @ts-ignore + }, [datasetFields, dataset.data]); + const handleFormValuesChange = useMemoizedFn((styleConfig: Pick) => { if (styleConfig.sourceConfig && datasetId) { styleConfig.sourceConfig.datasetId = datasetId; @@ -103,7 +117,7 @@ const LayerForm: React.FC = ({ className, config, onChange }) => )} diff --git a/packages/li-p2/src/LayerAttribute/BubbleLayerStyle/helper.ts b/packages/li-p2/src/LayerAttribute/BubbleLayerStyle/helper.ts index 7b99cdae..e89cf631 100644 --- a/packages/li-p2/src/LayerAttribute/BubbleLayerStyle/helper.ts +++ b/packages/li-p2/src/LayerAttribute/BubbleLayerStyle/helper.ts @@ -5,15 +5,24 @@ import type { BubbleLayerStyleAttributeValue } from './types'; * 将表单的平铺数据转为图层样式的数据结构 * */ export const bubbleLayerStyleFlatToConfig = (style: Record) => { + const fillColor = style.fillColorField + ? { + field: style.fillColorField, + value: style.fillColorScale.isCustom ? style.fillColorScale.range : style.fillColorRange?.colors, + scale: style.fillColorScale.isCustom + ? { + type: style.fillColorScale.type, + domain: style.fillColorScale.domain, + } + : { + type: style.fillColorScale.type, + }, + isReversed: style.fillColorRange?.isReversed ?? false, + } + : style.fillColor; + const styleConfig: BubbleLayerStyleAttributeValue = { - fillColor: style.fillColorField - ? { - field: style.fillColorField, - value: style.fillColorRange.colors, - scale: { type: style.fillColorScale }, - isReversed: style.fillColorRange.isReversed, - } - : style.fillColor, + fillColor, opacity: style.fillColorOpacity, strokeColor: style.strokeColor, lineWidth: style.lineWidth, @@ -43,6 +52,7 @@ export const bubbleLayerStyleFlatToConfig = (style: Record) => { // rings: style.animateRings, // }, }; + return styleConfig; }; @@ -63,6 +73,19 @@ export const bubbleLayerStyleConfigToFlat = (styleConfig: BubbleLayerStyleAttrib maxZoom = 24, blend, } = styleConfig; + + const isCustom = typeof fillColor === 'object' && fillColor?.scale?.domain && fillColor?.scale?.domain.length !== 0; + + const fillColorScale = + typeof fillColor === 'object' + ? { + type: fillColor?.scale?.type, + domain: fillColor?.scale?.domain, + range: fillColor?.value, + isCustom, + } + : undefined; + const config = { fillColorField: typeof fillColor === 'object' ? fillColor?.field : undefined, fillColorRange: @@ -73,7 +96,7 @@ export const bubbleLayerStyleConfigToFlat = (styleConfig: BubbleLayerStyleAttrib isReversed: fillColor?.isReversed || false, } : undefined, - fillColorScale: typeof fillColor === 'object' ? fillColor?.scale?.type : undefined, + fillColorScale, fillColor: typeof fillColor !== 'object' ? fillColor : undefined, fillColorOpacity: opacity, strokeColor: strokeColor, diff --git a/packages/li-p2/src/LayerAttribute/ChoroplethLayerStyle/helper.ts b/packages/li-p2/src/LayerAttribute/ChoroplethLayerStyle/helper.ts index a270546a..1097147b 100644 --- a/packages/li-p2/src/LayerAttribute/ChoroplethLayerStyle/helper.ts +++ b/packages/li-p2/src/LayerAttribute/ChoroplethLayerStyle/helper.ts @@ -5,15 +5,24 @@ import type { ChoroplethLayerStyleAttributeValue } from './types'; * 将表单的平铺数据转为图层样式的数据结构 * */ export const choroplethLayerStyleFlatToConfig = (style: Record) => { + const fillColor = style.fillColorField + ? { + field: style.fillColorField, + value: style.fillColorScale.isCustom ? style.fillColorScale.range : style.fillColorRange?.colors, + scale: style.fillColorScale.isCustom + ? { + type: style.fillColorScale.type, + domain: style.fillColorScale.domain, + } + : { + type: style.fillColorScale.type, + }, + isReversed: style.fillColorRange?.isReversed ?? false, + } + : style.fillColor; + const styleConfig: ChoroplethLayerStyleAttributeValue = { - fillColor: style.fillColorField - ? { - field: style.fillColorField, - value: style.fillColorRange.colors, - scale: { type: style.fillColorScale }, - isReversed: style.fillColorRange.isReversed, - } - : style.fillColor, + fillColor, opacity: style.fillColorOpacity, strokeColor: style.strokeColor, lineWidth: style.lineWidth, @@ -52,6 +61,19 @@ export const choroplethLayerStyleConfigToFlat = (styleConfig: ChoroplethLayerSty maxZoom = 24, blend, } = styleConfig; + + const isCustom = typeof fillColor === 'object' && fillColor?.scale?.domain && fillColor?.scale?.domain.length !== 0; + + const fillColorScale = + typeof fillColor === 'object' + ? { + type: fillColor?.scale?.type, + domain: fillColor?.scale?.domain, + range: fillColor?.value, + isCustom, + } + : undefined; + const config = { fillColorField: typeof fillColor === 'object' ? fillColor?.field : undefined, fillColorRange: @@ -62,7 +84,7 @@ export const choroplethLayerStyleConfigToFlat = (styleConfig: ChoroplethLayerSty isReversed: fillColor?.isReversed || false, } : undefined, - fillColorScale: typeof fillColor === 'object' ? fillColor?.scale?.type : undefined, + fillColorScale, fillColor: typeof fillColor !== 'object' ? fillColor : undefined, fillColorOpacity: opacity, strokeColor: strokeColor, diff --git a/packages/li-p2/src/LayerAttribute/GridLayerStyle/helper.ts b/packages/li-p2/src/LayerAttribute/GridLayerStyle/helper.ts index eee65b19..cb574309 100644 --- a/packages/li-p2/src/LayerAttribute/GridLayerStyle/helper.ts +++ b/packages/li-p2/src/LayerAttribute/GridLayerStyle/helper.ts @@ -4,17 +4,26 @@ import type { GridLayerStyleAttributeValue } from './types'; * 将表单的平铺数据转为图层样式的数据结构 * */ export const gridLayerStyleFlatToConfig = (style: Record) => { + const fillColor = style.fillColorField + ? { + field: style.fillColorField, + value: style.fillColorScale.isCustom ? style.fillColorScale.range : style.fillColorRange?.colors, + scale: style.fillColorScale.isCustom + ? { + type: style.fillColorScale.type, + domain: style.fillColorScale.domain, + } + : { + type: style.fillColorScale.type, + }, + isReversed: style.fillColorRange?.isReversed ?? false, + } + : style.fillColor; + const styleConfig = { // 网格半径 表单上为公里单位转化为米 aggregateSize: Number(style.aggregateSize) * 1000, - color: style.fillColorField - ? { - field: style.fillColorField, - value: style.fillColorRange.colors, - isReversed: style.fillColorRange.isReversed, - scale: { type: style.fillColorScale }, - } - : style.fillColor, + color: fillColor, style: { opacity: style.fillColorOpacity, coverage: style.coverage, @@ -33,6 +42,19 @@ export const gridLayerStyleFlatToConfig = (style: Record) => { * */ export const gridLayerStyleConfigToFlat = (styleConfig: GridLayerStyleAttributeValue) => { const { aggregateSize, style, color, minZoom = 0, maxZoom = 24, blend } = styleConfig; + + const isCustom = typeof color === 'object' && color?.scale?.domain && color?.scale?.domain.length !== 0; + + const fillColorScale = + typeof color === 'object' + ? { + type: color?.scale?.type, + domain: color?.scale?.domain, + range: color?.value, + isCustom, + } + : undefined; + const config = { fillColorField: typeof color === 'object' ? color?.field : undefined, fillColorRange: @@ -43,7 +65,7 @@ export const gridLayerStyleConfigToFlat = (styleConfig: GridLayerStyleAttributeV isReversed: color?.isReversed || false, } : undefined, - fillColorScale: typeof color === 'object' ? color?.scale?.type : undefined, + fillColorScale, fillColor: typeof color !== 'object' ? color : undefined, fillColorOpacity: style?.opacity, // 网格半径 表单上为公里单位 米转公里 diff --git a/packages/li-p2/src/LayerAttribute/HexbinLayerStyle/helper.ts b/packages/li-p2/src/LayerAttribute/HexbinLayerStyle/helper.ts index 231bd923..0e837b1d 100644 --- a/packages/li-p2/src/LayerAttribute/HexbinLayerStyle/helper.ts +++ b/packages/li-p2/src/LayerAttribute/HexbinLayerStyle/helper.ts @@ -4,16 +4,25 @@ import type { HexbinLayerStyleAttributeValue } from './types'; * 将表单的平铺数据转为图层样式的数据结构 * */ export const hexbinLayerStyleFlatToConfig = (style: Record) => { + const fillColor = style.fillColorField + ? { + field: style.fillColorField, + value: style.fillColorScale.isCustom ? style.fillColorScale.range : style.fillColorRange?.colors, + scale: style.fillColorScale.isCustom + ? { + type: style.fillColorScale.type, + domain: style.fillColorScale.domain, + } + : { + type: style.fillColorScale.type, + }, + isReversed: style.fillColorRange?.isReversed ?? false, + } + : style.fillColor; + const styleConfig = { shape: 'hexagonColumn' as const, - color: style.fillColorField - ? { - field: style.fillColorField, - value: style.fillColorRange.colors, - isReversed: style.fillColorRange.isReversed, - scale: { type: style.fillColorScale }, - } - : style.fillColor, + color: fillColor, // 网格半径 表单上为公里单位转化为米 aggregateSize: Number(style.aggregateSize) * 1000, style: { @@ -35,6 +44,18 @@ export const hexbinLayerStyleFlatToConfig = (style: Record) => { export const hexbinLayerStyleConfigToFlat = (styleConfig: HexbinLayerStyleAttributeValue) => { const { aggregateSize, style, color, minZoom = 0, maxZoom = 24, blend } = styleConfig; + const isCustom = typeof color === 'object' && color?.scale?.domain && color?.scale?.domain.length !== 0; + + const fillColorScale = + typeof color === 'object' + ? { + type: color?.scale?.type, + domain: color?.scale?.domain, + range: color?.value, + isCustom, + } + : undefined; + const config = { fillColorField: typeof color === 'object' ? color?.field : undefined, fillColorRange: @@ -45,7 +66,7 @@ export const hexbinLayerStyleConfigToFlat = (styleConfig: HexbinLayerStyleAttrib isReversed: color?.isReversed || false, } : undefined, - fillColorScale: typeof color === 'object' ? color?.scale?.type : undefined, + fillColorScale, fillColor: typeof color !== 'object' ? color : undefined, fillColorOpacity: style?.opacity, // 网格半径 表单上为公里单位 米转公里 diff --git a/packages/li-p2/src/LayerAttribute/LineLayerStyle/helper.ts b/packages/li-p2/src/LayerAttribute/LineLayerStyle/helper.ts index 8b606530..f2267ed1 100644 --- a/packages/li-p2/src/LayerAttribute/LineLayerStyle/helper.ts +++ b/packages/li-p2/src/LayerAttribute/LineLayerStyle/helper.ts @@ -5,6 +5,22 @@ import type { LineLayerStyleAttributeValue } from './types'; * 将表单的平铺数据转为图层样式的数据结构 * */ export const lineLayerStyleFlatToConfig = (style: Record) => { + const fillColor = style.fillColorField + ? { + field: style.fillColorField, + value: style.fillColorScale.isCustom ? style.fillColorScale.range : style.fillColorRange?.colors, + scale: style.fillColorScale.isCustom + ? { + type: style.fillColorScale.type, + domain: style.fillColorScale.domain, + } + : { + type: style.fillColorScale.type, + }, + isReversed: style.fillColorRange?.isReversed ?? false, + } + : style.fillColor; + const styleConfig: LineLayerStyleAttributeValue = { size: style.sizeField ? { @@ -13,14 +29,7 @@ export const lineLayerStyleFlatToConfig = (style: Record) => { } : style.size, - color: style.fillColorField - ? { - field: style.fillColorField, - value: style.fillColorRange.colors, - scale: { type: style.fillColorScale }, - isReversed: style.fillColorRange.isReversed, - } - : style.sourceColor, + color: fillColor, style: { opacity: style.fillColorOpacity, lineType: 'solid' as const, @@ -48,6 +57,19 @@ export const lineLayerStyleFlatToConfig = (style: Record) => { * */ export const lineLayerStyleConfigToFlat = (styleConfig: LineLayerStyleAttributeValue) => { const { size, color, style, minZoom = 0, maxZoom = 24, blend, animate } = styleConfig; + + const isCustom = typeof color === 'object' && color?.scale?.domain && color?.scale?.domain.length !== 0; + + const fillColorScale = + typeof color === 'object' + ? { + type: color?.scale?.type, + domain: color?.scale?.domain, + range: color?.value, + isCustom, + } + : undefined; + const config = { size: typeof size === 'object' ? undefined : size, // @ts-ignore @@ -63,7 +85,7 @@ export const lineLayerStyleConfigToFlat = (styleConfig: LineLayerStyleAttributeV isReversed: color?.isReversed || false, } : undefined, - fillColorScale: typeof color === 'object' ? color?.scale?.type : undefined, + fillColorScale, fillColorOpacity: style?.opacity, diff --git a/packages/li-p2/src/LayerAttribute/LineLayerStyle/schema.ts b/packages/li-p2/src/LayerAttribute/LineLayerStyle/schema.ts index 7558146d..41d17c75 100644 --- a/packages/li-p2/src/LayerAttribute/LineLayerStyle/schema.ts +++ b/packages/li-p2/src/LayerAttribute/LineLayerStyle/schema.ts @@ -45,8 +45,11 @@ export default (options: AttributeSchemaOptions = {}) => { 'x-component': 'ScaleSelector', 'x-component-props': { placeholder: '请选择', - type: + dataType: '{{ $form.getFieldState("fillColorField",state=> { return state.dataSource.find((item) => item.value === state.value)?.type })}}', + domain: + '{{ $form.getFieldState("fillColorField",state=> { return state.dataSource.find((item) => item.value === state.value)?.domain })}}', + defaultColors: '{{ $form.getFieldState("fillColorRange",state=> { return state?.value?.colors })}}', }, 'x-decorator-props': {}, 'x-reactions': [ @@ -60,7 +63,6 @@ export default (options: AttributeSchemaOptions = {}) => { }, ], }, - // 起点颜色选择器 sourceColor: { title: '起点颜色', @@ -108,20 +110,21 @@ export default (options: AttributeSchemaOptions = {}) => { type: 'object', title: '颜色', default: { - colors: ['#a6cee3', '#1f78b4', '#b2df8a'], + colors: ['#ffffcc', '#d9f0a3', '#addd8e', '#78c679', '#31a354', '#006837'], isReversed: false, }, 'x-decorator': 'FormItem', 'x-component': 'ColorRangeSelector', - 'x-component-props': {}, + 'x-component-props': { + options: [...colorRanges], + }, 'x-decorator-props': {}, - enum: [...colorRanges], 'x-reactions': [ { - dependencies: ['fillColorField'], + dependencies: ['fillColorField', 'fillColorScale'], fulfill: { state: { - visible: '{{ $deps[0] !== undefined }}', + visible: '{{ $deps[0] !== undefined && !$deps[1].isCustom }}', }, }, }, diff --git a/packages/li-p2/src/LayerAttribute/common-schema/fill-color-collapse.ts b/packages/li-p2/src/LayerAttribute/common-schema/fill-color-collapse.ts index ed349e40..999ee451 100644 --- a/packages/li-p2/src/LayerAttribute/common-schema/fill-color-collapse.ts +++ b/packages/li-p2/src/LayerAttribute/common-schema/fill-color-collapse.ts @@ -40,8 +40,11 @@ export default (options: AttributeSchemaOptions) => { 'x-component': 'ScaleSelector', 'x-component-props': { placeholder: '请选择', - type: + dataType: '{{ $form.getFieldState("fillColorField",state=> { return state.dataSource.find((item) => item.value === state.value)?.type })}}', + domain: + '{{ $form.getFieldState("fillColorField",state=> { return state.dataSource.find((item) => item.value === state.value)?.domain })}}', + defaultColors: '{{ $form.getFieldState("fillColorRange",state=> { return state?.value?.colors })}}', }, 'x-decorator-props': {}, 'x-reactions': [ @@ -55,6 +58,7 @@ export default (options: AttributeSchemaOptions) => { }, ], }, + // 颜色选择器 fillColor: { type: 'string', @@ -77,6 +81,7 @@ export default (options: AttributeSchemaOptions) => { }, ], }, + // 色带 fillColorRange: { type: 'object', @@ -93,10 +98,10 @@ export default (options: AttributeSchemaOptions) => { 'x-decorator-props': {}, 'x-reactions': [ { - dependencies: ['fillColorField'], + dependencies: ['fillColorField', 'fillColorScale'], fulfill: { state: { - visible: '{{ $deps[0] !== undefined }}', + visible: '{{ $deps[0] !== undefined && !$deps[1].isCustom }}', }, }, }, diff --git a/packages/li-p2/src/LayerAttribute/components/ScaleSelector/CustomMappingColors/CustomItem/Item/index.tsx b/packages/li-p2/src/LayerAttribute/components/ScaleSelector/CustomMappingColors/CustomItem/Item/index.tsx new file mode 100644 index 00000000..647b3d2a --- /dev/null +++ b/packages/li-p2/src/LayerAttribute/components/ScaleSelector/CustomMappingColors/CustomItem/Item/index.tsx @@ -0,0 +1,129 @@ +import { usePrefixCls } from '@formily/antd-v5/esm/__builtins__'; +import { InputNumber, Select } from 'antd'; +import classnames from 'classnames'; +import React, { useEffect, useState } from 'react'; +import useStyle from './style'; + +type ItemProps = { + customType: 'string' | 'number'; + value: (string | number)[]; + options: { label: string; value: string }[]; + min: number; + max: number; + position: string | null; + onChange: (val: (string | number)[]) => void; +}; + +const Item = ({ customType, value, options, min, max, position, onChange }: ItemProps) => { + const prefixCls = usePrefixCls('formily-scale-selector__custom-content__custom-item__item'); + const [wrapSSR, hashId] = useStyle(prefixCls); + const [itemVal, setItemVal] = useState<(string | number)[]>(value); + + const onSelectChange = (val: string[]) => { + setItemVal(val); + onChange(val); + }; + + const onFirstInputChange = (e: number) => { + const val = itemVal?.length === 2 ? [e, itemVal[1]] : [e, Infinity]; + onChange(val); + setItemVal(val); + }; + + const onLastInputChange = (e: number) => { + if (position === 'first') { + const val = [-Infinity, e]; + onChange(val); + setItemVal(val); + } else if (position === 'last') { + const val = [e, Infinity]; + onChange(val); + setItemVal(val); + } else { + const val = itemVal?.length > 0 ? [itemVal[0], e] : [-Infinity, e]; + onChange(val); + setItemVal(val); + } + }; + + useEffect(() => { + setItemVal(value); + }, [value]); + + return wrapSSR( +
+ {customType === 'string' && ( + - {selectOptions?.map((item, index) => { + // 自定义 scale 且数据 domain 发生更新时,自动计算默认值 + useUpdateEffect(() => { + if (selectedType === 'custom' && value?.domain && value.domain.length !== 0) { + const range = value.range ? [...new Set(value.range)] : defaultColors; + const _defaultValue = getDefaultValue(dataType, domain, range); + if (onChange) + onChange({ + ..._defaultValue, + }); + } + }, [domain.toString()]); + + return wrapSSR( + + }} + options={selectOptions} + />, ); }; diff --git a/packages/li-p2/src/LayerAttribute/components/ScaleSelector/style.ts b/packages/li-p2/src/LayerAttribute/components/ScaleSelector/style.ts new file mode 100644 index 00000000..b73bb5f6 --- /dev/null +++ b/packages/li-p2/src/LayerAttribute/components/ScaleSelector/style.ts @@ -0,0 +1,41 @@ +import { genStyleHook } from '@formily/antd-v5/esm/__builtins__'; + +export default genStyleHook('scale-selector', (token) => { + const { componentCls, controlItemBgHover, controlItemBgActive, colorTextBase } = token; + + return { + [componentCls]: {}, + + [`${componentCls}-dropdown`]: { + padding: '4px', + + [`${componentCls}-custom`]: { + padding: '5px 12px', + display: 'flex', + justifyContent: 'space-between', + alignItems: 'center', + }, + + [`${componentCls}-customcontent`]: { + padding: '5px 12px', + }, + }, + + [`${componentCls}-select-option`]: { + cursor: 'pointer', + height: '32px', + padding: '5px 12px', + borderRadius: '4px', + fontSize: '14px', + color: colorTextBase, + + '&:hover': { + background: controlItemBgHover, + }, + }, + + [`${componentCls}-select-option-selected`]: { + background: controlItemBgActive, + }, + }; +}); diff --git a/packages/li-p2/src/LayerAttribute/components/ScaleSelector/type.ts b/packages/li-p2/src/LayerAttribute/components/ScaleSelector/type.ts new file mode 100644 index 00000000..21f97257 --- /dev/null +++ b/packages/li-p2/src/LayerAttribute/components/ScaleSelector/type.ts @@ -0,0 +1,21 @@ +export type CustomMappingColorItem = { + color: string; + value: (string | number)[]; + id?: string; +}; + +export type CustomMappingData = { + type: 'number' | 'string' | 'custom'; + list: CustomMappingColorItem[]; +}; + +export type SelectType = 'custom' | 'quantize' | 'quantile' | 'cat'; + +export type SelectorValueType = 'cat' | 'threshold' | 'quantize' | 'quantile'; + +export type SelectorValue = { + type: SelectorValueType; + isCustom: boolean; + domain?: string[] | number[]; + range?: string[]; +}; diff --git a/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/index.tsx b/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/index.tsx index c99c24bc..7e311e92 100644 --- a/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/index.tsx +++ b/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/index.tsx @@ -10,6 +10,10 @@ import useStyle from './style'; import type { ColorRange, SelectorValue } from './types'; export interface ColorRangeSelectorProps { + /** + * 是否可用 + */ + disabled?: boolean; /** * 颜色值 */ @@ -41,6 +45,7 @@ const Internal = (props: ColorRangeSelectorProps) => { return wrapSSR(