W3C home > Mailing lists > Public > www-svg@w3.org > February 2004

Re: Newbie question - Grouping of objects?

From: Carlo Andreoli <barbetto80@hotmail.com>
Date: Mon, 2 Feb 2004 17:03:45 +0100
To: <www-svg@w3.org>
Message-ID: <BAY9-DAV656HAy6JbFB0004fdb5@hotmail.com>
i don't know if i fully understand your problem...it'snot completely clear...but try this: 
(language use JavaScipt) 

........ 
g = svgDocument.createElement("g"); 
g2 = svgDocument.createElement("g"); 

g.setAttribute("id","sample"); 
g2.setAttribute("id","sample2"); 
//create the objects for the goup 
newrect = svgDocument.createElement("rect"); 
newrect2 = svgDocument.createElement("rect"); 
newrect.setAttribute("x",0); 
newrect.setAttribute("y",0); 
newrect.setAttribute("width",100); 
newrect.setAttribute("height",100); 
newrect2.setAttribute("x",0); 
newrect2.setAttribute("y",0); 
newrect2.setAttribute("width",50); 
newrect2.setAttribute("height",30); 
//put them in a group 
g.appendChild(newrect); 
g.appendChild(newrect2); 
g2=g; 
.............. 

here you create the group...to use it: 

............. 
var SVGRoot = svgDocument.documentElement; 
SVGRoot.appendChild(g); 
SVGRoot.appendChild(g2); 
............. 

here you scale the group...to do this: 
............. 
g.setAttribute("transform",translate(20,20)); 
g.setAttribute("transform","scale(2,2,)"); 
g2.setAttribute("transform",translate(40,40); 
g2.setAttribute("transform","scale(2,2,)"); 
............. 

pay attention...translate refer to the original position 
pay attention!!!!!!...scale attribute: try some exmple to understand howit works 
Received on Monday, 2 February 2004 11:04:54 GMT

This archive was generated by hypermail 2.3.1 : Friday, 8 March 2013 15:54:26 GMT