I've been struggling to figure out if it's possible to dynamically set points on an SVG polygon using variables that are defined by an XML document which is constantly changing.
All I want is to set the path like this:
var polygonToUse = window.document.createElementNS(svgns,"polygon");
polygonToUse.setAttributeNS(null,"points", "M"+var1+", "+var2+", L"+var3+" ...etc);
polygongroup.appendChild(polygonToUse);
Is there no way to achieve this?
I attempted what I described above, but encountered errors while running it.
I am working with pure JavaScript and integrating it into a report created in Jaspersoft Studio.
I would even be satisfied with creating a basic shape and updating its coordinates. Not sure if that's feasible either.
XML Data:
<mach_name>BASE-VISUALIZATION</mach_name>
<mach_keywords>BASE-SHAPE</mach_keywords>
<mach_keywords_list>
<keyword>BASE-SHAPE</keyword>
</mach_keywords_list>
<Depth>12</Depth>
<Cstmr>3.5</Cstmr>
<Vndr>4</Vndr>
<Bheight>2</Bheight>
<TYPE>4</TYPE>
Variables:
var svg =
window.document.createElementNS("http://www.w3.org/2000/svg","svg");
svg.setAttributeNS(null,"height",instanceData.height);
svg.setAttributeNS(null,"width",instanceData.width);
var b=((instanceData.width<instanceData.height)?
instanceData.width:instanceData.height)/10;
var bx=b;
var by=b;
var dx=instanceData.width-b*2;
var dy=instanceData.height-b*2;
var scalew=dx/width*.75;
var scaleh=dy/height*.75;
var scale=(scalew<scaleh)?(scalew):scaleh;
bx+=(dx-width*scale)/2;
by-=(dy-height*scale)/2;
var depth=parseFloat(instanceData.Depth);
var bwidth=parseFloat(instanceData.basewidth);
var Cstmr=parseFloat(instanceData.Cstmr);
var Vndr=parseFloat(instanceData.Vndr);
var jw=4.5*scale
var x=0
var y=0
brJambGroup=document.createElementNS(svgns,"g");
brJambGroup.setAttribute("name","mygroup");
var brjambshape = window.document.createElementNS(svgns,"polygon");
brjambshape.setAttributeNS(null, "points",(bx+(depth-Cstmr-4.5)*scale)
(by+dy+height*scale), (bx+(depth-Cstmr)*scale) (by+dy+height*scale),
(bx+(depth-Cstmr)*scale) (by+dy+(height-2.5)*scale), (bx+(depth-
Cstmr-.75)*scale) (by+dy+(height-2.5)*scale), (bx+(depth-
Cstmr-.75)*scale) (by+dy+(height-1.75)*scale), (bx+(depth-Cstmr-
4.5)*scale) (by+dy+(height-1.75)*scale), (bx+(depth-Cstmr-4.5)*scale)
(by+dy+height*scale));
brjambshape.setAttributeNS(null, "stroke","red");
brjambshape.setAttributeNS(null,"fill","none");
brJambGroup.appendChild(brjambshape);
if(TYPE.toString()=="4")
{
svg.appendChild(basegroup);
//svg.appendChild(nbrjambgroup);
svg.appendChild(brJambGroup);
}
The inputtable variables include: Height: 34 Width: 12 Type: 1 Depth: 12 Basewidth: 34 Customer: 3.5 Vendor: 4 jw: 4.5scale jh: 1.75scale x=0 y=0