The graphic is horseshoe shaped, a sort of five-sided hexagon !!!
I think I've simplified the task by using only one iteration,
and by combining 3 functions in init().
I've also peppered the script with alerts.
Can anyone help?
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" baseProfile="full"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="480" height="480"
onload="init(evt)">
<defs> <polygon id="hex"
points= "60, 16 44,-44 -16,-60 -60,-16 -44, 44
16,60 5,70 9,86 -66,66 -90,-24
-24,-90 66,-66 86,9 70,5" />
</defs>
<script type="text/ecmascript">
<![CDATA[
var svgns="http://www.w3.org/2000/svg";
var sns = "http://www.w3.org/2000/xlink/namespace";
var xns = "http://www.w3.org/1999/xlink";
var xrf = "xlink:href";
var svg;
var tgt;
var svgdoc;
var grp;
var hx;
var x = 335;
var y 335;
var clr = "#0f0";
var rot = 120;
// Following are used only in ALERTS
var par, xrf, xx, yy, frst, sty, trnsf;
function init(evt) {
tgt = evt.target;
if(window.svgDocument == null)
{ svgdoc = tgt.ownerDocument; }
alert("SVGDOC="+svgdoc);
grp=document.createElementNS(svgns,'g');
alert("GROUP="+grp);
// svgdoc.appendChild(grp);
// par = getParentNode(grp);
//alert("PARENT="+par);
hx = document.createElementNS(svgns,'use');
alert("USE="+hx);
hx.setAttribute("x",x);
xx = hx.getAttribute("x");
hx.setAttribute("y",y);
yy = hx.getAttribute("y");
alert("X,Y="+xx+','+yy);
hx.setAttribute("xlink:href","#hex");
xrf = hx.getAttribute("xlink:href");
alert("XREF="+xrf);
hx.setAttribute("style",
"stroke: #000; stroke-width: 1; fill: clr;");
styl = hx.getAttribute("style");
alert("STYLE="+styl);
fil = hx.getAttribute("style.fill");
alert("STYLE.FILL="+styl.fill);
strok = hx.getAttribute("style.stroke");
alert("STYLE.STROKE="+strok);
swdth = hx.getAttribute("style.stroke-width");
alert("STYLE.WIDTH="+styl.swdth);
hx.setAttribute("transform","rotate(rot)");
trnsf = hx.getAttribute("transform");
alert("TRNSF="+trnsf);
trot = hx.getAttribute("transform.rotate");
alert("TRNSF.ROT="+trot);
grp.appendChild(hx);
frst = getFirstChild(grp);
alert("FIRST="+frst);
}
// ]]>
</script>
</svg>
After creating the group <g>,
grp=document.createElementNS(svgns,'g');
alert("GROUP="+grp);
I tried to append it to svgdoc
// svgdoc.appendChild(grp);
That failed. I assume because it is already attached ???
So it's commented out.
So I tried to inspect it's parent.. That also failed.
// par = getParentNode(grp);
//alert("PARENT="+par);
Also commented out.
After that I inspect every step with an alert.
( The sub-attributes of my 'style' and 'transform'
seem particularly strange.) (I may be mis-coding them.)
Right at the end, I try to append my 'hex' (the horseshoe graphic)
to the <g> group.
grp.appendChild(hx);
It crashes, No graphic appears
Moreover, grp appears to have no children.
frst = getFirstChild(grp);
alert("FIRST="+frst);
I don't know where to start.
Please don't tell me 'Start Again!'.