Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make a block comment in SVG

I'm trying to learn SVG for the first time but the code seems to have an issue with my block comments. I'm using:

/* This is my  * block comment  */ 

And when I run my code, I get the following error:

'return' statement outside of function line: 116, column: 4 

That so happens to be immediately before my block comment.

like image 755
ardavis Avatar asked Mar 15 '11 04:03

ardavis


People also ask

How do you comment out code?

The leading characters // are added to the beginning of each line when commenting one or more lines of code. You can also block comment multiple lines of code using the characters /* */ .

Is SVG a image?

Scalable Vector Graphics (SVG) is an XML-based vector image format for defining two-dimensional graphics, having support for interactivity and animation. The SVG specification is an open standard developed by the World Wide Web Consortium (W3C) since 1999.


2 Answers

As SVG is XML, you can use XML style comments:

<!--      comment  --> 

For example:

<g onclick = "setScale(1)">     <rect id = "scale1" x = "120" y = "10" width = "30" height = "30"         fill = "#ffc" stroke = "black"/>     <!--          this text describes middle rectangle     -->     <text x = "135" y = "30" text-anchor = "middle">M</text> </g> 

Or you can exclude some part of code:

<!--      this group is disabled for testing     <g onclick = "setScale(1)">     <rect id = "scale1" x = "120" y = "10" width = "30" height = "30"         fill = "#ffc" stroke = "black"/>     <text x = "135" y = "30" text-anchor = "middle">M</text> </g> --> 
like image 168
Yuriy Avatar answered Sep 20 '22 01:09

Yuriy


An svg document is much the same as an html document as far as the DOM is concerned.

This line will break in all browsers:

svgDocument = evt.getTarget().getOwnerDocument(); 

And could simply be replaced by:

svgDocument = document; 

Actually there's no real need to create a variable svgDocument since document is always defined and referring to the current document (the svg).

Please read https://jwatt.org/svg/authoring/ and in particular https://jwatt.org/svg/authoring/#asv-getters-and-setters.

like image 25
Erik Dahlström Avatar answered Sep 20 '22 01:09

Erik Dahlström