Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drawing-app
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
Model registry
Operate
Environments
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
Show more breadcrumbs
sweng-group-15
drawing-app
Commits
fb990695
Commit
fb990695
authored
5 years ago
by
Yuriy Maksymets
Browse files
Options
Downloads
Patches
Plain Diff
WIP: erasing intervals
parent
21d7ebc8
No related branches found
No related tags found
2 merge requests
!57
Erasure intervals
,
!48
Intuitive erasing
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app.js
+56
-18
56 additions, 18 deletions
src/app.js
with
56 additions
and
18 deletions
src/app.js
+
56
−
18
View file @
fb990695
...
@@ -66,11 +66,30 @@ function eraseAt(x, y, room) {
...
@@ -66,11 +66,30 @@ function eraseAt(x, y, room) {
})
})
}
}
const
SVG_URL
=
"
http://www.w3.org/2000/svg
"
const
SVG
=
{
create
:
{
circle
:
()
=>
SVG
.
create
.
elem
(
"
circle
"
),
group
:
()
=>
SVG
.
create
.
elem
(
"
g
"
),
path
:
()
=>
SVG
.
create
.
elem
(
"
path
"
),
elem
:
(
elemName
)
=>
document
.
createElementNS
(
SVG_URL
,
elemName
),
},
}
const
TEST_ERASE_INTERVAL
=
{
0
:
{
start
:
[
120
,
120
,
true
],
end
:
[
140
,
140
,
true
],
},
}
const
addOrUpdatePathElem
=
(
pathElems
,
id
,
points
)
=>
{
const
addOrUpdatePathElem
=
(
pathElems
,
id
,
points
)
=>
{
let
pathElem
=
pathElems
.
get
(
id
)
let
pathElem
=
pathElems
.
get
(
id
)
if
(
pathElem
==
null
)
{
if
(
pathElem
==
null
)
{
pathElem
=
document
.
createElementNS
(
"
http://www.w3.org/2000/svg
"
,
"
g
"
)
pathElem
=
SVG
.
create
.
group
()
console
.
log
(
pathElem
)
pathElem
.
setAttribute
(
"
stroke
"
,
STROKECOLOUR
)
pathElem
.
setAttribute
(
"
stroke
"
,
STROKECOLOUR
)
pathElem
.
setAttribute
(
"
stroke-width
"
,
STROKERADIUS
*
2
)
pathElem
.
setAttribute
(
"
stroke-width
"
,
STROKERADIUS
*
2
)
...
@@ -91,45 +110,64 @@ const addOrUpdatePathElem = (pathElems, id, points) => {
...
@@ -91,45 +110,64 @@ const addOrUpdatePathElem = (pathElems, id, points) => {
// Push a fake path split to generate the last path
// Push a fake path split to generate the last path
points
.
push
([
-
1
,
-
1
,
false
])
points
.
push
([
-
1
,
-
1
,
false
])
const
originalID
=
(
i
)
=>
i
-
1
let
subPath
=
[]
let
toAdd
=
undefined
let
subpath
=
[]
for
(
let
i
=
0
;
i
<
points
.
length
;
i
++
)
{
const
point
=
points
[
i
]
console
.
log
(
subPath
)
if
(
toAdd
)
{
subPath
.
push
(
toAdd
)
toAdd
=
undefined
}
for
(
const
point
of
points
)
{
if
(
point
[
0
]
===
undefined
)
{
if
(
point
[
0
]
===
undefined
)
{
continue
continue
}
}
if
(
point
[
2
]
===
false
)
{
if
(
point
[
2
]
===
false
)
{
if
(
subpath
.
length
==
1
)
{
// End of subpath
const
subpathElem
=
document
.
createElementNS
(
if
(
subPath
.
length
==
1
)
{
"
http://www.w3.org/2000/svg
"
,
const
subpathElem
=
SVG
.
create
.
circle
()
"
circle
"
,
)
subpathElem
.
setAttribute
(
"
stroke
"
,
"
none
"
)
subpathElem
.
setAttribute
(
"
stroke
"
,
"
none
"
)
subpathElem
.
setAttribute
(
"
fill
"
,
STROKECOLOUR
)
subpathElem
.
setAttribute
(
"
fill
"
,
STROKECOLOUR
)
subpathElem
.
setAttribute
(
"
cx
"
,
sub
p
ath
[
0
][
0
])
subpathElem
.
setAttribute
(
"
cx
"
,
sub
P
ath
[
0
][
0
])
subpathElem
.
setAttribute
(
"
cy
"
,
sub
p
ath
[
0
][
1
])
subpathElem
.
setAttribute
(
"
cy
"
,
sub
P
ath
[
0
][
1
])
subpathElem
.
setAttribute
(
"
r
"
,
STROKERADIUS
)
subpathElem
.
setAttribute
(
"
r
"
,
STROKERADIUS
)
pathElem
.
appendChild
(
subpathElem
)
pathElem
.
appendChild
(
subpathElem
)
}
else
if
(
subpath
.
length
>
0
)
{
}
else
if
(
subPath
.
length
>
0
)
{
const
subpathElem
=
document
.
createElementNS
(
const
subpathElem
=
SVG
.
create
.
path
()
"
http://www.w3.org/2000/svg
"
,
"
path
"
,
)
subpathElem
.
setAttribute
(
"
d
"
,
lineFn
(
sub
p
ath
))
subpathElem
.
setAttribute
(
"
d
"
,
lineFn
(
sub
P
ath
))
pathElem
.
appendChild
(
subpathElem
)
pathElem
.
appendChild
(
subpathElem
)
}
}
sub
p
ath
=
[]
sub
P
ath
=
[]
continue
continue
}
}
subpath
.
push
(
point
)
// Valid point inside a subpath
subPath
.
push
(
point
)
const
eraseInterval
=
TEST_ERASE_INTERVAL
[
originalID
(
i
)]
if
(
eraseInterval
)
{
// console.log(eraseInterval)
subPath
.
push
(
eraseInterval
.
start
)
const
subpathElem
=
SVG
.
create
.
path
()
subpathElem
.
setAttribute
(
"
d
"
,
lineFn
(
subPath
))
pathElem
.
appendChild
(
subpathElem
)
subPath
=
[]
toAdd
=
eraseInterval
.
end
}
}
}
return
pathElem
return
pathElem
...
...
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