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
GitLab 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
4fb33fcd
Commit
4fb33fcd
authored
Jan 12, 2024
by
Samuel Jugnet
Browse files
Options
Downloads
Patches
Plain Diff
delete selectioned shape on del keypress
parent
5b1ad5cb
Branches
Branches containing commit
No related tags found
1 merge request
!10
Draft: MigratingAnnotationCreation to MUI5.
Pipeline
#1718
failed
Jan 12, 2024
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/AnnotationDrawing.js
+208
-124
208 additions, 124 deletions
src/AnnotationDrawing.js
src/shapes/LineNode.js
+68
-0
68 additions, 0 deletions
src/shapes/LineNode.js
src/shapes/ParentComponent.js
+27
-0
27 additions, 0 deletions
src/shapes/ParentComponent.js
with
303 additions
and
124 deletions
src/AnnotationDrawing.js
+
208
−
124
View file @
4fb33fcd
...
@@ -76,7 +76,7 @@ class AnnotationDrawing extends Component {
...
@@ -76,7 +76,7 @@ class AnnotationDrawing extends Component {
return
;
return
;
}
}
console
.
log
(
'
selected shape id
'
,
selectedShapeId
);
if
(
!
selectedShapeId
)
{
if
(
!
selectedShapeId
)
{
return
;
return
;
}
}
...
@@ -154,11 +154,14 @@ class AnnotationDrawing extends Component {
...
@@ -154,11 +154,14 @@ class AnnotationDrawing extends Component {
y
:
pos
.
y
,
y
:
pos
.
y
,
width
:
0
,
width
:
0
,
height
:
0
,
height
:
0
,
stroke
:
this
.
props
.
strokeColor
,
stroke
Color
:
this
.
props
.
strokeColor
,
strokeWidth
:
this
.
props
.
strokeWidth
,
strokeWidth
:
this
.
props
.
strokeWidth
,
fill
:
this
.
props
.
fillColor
,
fill
:
this
.
props
.
fillColor
,
id
:
uuidv4
(),
id
:
uuidv4
(),
},
},
},()
=>
{
// Add global key press event listener
window
.
addEventListener
(
'
keydown
'
,
this
.
handleKeyPress
);
});
});
break
;
break
;
case
"
text
"
:
case
"
text
"
:
...
@@ -173,10 +176,34 @@ class AnnotationDrawing extends Component {
...
@@ -173,10 +176,34 @@ class AnnotationDrawing extends Component {
id
:
uuidv4
(),
id
:
uuidv4
(),
};
};
this
.
setState
({
newShape
:
shape
},
()
=>
{
this
.
setState
({
shapes
:
[...
this
.
state
.
shapes
,
shape
],
selectedShape
:
shape
,
selectedShapeId
:
shape
.
id
,
newShape
:
shape
,
currentShape
:
shape
,
},()
=>
{
// Add global key press event listener
// Add global key press event listener
window
.
addEventListener
(
'
keydown
'
,
this
.
handleKeyPress
);
window
.
addEventListener
(
'
keydown
'
,
this
.
handleKeyPress
);
});
});
console
.
log
(
'
text
'
,
shape
);
break
;
case
"
line
"
:
shape
=
{
type
:
'
line
'
,
x
:
pos
.
x
,
y
:
pos
.
y
,
with
:
10
,
height
:
10
,
fill
:
this
.
props
.
fillColor
,
points
:
[
0
,
0
,
0
,
0
,
0
,
0
],
id
:
uuidv4
(),
};
this
.
setState
({
this
.
setState
({
shapes
:
[...
this
.
state
.
shapes
,
shape
],
shapes
:
[...
this
.
state
.
shapes
,
shape
],
...
@@ -184,9 +211,13 @@ class AnnotationDrawing extends Component {
...
@@ -184,9 +211,13 @@ class AnnotationDrawing extends Component {
selectedShapeId
:
shape
.
id
,
selectedShapeId
:
shape
.
id
,
newShape
:
shape
,
newShape
:
shape
,
currentShape
:
shape
,
currentShape
:
shape
,
},()
=>
{
// Add global key press event listener
window
.
addEventListener
(
'
keydown
'
,
this
.
handleKeyPress
);
});
});
console
.
log
(
'
text
'
,
shape
);
break
;
break
;
case
"
freehand
"
:
case
"
freehand
"
:
...
@@ -210,6 +241,9 @@ class AnnotationDrawing extends Component {
...
@@ -210,6 +241,9 @@ class AnnotationDrawing extends Component {
selectedShapeId
:
shape
.
id
,
selectedShapeId
:
shape
.
id
,
newShape
:
shape
,
newShape
:
shape
,
currentShape
:
shape
,
currentShape
:
shape
,
},()
=>
{
// Add global key press event listener
window
.
addEventListener
(
'
keydown
'
,
this
.
handleKeyPress
);
});
});
// other cases
// other cases
...
@@ -257,6 +291,20 @@ class AnnotationDrawing extends Component {
...
@@ -257,6 +291,20 @@ class AnnotationDrawing extends Component {
switch
(
this
.
props
.
activeTool
)
{
switch
(
this
.
props
.
activeTool
)
{
case
'
rectangle
'
:
case
'
rectangle
'
:
case
'
ellipse
'
:
case
'
ellipse
'
:
// prevent negative radius for ellipse
if
(
this
.
state
.
currentShape
.
type
===
'
ellipse
'
)
{
if
(
pos
.
x
<
this
.
state
.
currentShape
.
x
)
{
pos
.
x
=
this
.
state
.
currentShape
.
x
;
}
if
(
pos
.
y
<
this
.
state
.
currentShape
.
y
)
{
pos
.
y
=
this
.
state
.
currentShape
.
y
;
}
}
this
.
setState
({
this
.
setState
({
currentShape
:
{
currentShape
:
{
...
this
.
state
.
currentShape
,
...
this
.
state
.
currentShape
,
...
@@ -266,6 +314,18 @@ class AnnotationDrawing extends Component {
...
@@ -266,6 +314,18 @@ class AnnotationDrawing extends Component {
});
});
break
;
break
;
case
"
line
"
:
// update ponts
this
.
setState
({
currentShape
:
{
...
this
.
state
.
currentShape
,
points
:
[
0
,
0
,
0
,
0
,
pos
.
x
,
pos
.
y
],
},
});
case
"
freehand
"
:
case
"
freehand
"
:
this
.
setState
({
this
.
setState
({
shapes
:
this
.
state
.
shapes
.
map
(
shape
=>
shape
.
id
===
this
.
state
.
selectedShapeId
shapes
:
this
.
state
.
shapes
.
map
(
shape
=>
shape
.
id
===
this
.
state
.
selectedShapeId
...
@@ -292,11 +352,35 @@ class AnnotationDrawing extends Component {
...
@@ -292,11 +352,35 @@ class AnnotationDrawing extends Component {
if
(
!
this
.
state
.
isDrawing
)
return
;
if
(
!
this
.
state
.
isDrawing
)
return
;
if
(
!
this
.
state
.
currentShape
)
return
;
if
(
!
this
.
state
.
currentShape
)
return
;
switch
(
this
.
props
.
activeTool
)
{
case
'
rectangle
'
:
case
'
ellipse
'
:
this
.
setState
((
prevState
)
=>
({
isDrawing
:
false
,
shapes
:
[...
prevState
.
shapes
,
prevState
.
currentShape
],
currentShape
:
null
,
}));
break
;
case
"
line
"
:
this
.
setState
((
prevState
)
=>
({
this
.
setState
((
prevState
)
=>
({
isDrawing
:
false
,
isDrawing
:
false
,
shapes
:
[...
prevState
.
shapes
,
prevState
.
currentShape
],
shapes
:
[...
prevState
.
shapes
,
prevState
.
currentShape
],
currentShape
:
null
,
currentShape
:
null
,
}));
}));
break
;
case
"
freehand
"
:
this
.
setState
((
prevState
)
=>
({
isDrawing
:
false
,
shapes
:
[...
prevState
.
shapes
,
prevState
.
currentShape
],
currentShape
:
null
,
}));
break
;
default
:
}
}
}
catch
(
e
)
{
catch
(
e
)
{
console
.
log
(
'
error
'
,
e
);
console
.
log
(
'
error
'
,
e
);
...
...
This diff is collapsed.
Click to expand it.
src/shapes/LineNode.js
0 → 100644
+
68
−
0
View file @
4fb33fcd
import
React
,
{
Component
,
useState
}
from
'
react
'
;
import
ReactDOM
from
'
react-dom
'
;
import
PropTypes
from
'
prop-types
'
;
import
{
Stage
,
Layer
,
Star
,
Text
,
Circle
,
Rect
,
Ellipse
,
Transformer
,
Shape
,
Line
,
}
from
'
react-konva
'
;
class
LineNode
extends
React
.
Component
{
constructor
(
props
)
{
super
(
props
);
this
.
shapeRef
=
React
.
createRef
();
this
.
trRef
=
React
.
createRef
();
}
componentDidMount
()
{
if
(
this
.
trRef
.
current
)
{
this
.
trRef
.
current
.
nodes
([
this
.
shapeRef
.
current
]);
this
.
trRef
.
current
.
getLayer
().
batchDraw
();
}
}
handleClick
=
()
=>
{
this
.
props
.
onShapeClick
(
this
.
props
.
shape
);
};
render
()
{
const
{
activeTool
}
=
this
.
props
;
const
isSelected
=
this
.
props
.
selectedShapeId
===
this
.
props
.
shape
.
id
return
(
<
React
.
Fragment
>
<
Line
// map props to konva
ref
=
{
this
.
shapeRef
}
x
=
{
this
.
props
.
x
||
0
}
y
=
{
this
.
props
.
y
||
0
}
points
=
{
this
.
props
.
points
||
[
0
,
0
,
0
,
0
,
100
,
100
]}
fill
=
{
this
.
props
.
fill
}
stroke
=
{
this
.
props
.
fill
}
strokeWidth
=
{
this
.
props
.
strokeWidth
||
1
}
id
=
{
this
.
props
.
_id
}
draggable
=
{
activeTool
===
'
cursor
'
||
activeTool
===
'
edit
'
}
onClick
=
{
this
.
handleClick
}
/
>
<
Transformer
ref
=
{
this
.
trRef
}
visible
=
{
activeTool
===
'
edit
'
&&
isSelected
}
/
>
<
/React.Fragment
>
);
}
}
export
default
LineNode
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/shapes/ParentComponent.js
+
27
−
0
View file @
4fb33fcd
...
@@ -8,6 +8,7 @@ import Rectangle from './Rectangle';
...
@@ -8,6 +8,7 @@ import Rectangle from './Rectangle';
import
EllipseNode
from
'
./EllipseNode
'
;
import
EllipseNode
from
'
./EllipseNode
'
;
import
TextNode
from
'
./TextNode
'
;
import
TextNode
from
'
./TextNode
'
;
import
LineNode
from
'
./LineNode
'
;
import
{
import
{
Stage
,
Layer
,
Star
,
Text
,
Circle
,
Rect
Stage
,
Layer
,
Star
,
Text
,
Circle
,
Rect
,
Ellipse
,
Transformer
,
Shape
,
Ellipse
,
Transformer
,
Shape
...
@@ -183,6 +184,32 @@ class ParentComponent extends React.Component {
...
@@ -183,6 +184,32 @@ class ParentComponent extends React.Component {
/
>
/
>
);
);
break
;
break
;
case
'
line
'
:
return
(
<
LineNode
shape
=
{
shape
}
selectedShapeId
=
{
selid
}
selectedShape
=
{
selectedShape
}
onShapeClick
=
{
this
.
handleShapeClick
}
activeTool
=
{
this
.
props
.
activeTool
}
selected
=
{
selected
}
_id
=
{
shape
.
id
}
key
=
{
i
}
x
=
{
shape
.
x
}
y
=
{
shape
.
y
}
points
=
{
shape
.
points
}
fill
=
{
shape
.
fill
}
stroke
=
{
shape
.
strokeColor
}
strokeWidth
=
{
shape
.
strokeWidth
}
draggable
=
{
this
.
props
.
activeTool
===
'
cursor
'
}
onClick
=
{
this
.
props
.
activeTool
===
'
cursor
'
?
()
=>
this
.
setState
({
currentShape
:
shape
})
:
null
}
// onDragEnd={this.handleDragEnd(shape.id)} // Add this line
onDblClick
=
{
this
.
handleShapeDblClick
}
/>
);
}
}
})}
})}
<
/Layer
>
<
/Layer
>
...
...
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