Merge branch 'fe/feat/208-segmentation-label-edit' into 'fe/develop'

세그멘테이션 레이블 로컬에서 수정할 수 있도록 변경 - S22P21S002-208

See merge request s11-s-project/S11P21S002!152
This commit is contained in:
정현조 2024-09-24 09:55:03 +09:00
commit c65cb1204e
3 changed files with 15 additions and 12 deletions

View File

@ -1,6 +1,5 @@
import { Label } from '@/types'; import { Label } from '@/types';
import Konva from 'konva'; import Konva from 'konva';
import { useState } from 'react';
import { Line } from 'react-konva'; import { Line } from 'react-konva';
import PolygonTransformer from './PolygonTransformer'; import PolygonTransformer from './PolygonTransformer';
@ -8,21 +7,25 @@ export default function LabelPolygon({
isSelected, isSelected,
onSelect, onSelect,
info, info,
setLabel,
stage, stage,
dragLayer, dragLayer,
}: { }: {
isSelected: boolean; isSelected: boolean;
onSelect: () => void; onSelect: () => void;
info: Label; info: Label;
setLabel: (coordinate: [number, number][]) => void;
stage: Konva.Stage; stage: Konva.Stage;
dragLayer: Konva.Layer; dragLayer: Konva.Layer;
}) { }) {
const [coordinates, setCoordinates] = useState<Array<[number, number]>>(info.coordinates); const handleChange = (coordinates: [number, number][]) => {
setLabel(coordinates);
};
return ( return (
<> <>
<Line <Line
points={coordinates.flat()} points={info.coordinates.flat()}
stroke={info.color} stroke={info.color}
strokeWidth={1} strokeWidth={1}
onMouseDown={onSelect} onMouseDown={onSelect}
@ -33,8 +36,8 @@ export default function LabelPolygon({
/> />
{isSelected && ( {isSelected && (
<PolygonTransformer <PolygonTransformer
coordinates={coordinates} coordinates={info.coordinates}
setCoordinates={setCoordinates} setCoordinates={handleChange}
stage={stage} stage={stage}
dragLayer={dragLayer} dragLayer={dragLayer}
/> />

View File

@ -119,7 +119,7 @@ export default function ImageCanvas() {
setPolygonPoints([]); setPolygonPoints([]);
if (polygonPoints.length < 4) return; if (polygonPoints.length < 4) return;
const color = Math.floor(Math.random() * 65535) const color = Math.floor(Math.random() * 0xffffff)
.toString(16) .toString(16)
.padStart(6, '0'); .padStart(6, '0');
const id = labels.length + 1; const id = labels.length + 1;
@ -146,7 +146,7 @@ export default function ImageCanvas() {
return; return;
} }
setRectPoints([]); setRectPoints([]);
const color = Math.floor(Math.random() * 65535) const color = Math.floor(Math.random() * 0xffffff)
.toString(16) .toString(16)
.padStart(6, '0'); .padStart(6, '0');
const id = labels.length; const id = labels.length;
@ -289,6 +289,7 @@ export default function ImageCanvas() {
isSelected={label.id === selectedLabelId} isSelected={label.id === selectedLabelId}
onSelect={() => setSelectedLabelId(label.id)} onSelect={() => setSelectedLabelId(label.id)}
info={label} info={label}
setLabel={setLabel(label.id)}
stage={stageRef.current as Konva.Stage} stage={stageRef.current as Konva.Stage}
dragLayer={dragLayerRef.current as Konva.Layer} dragLayer={dragLayerRef.current as Konva.Layer}
/> />

View File

@ -36,20 +36,19 @@ export default function ProjectDirectoryItem({
<button className="flex items-center"> <button className="flex items-center">
<ChevronRight <ChevronRight
size={16} size={16}
className={`stroke-gray-500 transition-transform ${isExpanded ? 'rotate-90' : ''}`} className={cn('stroke-gray-500 transition-transform', isExpanded ? 'rotate-90' : '')}
/> />
</button> </button>
<span className="overflow-hidden text-ellipsis whitespace-nowrap">{item.title}</span> <span className="overflow-hidden text-ellipsis whitespace-nowrap">{item.title}</span>
</div> </div>
{isExpanded && ( {
<div className="caption flex flex-col"> <div className={cn('caption flex flex-col', isExpanded ? '' : 'hidden')}>
{folderData.children.map((item) => ( {folderData.children.map((item) => (
<ProjectDirectoryItem <ProjectDirectoryItem
key={`${projectId}-${item.title}`} key={`${projectId}-${item.title}`}
projectId={projectId} projectId={projectId}
item={item} item={item}
depth={depth + 1} depth={depth + 1}
initialExpanded={true}
/> />
))} ))}
{folderData.images.map((item) => ( {folderData.images.map((item) => (
@ -61,7 +60,7 @@ export default function ProjectDirectoryItem({
/> />
))} ))}
</div> </div>
)} }
</> </>
); );
} }