Skip to content

Commit

Permalink
chore: 问题标注
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Dec 1, 2023
1 parent 9234258 commit addfc01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ const CustomNumber = (props: CustomNumberProps) => {
const [wrapSSR, hashId] = useStyle(prefixCls);

const addPaletteRangeItem = () => {
// 初始为0
// 初始为空数组
if (defaultValue.length === 0) {
// 取最大最小值的平均数
const _medianValue = Number(((Number(domain[1]) - Number(domain[0])) / 2).toFixed(2));
const addList: CustomMappingColorItem[] = [
{
id: uniqueId(),
value: [-Infinity, _medianValue],
// TODO 换一个颜色
color: '#5B8FF9',
},
{
Expand All @@ -35,11 +37,14 @@ const CustomNumber = (props: CustomNumberProps) => {
color: '#5B8FF9',
},
];
return onChange(addList);

onChange(addList);
return;
}

const _domain: [number, number] =
defaultValue.length === 1 ? domain : [Number(defaultValue[defaultValue.length - 1].value[0]), domain[1]];

const _medianValue: number = Number(((Number(_domain[1]) - Number(_domain[0])) / 2).toFixed(2));
const ranges = [Number(_domain[0]), Number((_medianValue + _domain[0]).toFixed(2))];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { usePrefixCls } from '@formily/antd-v5/esm/__builtins__';
import { connect } from '@formily/react';
import { useUpdateEffect } from 'ahooks';
import { Select, Divider } from 'antd';
import { Divider, Select } from 'antd';
import cls from 'classnames';
import React, { useEffect, useMemo, useState } from 'react';
import { DEHAULT_OPTIONS } from './constants';
Expand Down Expand Up @@ -35,6 +35,7 @@ type ScaleSelectorProp = {

const Internal = (props: ScaleSelectorProp) => {
const prefixCls = usePrefixCls('formily-scale-selector');
// TODO: dataType string 或 number 设置不同的 defaultColors
const { dataType, value, domain = [], defaultColors = ['#f00', '#ff0', '#00f', '#faa'], onChange } = props;
const [wrapSSR, hashId] = useStyle(prefixCls);

Expand Down Expand Up @@ -100,6 +101,7 @@ const Internal = (props: ScaleSelectorProp) => {
// 自定义 scale 且数据 domain 发生更新时,自动计算默认值
useUpdateEffect(() => {
if (selectedType === 'custom' && value?.domain && value.domain.length !== 0) {
// TODO value.range 空数组情况
const range = value.range ? [...new Set(value.range)] : defaultColors;
const _defaultValue = getDefaultValue(dataType, domain, range);
if (onChange)
Expand Down

0 comments on commit addfc01

Please sign in to comment.