Skip to content

Added comment box option when creating a new area/point/polygon #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Annotator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const Annotator = ({
hideHeaderText,
hideNext,
hidePrev,
allowComments,
}: Props) => {
if (typeof selectedImage === "string") {
selectedImage = (images || []).findIndex((img) => img.src === selectedImage)
Expand Down Expand Up @@ -125,6 +126,7 @@ export const Annotator = ({
history: [],
videoName,
keypointDefinitions,
allowComments,
...(annotationType === "image"
? {
selectedImage,
Expand Down
31 changes: 31 additions & 0 deletions src/Annotator/index.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,37 @@ storiesOf("Annotator", module)
]}
/>
))
.add("Basic - Allow Comments", () => (
<Annotator
onExit={actionAddon("onExit")}
middlewares={middlewares}
labelImages
regionClsList={["Alpha", "Beta", "Charlie", "Delta"]}
regionTagList={["tag1", "tag2", "tag3"]}
imageClsList={["Alpha", "Beta", "Charlie", "Delta"]}
imageTagList={["tag1", "tag2", "tag3"]}
images={[
{
src: exampleImage,
name: "Seve's Desk",
regions: testRegions,
},
{
src: "https://loremflickr.com/100/100/cars?lock=1",
name: "Frame 0036",
},
{
src: "https://loremflickr.com/100/100/cars?lock=2",
name: "Frame 0037",
},
{
src: "https://loremflickr.com/100/100/cars?lock=3",
name: "Frame 0038",
},
]}
allowComments
/>
))
.add("Fixed Size Container", () => (
<div style={{ width: 500, height: 500 }}>
<Annotator
Expand Down
3 changes: 3 additions & 0 deletions src/Annotator/reducers/general-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ export default (state: MainLayoutState, action: Action) => {
if (!isEqual(oldRegion.tags, action.region.tags)) {
state = saveToHistory(state, "Change Region Tags")
}
if (!isEqual(oldRegion.comment, action.region.comment)) {
state = saveToHistory(state, "Change Region Comment")
}
return setIn(
state,
[...pathToActiveImage, "regions", regionIndex],
Expand Down
1 change: 1 addition & 0 deletions src/DemoSite/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const examples = {
name: "bianchi-oltre-xr4",
},
],
allowComments: true,
}),
"Simple Segmentation": () => ({
taskDescription:
Expand Down
5 changes: 4 additions & 1 deletion src/ImageCanvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type Props = {
fullImageSegmentationMode?: boolean,
autoSegmentationOptions?: Object,
modifyingAllowedArea?: boolean,

allowComments?: Boolean,
onChangeRegion: (Region) => any,
onBeginRegionEdit: (Region) => any,
onCloseRegionEdit: (Region) => any,
Expand Down Expand Up @@ -139,6 +139,7 @@ export const ImageCanvas = ({
zoomOnAllowedArea = true,
modifyingAllowedArea = false,
keypointDefinitions,
allowComments,
}: Props) => {
const classes = useStyles()

Expand Down Expand Up @@ -388,6 +389,7 @@ export const ImageCanvas = ({
imageSrc={imageSrc}
RegionEditLabel={RegionEditLabel}
onRegionClassAdded={onRegionClassAdded}
allowComments={allowComments}
/>
</PreventScrollToParents>
)}
Expand All @@ -402,6 +404,7 @@ export const ImageCanvas = ({
editing
region={highlightedRegion}
imageSrc={imageSrc}
allowComments={allowComments}
/>
</div>
)}
Expand Down
1 change: 1 addition & 0 deletions src/MainLayout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export const MainLayout = ({
onChangeVideoTime={action("CHANGE_VIDEO_TIME", "newTime")}
onChangeVideoPlaying={action("CHANGE_VIDEO_PLAYING", "isPlaying")}
onRegionClassAdded={onRegionClassAdded}
allowComments={state.allowComments}
/>
)

Expand Down
29 changes: 27 additions & 2 deletions src/RegionLabel/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

import React, { useState, memo } from "react"
import React, { useRef, memo } from "react"
import Paper from "@material-ui/core/Paper"
import { makeStyles } from "@material-ui/core/styles"
import styles from "./styles"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to import TextField (it doesn't compile?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seveibar
That's right, sorry I missed that

Expand All @@ -10,7 +10,7 @@ import IconButton from "@material-ui/core/IconButton"
import Button from "@material-ui/core/Button"
import TrashIcon from "@material-ui/icons/Delete"
import CheckIcon from "@material-ui/icons/Check"
import UndoIcon from "@material-ui/icons/Undo"
import TextField from "@material-ui/core/TextField"
import Select from "react-select"
import CreatableSelect from "react-select/creatable"

Expand All @@ -30,6 +30,7 @@ type Props = {
onClose: (Region) => null,
onOpen: (Region) => null,
onRegionClassAdded: () => {},
allowComments?: boolean,
}

export const RegionLabel = ({
Expand All @@ -42,8 +43,16 @@ export const RegionLabel = ({
onClose,
onOpen,
onRegionClassAdded,
allowComments,
}: Props) => {
const classes = useStyles()
const commentInputRef = useRef(null)
const onCommentInputClick = (_) => {
// The TextField wraps the <input> tag with two divs
const commentInput = commentInputRef.current.children[0].children[0]

if (commentInput) return commentInput.focus()
}

return (
<Paper
Expand Down Expand Up @@ -142,6 +151,22 @@ export const RegionLabel = ({
/>
</div>
)}
{allowComments && (
<TextField
InputProps={{
className: classes.commentBox,
}}
fullWidth
multiline
rows={3}
ref={commentInputRef}
onClick={onCommentInputClick}
value={region.comment || ""}
onChange={(event) =>
onChange({ ...(region: any), comment: event.target.value })
}
/>
)}
{onClose && (
<div style={{ marginTop: 4, display: "flex" }}>
<div style={{ flexGrow: 1 }} />
Expand Down
4 changes: 4 additions & 0 deletions src/RegionLabel/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ export default {
},
},
},
commentBox: {
fontWeight: 400,
fontSize: 13,
},
}
2 changes: 2 additions & 0 deletions src/RegionTags/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const RegionTags = ({
imageSrc,
RegionEditLabel,
onRegionClassAdded,
allowComments,
}) => {
const RegionLabel =
RegionEditLabel != null ? RegionEditLabel : DefaultRegionLabel
Expand Down Expand Up @@ -118,6 +119,7 @@ export const RegionTags = ({
regions={regions}
imageSrc={imageSrc}
onRegionClassAdded={onRegionClassAdded}
allowComments={allowComments}
/>
</div>
</div>
Expand Down