Skip to content

Commit

Permalink
fix: 问题处理
Browse files Browse the repository at this point in the history
  • Loading branch information
yxh01132861 committed Oct 18, 2023
1 parent 40b1363 commit 5a21d9a
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 209 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { max, min, pick } from 'lodash-es';
import React, { useMemo, useState } from 'react';
import { useEditorDatasets, useEditorService, useEditorState } from '../../../../hooks';
import BaseFormSchemaField from '../BaseFormSchemaField';
import { dataFormatProcessing } from './helper';
import './index.less';
import StyleForm from './StyleForm';

Expand Down Expand Up @@ -47,23 +46,11 @@ const LayerForm: React.FC<LayerFormProps> = ({ className, config, onChange }) =>
return datasetFields.map((item) => {
// @ts-ignore
const itemValue = dataset.data.map((_item: Record<string, any>) => _item[item.value]);

const list = dataFormatProcessing({
dataset: itemValue.map((_item: string | number) => ({ label: _item, value: _item })),
label: 'label',
value: 'value',
});
const domain = item.type === 'number' ? [min(itemValue), max(itemValue)] : [...new Set(itemValue)];

return {
...item,
domin:
item.type === 'number'
? {
min: min(itemValue),
max: max(itemValue),
list,
}
: { list },
domain,
};
});
// @ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions packages/li-p2/src/LayerAttribute/BubbleLayerStyle/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const bubbleLayerStyleFlatToConfig = (style: Record<string, any>) => {
const fillColor = style.fillColorField
? {
field: style.fillColorField,
value: typeof style.fillColorScale === 'string' ? style.fillColorRange?.colors : style.fillColorScale?.colors,
value: typeof style.fillColorScale === 'string' ? style.fillColorRange?.colors : style.fillColorScale?.ranges,
scale:
typeof style.fillColorScale === 'string'
? { type: style.fillColorScale }
Expand Down Expand Up @@ -79,7 +79,7 @@ export const bubbleLayerStyleConfigToFlat = (styleConfig: BubbleLayerStyleAttrib
? {
type: fillColor?.scale?.type ?? '',
domain: fillColor?.scale?.domain ?? [],
colors: fillColor?.value,
ranges: fillColor?.value,
}
: fillColor?.scale?.type
: undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const choroplethLayerStyleFlatToConfig = (style: Record<string, any>) =>
const fillColor = style.fillColorField
? {
field: style.fillColorField,
value: typeof style.fillColorScale === 'string' ? style.fillColorRange.colors : style.fillColorScale.colors,
value: typeof style.fillColorScale === 'string' ? style.fillColorRange.colors : style.fillColorScale.ranges,
scale:
typeof style.fillColorScale === 'string'
? { type: style.fillColorScale }
Expand Down Expand Up @@ -67,7 +67,7 @@ export const choroplethLayerStyleConfigToFlat = (styleConfig: ChoroplethLayerSty
? {
type: fillColor?.scale?.type ?? '',
domain: fillColor?.scale?.domain ?? [],
colors: fillColor?.value,
ranges: fillColor?.value,
}
: fillColor?.scale?.type
: undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/li-p2/src/LayerAttribute/GridLayerStyle/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const gridLayerStyleFlatToConfig = (style: Record<string, any>) => {
const fillColor = style.fillColorField
? {
field: style.fillColorField,
value: typeof style.fillColorScale === 'string' ? style.fillColorRange.colors : style.fillColorScale.colors,
value: typeof style.fillColorScale === 'string' ? style.fillColorRange.colors : style.fillColorScale.ranges,
scale:
typeof style.fillColorScale === 'string'
? { type: style.fillColorScale }
Expand Down Expand Up @@ -48,7 +48,7 @@ export const gridLayerStyleConfigToFlat = (styleConfig: GridLayerStyleAttributeV
? {
type: color?.scale?.type ?? '',
domain: color?.scale?.domain ?? [],
colors: color?.value,
ranges: color?.value,
}
: color?.scale?.type
: undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/li-p2/src/LayerAttribute/HexbinLayerStyle/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const hexbinLayerStyleFlatToConfig = (style: Record<string, any>) => {
const fillColor = style.fillColorField
? {
field: style.fillColorField,
value: typeof style.fillColorScale === 'string' ? style.fillColorRange.colors : style.fillColorScale.colors,
value: typeof style.fillColorScale === 'string' ? style.fillColorRange.colors : style.fillColorScale.ranges,
scale:
typeof style.fillColorScale === 'string'
? { type: style.fillColorScale }
Expand Down Expand Up @@ -49,7 +49,7 @@ export const hexbinLayerStyleConfigToFlat = (styleConfig: HexbinLayerStyleAttrib
? {
type: color?.scale?.type ?? '',
domain: color?.scale?.domain ?? [],
colors: color?.value,
ranges: color?.value,
}
: color?.scale?.type
: undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/li-p2/src/LayerAttribute/LineLayerStyle/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const lineLayerStyleFlatToConfig = (style: Record<string, any>) => {
const fillColor = style.fillColorField
? {
field: style.fillColorField,
value: typeof style.fillColorScale === 'string' ? style.fillColorRange.colors : style.fillColorScale.colors,
value: typeof style.fillColorScale === 'string' ? style.fillColorRange.colors : style.fillColorScale.ranges,
scale:
typeof style.fillColorScale === 'string'
? { type: style.fillColorScale }
Expand Down Expand Up @@ -62,7 +62,7 @@ export const lineLayerStyleConfigToFlat = (styleConfig: LineLayerStyleAttributeV
? {
type: color?.scale?.type ?? '',
domain: color?.scale?.domain ?? [],
colors: color?.value,
ranges: color?.value,
}
: color?.scale?.type
: undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ export default (options: AttributeSchemaOptions) => {
'x-component': 'ScaleSelector',
'x-component-props': {
placeholder: '请选择',
type:
fieldType:
'{{ $form.getFieldState("fillColorField",state=> { return state.dataSource.find((item) => item.value === state.value)?.type })}}',
dataset:
'{{ $form.getFieldState("fillColorField",state=> { return state.dataSource.find((item) => item.value === state.value)?.domin })}}',
defaultColors: '{{ $form.getFieldState("fillColorRange",state=> { return state?.value?.colors })}}',
domain:
'{{ $form.getFieldState("fillColorField",state=> { return state.dataSource.find((item) => item.value === state.value)?.domain })}}',
defaultRanges: '{{ $form.getFieldState("fillColorRange",state=> { return state?.value?.colors })}}',
},
'x-decorator-props': {},
'x-reactions': [
Expand Down Expand Up @@ -108,21 +108,23 @@ export default (options: AttributeSchemaOptions) => {
{
dependencies: ['fillColorScale'],
fulfill: {
run: `$form.setFieldState("fillColorRange", (_state) => {
_state.disabled = $form.getFieldState("fillColorScale", (state) => state.value?.type === "threshold");
$form.getFieldState('fillColorScale', (state) => {
if (state.value?.domain) {
return (_state.value = {
colors: $form.getFieldState('fillColorScale', (state) => state.value?.colors)
? $form.getFieldState('fillColorScale', (state) => state.value.colors)
: ['#ffffcc', '#d9f0a3', '#addd8e', '#78c679', '#31a354', '#006837'],
});
} else {
return;
}
});
})`,
run: `$form.setFieldState('fillColorRange', (_state) => {
_state.visible =
!$form.getFieldState('fillColorScale', (state) => state.value?.domain) &&
$form.getFieldState('fillColorField', (state) => state.value);
});
`,
},
},
{
dependencies: ['fillColorField'],
fulfill: {
run: `$form.setFieldState('fillColorRange', (_state) => {
_state.visible =
!$form.getFieldState('fillColorScale', (state) => state.value?.domain) &&
$form.getFieldState('fillColorField', (state) => state.value);
});
`,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import useStyle from './style';
type ItemProps = {
customType: CustomType;
value: (string | number | null)[];
options: { label: string; value: string; count: number }[];
options: { label: string; value: string }[];
min: number;
max: number;
position: string | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type RangeItemProps = {
customType: CustomType;
position: string | null;
selectedOption: (string | number | null)[];
selectOptions: { label: string; value: string; count: number }[];
selectOptions: { label: string; value: string }[];
min?: number;
max?: number;
color: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,41 @@ import { usePrefixCls } from '@formily/antd-v5/esm/__builtins__';
import classnames from 'classnames';
import { isEmpty, uniqueId } from 'lodash-es';
import React, { useEffect, useMemo, useState } from 'react';
import type { CustomItems, CustomItemType, CustomItemValueType, DatasetType } from '../type';
import type { CustomItems, CustomItemType, CustomItemValueType } from '../type';
import CustomItem from './CustomItem';
import useStyle from './style';

type CustomContentProps = {
fieldType: 'string' | 'number';
dataset: DatasetType | any;
customRanges: CustomItemType;
domain: string[] | [number, number];
customRanges?: CustomItemType;
onChange: (value: CustomItemType) => void;
className?: string;
};

const CustomContent = (props: CustomContentProps) => {
const { fieldType = 'string', dataset, customRanges: defaultCustomRanges, onChange, className } = props;
const { fieldType = 'string', domain, customRanges: defaultCustomRanges, onChange, className } = props;
const prefixCls = usePrefixCls('formily-color-range-selector__custom-range');
const [wrapSSR, hashId] = useStyle(prefixCls);
const [customRanges, setCustomRanges] = useState<CustomItems[]>([]);

const selectedOption = useMemo(() => {
if (!customRanges.length) {
return [];
if (fieldType === 'string' && customRanges.length) {
const values = customRanges.map((item) => item.value).flat();
return values;
}

const values = customRanges.map((item) => item.value).flat();
return values;
return [];
}, [customRanges]);

const selectOptions = useMemo(() => {
if (fieldType === 'string') {
return (domain as string[]).map((value: string) => ({ label: value, value }));
}

return [];
}, [domain]);

useEffect(() => {
if (defaultCustomRanges?.list?.length) {
const list = defaultCustomRanges.list.map((item: CustomItems) => {
Expand Down Expand Up @@ -149,8 +157,7 @@ const CustomContent = (props: CustomContentProps) => {
return wrapSSR(
<div className={classnames(`${prefixCls}`, hashId, className)}>
{customRanges.map((customItem: CustomItems, index: number) => {
const min = index === 0 ? dataset?.min : customRanges[index - 1].value[1];
const max = dataset?.max;
const [min, max] = domain as [number, number];
const position = index === 0 ? 'first' : index === customRanges.length - 1 ? 'last' : null;

return (
Expand All @@ -160,7 +167,7 @@ const CustomContent = (props: CustomContentProps) => {
color={customItem.color}
value={customItem.value}
selectedOption={selectedOption}
selectOptions={dataset.list}
selectOptions={selectOptions}
min={min}
max={max}
position={position}
Expand All @@ -175,7 +182,7 @@ const CustomContent = (props: CustomContentProps) => {
</div>

<div className={`${prefixCls}__btn`}>
<span onClick={onSubmit}>确定</span>
<span onClick={onSubmit}>应用</span>
</div>
</div>,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import type { ColorScaleSelectOptionType } from './index';
import type { SelectType } from './type';

export const THRESHOLD = 'custom';

export const DEHAULT_OPTIONS: ColorScaleSelectOptionType[] = [
export const DEHAULT_OPTIONS: {
label: string;
type: 'number' | 'string' | 'custom';
value: SelectType;
}[] = [
{
label: '等间距',
value: 'quantize',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,16 @@ const schema = {
type: 'number',
title: '颜色划分',
default: {
type: 'threshold',
domain: [5, 5.6, 5.7],
colors: ['#63759a', '#e61486', '#f00', '#0f0'],
type: 'threshold', //选择的筛选字段的类型
domain: [3, 5.666666666666666, 8.333333333333332],
ranges: ['#63759a', '#e61486', '#f00', '#faa'],
},
'x-decorator': 'FormItem',
'x-component': 'ScaleSelector',
'x-component-props': {
placeholder: '请选择',
type: 'number', //选择的筛选字段的类型
dataset: {
min: 5,
max: 7.9,
list: [
{ label: 5, value: 5, count: 17 },
{ label: 5.2, value: 5.2, count: 4 },
{ label: 5.8, value: 5.8, count: 3 },
{ label: 5.6, value: 5.6, count: 2 },
{ label: 5.4, value: 5.4, count: 2 },
{ label: 5.3, value: 5.3, count: 4 },
{ label: 6.1, value: 6.1, count: 1 },
{ label: 5.5, value: 5.5, count: 1 },
{ label: 5.7, value: 5.7, count: 2 },
{ label: 7.9, value: 7.9, count: 1 },
],
},
fieldType: 'number', //选择的筛选字段的类型
domain: [2, 10],
defaultColors: ['#f00', '#ff0', '#00f', '#faa'],
},
},
Expand Down
Loading

0 comments on commit 5a21d9a

Please sign in to comment.