Skip to content

Commit

Permalink
chore: Minor refactor. #1597
Browse files Browse the repository at this point in the history
  • Loading branch information
mturoci committed Nov 3, 2022
1 parent c1a98ac commit 62ef33b
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions ui/src/image_annotator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ const
}
else if (shape.polygon) return { tag, shape: { polygon: { vertices: shape.polygon.vertices.map(i => ({ x: i.x * aspectRatio, y: i.y * aspectRatio })) } } }
return { tag, shape }
}),
getFarItem = (key: S, text: S, onClick: () => void, activeShape: keyof ImageAnnotatorShape | 'select', iconName: S) => ({
key,
text,
onClick,
canCheck: true,
checked: activeShape === key,
iconProps: { iconName, styles: { root: { fontSize: 20 } } },
})


Expand Down Expand Up @@ -375,31 +383,11 @@ export const XImageAnnotator = ({ model }: { model: ImageAnnotator }) => {
},
]}
farItems={[
{
key: 'select',
text: 'Select',
onClick: chooseShape,
canCheck: true,
checked: activeShape === 'select',
iconProps: { iconName: 'TouchPointer', styles: { root: { fontSize: 20 } } },
},
{
key: 'rect',
text: 'Rectangle',
onClick: chooseShape,
canCheck: true,
checked: activeShape === 'rect',
iconProps: { iconName: 'RectangleShape', styles: { root: { fontSize: 20 } } },
},
{
key: 'polygon',
text: 'Polygon',
onClick: chooseShape,
canCheck: true,
checked: activeShape === 'polygon',
iconProps: { iconName: 'SixPointStar', styles: { root: { fontSize: 20 } } },
},
]} />
getFarItem('select', 'Select', chooseShape, activeShape, 'TouchPointer'),
getFarItem('rect', 'Rectangle', chooseShape, activeShape, 'RectangleShape'),
getFarItem('polygon', 'Polygon', chooseShape, activeShape, 'SixPointStar'),
]}
/>
<div className={css.canvasContainer}>
<canvas ref={imgRef} className={css.canvas} />
<canvas ref={canvasRef} className={css.canvas} onMouseMove={onMouseMove} onMouseDown={onMouseDown} onClick={onClick} />
Expand Down

0 comments on commit 62ef33b

Please sign in to comment.