SVG.js - How to delete previously drawn elements in Angular? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How do I detect a click outside an element?How do I check if an element is hidden in jQuery?How to Check if element is visible after scrolling?How do I find out which DOM element has the focus?Deleting array elements in JavaScript - delete vs spliceHow do I add a class to a given element?How can I select an element with multiple classes in jQuery?How to move an element into another element?How do I remove a particular element from an array in JavaScript?How can I add new array elements at the beginning of an array in Javascript?
Did Deadpool rescue all of the X-Force?
When a candle burns, why does the top of wick glow if bottom of flame is hottest?
Take 2! Is this homebrew Lady of Pain warlock patron balanced?
Crossing US/Canada Border for less than 24 hours
Maximum summed subsequences with non-adjacent items
Do any jurisdictions seriously consider reclassifying social media websites as publishers?
Why is my ESD wriststrap failing with nitrile gloves on?
How to install press fit bottom bracket into new frame
Chebyshev inequality in terms of RMS
What is the appropriate index architecture when forced to implement IsDeleted (soft deletes)?
Hangman Game with C++
How to react to hostile behavior from a senior developer?
Why is Nikon 1.4g better when Nikon 1.8g is sharper?
What was the first language to use conditional keywords?
Significance of Cersei's obsession with elephants?
Amount of permutations on an NxNxN Rubik's Cube
Generate an RGB colour grid
How much damage would a cupful of neutron star matter do to the Earth?
Does the Weapon Master feat grant you a fighting style?
If Windows 7 doesn't support WSL, then what does Linux subsystem option mean?
SF book about people trapped in a series of worlds they imagine
Denied boarding although I have proper visa and documentation. To whom should I make a complaint?
Should I follow up with an employee I believe overracted to a mistake I made?
Time to Settle Down!
SVG.js - How to delete previously drawn elements in Angular?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How do I detect a click outside an element?How do I check if an element is hidden in jQuery?How to Check if element is visible after scrolling?How do I find out which DOM element has the focus?Deleting array elements in JavaScript - delete vs spliceHow do I add a class to a given element?How can I select an element with multiple classes in jQuery?How to move an element into another element?How do I remove a particular element from an array in JavaScript?How can I add new array elements at the beginning of an array in Javascript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am a beginner full-stack web developer.
I helped build a game-cast app for ping-pong using the MEAN stack, SVG.js, and sockets. GitHub link: https://github.com/ChristopherRoySchneider/pingpong
In the app, a "game-caster" is in charge of emitting "game events" via sockets that other users of the site can see live. These game events can consist of, among other bits of data, an SVG circle element drawn on an SVG rectangle element (representing the ping-pong table) that shows where the ping-pong ball last landed on a score.
The user watching a match can choose which game of that particular match he or she would like to view via a drop-down menu. The app then draws all the previous balls on the table for the game chosen.
I am having trouble figuring out how to delete previously drawn ping-pong balls from the table when a user changes the game viewed. Currently, all previously drawn balls remain on the table.
I have tried to use the SVG.js clear() method to clear the table when the user chooses a different game. This works, but then redraws the table underneath where the old table used to be.
Here's the branch in which I'm attempting to squash this bug:
https://github.com/ChristopherRoySchneider/pingpong/tree/table-redraw
In ngOnChanges, I have the following code:
ngOnChanges()
this.draw.clear();
this.makeTable();
this.game = this.match.games[this.gameIndex];
this.drawPreviousBalls(this.game);
Here is the makeTable function:
makeTable()
this.draw = SVG('drawing').size(640, 356);
this.table = this.draw.rect(640, 356).attr(
'fill': '#022b6d',
'stroke': '#fff',
'stroke-width': 10
);
this.centerLine = this.draw.line([[0, 178], [640, 178]]).stroke(
'color': '#fff',
'width': 5
)
this.net = this.draw.line([[320, 0], [320, 356]]).stroke(
'color': '#fff',
'width': 5
)
And my drawPreviousBalls function, which calls a drawBall function:
drawPreviousBalls(game: Game)
for (let gameEvent of game.game_events)
if (gameEvent.x)
this.drawBall(gameEvent.x, gameEvent.y);
drawBall(x: number, y: number)
this.x = x;
this.y = y;
if(this.draw)
this.ball = this.draw.circle(10).attr(
cx: this.x,
cy: this.y,
fill: '#fff'
);
Any help would be greatly appreciated!
javascript angular svg mean-stack svg.js
add a comment |
I am a beginner full-stack web developer.
I helped build a game-cast app for ping-pong using the MEAN stack, SVG.js, and sockets. GitHub link: https://github.com/ChristopherRoySchneider/pingpong
In the app, a "game-caster" is in charge of emitting "game events" via sockets that other users of the site can see live. These game events can consist of, among other bits of data, an SVG circle element drawn on an SVG rectangle element (representing the ping-pong table) that shows where the ping-pong ball last landed on a score.
The user watching a match can choose which game of that particular match he or she would like to view via a drop-down menu. The app then draws all the previous balls on the table for the game chosen.
I am having trouble figuring out how to delete previously drawn ping-pong balls from the table when a user changes the game viewed. Currently, all previously drawn balls remain on the table.
I have tried to use the SVG.js clear() method to clear the table when the user chooses a different game. This works, but then redraws the table underneath where the old table used to be.
Here's the branch in which I'm attempting to squash this bug:
https://github.com/ChristopherRoySchneider/pingpong/tree/table-redraw
In ngOnChanges, I have the following code:
ngOnChanges()
this.draw.clear();
this.makeTable();
this.game = this.match.games[this.gameIndex];
this.drawPreviousBalls(this.game);
Here is the makeTable function:
makeTable()
this.draw = SVG('drawing').size(640, 356);
this.table = this.draw.rect(640, 356).attr(
'fill': '#022b6d',
'stroke': '#fff',
'stroke-width': 10
);
this.centerLine = this.draw.line([[0, 178], [640, 178]]).stroke(
'color': '#fff',
'width': 5
)
this.net = this.draw.line([[320, 0], [320, 356]]).stroke(
'color': '#fff',
'width': 5
)
And my drawPreviousBalls function, which calls a drawBall function:
drawPreviousBalls(game: Game)
for (let gameEvent of game.game_events)
if (gameEvent.x)
this.drawBall(gameEvent.x, gameEvent.y);
drawBall(x: number, y: number)
this.x = x;
this.y = y;
if(this.draw)
this.ball = this.draw.circle(10).attr(
cx: this.x,
cy: this.y,
fill: '#fff'
);
Any help would be greatly appreciated!
javascript angular svg mean-stack svg.js
You create a new svg document on every draw. So please justremove()
the old one
– Fuzzyma
Mar 9 at 8:00
add a comment |
I am a beginner full-stack web developer.
I helped build a game-cast app for ping-pong using the MEAN stack, SVG.js, and sockets. GitHub link: https://github.com/ChristopherRoySchneider/pingpong
In the app, a "game-caster" is in charge of emitting "game events" via sockets that other users of the site can see live. These game events can consist of, among other bits of data, an SVG circle element drawn on an SVG rectangle element (representing the ping-pong table) that shows where the ping-pong ball last landed on a score.
The user watching a match can choose which game of that particular match he or she would like to view via a drop-down menu. The app then draws all the previous balls on the table for the game chosen.
I am having trouble figuring out how to delete previously drawn ping-pong balls from the table when a user changes the game viewed. Currently, all previously drawn balls remain on the table.
I have tried to use the SVG.js clear() method to clear the table when the user chooses a different game. This works, but then redraws the table underneath where the old table used to be.
Here's the branch in which I'm attempting to squash this bug:
https://github.com/ChristopherRoySchneider/pingpong/tree/table-redraw
In ngOnChanges, I have the following code:
ngOnChanges()
this.draw.clear();
this.makeTable();
this.game = this.match.games[this.gameIndex];
this.drawPreviousBalls(this.game);
Here is the makeTable function:
makeTable()
this.draw = SVG('drawing').size(640, 356);
this.table = this.draw.rect(640, 356).attr(
'fill': '#022b6d',
'stroke': '#fff',
'stroke-width': 10
);
this.centerLine = this.draw.line([[0, 178], [640, 178]]).stroke(
'color': '#fff',
'width': 5
)
this.net = this.draw.line([[320, 0], [320, 356]]).stroke(
'color': '#fff',
'width': 5
)
And my drawPreviousBalls function, which calls a drawBall function:
drawPreviousBalls(game: Game)
for (let gameEvent of game.game_events)
if (gameEvent.x)
this.drawBall(gameEvent.x, gameEvent.y);
drawBall(x: number, y: number)
this.x = x;
this.y = y;
if(this.draw)
this.ball = this.draw.circle(10).attr(
cx: this.x,
cy: this.y,
fill: '#fff'
);
Any help would be greatly appreciated!
javascript angular svg mean-stack svg.js
I am a beginner full-stack web developer.
I helped build a game-cast app for ping-pong using the MEAN stack, SVG.js, and sockets. GitHub link: https://github.com/ChristopherRoySchneider/pingpong
In the app, a "game-caster" is in charge of emitting "game events" via sockets that other users of the site can see live. These game events can consist of, among other bits of data, an SVG circle element drawn on an SVG rectangle element (representing the ping-pong table) that shows where the ping-pong ball last landed on a score.
The user watching a match can choose which game of that particular match he or she would like to view via a drop-down menu. The app then draws all the previous balls on the table for the game chosen.
I am having trouble figuring out how to delete previously drawn ping-pong balls from the table when a user changes the game viewed. Currently, all previously drawn balls remain on the table.
I have tried to use the SVG.js clear() method to clear the table when the user chooses a different game. This works, but then redraws the table underneath where the old table used to be.
Here's the branch in which I'm attempting to squash this bug:
https://github.com/ChristopherRoySchneider/pingpong/tree/table-redraw
In ngOnChanges, I have the following code:
ngOnChanges()
this.draw.clear();
this.makeTable();
this.game = this.match.games[this.gameIndex];
this.drawPreviousBalls(this.game);
Here is the makeTable function:
makeTable()
this.draw = SVG('drawing').size(640, 356);
this.table = this.draw.rect(640, 356).attr(
'fill': '#022b6d',
'stroke': '#fff',
'stroke-width': 10
);
this.centerLine = this.draw.line([[0, 178], [640, 178]]).stroke(
'color': '#fff',
'width': 5
)
this.net = this.draw.line([[320, 0], [320, 356]]).stroke(
'color': '#fff',
'width': 5
)
And my drawPreviousBalls function, which calls a drawBall function:
drawPreviousBalls(game: Game)
for (let gameEvent of game.game_events)
if (gameEvent.x)
this.drawBall(gameEvent.x, gameEvent.y);
drawBall(x: number, y: number)
this.x = x;
this.y = y;
if(this.draw)
this.ball = this.draw.circle(10).attr(
cx: this.x,
cy: this.y,
fill: '#fff'
);
Any help would be greatly appreciated!
javascript angular svg mean-stack svg.js
javascript angular svg mean-stack svg.js
asked Mar 8 at 20:19
seesoseeso
12
12
You create a new svg document on every draw. So please justremove()
the old one
– Fuzzyma
Mar 9 at 8:00
add a comment |
You create a new svg document on every draw. So please justremove()
the old one
– Fuzzyma
Mar 9 at 8:00
You create a new svg document on every draw. So please just
remove()
the old one– Fuzzyma
Mar 9 at 8:00
You create a new svg document on every draw. So please just
remove()
the old one– Fuzzyma
Mar 9 at 8:00
add a comment |
1 Answer
1
active
oldest
votes
You don't need to keep redrawing the table. It's a static size, so just draw it once and leave it.
What I would do is make an SVG group element (<g>
) that you keep all your ball elements in.
this.balls = this.draw.group();
Then before you redraw all your balls in their new positions, just do
this.balls.clear();
Ie.
drawPreviousBalls(game: Game)
this.balls.clear();
for (let gameEvent of game.game_events)
if (gameEvent.x)
this.drawBall(gameEvent.x, gameEvent.y);
drawBall(x: number, y: number)
this.x = x;
this.y = y;
if (this.draw)
this.ball = this.balls.circle(10).attr(
cx: this.x,
cy: this.y,
fill: '#fff'
);
Paul, thanks so much! Gonna try this out.
– seeso
Mar 11 at 18:01
I ran with your suggestions and got it working! Thanks again, Paul. I upvoted your answer, but I'm too new for it to show up.
– seeso
Mar 11 at 21:21
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070445%2fsvg-js-how-to-delete-previously-drawn-elements-in-angular%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You don't need to keep redrawing the table. It's a static size, so just draw it once and leave it.
What I would do is make an SVG group element (<g>
) that you keep all your ball elements in.
this.balls = this.draw.group();
Then before you redraw all your balls in their new positions, just do
this.balls.clear();
Ie.
drawPreviousBalls(game: Game)
this.balls.clear();
for (let gameEvent of game.game_events)
if (gameEvent.x)
this.drawBall(gameEvent.x, gameEvent.y);
drawBall(x: number, y: number)
this.x = x;
this.y = y;
if (this.draw)
this.ball = this.balls.circle(10).attr(
cx: this.x,
cy: this.y,
fill: '#fff'
);
Paul, thanks so much! Gonna try this out.
– seeso
Mar 11 at 18:01
I ran with your suggestions and got it working! Thanks again, Paul. I upvoted your answer, but I'm too new for it to show up.
– seeso
Mar 11 at 21:21
add a comment |
You don't need to keep redrawing the table. It's a static size, so just draw it once and leave it.
What I would do is make an SVG group element (<g>
) that you keep all your ball elements in.
this.balls = this.draw.group();
Then before you redraw all your balls in their new positions, just do
this.balls.clear();
Ie.
drawPreviousBalls(game: Game)
this.balls.clear();
for (let gameEvent of game.game_events)
if (gameEvent.x)
this.drawBall(gameEvent.x, gameEvent.y);
drawBall(x: number, y: number)
this.x = x;
this.y = y;
if (this.draw)
this.ball = this.balls.circle(10).attr(
cx: this.x,
cy: this.y,
fill: '#fff'
);
Paul, thanks so much! Gonna try this out.
– seeso
Mar 11 at 18:01
I ran with your suggestions and got it working! Thanks again, Paul. I upvoted your answer, but I'm too new for it to show up.
– seeso
Mar 11 at 21:21
add a comment |
You don't need to keep redrawing the table. It's a static size, so just draw it once and leave it.
What I would do is make an SVG group element (<g>
) that you keep all your ball elements in.
this.balls = this.draw.group();
Then before you redraw all your balls in their new positions, just do
this.balls.clear();
Ie.
drawPreviousBalls(game: Game)
this.balls.clear();
for (let gameEvent of game.game_events)
if (gameEvent.x)
this.drawBall(gameEvent.x, gameEvent.y);
drawBall(x: number, y: number)
this.x = x;
this.y = y;
if (this.draw)
this.ball = this.balls.circle(10).attr(
cx: this.x,
cy: this.y,
fill: '#fff'
);
You don't need to keep redrawing the table. It's a static size, so just draw it once and leave it.
What I would do is make an SVG group element (<g>
) that you keep all your ball elements in.
this.balls = this.draw.group();
Then before you redraw all your balls in their new positions, just do
this.balls.clear();
Ie.
drawPreviousBalls(game: Game)
this.balls.clear();
for (let gameEvent of game.game_events)
if (gameEvent.x)
this.drawBall(gameEvent.x, gameEvent.y);
drawBall(x: number, y: number)
this.x = x;
this.y = y;
if (this.draw)
this.ball = this.balls.circle(10).attr(
cx: this.x,
cy: this.y,
fill: '#fff'
);
answered Mar 9 at 21:27
Paul LeBeauPaul LeBeau
58.1k56996
58.1k56996
Paul, thanks so much! Gonna try this out.
– seeso
Mar 11 at 18:01
I ran with your suggestions and got it working! Thanks again, Paul. I upvoted your answer, but I'm too new for it to show up.
– seeso
Mar 11 at 21:21
add a comment |
Paul, thanks so much! Gonna try this out.
– seeso
Mar 11 at 18:01
I ran with your suggestions and got it working! Thanks again, Paul. I upvoted your answer, but I'm too new for it to show up.
– seeso
Mar 11 at 21:21
Paul, thanks so much! Gonna try this out.
– seeso
Mar 11 at 18:01
Paul, thanks so much! Gonna try this out.
– seeso
Mar 11 at 18:01
I ran with your suggestions and got it working! Thanks again, Paul. I upvoted your answer, but I'm too new for it to show up.
– seeso
Mar 11 at 21:21
I ran with your suggestions and got it working! Thanks again, Paul. I upvoted your answer, but I'm too new for it to show up.
– seeso
Mar 11 at 21:21
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070445%2fsvg-js-how-to-delete-previously-drawn-elements-in-angular%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You create a new svg document on every draw. So please just
remove()
the old one– Fuzzyma
Mar 9 at 8:00