From 16fb75af1300a0b9be6651ecaeca3054a3521d1b Mon Sep 17 00:00:00 2001 From: fredzhu Date: Thu, 4 Jan 2024 10:10:23 +0800 Subject: [PATCH] feature(dataset): fix dataset visualization for large-scale categories --- .../src/components/CategoryFilter/index.tsx | 28 ++++++++----------- .../components/src/Annotator/utils/color.ts | 13 ++++++--- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/packages/app/src/components/CategoryFilter/index.tsx b/packages/app/src/components/CategoryFilter/index.tsx index 639dc06..2bacd76 100644 --- a/packages/app/src/components/CategoryFilter/index.tsx +++ b/packages/app/src/components/CategoryFilter/index.tsx @@ -1,5 +1,5 @@ -import React from 'react'; -import { Select } from 'antd'; +import React, { useMemo } from 'react'; +import { Select, SelectProps } from 'antd'; import { useLocale } from 'dds-utils/locale'; import styles from './index.less'; import { Category } from '@/types'; @@ -14,30 +14,26 @@ const CategoryFilter: React.FC = (props) => { const { localeText } = useLocale(); const { categoryId, categories, onCategoryChange } = props; + const options: SelectProps['options'] = useMemo(() => { + return categories.map((item) => ({ + label: item.name, + value: item.id, + })); + }, [categories]); + return (
{localeText('dataset.detail.category')}: + />
); }; diff --git a/packages/components/src/Annotator/utils/color.ts b/packages/components/src/Annotator/utils/color.ts index eb0adde..3f696b1 100644 --- a/packages/components/src/Annotator/utils/color.ts +++ b/packages/components/src/Annotator/utils/color.ts @@ -43,7 +43,12 @@ export const hexToRgba = (hex: string, opacity = 1) => { )},${op})`; }; -/** Generate a color list based on the number of categories. */ +/** + * Generate a color list based on the number of categories. + * max random 1000 + * @param count + * @returns + */ export const createColorList = (count: number) => { const colors = [ '#FFFF00', @@ -75,7 +80,7 @@ export const createColorList = (count: number) => { .padStart(2, '0')}${rgb[2] .toString(16) .padStart(2, '0')}`.toUpperCase(); - if (!colors.includes(hexColor)) { + if (count > 1000 || !colors.includes(hexColor)) { colors.push(hexColor); } } @@ -87,10 +92,10 @@ export const getCategoryColors = (list: string[]) => { if (!list.length) return {}; const sortList = [...list]; - const colors = createColorList(sortList.length); + const colors = createColorList(sortList.length) ; const result: Record = {}; sortList.forEach((item, index) => { - result[item] = colors[index]; + result[item] = colors[index] || '#fff'; }); return result; };