Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mirador annotations
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
IIIF
Mirador
Mirador annotations
Commits
df4e0e7b
Verified
Commit
df4e0e7b
authored
2 years ago
by
Loïs Poujade
Browse files
Options
Downloads
Patches
Plain Diff
wip0
parent
2681b842
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/AnnotationCreation.js
+27
-2
27 additions, 2 deletions
src/AnnotationCreation.js
src/AnnotationDrawing.js
+97
-56
97 additions, 56 deletions
src/AnnotationDrawing.js
with
124 additions
and
58 deletions
src/AnnotationCreation.js
+
27
−
2
View file @
df4e0e7b
...
@@ -114,8 +114,8 @@ class AnnotationCreation extends Component {
...
@@ -114,8 +114,8 @@ class AnnotationCreation extends Component {
popoverAnchorEl
:
null
,
popoverAnchorEl
:
null
,
popoverLineWeightAnchorEl
:
null
,
popoverLineWeightAnchorEl
:
null
,
svg
:
null
,
svg
:
null
,
tend
:
''
,
tend
:
Math
.
floor
(
props
.
currentTime
)
+
10
,
tstart
:
''
,
tstart
:
Math
.
floor
(
props
.
currentTime
)
,
textEditorStateBustingKey
:
0
,
textEditorStateBustingKey
:
0
,
xywh
:
null
,
xywh
:
null
,
...
annoState
,
...
annoState
,
...
@@ -125,6 +125,10 @@ class AnnotationCreation extends Component {
...
@@ -125,6 +125,10 @@ class AnnotationCreation extends Component {
this
.
updateBody
=
this
.
updateBody
.
bind
(
this
);
this
.
updateBody
=
this
.
updateBody
.
bind
(
this
);
this
.
updateTstart
=
this
.
updateTstart
.
bind
(
this
);
this
.
updateTstart
=
this
.
updateTstart
.
bind
(
this
);
this
.
updateTend
=
this
.
updateTend
.
bind
(
this
);
this
.
updateTend
=
this
.
updateTend
.
bind
(
this
);
this
.
setTstartNow
=
this
.
setTstartNow
.
bind
(
this
);
this
.
setTendNow
=
this
.
setTendNow
.
bind
(
this
);
this
.
seekToTstart
=
this
.
seekToTstart
.
bind
(
this
);
this
.
seekToTend
=
this
.
seekToTend
.
bind
(
this
);
this
.
updateGeometry
=
this
.
updateGeometry
.
bind
(
this
);
this
.
updateGeometry
=
this
.
updateGeometry
.
bind
(
this
);
this
.
changeTool
=
this
.
changeTool
.
bind
(
this
);
this
.
changeTool
=
this
.
changeTool
.
bind
(
this
);
this
.
changeClosedMode
=
this
.
changeClosedMode
.
bind
(
this
);
this
.
changeClosedMode
=
this
.
changeClosedMode
.
bind
(
this
);
...
@@ -227,6 +231,8 @@ class AnnotationCreation extends Component {
...
@@ -227,6 +231,8 @@ class AnnotationCreation extends Component {
svg
:
null
,
svg
:
null
,
textEditorStateBustingKey
:
textEditorStateBustingKey
+
1
,
textEditorStateBustingKey
:
textEditorStateBustingKey
+
1
,
xywh
:
null
,
xywh
:
null
,
tsart
:
null
,
tend
:
null
});
});
}
}
...
@@ -255,6 +261,19 @@ class AnnotationCreation extends Component {
...
@@ -255,6 +261,19 @@ class AnnotationCreation extends Component {
/** update annotation end time */
/** update annotation end time */
updateTend
(
ev
)
{
this
.
setState
({
tend
:
ev
.
target
.
value
});
}
updateTend
(
ev
)
{
this
.
setState
({
tend
:
ev
.
target
.
value
});
}
/** set annotation start time to current time */
setTstartNow
()
{
this
.
setState
({
tstart
:
Math
.
floor
(
this
.
currentTime
)
});
}
/** set annotation end time to current time */
setTendNow
()
{
this
.
setState
({
tend
:
Math
.
floor
(
this
.
props
.
currentTime
)
});
}
/** seekTo annotation start time */
seekToTstart
()
{
this
.
props
.
setSeekTo
(
this
.
state
.
tstart
);
}
/** seekTo annotation end time */
seekToTend
()
{
this
.
props
.
setSeekTo
(
this
.
state
.
tend
);
}
/** */
/** */
updateGeometry
({
svg
,
xywh
})
{
updateGeometry
({
svg
,
xywh
})
{
this
.
setState
({
this
.
setState
({
...
@@ -406,7 +425,11 @@ class AnnotationCreation extends Component {
...
@@ -406,7 +425,11 @@ class AnnotationCreation extends Component {
<
/Grid
>
<
/Grid
>
<
Grid
item
xs
=
{
12
}
>
<
Grid
item
xs
=
{
12
}
>
<
input
name
=
"
tstart
"
type
=
"
number
"
step
=
"
1
"
value
=
{
tstart
}
onChange
=
{
this
.
updateTstart
}
/
>
<
input
name
=
"
tstart
"
type
=
"
number
"
step
=
"
1
"
value
=
{
tstart
}
onChange
=
{
this
.
updateTstart
}
/
>
<
Button
onClick
=
{
this
.
setTstartNow
}
>
now
<
/Button
>
<
Button
onClick
=
{
this
.
seekToTstart
}
>
seek
<
/Button
>
<
input
name
=
"
tend
"
type
=
"
number
"
step
=
"
1
"
value
=
{
tend
}
onChange
=
{
this
.
updateTend
}
/
>
<
input
name
=
"
tend
"
type
=
"
number
"
step
=
"
1
"
value
=
{
tend
}
onChange
=
{
this
.
updateTend
}
/
>
<
Button
onClick
=
{
this
.
setTendNow
}
>
now
<
/Button
>
<
Button
onClick
=
{
this
.
seekToTend
}
>
seek
<
/Button
>
<
/Grid
>
<
/Grid
>
<
Grid
item
xs
=
{
12
}
>
<
Grid
item
xs
=
{
12
}
>
<
Typography
variant
=
"
overline
"
>
<
Typography
variant
=
"
overline
"
>
...
@@ -495,6 +518,7 @@ const styles = (theme) => ({
...
@@ -495,6 +518,7 @@ const styles = (theme) => ({
});
});
AnnotationCreation
.
propTypes
=
{
AnnotationCreation
.
propTypes
=
{
currentTime
:
PropTypes
.
number
,
// TODO proper web annotation type ?
// TODO proper web annotation type ?
annotation
:
PropTypes
.
object
,
// eslint-disable-line react/forbid-prop-types
annotation
:
PropTypes
.
object
,
// eslint-disable-line react/forbid-prop-types
canvases
:
PropTypes
.
arrayOf
(
canvases
:
PropTypes
.
arrayOf
(
...
@@ -515,6 +539,7 @@ AnnotationCreation.propTypes = {
...
@@ -515,6 +539,7 @@ AnnotationCreation.propTypes = {
id
:
PropTypes
.
string
.
isRequired
,
id
:
PropTypes
.
string
.
isRequired
,
receiveAnnotation
:
PropTypes
.
func
.
isRequired
,
receiveAnnotation
:
PropTypes
.
func
.
isRequired
,
windowId
:
PropTypes
.
string
.
isRequired
,
windowId
:
PropTypes
.
string
.
isRequired
,
setSeekTo
:
PropTypes
.
func
.
isRequired
,
};
};
AnnotationCreation
.
defaultProps
=
{
AnnotationCreation
.
defaultProps
=
{
...
...
This diff is collapsed.
Click to expand it.
src/AnnotationDrawing.js
+
97
−
56
View file @
df4e0e7b
import
React
,
{
Component
}
from
'
react
'
;
import
React
,
{
Component
}
from
'
react
'
;
import
ReactDOM
from
'
react-dom
'
;
import
ReactDOM
from
'
react-dom
'
;
import
PropTypes
from
'
prop-types
'
;
import
PropTypes
from
'
prop-types
'
;
import
ResizeObserver
from
'
react-resize-observer
'
;
import
{
OSDReferences
}
from
'
mirador/dist/es/src/plugins/OSDReferences
'
;
import
{
OSDReferences
}
from
'
mirador/dist/es/src/plugins/OSDReferences
'
;
import
{
Video
Viewer
sReferences
}
from
'
mirador/dist/es/src/plugins/Video
Viewer
sReferences
'
;
import
{
VideosReferences
}
from
'
mirador/dist/es/src/plugins/VideosReferences
'
;
import
{
renderWithPaperScope
,
PaperContainer
}
from
'
@psychobolt/react-paperjs
'
;
import
{
renderWithPaperScope
,
PaperContainer
,
Size
}
from
'
@psychobolt/react-paperjs
'
;
import
import
{
{
EllipseTool
,
EllipseTool
,
...
@@ -17,23 +18,16 @@ import flatten from 'lodash/flatten';
...
@@ -17,23 +18,16 @@ import flatten from 'lodash/flatten';
import
EditTool
from
'
./EditTool
'
;
import
EditTool
from
'
./EditTool
'
;
import
{
mapChildren
}
from
'
./utils
'
;
import
{
mapChildren
}
from
'
./utils
'
;
/** Use a canvas "like a OSD viewport" (temporary) */
function
viewportFromAnnotationOverlayVideo
(
annotationOverlayVideo
)
{
const
{
canvas
}
=
annotationOverlayVideo
;
return
{
getCenter
:
()
=>
({
x
:
canvas
.
getWidth
()
/
2
,
y
:
canvas
.
getHeight
()
/
2
}),
getFlip
:
()
=>
false
,
getRotation
:
()
=>
false
,
getZoom
:
()
=>
1
,
};
}
/** */
/** */
class
AnnotationDrawing
extends
Component
{
class
AnnotationDrawing
extends
Component
{
/** */
/** */
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
);
super
(
props
);
this
.
paper
=
null
;
this
.
getViewProps
=
this
.
getViewProps
.
bind
(
this
);
this
.
onPaperResize
=
this
.
onPaperResize
.
bind
(
this
);
this
.
paperDidMount
=
this
.
paperDidMount
.
bind
(
this
);
this
.
addPath
=
this
.
addPath
.
bind
(
this
);
this
.
addPath
=
this
.
addPath
.
bind
(
this
);
}
}
...
@@ -65,36 +59,76 @@ class AnnotationDrawing extends Component {
...
@@ -65,36 +59,76 @@ class AnnotationDrawing extends Component {
});
});
}
}
/** */
onPaperResize
(
ev
)
{
paperThing
()
{
if
(
this
.
paper
)
{
console
.
debug
(
'
size:
'
,
this
.
paper
.
view
.
viewSize
);
console
.
debug
(
'
el:
'
,
this
.
paper
.
view
.
element
);
const
{
canvasOverlay
}
=
VideosReferences
.
get
(
this
.
props
.
windowId
);
const
height
=
canvasOverlay
.
ref
.
current
.
height
;
const
width
=
canvasOverlay
.
ref
.
current
.
width
;
this
.
paper
.
view
.
viewSize
=
new
this
.
paper
.
Size
(
width
,
height
);
this
.
paper
.
view
.
zoom
=
canvasOverlay
.
scale
;
console
.
debug
(
'
new scale:
'
,
canvasOverlay
.
scale
);
}
}
getViewport
()
{
const
{
canvasOverlay
}
=
VideosReferences
.
get
(
this
.
props
.
windowId
);
const
height
=
canvasOverlay
.
ref
.
current
.
height
;
const
width
=
canvasOverlay
.
ref
.
current
.
width
;
return
{
getCenter
:
()
=>
({
x
:
width
/
2
,
y
:
height
/
2
}),
getFlip
:
()
=>
false
,
getRotation
:
()
=>
false
,
getZoom
:
()
=>
canvasOverlay
.
scale
,
};
}
getViewProps
()
{
const
{
windowId
}
=
this
.
props
;
const
{
windowId
}
=
this
.
props
;
let
viewport
=
null
;
let
viewport
=
null
;
let
img
=
null
;
let
img
=
null
;
if
(
OSDReferences
.
get
(
windowId
))
{
if
(
OSDReferences
.
get
(
windowId
))
{
console
.
debug
(
'
[annotation-plugin] OSD reference:
'
,
OSDReferences
.
get
(
windowId
));
viewport
=
OSDReferences
.
get
(
windowId
).
current
.
viewport
;
viewport
=
OSDReferences
.
get
(
windowId
).
current
.
viewport
;
img
=
OSDReferences
.
get
(
windowId
).
current
.
world
.
getItemAt
(
0
);
img
=
OSDReferences
.
get
(
windowId
).
current
.
world
.
getItemAt
(
0
);
}
else
if
(
VideoViewersReferences
.
get
(
windowId
))
{
}
else
if
(
VideosReferences
.
get
(
windowId
))
{
console
.
debug
(
'
[annotation-plugin] VideoViewers reference:
'
,
VideoViewersReferences
.
get
(
windowId
));
viewport
=
this
.
getViewport
();
viewport
=
viewportFromAnnotationOverlayVideo
(
VideoViewersReferences
.
get
(
windowId
).
props
);
}
}
const
{
activeTool
,
fillColor
,
strokeColor
,
strokeWidth
,
svg
,
}
=
this
.
props
;
if
(
!
activeTool
||
activeTool
===
'
cursor
'
)
return
null
;
// Setup Paper View to have the same center and zoom as the OSD Viewport/video canvas
// Setup Paper View to have the same center and zoom as the OSD Viewport/video canvas
const
center
=
img
const
center
=
img
?
img
.
viewportToImageCoordinates
(
viewport
.
getCenter
(
true
))
?
img
.
viewportToImageCoordinates
(
viewport
.
getCenter
(
true
))
:
viewport
.
getCenter
();
:
viewport
.
getCenter
();
const
flipped
=
viewport
.
getFlip
();
const
flipped
=
viewport
.
getFlip
();
const
viewProps
=
{
return
{
center
:
new
Point
(
center
.
x
,
center
.
y
),
center
:
new
Point
(
center
.
x
,
center
.
y
),
rotation
:
viewport
.
getRotation
(),
rotation
:
viewport
.
getRotation
(),
scaling
:
new
Point
(
flipped
?
-
1
:
1
,
1
),
scaling
:
new
Point
(
flipped
?
-
1
:
1
,
1
),
zoom
:
img
?
img
.
viewportToImageZoom
(
viewport
.
getZoom
())
:
viewport
.
getZoom
(),
zoom
:
img
?
img
.
viewportToImageZoom
(
viewport
.
getZoom
())
:
viewport
.
getZoom
(),
};
};
}
componentDidMount
()
{
console
.
debug
(
'
componentDidMount
'
);
this
.
onPaperResize
();
}
componentDidUpdate
()
{
console
.
debug
(
'
componentDidUpdate
'
);
this
.
onPaperResize
();
}
paperDidMount
(
paper
)
{
console
.
debug
(
'
paper mounted:
'
,
paper
);
this
.
paper
=
paper
;
}
/** */
paperThing
()
{
const
{
activeTool
,
fillColor
,
strokeColor
,
strokeWidth
,
svg
,
}
=
this
.
props
;
if
(
!
activeTool
||
activeTool
===
'
cursor
'
)
return
null
;
let
ActiveTool
=
RectangleTool
;
let
ActiveTool
=
RectangleTool
;
switch
(
activeTool
)
{
switch
(
activeTool
)
{
case
'
rectangle
'
:
case
'
rectangle
'
:
...
@@ -116,6 +150,11 @@ class AnnotationDrawing extends Component {
...
@@ -116,6 +150,11 @@ class AnnotationDrawing extends Component {
break
;
break
;
}
}
const
{
canvasOverlay
}
=
VideosReferences
.
get
(
this
.
props
.
windowId
);
const
height
=
canvasOverlay
.
ref
.
current
.
height
;
const
width
=
canvasOverlay
.
ref
.
current
.
width
;
// canvasProps={{ style: { left: 0, position: 'absolute', top: 0}, height: height, width: width, resize: 'true' }}
return
(
return
(
<
div
<
div
className
=
"
foo
"
className
=
"
foo
"
...
@@ -124,8 +163,9 @@ class AnnotationDrawing extends Component {
...
@@ -124,8 +163,9 @@ class AnnotationDrawing extends Component {
}}
}}
>
>
<
PaperContainer
<
PaperContainer
canvasProps
=
{{
style
:
{
height
:
'
100%
'
,
width
:
'
100%
'
}
}}
canvasProps
=
{{
style
:
{
position
:
'
absolute
'
,
left
:
0
,
top
:
0
},
height
,
width
}}
viewProps
=
{
viewProps
}
viewProps
=
{
this
.
getViewProps
}
onMount
=
{
this
.
paperDidMount
}
>
>
{
renderWithPaperScope
((
paper
)
=>
{
{
renderWithPaperScope
((
paper
)
=>
{
const
paths
=
flatten
(
paper
.
project
.
layers
.
map
((
layer
)
=>
(
const
paths
=
flatten
(
paper
.
project
.
layers
.
map
((
layer
)
=>
(
...
@@ -149,6 +189,7 @@ class AnnotationDrawing extends Component {
...
@@ -149,6 +189,7 @@ class AnnotationDrawing extends Component {
);
);
})}
})}
<
/PaperContainer
>
<
/PaperContainer
>
<
ResizeObserver
onResize
=
{
this
.
onPaperResize
}
/
>
<
/div
>
<
/div
>
);
);
}
}
...
@@ -156,10 +197,10 @@ class AnnotationDrawing extends Component {
...
@@ -156,10 +197,10 @@ class AnnotationDrawing extends Component {
/** */
/** */
render
()
{
render
()
{
const
{
windowId
}
=
this
.
props
;
const
{
windowId
}
=
this
.
props
;
console
.
log
(
'
[render] videoref :
'
,
VideosReferences
.
get
(
windowId
));
const
container
=
OSDReferences
.
get
(
windowId
)
const
container
=
OSDReferences
.
get
(
windowId
)
?
OSDReferences
.
get
(
windowId
).
current
.
element
?
OSDReferences
.
get
(
windowId
).
current
.
element
:
VideoViewersReferences
.
get
(
windowId
).
apiRef
.
current
;
:
VideosReferences
.
get
(
windowId
).
ref
.
current
.
parentElement
;
return
(
return
(
ReactDOM
.
createPortal
(
this
.
paperThing
(),
container
)
ReactDOM
.
createPortal
(
this
.
paperThing
(),
container
)
);
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment