Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Loïs Poujade
Mirador annotations
Commits
4e3ff3a9
Commit
4e3ff3a9
authored
May 21, 2020
by
Jack Reed
Browse files
Options
Downloads
Patches
Plain Diff
Enable moving of shapes
parent
c4a4d04e
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/AnnotationCreation.js
+4
-0
4 additions, 0 deletions
src/AnnotationCreation.js
src/AnnotationDrawing.js
+6
-8
6 additions, 8 deletions
src/AnnotationDrawing.js
src/EditTool.js
+102
-0
102 additions, 0 deletions
src/EditTool.js
src/utils.js
+9
-0
9 additions, 0 deletions
src/utils.js
with
121 additions
and
8 deletions
src/AnnotationCreation.js
+
4
−
0
View file @
4e3ff3a9
...
@@ -13,6 +13,7 @@ import FormatColorFillIcon from '@material-ui/icons/FormatColorFill';
...
@@ -13,6 +13,7 @@ import FormatColorFillIcon from '@material-ui/icons/FormatColorFill';
import
StrokeColorIcon
from
'
@material-ui/icons/BorderColor
'
;
import
StrokeColorIcon
from
'
@material-ui/icons/BorderColor
'
;
import
LineWeightIcon
from
'
@material-ui/icons/LineWeight
'
;
import
LineWeightIcon
from
'
@material-ui/icons/LineWeight
'
;
import
ArrowDropDownIcon
from
'
@material-ui/icons/ArrowDropDown
'
;
import
ArrowDropDownIcon
from
'
@material-ui/icons/ArrowDropDown
'
;
import
FormatShapesIcon
from
'
@material-ui/icons/FormatShapes
'
;
import
Popover
from
'
@material-ui/core/Popover
'
;
import
Popover
from
'
@material-ui/core/Popover
'
;
import
Divider
from
'
@material-ui/core/Divider
'
;
import
Divider
from
'
@material-ui/core/Divider
'
;
import
MenuItem
from
'
@material-ui/core/MenuItem
'
;
import
MenuItem
from
'
@material-ui/core/MenuItem
'
;
...
@@ -204,6 +205,9 @@ class AnnotationCreation extends Component {
...
@@ -204,6 +205,9 @@ class AnnotationCreation extends Component {
<
ToggleButton
value
=
"
cursor
"
aria
-
label
=
"
select cursor
"
>
<
ToggleButton
value
=
"
cursor
"
aria
-
label
=
"
select cursor
"
>
<
CursorIcon
/>
<
CursorIcon
/>
<
/ToggleButton
>
<
/ToggleButton
>
<
ToggleButton
value
=
"
edit
"
aria
-
label
=
"
select cursor
"
>
<
FormatShapesIcon
/>
<
/ToggleButton
>
<
/ToggleButtonGroup
>
<
/ToggleButtonGroup
>
<
Divider
flexItem
orientation
=
"
vertical
"
className
=
{
classes
.
divider
}
/
>
<
Divider
flexItem
orientation
=
"
vertical
"
className
=
{
classes
.
divider
}
/
>
<
ToggleButtonGroup
<
ToggleButtonGroup
...
...
This diff is collapsed.
Click to expand it.
src/AnnotationDrawing.js
+
6
−
8
View file @
4e3ff3a9
...
@@ -6,6 +6,8 @@ import { renderWithPaperScope, PaperContainer } from '@psychobolt/react-paperjs'
...
@@ -6,6 +6,8 @@ import { renderWithPaperScope, PaperContainer } from '@psychobolt/react-paperjs'
import
{
EllipseTool
,
PolygonTool
,
RectangleTool
}
from
'
@psychobolt/react-paperjs-editor
'
;
import
{
EllipseTool
,
PolygonTool
,
RectangleTool
}
from
'
@psychobolt/react-paperjs-editor
'
;
import
{
Point
}
from
'
paper
'
;
import
{
Point
}
from
'
paper
'
;
import
flatten
from
'
lodash/flatten
'
;
import
flatten
from
'
lodash/flatten
'
;
import
EditTool
from
'
./EditTool
'
;
import
{
mapChildren
}
from
'
./utils
'
;
/** */
/** */
class
AnnotationDrawing
extends
Component
{
class
AnnotationDrawing
extends
Component
{
...
@@ -31,16 +33,9 @@ class AnnotationDrawing extends Component {
...
@@ -31,16 +33,9 @@ class AnnotationDrawing extends Component {
x
,
y
,
width
,
height
,
x
,
y
,
width
,
height
,
}
=
bounds
;
}
=
bounds
;
/** */
function
mapChildren
(
layerThing
)
{
if
(
layerThing
.
children
)
{
return
flatten
(
layerThing
.
children
.
map
((
child
)
=>
mapChildren
(
child
)));
}
return
layerThing
;
}
// Reset strokeWidth for persistence
// Reset strokeWidth for persistence
path
.
strokeWidth
=
strokeWidth
;
// eslint-disable-line no-param-reassign
path
.
strokeWidth
=
strokeWidth
;
// eslint-disable-line no-param-reassign
path
.
data
.
state
=
null
;
// eslint-disable-line no-param-reassign
const
svgExports
=
flatten
(
path
.
project
.
layers
.
map
((
layer
)
=>
(
const
svgExports
=
flatten
(
path
.
project
.
layers
.
map
((
layer
)
=>
(
flatten
(
mapChildren
(
layer
)).
map
((
aPath
)
=>
aPath
.
exportSVG
({
asString
:
true
}))
flatten
(
mapChildren
(
layer
)).
map
((
aPath
)
=>
aPath
.
exportSVG
({
asString
:
true
}))
)));
)));
...
@@ -86,6 +81,9 @@ class AnnotationDrawing extends Component {
...
@@ -86,6 +81,9 @@ class AnnotationDrawing extends Component {
case
'
polygon
'
:
case
'
polygon
'
:
ActiveTool
=
PolygonTool
;
ActiveTool
=
PolygonTool
;
break
;
break
;
case
'
edit
'
:
ActiveTool
=
EditTool
;
break
;
default
:
default
:
break
;
break
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/EditTool.js
0 → 100644
+
102
−
0
View file @
4e3ff3a9
import
React
,
{
Component
}
from
'
react
'
;
import
PropTypes
from
'
prop-types
'
;
import
{
Tool
}
from
'
@psychobolt/react-paperjs
'
;
import
flatten
from
'
lodash/flatten
'
;
import
{
mapChildren
}
from
'
./utils
'
;
/** */
class
EditTool
extends
Component
{
/** */
constructor
(
props
)
{
super
(
props
);
this
.
onMouseMove
=
this
.
onMouseMove
.
bind
(
this
);
this
.
onMouseDown
=
this
.
onMouseDown
.
bind
(
this
);
this
.
onMouseDrag
=
this
.
onMouseDrag
.
bind
(
this
);
this
.
onMouseUp
=
this
.
onMouseUp
.
bind
(
this
);
}
/** */
onMouseDown
(
e
)
{
const
{
paper
}
=
this
.
props
;
const
{
project
}
=
paper
;
const
paths
=
flatten
(
project
.
layers
.
map
((
layer
)
=>
(
flatten
(
mapChildren
(
layer
)).
map
((
aPath
)
=>
aPath
)
)));
paths
.
forEach
((
path
)
=>
{
if
(
path
.
contains
(
e
.
point
))
{
path
.
data
.
state
=
'
moving
'
;
// eslint-disable-line no-param-reassign
}
});
}
/** */
onMouseDrag
(
e
)
{
const
{
paper
}
=
this
.
props
;
const
{
project
}
=
paper
;
const
paths
=
flatten
(
project
.
layers
.
map
((
layer
)
=>
(
flatten
(
mapChildren
(
layer
)).
map
((
aPath
)
=>
aPath
)
)));
paths
.
forEach
((
path
)
=>
{
if
(
path
.
data
.
state
===
'
moving
'
)
{
// We need to do the JavaScript version rather than the PaperScript
// https://github.com/paperjs/paper.js/issues/1486
path
.
position
=
path
.
position
.
add
(
// eslint-disable-line no-param-reassign
e
.
point
.
subtract
(
e
.
lastPoint
),
);
}
});
}
/** */
onMouseMove
(
e
)
{
const
{
paper
}
=
this
.
props
;
const
{
project
}
=
paper
;
const
paths
=
flatten
(
project
.
layers
.
map
((
layer
)
=>
(
flatten
(
mapChildren
(
layer
)).
map
((
aPath
)
=>
aPath
)
)));
project
.
activeLayer
.
selected
=
false
;
paths
.
forEach
((
path
)
=>
{
if
(
path
.
contains
(
e
.
point
))
{
path
.
selected
=
true
;
// eslint-disable-line no-param-reassign
}
});
}
/** */
onMouseUp
(
e
)
{
const
{
paper
}
=
this
.
props
;
const
{
project
}
=
paper
;
const
paths
=
flatten
(
project
.
layers
.
map
((
layer
)
=>
(
flatten
(
mapChildren
(
layer
)).
map
((
aPath
)
=>
aPath
)
)));
paths
.
forEach
((
path
)
=>
{
path
.
data
.
state
=
null
;
// eslint-disable-line no-param-reassign
});
}
/** */
render
()
{
return
(
<
Tool
onMouseDown
=
{
this
.
onMouseDown
}
onMouseDrag
=
{
this
.
onMouseDrag
}
onMouseMove
=
{
this
.
onMouseMove
}
onMouseUp
=
{
this
.
onMouseUp
}
/
>
);
}
}
EditTool
.
propTypes
=
{
paper
:
PropTypes
.
object
.
isRequired
,
// eslint-disable-line react/forbid-prop-types
};
export
default
React
.
forwardRef
((
props
,
ref
)
=>
<
EditTool
innerRef
=
{
ref
}
{...
props
}
/>
)
; /
/
eslint
-
disable
-
line
This diff is collapsed.
Click to expand it.
src/utils.js
0 → 100644
+
9
−
0
View file @
4e3ff3a9
import
flatten
from
'
lodash/flatten
'
;
/** */
export
function
mapChildren
(
layerThing
)
{
if
(
layerThing
.
children
)
{
return
flatten
(
layerThing
.
children
.
map
((
child
)
=>
mapChildren
(
child
)));
}
return
layerThing
;
}
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