Skip to content

Commit f5dc3ac

Browse files
committed
zooming on allowed area
1 parent cb4365b commit f5dc3ac

File tree

6 files changed

+50
-7
lines changed

6 files changed

+50
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"react-hotkeys": "^2.0.0",
1919
"react-json-view": "^1.19.1",
2020
"react-markdown": "^4.0.6",
21-
"react-material-workspace-layout": "^0.1.16",
21+
"react-material-workspace-layout": "^0.1.17",
2222
"react-monaco-editor": "^0.25.1",
2323
"react-remove-scroll": "^2.0.4",
2424
"react-select": "^3.0.8",

src/ImageCanvas/index.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// @flow weak
22

3-
import React, { useRef, useState, useLayoutEffect, useMemo } from "react"
3+
import React, {
4+
useRef,
5+
useState,
6+
useLayoutEffect,
7+
useEffect,
8+
useMemo,
9+
} from "react"
410
import type { Node } from "react"
511
import { Matrix } from "transformation-matrix-js"
612
import Crosshairs from "../Crosshairs"
@@ -48,6 +54,7 @@ type Props = {
4854
allowedArea?: { x: number, y: number, w: number, h: number },
4955
RegionEditLabel?: Node,
5056
videoPlaying?: boolean,
57+
zoomOnAllowedArea?: boolean,
5158
fullImageSegmentationMode?: boolean,
5259
autoSegmentationOptions?: Object,
5360

@@ -70,7 +77,15 @@ type Props = {
7077
onChangeVideoPlaying?: Function,
7178
}
7279

73-
const getDefaultMat = () => Matrix.from(1, 0, 0, 1, -10, -10)
80+
const getDefaultMat = (allowedArea = null, { iw, ih } = {}) => {
81+
let mat = Matrix.from(1, 0, 0, 1, -10, -10)
82+
if (allowedArea && iw) {
83+
mat = mat
84+
.translate(allowedArea.x * iw, allowedArea.y * ih)
85+
.scaleU(allowedArea.w + 0.05)
86+
}
87+
return mat
88+
}
7489

7590
export const ImageCanvas = ({
7691
regions,
@@ -110,6 +125,7 @@ export const ImageCanvas = ({
110125
onChangeVideoTime,
111126
onChangeVideoPlaying,
112127
onRegionClassAdded,
128+
zoomOnAllowedArea = true,
113129
}: Props) => {
114130
const classes = useStyles()
115131

@@ -155,6 +171,7 @@ export const ImageCanvas = ({
155171

156172
const [imageDimensions, changeImageDimensions] = useState()
157173
const imageLoaded = Boolean(imageDimensions && imageDimensions.naturalWidth)
174+
158175
const onVideoOrImageLoaded = useEventCallback(
159176
({ naturalWidth, naturalHeight, duration }) => {
160177
const dims = { naturalWidth, naturalHeight, duration }
@@ -190,6 +207,17 @@ export const ImageCanvas = ({
190207
}
191208
}
192209

210+
useEffect(() => {
211+
if (!imageLoaded) return
212+
changeMat(
213+
getDefaultMat(
214+
zoomOnAllowedArea ? allowedArea : null,
215+
layoutParams.current
216+
)
217+
)
218+
// eslint-disable-next-line
219+
}, [imageLoaded])
220+
193221
useLayoutEffect(() => {
194222
if (!imageDimensions) return
195223
const { clientWidth, clientHeight } = canvas

src/ImageCanvas/index.story.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,13 @@ storiesOf("ImageCanvas", module)
138138
{...events}
139139
/>
140140
))
141+
.add("Allowed Area (2)", () => (
142+
<ImageCanvas
143+
showTags
144+
regions={[]}
145+
imageSrc={exampleImage}
146+
zoomWithPrimary
147+
allowedArea={{ x: 0.6, y: 0.6, w: 0.2, h: 0.2 }}
148+
{...events}
149+
/>
150+
))

src/MainLayout/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export const MainLayout = ({
105105
const canvas = (
106106
<ImageCanvas
107107
{...settings}
108+
showCrosshairs={
109+
settings.showCrosshairs &&
110+
!["select", "pan", "zoom"].includes(state.selectedTool)
111+
}
108112
key={state.selectedImage}
109113
showMask={state.showMask}
110114
fullImageSegmentationMode={state.fullImageSegmentationMode}

src/RegionShapes/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export const RegionShapes = ({
157157
}}
158158
>
159159
<WrappedRegionList
160+
key="wrapped-region-list"
160161
regions={regions}
161162
iw={iw}
162163
ih={ih}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14546,10 +14546,10 @@ react-markdown@^4.0.6:
1454614546
unist-util-visit "^1.3.0"
1454714547
xtend "^4.0.1"
1454814548

14549-
react-material-workspace-layout@^0.1.16:
14550-
version "0.1.16"
14551-
resolved "https://registry.yarnpkg.com/react-material-workspace-layout/-/react-material-workspace-layout-0.1.16.tgz#fa51c8a52e19cc3f8cc1627d69f761851447621e"
14552-
integrity sha512-knxP+1dYMueWdpp/LZoTt23P5LJjtoexZsKBTgRZFMZwvc1uXSK3u2Lwxf6jw5AMI55mrTrWNhB7aqOpzROtjA==
14549+
react-material-workspace-layout@^0.1.17:
14550+
version "0.1.17"
14551+
resolved "https://registry.yarnpkg.com/react-material-workspace-layout/-/react-material-workspace-layout-0.1.17.tgz#98a997e7d8671444fafe53caa4298b6643d1b9cb"
14552+
integrity sha512-GY+jFZ14IYKyzIW/KI8/R0Mttb5dTRdYDKdj++YAU/Z3HSQ7kZJ678mv5Nl7X0o081IpMFg5CRiBvvdozUmBtQ==
1455314553
dependencies:
1455414554
"@material-ui/core" "^4.10.0"
1455514555
"@material-ui/icons" "^4.9.1"

0 commit comments

Comments
 (0)