javascript - How to append arrow marker dynamically in line only using svg HTML5 -


https://jsfiddle.net/0hh4rkso/12/ tried. need append arrow marker in rectangle connecting lines.i need dynamically wrote javascript function given below. in middle of given size plotting rectangle , connected line element.but not able append arrow in line.some 1 please give solution.

var svg=function(h,w){             // fun create svg var svg=document.createelementns(ns,"svg");   svg.width=w;   svg.height=h;    return svg; } var rect=function(x,y,h,w){        // fun create rectangle    var rectsvgobj = document.createelementns(ns, 'rect');    rectsvgobj.setattributens(null, "id", "rectid");    rectsvgobj.setattributens(null, 'x',x);    rectsvgobj.setattributens(null, 'y', y);    rectsvgobj.setattributens(null, 'height', h);    rectsvgobj.setattributens(null, 'width', w);    rectsvgobj.setattributens(null, 'fill', 'none');    rectsvgobj.setattributens(null, "stroke", "black");   return rectsvgobj; } var arrow= function(){                   // fun arrow     var markerobj = document.createelementns(ns,"marker");   markerobj.setattributens(null, "id", "markerarrow1");      var arrowobj=document.createelementns(ns,"path");    arrowobj.setattributens(null, "id", "markerarrow");   arrowobj.setattributens(null, "d","m2,2 l2,13 l8,7 l2,2" );   markerobj.appendchild(arrowobj); return markerobj; } var lines= function(x1,y1,x2,y2){        // lines    var linesvgobj = document.createelementns(ns, 'line');    linesvgobj.setattributens(null, "id", "lineid");    linesvgobj.setattributens(null, 'x1',x1);    linesvgobj.setattributens(null, 'y1', y1);    linesvgobj.setattributens(null, 'x2', x2);    linesvgobj.setattributens(null, 'y2', y2);    linesvgobj.setattributens(null, "stroke", "blue");    linesvgobj.setattributens(null,'marker-mid',        'url(#markerarrow1)'); return linesvgobj; } var svg=svg(height,width);   document.body.appendchild(svg);      // append svg body  var markerarrw =arrow();   svg.appendchild(markerarrw);   x=cx; y=cy;    var r= rect(x,y,rheight,rwidth);       svg.appendchild(r);                 // append rect1 svg   // input rects plote var lx2=arrowpoint_x; var ly2=arrowpoint_y; var irect_x=0; var irect_y=0; for(var i=1;i<=limit;i++){         // append inputs rect+line     irect_x=cx-(cx/2);     irect_y=cy;  if (i%2== 0){      irect_y=(irect_y-(irh*i))+20;    }else{        irect_y= (irect_y+(irh*i))-20;   }        var irect= rect(irect_x,irect_y,irh,irw);     svg.appendchild(irect);       var lx1=irect_x+irw;     var ly1=irect_y+(irh/2);     var l=lines(lx1,ly1,lx2,ly2);     svg.appendchild(l);    } 

following example given svg marker. if add in defs sections , reference later works. i've updated fiddle code but, not see if set marker-mid, marker-start & marker-end seem work.

https://jsfiddle.net/0hh4rkso/10/


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -