Skip to content

Commit

Permalink
feat: add display value
Browse files Browse the repository at this point in the history
  • Loading branch information
wadjih-bencheikh18 committed Aug 23, 2023
1 parent 69e94e3 commit dada7ee
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
15 changes: 15 additions & 0 deletions src/components/roi/ROIEditPreference.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function ROIEditPreference() {
<Table.Header>
<ValueRenderers.Title value="Kind" />
<ValueRenderers.Title value="Color" />
<ValueRenderers.Title value="Display" />
<ValueRenderers.Title value="Display value" />
<ValueRenderers.Title value="Font size" />
<ValueRenderers.Title value="Font color" />
Expand Down Expand Up @@ -184,6 +185,20 @@ function ROIEditPreference() {
}
/>
</ValueRenderers.Component>
<ValueRenderers.Component>
<Checkbox
checked={annotationsPreferences[key].displayValue}
onChange={(checked) =>
setAnnotationsPreferences({
...annotationsPreferences,
[key]: {
...annotationsPreferences[key],
displayValue: checked as boolean,
},
})
}
/>
</ValueRenderers.Component>
<ValueRenderers.Component>
<Input
type="number"
Expand Down
10 changes: 6 additions & 4 deletions src/components/roi/annotation/ConvexHullAnnotation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function ConvexHullAnnotation({ roi }: ConvexHullAnnotationProps) {
);

const preferences = usePreferences();
const { color, enabled, fontColor, fontSize } =
const { color, enabled, fontColor, fontSize, displayValue } =
preferences.rois.annotations.convexHull;

const polygonStyle: CSSProperties = useMemo(
Expand All @@ -43,9 +43,11 @@ function ConvexHullAnnotation({ roi }: ConvexHullAnnotationProps) {
return (
<g>
<polygon points={svgPoints} style={polygonStyle} />
<text x={roi.width / 2} y={roi.height + 1} style={textStyle}>
{roi.convexHull.surface}
</text>
{displayValue && (
<text x={roi.width / 2} y={roi.height + 1} style={textStyle}>
{roi.convexHull.surface}
</text>
)}
</g>
);
}
Expand Down
20 changes: 11 additions & 9 deletions src/components/roi/annotation/FeretAnnotation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function FeretAnnotation({ roi }: FeretAnnotationProps) {
);

const preferences = usePreferences();
const { color, enabled, fontColor, fontSize } =
const { color, enabled, fontColor, fontSize, displayValue } =
preferences.rois.annotations.feretDiameters;

const lineStyle: CSSProperties = useMemo(
Expand Down Expand Up @@ -67,14 +67,16 @@ function FeretAnnotation({ roi }: FeretAnnotationProps) {
key={`${roi.id}-${index}`}
>
<line x1={x1} y1={y1} x2={x2} y2={y2} style={lineStyle} />
<text
x={0}
y={0}
transform={`translate(${x}, ${y}) rotate(${rotation})`}
style={textStyle}
>
{length.toFixed(2)}
</text>
{displayValue && (
<text
x={0}
y={0}
transform={`translate(${x}, ${y}) rotate(${rotation})`}
style={textStyle}
>
{length.toFixed(2)}
</text>
)}
</g>
);
})}
Expand Down
10 changes: 6 additions & 4 deletions src/components/roi/annotation/MBRAnnotation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function MBRAnnotation({ roi }: MBRAnnotationProps) {
[roi.mbr.points],
);
const preferences = usePreferences();
const { color, enabled, fontSize, fontColor } =
const { color, enabled, fontSize, fontColor, displayValue } =
preferences.rois.annotations.minimalBoundingRectangle;

const polygonStyle: CSSProperties = useMemo(
Expand All @@ -43,9 +43,11 @@ function MBRAnnotation({ roi }: MBRAnnotationProps) {
return (
<g>
<polygon points={svgPoints} style={polygonStyle} />
<text x={roi.width / 2} y={-1} style={textStyle}>
{roi.width} x {roi.height} ({roi.surface} pixels)
</text>
{displayValue && (
<text x={roi.width / 2} y={-1} style={textStyle}>
{roi.width} x {roi.height} ({roi.surface} pixels)
</text>
)}
</g>
);
}
Expand Down
9 changes: 7 additions & 2 deletions src/state/preferences/PreferencesReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type AnnotationsPreferences = {
color: string;
fontColor: string;
fontSize: number;
displayValue: boolean;
};
};

Expand All @@ -62,24 +63,28 @@ export const initialPreferencesState: PreferencesState = {
color: '#ff0000',
fontColor: '#ff0000',
fontSize: 2,
displayValue: true,
},
minimalBoundingRectangle: {
enabled: true,
color: '#0000ff',
fontColor: '#0000ff',
fontSize: 2,
displayValue: true,
},
feretDiameters: {
enabled: true,
color: '#000000',
color: '#ff00ff',
fontColor: '#ff00ff',
fontSize: 2,
displayValue: true,
},
surface: {
enabled: true,
enabled: false,
color: '#00ff00',
fontColor: '#00ff00',
fontSize: 2,
displayValue: true,
},
},
},
Expand Down

0 comments on commit dada7ee

Please sign in to comment.