Skip to content

Commit b0623da

Browse files
authored
fix: Merge pull request #84 from UniversalDataTool/remove-image-selector
fix allowed area clamping math
2 parents debdc11 + 87f9ddf commit b0623da

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

src/Annotator/index.story.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ storiesOf("Annotator", module)
181181
regionClsList={["Hand", "Face"]}
182182
regionTagList={["Open Pinch", "Closed Pinch", "In Frame"]}
183183
showTags={false}
184-
allowedArea={{ x: 0.25, y: 0.25, w: 0.5, h: 0.5 }}
184+
allowedArea={{ x: 0, y: 0.6, w: 0.3, h: 0.3 }}
185185
images={[
186186
{
187187
src:

src/Annotator/reducers/general-reducer.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ import clamp from "clamp"
1414
const getRandomId = () => Math.random().toString().split(".")[1]
1515

1616
export default (state: MainLayoutState, action: Action) => {
17+
if (
18+
state.allowedArea &&
19+
["MOUSE_DOWN", "MOUSE_UP", "MOUSE_MOVE"].includes(action.type)
20+
) {
21+
const aa = state.allowedArea
22+
action.x = clamp(action.x, aa.x, aa.x + aa.w)
23+
action.y = clamp(action.y, aa.y, aa.y + aa.h)
24+
}
25+
1726
if (action.type === "ON_CLS_ADDED" && action.cls && action.cls !== "") {
1827
const oldRegionClsList = state.regionClsList
1928
const newState = {
@@ -208,12 +217,7 @@ export default (state: MainLayoutState, action: Action) => {
208217
})
209218
}
210219
case "MOUSE_MOVE": {
211-
let { x, y } = action
212-
if (state.allowedArea) {
213-
const aa = state.allowedArea
214-
x = clamp(x, aa.x, aa.x + aa.w)
215-
y = clamp(y, aa.x, aa.x + aa.w)
216-
}
220+
const { x, y } = action
217221

218222
if (!state.mode) return state
219223
if (!activeImage) return state
@@ -359,13 +363,7 @@ export default (state: MainLayoutState, action: Action) => {
359363
}
360364
case "MOUSE_DOWN": {
361365
if (!activeImage) return state
362-
let { x, y } = action
363-
364-
if (state.allowedArea) {
365-
const aa = state.allowedArea
366-
x = clamp(x, aa.x, aa.x + aa.w)
367-
y = clamp(y, aa.x, aa.x + aa.w)
368-
}
366+
const { x, y } = action
369367

370368
state = setIn(state, ["mouseDownAt"], { x, y })
371369

@@ -534,12 +532,7 @@ export default (state: MainLayoutState, action: Action) => {
534532
return setIn(state, [...pathToActiveImage, "regions"], regions)
535533
}
536534
case "MOUSE_UP": {
537-
let { x, y } = action
538-
if (state.allowedArea) {
539-
const aa = state.allowedArea
540-
x = clamp(x, aa.x, aa.x + aa.w)
541-
y = clamp(y, aa.x, aa.x + aa.w)
542-
}
535+
const { x, y } = action
543536

544537
const { mouseDownAt = { x, y } } = state
545538
if (!state.mode) return state

0 commit comments

Comments
 (0)