How to use svgDocument method in wpt

Best JavaScript code snippet using wpt

svg-editor.js

Source:svg-editor.js Github

copy

Full Screen

1function SVGIsInstalled() {2 if (IE) {3 //this needs to be translated from VB4 //return IsObject(CreateObject("Adobe.SVGCtl"));5 return true;6 }7 else if ((navigator.mimeTypes != null) &&8 (navigator.mimeTypes.length > 0) &&9 (navigator.mimeTypes["image/svg+xml"] != null)) return true;10 alert("SVG is not installed");11 return false;12}13function loadSVGEditor(sourceObject,svgSrc,imageSrc) {14 // press the line button by default15 pressButton("svgLine");16 //Save the sourceObject in the main editor so17 //we can return the results of the svg editing18 //session.19 editorSourceObject = sourceObject;20 //Make sure the svgDiv is empty.21 var div = document.getElementById("svgDiv");22 while (div.firstChild != null) div.removeChild(div.firstChild);23 //Swap around the divs to hide the main24 //editor and display the SVG editor.25 swapEditorDivs();26 //Display the image so we can get its size27 var img = document.createElement("IMG");28 img.setAttribute("src", imageSrc);29 div.appendChild(img);30 //Wait for the image to load and then use31 //its size to set the size of the svg editor.32 loadSVG(svgSrc,img);33}34var tempImage;35var tempSvgSrc;36function reloadSVG() {37 loadSVG(tempSvgSrc,tempImage);38}39function loadSVG(svgSrc,image) {40 //Wait for the image to load41 if (!image.complete) {42 tempSvgSrc = svgSrc;43 tempImage = image;44 setTimeout("reloadSVG();",10);45 return;46 }47 //Get the parameters of the image to be annotated48 var width = getObjectWidth(image);49 var height = getObjectHeight(image);50 //The image is loaded and we have its size. Now remove it.51 image.parentNode.removeChild(image);52 //Initialize the variables.53 svgInitialize();54 //Embed an SVG file. There doesn't seem to be a way to55 //construct this programmatically, so this has to be a file56 //in the root of the servlet.57 embedSVG(embedID,svgSrc,width,height);58 //Construct the root element in the SVG document.59 createSVGRoot(embedID,image.src);60}61function swapEditorDivs() {62 //Swap around the editor divs.63 var mainEditorDiv = document.getElementById("mainEditorDiv");64 var svgEditorDiv = document.getElementById("svgEditorDiv");65 var vis = svgEditorDiv.style.visibility;66 if (vis != "visible") {67 mainEditorDiv.style.visibility = "hidden";68 mainEditorDiv.style.display = "none";69 svgEditorDiv.style.visibility = "visible";70 svgEditorDiv.style.display = "block";71 }72 else {73 svgEditorDiv.style.visibility = "hidden";74 svgEditorDiv.style.display = "none";75 mainEditorDiv.style.visibility = "visible";76 mainEditorDiv.style.display = "block";77 }78}79function embedSVG(id,svgSrc,width,height) {80 var svg = document.createElement("EMBED");81 svg.setAttribute("id",id);82 svg.setAttribute("src",svgSrc);83 svg.setAttribute("width",width);84 svg.setAttribute("height",height);85 svg.setAttribute("type","image/svg+xml");86 var div = document.getElementById("svgDiv");87 if (div != null) {88 while (div.firstChild != null) div.removeChild(div.firstChild);89 div.appendChild(svg);90 }91}92function createSVGRoot(id,href) {93 try {94 var embed = document.getElementById(id);95 var width = embed.getAttribute("width");96 var height = embed.getAttribute("height");97 var svgdoc = embed.getSVGDocument();98 var root = svgdoc.rootElement;99 root.setAttribute("width",width);100 root.setAttribute("height",height);101 //test to see if it's IE102 if( document.all ) {103 root.setAttribute("onmousedown","svgMousedown(evt);");104 root.setAttribute("onmousemove","svgMousemove(evt);");105 root.setAttribute("onmouseup","svgMouseup(evt);");106 root.setAttribute("onkeypress","svgKeypressed(evt);");107 } else {108 svgdoc.addEventListener("mousemove", svgMousemove, true);109 svgdoc.addEventListener("mousedown", svgMousedown, true);110 svgdoc.addEventListener("mouseup", svgMouseup, true);111 svgdoc.addEventListener("keypress", svgKeypressed, true);112 }113 var viewBox = "0 0 " + width + " " + height;114 root.setAttribute("viewBox",viewBox);115 var imageElements = root.getElementsByTagName("image");116 if (imageElements.length == 0) {117 var image = svgdoc.createElementNS("http://www.w3.org/2000/svg","image");118 image.setAttribute("id","img");119 image.setAttributeNS("http://www.w3.org/1999/xlink","href",href);120 image.setAttribute("x",0);121 image.setAttribute("y",0);122 image.setAttribute("width",width);123 image.setAttribute("height",height);124 if (root.firstChild == null) root.appendChild(image);125 else root.insertBefore(image,root.firstChild);126 }127 }128 catch (ex) { setTimeout("createSVGRoot(\""+id+"\",\""+href+"\");",10); }129}130function svgInitialize() {131 svgCurrentElement = null;132 svgCurrentMode = "";133 svgCurrentSelectDot = null;134 svgX = 0;135 svgY = 0;136 svgLastX = 0;137 svgLastY = 0;138 svgType = "line";139 stroke = "red";140 strokeWidth = 3;141 font = "serif";142 fontSize = 20;143 fontStyle = "normal";144 fontWeight = "normal";145 arrowSize = 20;146}147function getSVGDocument() {148 var embed = document.getElementById(embedID);149 return embed.getSVGDocument();150}151function getSVGRoot() {152 return getSVGDocument().rootElement;153}154function svgSave(event) {155 if (editorSourceObject == null) return;156 svgDeselectAll(getSVGRoot());157 editorSourceObject.svgText = getSVGText();158 saveClicked();159 swapEditorDivs();160}161//-----------------------------------------------------------------------162// A few debugging routines163function showSize(img) {164 if (img != null) {165 alert("width = "+img.offsetWidth+"\n"+"height = "+img.offsetHeight);166 }167 else alert(id + " is null");168}169function showTree() {170 alert(getTree(getSVGRoot(),""));171}172function showProps() {173 var svgdoc = getSVGDocument();174 var text = "";175 for (name in svgdoc) text += name + "\n";176 alert("svgDocument properties\n\n" + text);177}178function getTree(node,margin) {179 var text = "";180 if (node.nodeType == 1) {181 text += margin + node.tagName + "\n";182 var child = node.firstChild;183 while (child != null) {184 text += getTree(child, margin + " ");185 child = child.nextSibling;186 }187 }188 return text;189}190function showCurrentElementProps() {191 showElementProps(svgCurrentElement);192}193function showElementProps(element) {194 if (element == null) return;195 var text = "";196 var name;197 for (name in element) {198 if (name == "id")199 text += name + " = " + element.getAttribute(name) + "\n";200 else201 text += name + "\n";202 }203 alert(element.tagName + " properties\n\n" + text);204}205//-----------------------------------------------------------------------206var embedID = "svgEmbed";207var editorSourceObject = null;208var svgCurrentElement = null;209var svgCurrentMode = "";210var svgCurrentSelectDot = null;211var svgX = 0;212var svgY = 0;213var svgLastX = 0;214var svgLastY = 0;215var svgType = "line";216var stroke = "red";217var strokeWidth = 3;218var font = "serif";219var fontSize = 20;220var fontStyle = "normal";221var fontWeight = "normal";222var arrowSize = 20;223// images array of buttons that are popped out224var svgToolButtonArray = new Array();225svgToolButtonArray['svgArrow'] = "svg-buttons/arrow.gif";226svgToolButtonArray['svgSelect'] = "svg-buttons/select.gif";227svgToolButtonArray['svgLine'] = "svg-buttons/line.gif";228svgToolButtonArray['svgCircle'] = "svg-buttons/circle.gif";229svgToolButtonArray['svgText'] = "svg-buttons/text.gif";230// images array of buttons that are pressed in231var svgToolButtonPressedArray = new Array();232svgToolButtonPressedArray['svgArrow'] = "svg-buttons/arrow-pressed.gif";233svgToolButtonPressedArray['svgSelect'] = "svg-buttons/select-pressed.gif";234svgToolButtonPressedArray['svgLine'] = "svg-buttons/line-pressed.gif";235svgToolButtonPressedArray['svgCircle'] = "svg-buttons/circle-pressed.gif";236svgToolButtonPressedArray['svgText'] = "svg-buttons/text-pressed.gif";237// Set the graphical representations of the buttons so only one is pressed238function pressButton(buttonID) {239 for( var i in svgToolButtonArray ) {240 // if the button in the loop matches the buttonID, press it241 if( buttonID == i ) {242 document.getElementById(i).setAttribute("src", changeImageSource(svgToolButtonPressedArray[i], document.getElementById(i).getAttribute("src")));243 // otherwise, pop it out244 } else {245 document.getElementById(i).setAttribute("src", changeImageSource(svgToolButtonArray[i], document.getElementById(i).getAttribute("src")));246 }247 }248}249// This is a little odd, we can't replace the entire source because the file path differs from250// site to site depending on the name of the user's storage service, so we'll have to leave that part intact251function changeImageSource (newImage, oldImage) {252 var newSource = "";253 // IE urls contain http://server, so we have254 // to strip that part off, but only in IE.255 if( oldImage.indexOf("//") > 0 ) {256 oldImage = oldImage.substring(oldImage.indexOf("//")+2, oldImage.length);257 }258 // old image starts with a leading slash, we don't need to get that259 oldImage = oldImage.substring(oldImage.indexOf("/")+1, oldImage.length);260 newSource ="/" + oldImage.substring(0, oldImage.indexOf("/")+1) + newImage;261 return newSource;262}263function setType(theType) {264 switch (theType) {265 case "select":266 pressButton("svgSelect");267 break;268 case "text":269 pressButton("svgText");270 break;271 case "circle":272 pressButton("svgCircle");273 break;274 case "line":275 pressButton("svgLine");276 break;277 case "arrow":278 pressButton("svgArrow");279 break;280 }281 svgType = theType;282 svgFixText();283 svgDeselectAll(getSVGRoot());284 svgCurrentElement = null;285}286function setStroke(theStroke) {287 stroke = theStroke;288 if (svgCurrentElement != null) {289 svgCurrentElement.setAttribute("stroke",stroke);290 var fill = svgCurrentElement.getAttribute("fill");291 if ((fill != null) && (fill.toLowerCase() != "none"))292 svgCurrentElement.setAttribute("fill",stroke);293 }294}295function setStrokeWidth(inc) {296 strokeWidth += inc;297 strokeWidth = Math.min(strokeWidth,7);298 strokeWidth = Math.max(strokeWidth,1);299 if ((svgCurrentElement != null) && !isText(svgCurrentElement))300 svgCurrentElement.setAttribute("stroke-width",strokeWidth);301}302function setArrowSize(inc) {303 arrowSize += inc * 10;304 arrowSize = Math.min(arrowSize,40);305 arrowSize = Math.max(arrowSize,10);306 if (isArrow(svgCurrentElement))307 drawArrow(svgCurrentElement);308}309function setFont() {310 var selector = document.getElementById("svgFontSelector");311 var options = selector.getElementsByTagName("OPTION");312 font = options[selector.selectedIndex].value;313 if (isText(svgCurrentElement)) {314 svgCurrentElement.setAttribute("font-family",font);315 }316}317function setFontSize(inc) {318 fontSize += inc;319 fontSize = Math.min(fontSize,96);320 fontSize = Math.max(fontSize,12);321 if (isText(svgCurrentElement))322 svgCurrentElement.setAttribute("font-size",fontSize);323}324function setFontStyle() {325 fontStyle = (fontStyle == "normal") ? "italic" : "normal";326 if (isText(svgCurrentElement))327 svgCurrentElement.setAttribute("font-style",fontStyle);328}329function setFontWeight() {330 fontWeight = (fontWeight == "normal") ? "bold" : "normal";331 if (isText(svgCurrentElement))332 svgCurrentElement.setAttribute("font-weight",fontWeight);333}334function isText(w) {335 if (w == null) return false;336 var svgType = w.getAttribute("type");337 return (svgType == "text");338}339function isArrow(w) {340 if (w == null) return false;341 var svgType = w.getAttribute("type");342 return (svgType == "arrow");343}344function setXY(event) {345 svgX = event.clientX;346 svgY = event.clientY;347}348function setLastXY() {349 svgLastX = svgX;350 svgLastY = svgY;351}352function svgAppend(w) {353 getSVGRoot().appendChild(w);354}355function svgBringToFront(w) {356 var svg = getSVGRoot();357 svg.removeChild(w);358 svg.appendChild(w);359}360function svgDeselectAll(node) {361 var count = 0;362 if (node.nodeType == 1 || node.nodeType == "1") {363 var svgType = node.getAttribute("type");364 //if (svgType == null) return;365 if (svgType == "select") {366 node.parentNode.removeChild(node);367 }368 else if (svgType == "text") {369 deselectText(node);370 }371 else {372 var child = node.firstChild;373 while (child != null) {374 var nextChild = child.nextSibling;375 svgDeselectAll(child);376 child = nextChild;377 }378 }379 }380}381function svgKeypressed(evt) {382 if (svgCurrentElement != null) {383 var svgType = svgCurrentElement.getAttribute("type");384 if (svgType == "text") {385 var child = svgCurrentElement.firstChild;386 if (child != null) {387 var text = child.nodeValue;388 if ((text.length > 0) && (text.charAt(text.length-1) == "|"))389 text = text.substring(0,text.length-1);390 var code = evt.charCode;391 if (code < 32) {392 if ((code == 8) && (text.length > 0)) {393 text = text.substring(0,text.length-1) + "|";394 }395 else return;396 }397 else {398 text += String.fromCharCode(code) + "|";399 }400 svgCurrentElement.removeChild(child);401 var newText = getSVGDocument().createTextNode(text);402 svgCurrentElement.appendChild(newText);403 }404 }405 else if (evt.charCode == 8) svgCut();406 }407}408function svgCut() {409 if (svgCurrentElement != null) {410 var svg = getSVGRoot();411 svg.removeChild(svgCurrentElement);412 svgCurrentElement = null;413 svgDeselectAll(getSVGRoot());414 }415}416function svgFixText() {417 if ((svgCurrentElement != null) && (svgCurrentElement.getAttribute("type") == "text")) {418 if (isEmptyText(svgCurrentElement)) svgCut();419 else deselectText(svgCurrentElement);420 }421}422function svgMousedown(evt) {423 if (evt.ctrlKey || evt.altKey || evt.metaKey) return;424 var target = evt.target;425 var svgDocument = getSVGDocument();426 var svg = svgDocument.rootElement;427 var img = svgDocument.getElementById("img");428 svgX = evt.clientX;429 svgY = evt.clientY;430 setLastXY();431 svgDeselectAll(getSVGRoot());432 svgFixText();433 if ((target === svg) || (target === img)) {434 svgCurrentElement = newElement();435 svgCurrentMode = "new";436 } else if (target.getAttribute("type") == "select") {437 svgCurrentMode = "resize";438 svgCurrentSelectDot = target.getAttribute("dotID");439 } else {440 svgCurrentElement = target;441 svgBringToFront(target);442 svgCurrentMode = "drag";443 }444}445function svgMousemove(evt) {446 if (evt.ctrlKey || evt.altKey || evt.metaKey) return;447// setXY(evt);448 svgX = evt.clientX;449 svgY = evt.clientY;450 if (svgCurrentElement != null) {451 switch (svgCurrentMode) {452 case "new":453 extendElement(svgCurrentElement); break;454 case "drag":455 dragElement(svgCurrentElement); break;456 case "resize":457 resizeElement(svgCurrentElement); break;458 }459 }460}461function svgMouseup(evt) {462 svgCurrentMode = "";463 if (svgCurrentElement != null) {464 if (isEmpty(svgCurrentElement)) svgCut();465 else selectElement();466 }467}468function newElement() {469 switch (svgType) {470 case "line": return newLine(svgX,svgY,stroke,strokeWidth);471 case "circle": return newCircle(svgX,svgY,0,stroke,strokeWidth);472 case "arrow": return newArrow(svgX,svgY,stroke,strokeWidth);473 case "text": return newText(svgX,svgY,stroke,strokeWidth);474 default: return null;475 }476 return null;477}478function extendElement() {479 var svgType = svgCurrentElement.getAttribute("type");480 switch (svgType) {481 case "line": return extendLine(svgCurrentElement);482 case "circle": return extendCircle(svgCurrentElement);483 case "arrow": return extendArrow(svgCurrentElement);484 case "text": return extendText(svgCurrentElement);485 }486}487function dragElement() {488 var svgType = svgCurrentElement.getAttribute("type");489 switch (svgType) {490 case "line": return dragLine(svgCurrentElement);491 case "circle": return dragCircle(svgCurrentElement);492 case "arrow": return dragArrow(svgCurrentElement);493 case "text": return dragText(svgCurrentElement);494 }495}496function resizeElement() {497 var svgType = svgCurrentElement.getAttribute("type");498 switch (svgType) {499 case "line": return resizeLine(svgCurrentElement);500 case "circle": return resizeCircle(svgCurrentElement);501 case "arrow": return resizeArrow(svgCurrentElement);502 }503 return false;504}505function selectElement() {506 var svgType = svgCurrentElement.getAttribute("type");507 switch (svgType) {508 case "line": return selectLine(svgCurrentElement);509 case "circle": return selectCircle(svgCurrentElement);510 case "arrow": return selectArrow(svgCurrentElement);511 case "text": return selectText(svgCurrentElement);512 }513}514function isEmpty() {515 var svgType = svgCurrentElement.getAttribute("type");516 switch (svgType) {517 case "line": return isEmptyLine(svgCurrentElement);518 case "circle": return isEmptyCircle(svgCurrentElement);519 case "arrow": return isEmptyArrow(svgCurrentElement);520 }521 return false;522}523function newLine(svgX,svgY,stroke,strokeWidth) {524 var svgDocument = getSVGDocument();525 var w = svgDocument.createElementNS("http://www.w3.org/2000/svg", "line");526 w.setAttribute("type","line");527 w.setAttribute("x1",svgX);528 w.setAttribute("y1",svgY);529 w.setAttribute("x2",svgX);530 w.setAttribute("y2",svgY);531 w.setAttribute("stroke",stroke);532 w.setAttribute("stroke-width",strokeWidth);533 svgAppend(w);534 return w;535}536function extendLine(w) {537 w.setAttribute("x2",svgX);538 w.setAttribute("y2",svgY);539}540function resizeLine(w) {541 switch (svgCurrentSelectDot) {542 case "p1":543 w.setAttribute("x1",svgX);544 w.setAttribute("y1",svgY);545 break;546 case "p2":547 w.setAttribute("x2",svgX);548 w.setAttribute("y2",svgY);549 break;550 }551}552function dragLine(w) {553 var dx = svgX - svgLastX;554 var dy = svgY - svgLastY;555 var x1 = Number(w.getAttribute("x1")) + dx;556 var y1 = Number(w.getAttribute("y1")) + dy;557 var x2 = Number(w.getAttribute("x2")) + dx;558 var y2 = Number(w.getAttribute("y2")) + dy;559 w.setAttribute("x1",x1);560 w.setAttribute("y1",y1);561 w.setAttribute("x2",x2);562 w.setAttribute("y2",y2);563 setLastXY();564}565function selectLine(w) {566 var x1 = Number(w.getAttribute("x1"));567 var y1 = Number(w.getAttribute("y1"));568 selectDot(x1,y1,"p1");569 var x2 = Number(w.getAttribute("x2"));570 var y2 = Number(w.getAttribute("y2"));571 selectDot(x2,y2,"p2");572}573function isEmptyLine(w) {574 var x1 = Number(w.getAttribute("x1"));575 var y1 = Number(w.getAttribute("y1"));576 var x2 = Number(w.getAttribute("x2"));577 var y2 = Number(w.getAttribute("y2"));578 return (x1 == x2) && (y1 == y2);579}580function selectDot(svgX,svgY,dotID) {581 var svgDocument = getSVGDocument();582 var w = svgDocument.createElementNS("http://www.w3.org/2000/svg", "circle");583 w.setAttribute("type","select");584 w.setAttribute("cx",svgX);585 w.setAttribute("cy",svgY);586 w.setAttribute("r",2.5);587 w.setAttribute("stroke","yellow");588 w.setAttribute("stroke-width",1);589 w.setAttribute("fill","yellow");590 w.setAttribute("dotID",dotID);591 svgAppend(w);592}593function newCircle(cx,cy,r,stroke,strokeWidth) {594 var svgDocument = getSVGDocument();595 var w = svgDocument.createElementNS("http://www.w3.org/2000/svg", "circle");596 w.setAttribute("type","circle");597 w.setAttribute("cx",cx);598 w.setAttribute("cy",cy);599 w.setAttribute("r",r);600 w.setAttribute("stroke",stroke);601 w.setAttribute("stroke-width",strokeWidth);602 w.setAttribute("fill","none");603 svgAppend(w);604 return w;605}606function extendCircle(w) {607 var r = Math.sqrt(Math.pow(svgX-svgLastX,2) + Math.pow(svgY-svgLastY,2));608 w.setAttribute("r",r);609}610function resizeCircle(w) {611 var cx = Number(w.getAttribute("cx"));612 var cy = Number(w.getAttribute("cy"));613 var r = Math.sqrt(Math.pow(svgX-cx,2) + Math.pow(svgY-cy,2));614 w.setAttribute("r",r);615}616function dragCircle(w) {617 var cx = Number(w.getAttribute("cx"));618 var cy = Number(w.getAttribute("cy"));619 cx = cx + svgX - svgLastX;620 cy = cy + svgY - svgLastY;621 w.setAttribute("cx",cx);622 w.setAttribute("cy",cy);623 setLastXY();624}625function selectCircle(w) {626 var cx = Number(w.getAttribute("cx"));627 var cy = Number(w.getAttribute("cy"));628 var r = Number(w.getAttribute("r"));629 selectDot(cx+r,cy,"right");630 selectDot(cx-r,cy,"left");631 selectDot(cx,cy+r,"top");632 selectDot(cx,cy-r,"bottom");633}634function isEmptyCircle(w) {635 var r = Number(w.getAttribute("r"));636 return (r == 0);637}638function newArrow(svgX,svgY,stroke,strokeWidth) {639 var svgDocument = getSVGDocument();640 var w = svgDocument.createElementNS("http://www.w3.org/2000/svg", "polygon");641 w.setAttribute("type","arrow");642 var points = getPoints(svgX,svgY,svgX,svgY);643 w.setAttribute("points",points);644 w.setAttribute("stroke",stroke);645 w.setAttribute("stroke-width",strokeWidth);646 w.setAttribute("fill",stroke);647 w.setAttribute("x1",svgX);648 w.setAttribute("y1",svgY);649 w.setAttribute("x2",svgX);650 w.setAttribute("y2",svgY);651 svgAppend(w);652 return w;653}654function extendArrow(w) {655 var x1 = Number(w.getAttribute("x1"));656 var y1 = Number(w.getAttribute("y1"));657 var points = getPoints(x1,y1,svgX,svgY);658 w.setAttribute("points",points);659 w.setAttribute("x2",svgX);660 w.setAttribute("y2",svgY);661 setLastXY();662}663function resizeArrow(w) {664 resizeLine(w);665 drawArrow(w);666}667function drawArrow(w) {668 var x1 = Number(w.getAttribute("x1"));669 var y1 = Number(w.getAttribute("y1"));670 var x2 = Number(w.getAttribute("x2"));671 var y2 = Number(w.getAttribute("y2"));672 var points = getPoints(x1,y1,x2,y2);673 w.setAttribute("points",points);674}675function dragArrow(w) {676 var dx = svgX - svgLastX;677 var dy = svgY - svgLastY;678 var x1 = Number(w.getAttribute("x1")) + dx;679 var y1 = Number(w.getAttribute("y1")) + dy;680 var x2 = Number(w.getAttribute("x2")) + dx;681 var y2 = Number(w.getAttribute("y2")) + dy;682 w.setAttribute("x1",x1);683 w.setAttribute("y1",y1);684 w.setAttribute("x2",x2);685 w.setAttribute("y2",y2);686 var points = getPoints(x1,y1,x2,y2);687 w.setAttribute("points",points);688 setLastXY();689}690function getPoints(x1,y1,x2,y2) {691 var points = "";692 if ((x1 != x2) || (y1 != y2)) {693 var arrowWidth = 3 * arrowSize / 10;694 var ux = x1 - x2;695 var uy = y1 - y2;696 var len = Math.sqrt(ux*ux + uy*uy);697 ux = ux/len;698 uy = uy/len;699 vx = arrowWidth * uy;700 vy = -arrowWidth * ux;701 xp = x2 + arrowSize * ux;702 yp = y2 + arrowSize * uy;703 points += addPoint(x1,y1);704 points += addPoint(xp,yp);705 points += addPoint(xp + vx, yp + vy);706 points += addPoint(x2,y2);707 points += addPoint(xp - vx, yp - vy);708 points += addPoint(xp,yp);709 points += addPoint(x1,y1);710 }711 return points;712}713function addPoint(svgX,svgY) {714 return " " + svgX + " " + svgY;715}716function selectArrow(w) {717 selectLine(w);718}719function isEmptyArrow(w) {720 return isEmptyLine(w);721}722function newText(svgX,svgY,stroke,strokeWidth) {723 var svgDocument = getSVGDocument();724 var w = svgDocument.createElementNS("http://www.w3.org/2000/svg", "text");725 w.setAttribute("type","text");726 w.setAttribute("font-family",font);727 w.setAttribute("font-size",fontSize);728 w.setAttribute("font-weight",fontWeight);729 w.setAttribute("font-style",fontStyle);730 w.setAttribute("stroke",stroke);731 w.setAttribute("stroke-width",1);732 w.setAttribute("fill",stroke);733 w.setAttribute("x",svgX);734 w.setAttribute("y",svgY);735 var t = svgDocument.createTextNode("|");736 w.appendChild(t);737 svgAppend(w);738 return w;739}740function extendText(w) {741}742function dragText(w) {743 var dx = svgX - svgLastX;744 var dy = svgY - svgLastY;745 var xx = Number(w.getAttribute("x")) + dx;746 var yy = Number(w.getAttribute("y")) + dy;747 w.setAttribute("x",xx);748 w.setAttribute("y",yy);749 setLastXY();750}751function selectText(w) {752 var child = w.firstChild;753 if (child != null) {754 var text = child.nodeValue;755 if ((text.length > 0) && (text.charAt(text.length-1) == "|")) return;756 text += "|";757 w.removeChild(child);758 var newText = getSVGDocument().createTextNode(text);759 w.appendChild(newText);760 }761}762function deselectText(w) {763 var child = w.firstChild;764 if (child != null) {765 var text = child.nodeValue;766 if ((text.length > 0) && (text.charAt(text.length-1) == "|")) {767 text = text.substring(0,text.length-1);768 w.removeChild(child);769 var newText = getSVGDocument().createTextNode(text);770 w.appendChild(newText);771 }772 }773}774function isEmptyText(w) {775 var child = w.firstChild;776 if (child == null) return true;777 var text = child.nodeValue;778 if (text.length == 0) return true;779 if (text == "|") return true;780 return false;781}782//-------------------------------------------------------------783// Get the text of the entire SVG object784function getSVGText() {785 var text = svgGetNodeText(getSVGRoot());786 return text;787}788function svgGetNodeText(node) {789 switch (node.nodeType) {790 case 1: //ELEMENT_NODE:791 //Handle the image element separately.792 if (node.nodeName == "image") {793 var imageText = "<image id=\"img\"";794 var href = node.getAttributeNS("http://www.w3.org/1999/xlink","href");795 //Force href to be a local reference796 var k = href.lastIndexOf("/") + 1;797 href = href.substring(k);798 imageText += " xlink:href=\"" + href + "\"";799 imageText += " x=\"0\" y=\"0\"";800 imageText += " width=\"" + node.getAttribute("width") + "\"";801 imageText += " height=\"" + node.getAttribute("height") + "\"/>";802 return imageText;803 }804 var text = "<" + node.nodeName;805 //Suppress the attributes of the svg element.806 if (node.nodeName == "svg") {807 //Add the svg attributes that we need.808 text += " xmlns=\"http://www.w3.org/2000/svg\" ";809 text += "xmlns:xlink=\"http://www.w3.org/1999/xlink\" ";810 text += "viewBox=\"" + node.getAttribute("viewBox") + "\" "811 text += "height=\"" + node.getAttribute("height") + "\" "812 text += "width=\"" + node.getAttribute("width") + "\""813 } else {814 var attrs = node.attributes;815 for (var i=0; i<attrs.length; i++) {816 var attr = attrs.item(i);817 text += svgGetNodeText(attr);818 }819 }820 var child = node.firstChild;821 if (child == null) text += "/>";822 else {823 text += ">";824 while (child != null) {825 text += svgGetNodeText(child);826 child = child.nextSibling;827 }828 text += "</" + node.nodeName + ">";829 }830 return text;831 case 2: //ATTRIBUTE_NODE:832 return " " + node.nodeName + "=\"" + node.nodeValue + "\"";833 case 3: //TEXT_NODE:834 if (node.nodeValue.replace( /\s+/g, "" ) == "") return "";835 return node.nodeValue;836 }837 return "";...

Full Screen

Full Screen

minigame.js

Source:minigame.js Github

copy

Full Screen

1//Released to the public domain2//original author: Felipe Corrêa da Silva Sanches <juca@members.fsf.org>3var svgDocument;4var sprites;5var NUM_SPRITES;6var butterfly = new Array()7var hit;8var miss;9var time = 0;10var delta_t = 50; //frequency = 1/50ms = 20Hz11function on_load (evt){12 sprites = new Array();13 O=evt.target;14 svgDocument=O.ownerDocument;15 svgDocument.onkeydown = keydown;16 svgDocument.onkeyup = keyup;17 svgDocument.getElementById("start_button").onclick = start;18 svgDocument.getElementById("quit_button").onclick = game_over;19 svgDocument.getElementById("pause_button").onclick = pause;20 svgDocument.getElementById("rules_button").onclick = show_rules;21 svgDocument.getElementById("right_button").onclick = tux_right;22 svgDocument.getElementById("left_button").onclick = tux_left;23 svgDocument.getElementById("action_button").onmousedown = tux_hit;24 svgDocument.getElementById("action_button").onmouseup = tux_wing_down;25 svgDocument.getElementById("OK").onclick = hide_rules;26 sprites.push(svgDocument.getElementById("tuxA"));27 sprites.push(svgDocument.getElementById("downA"));28 sprites.push(svgDocument.getElementById("tuxB"));29 sprites.push(svgDocument.getElementById("downB"));30 sprites.push(svgDocument.getElementById("tuxC"));31 sprites.push(svgDocument.getElementById("downC"));32 sprites.push(svgDocument.getElementById("tuxD"));33 sprites.push(svgDocument.getElementById("downD"));34 sprites.push(svgDocument.getElementById("tuxE"));35 sprites.push(svgDocument.getElementById("downE"));36 sprites.push(svgDocument.getElementById("msn1A"));37 sprites.push(svgDocument.getElementById("msn2A"));38 sprites.push(svgDocument.getElementById("msn3A"));39 sprites.push(svgDocument.getElementById("msn4A"));40 sprites.push(svgDocument.getElementById("msn1B"));41 sprites.push(svgDocument.getElementById("msn2B"));42 sprites.push(svgDocument.getElementById("msn3B"));43 sprites.push(svgDocument.getElementById("msn4B"));44 sprites.push(svgDocument.getElementById("msn1C"));45 sprites.push(svgDocument.getElementById("msn2C"));46 sprites.push(svgDocument.getElementById("msn3C"));47 sprites.push(svgDocument.getElementById("msn4C"));48 sprites.push(svgDocument.getElementById("msn1D"));49 sprites.push(svgDocument.getElementById("msn2D"));50 sprites.push(svgDocument.getElementById("msn3D"));51 sprites.push(svgDocument.getElementById("msn4D"));52 sprites.push(svgDocument.getElementById("msn1E"));53 sprites.push(svgDocument.getElementById("msn2E"));54 sprites.push(svgDocument.getElementById("msn3E"));55 sprites.push(svgDocument.getElementById("msn4E"));56 sprites.push(svgDocument.getElementById("upA"));57 sprites.push(svgDocument.getElementById("upB"));58 sprites.push(svgDocument.getElementById("upC"));59 sprites.push(svgDocument.getElementById("upD"));60 sprites.push(svgDocument.getElementById("upE"));61 sprites.push(svgDocument.getElementById("missA"));62 sprites.push(svgDocument.getElementById("missB"));63 sprites.push(svgDocument.getElementById("missC"));64 sprites.push(svgDocument.getElementById("missD"));65 sprites.push(svgDocument.getElementById("missE"));66 sprites.push(svgDocument.getElementById("hitA"));67 sprites.push(svgDocument.getElementById("hitB"));68 sprites.push(svgDocument.getElementById("hitC"));69 sprites.push(svgDocument.getElementById("hitD"));70 sprites.push(svgDocument.getElementById("hitE"));71 sprites.push(svgDocument.getElementById("share_label"));72 for (i=1;i<=23;i++){73 sprites.push(svgDocument.getElementById("gnu-share-"+i));74 }75 sprites.push(svgDocument.getElementById("gnu"));76 sprites.push(svgDocument.getElementById("win"));77 NUM_SPRITES=48+23;78 window.setInterval(game_timer, delta_t);79 turn_off_by_id("rules")80 turn_off_by_id("loading");81}82var game_is_running = false;83function game_timer(){84 if (game_is_running)85 game_loop();86 else87 sequential_light();88 //random_light();89}90function show_rules(){91 turn_on_by_id("rules");92}93function hide_rules(){94 turn_off_by_id("rules");95}96var count_ticks = 0;97var probability = 0.1;98var ticks_per_level = new Array();99var is_paused = false;100function pause(){101 if (!game_is_running) return;102 if (is_paused){103 is_paused = false;104 turn_off_by_id("paused");105 } else {106 is_paused = true;107 turn_on_by_id("paused");108 }109}110(function() {111var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";112function base64encode(str) {113 var out, i, len;114 var c1, c2, c3;115 len = str.length;116 i = 0;117 out = "";118 while(i < len) {119 c1 = str.charCodeAt(i++) & 0xff;120 if(i == len)121 {122 out += base64EncodeChars.charAt(c1 >> 2);123 out += base64EncodeChars.charAt((c1 & 0x3) << 4);124 out += "==";125 break;126 }127 c2 = str.charCodeAt(i++);128 if(i == len)129 {130 out += base64EncodeChars.charAt(c1 >> 2);131 out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));132 out += base64EncodeChars.charAt((c2 & 0xF) << 2);133 out += "=";134 break;135 }136 c3 = str.charCodeAt(i++);137 out += base64EncodeChars.charAt(c1 >> 2);138 out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));139 out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));140 out += base64EncodeChars.charAt(c3 & 0x3F);141 }142 return out;143}144if (!window.base64encode) window.base64encode = base64encode;145})();146var sampleRate = 44100;147function encodeAudio8bit(data) {148 var n = data.length;149 var integer = 0, i;150 151 // 8-bit mono WAVE header template152 var header = "RIFF<##>WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00<##><##>\x01\x00\x08\x00data<##>";153 // Helper to insert a 32-bit little endian int.154 function insertLong(value) {155 var bytes = "";156 for (i = 0; i < 4; ++i) {157 bytes += String.fromCharCode(value % 256);158 value = Math.floor(value / 256);159 }160 header = header.replace('<##>', bytes);161 }162 // ChunkSize163 insertLong(36 + n);164 165 // SampleRate166 insertLong(sampleRate);167 // ByteRate168 insertLong(sampleRate);169 // Subchunk2Size170 insertLong(n);171 172 // Output sound data173 for (var i = 0; i < n; ++i) {174 header += String.fromCharCode(data[i] * 255);175 }176 177 return 'data:audio/wav;base64,' + base64encode(header);178}179function new_tone(n) {180 var audio = new Audio();181 var samples = [];182 for (var i=0;i<sampleRate/30;i++){183 samples.push( i%(n*50) > (n*25) ? 0 : 1);184 }185 audio.setAttribute("src",encodeAudio8bit(samples));186 audio.load();187 audio.autoplay = false;188 return function() {audio.play();};189}190window.beep = new_tone(1);191window.boop = new_tone(2);192window.dang = new_tone(5);193function game_loop(){194 if(is_paused) return;195 count_ticks++;196 if (count_ticks%(Math.floor(1000/delta_t))==0){197 time--;198 if (time==0) game_over();199 }200 if (count_ticks%(ticks_per_level[level-1])==0){201 beep();202 var play_miss_sound=false;203 for (i=0;i<5;i++){204 //count buterflies that were missed (not slapped by tux)205 if (butterfly[4][i]==1) {miss++;play_miss_sound=true};206 //Scroll down the butterflies:207 for (j=4;j>0;j--){208 butterfly[j][i]=butterfly[j-1][i];209 }210 211 if (Math.random() < probability)212 butterfly[0][i]=1;213 else214 butterfly[0][i]=0;215 }216 if (play_miss_sound) dang();217 for (i=0;i<5;i++){218 for (j=4;j>0;j--){219 if (butterfly[j][i]==1)220 turn_sprite_on("msn"+j, i);221 else222 turn_sprite_off("msn"+j, i);223 }224 }225 }226 //update market share bar227 // and blink GNU and MS-Windows Logos in frequencies also indicating the228 // size of their market share229 display_share();230 display_time();231}232function game_over(){233 game_is_running=false;234 turn_on_by_id("game-over");235}236function init_game(){237 ticks_per_level[0]=20;238 ticks_per_level[1]=15;239 ticks_per_level[2]=13;240 ticks_per_level[3]=12;241 ticks_per_level[4]=11;242 ticks_per_level[5]=10;243 ticks_per_level[6]=9;244 ticks_per_level[7]=8;245 ticks_per_level[8]=7;246 for (i=0;i<5;i++){247 butterfly.push(new Array());248 for (j=0;j<5;j++){249 butterfly[i][j]=0;250 }251 }252 253 set_score(0);254 set_level(1);255 //we start with 5% of a gnu/Linux market share256 // and the player has to defeat by slapping as much msn butterflies as she can :-) 257 //And yeah! A missed one costs you the same you gain from 5 good hits. Life is not easy for the Free Software Movement...258 share_k = 5259 hit = 0.5 * share_k;260 miss = 10;261 position = 2;262 game_is_running = true;263 is_paused = false;264 time = 4 * 60; //four minutes to save the world :-D TODO: change it to 2 minutes and add 'bonus times' rule265 clear_sprites();266}267function turn_on_by_id(id){268 svgDocument.getElementById(id).setAttribute("visibility", "visible");269}270function turn_off_by_id(id){271 svgDocument.getElementById(id).setAttribute("visibility", "hidden");272}273function set_digit(id, val){274 switch(val){275 case 0:276 turn_on_by_id(id+1);277 turn_on_by_id(id+2);278 turn_on_by_id(id+3);279 turn_off_by_id(id+4);280 turn_on_by_id(id+5);281 turn_on_by_id(id+6);282 turn_on_by_id(id+7);283 break;284 case 1:285 turn_off_by_id(id+1);286 turn_off_by_id(id+2);287 turn_on_by_id(id+3);288 turn_off_by_id(id+4);289 turn_off_by_id(id+5);290 turn_on_by_id(id+6);291 turn_off_by_id(id+7);292 break;293 case 2:294 turn_on_by_id(id+1);295 turn_off_by_id(id+2);296 turn_on_by_id(id+3);297 turn_on_by_id(id+4);298 turn_on_by_id(id+5);299 turn_off_by_id(id+6);300 turn_on_by_id(id+7);301 break;302 case 3:303 turn_on_by_id(id+1);304 turn_off_by_id(id+2);305 turn_on_by_id(id+3);306 turn_on_by_id(id+4);307 turn_off_by_id(id+5);308 turn_on_by_id(id+6);309 turn_on_by_id(id+7);310 break;311 case 4:312 turn_off_by_id(id+1);313 turn_on_by_id(id+2);314 turn_on_by_id(id+3);315 turn_on_by_id(id+4);316 turn_off_by_id(id+5);317 turn_on_by_id(id+6);318 turn_off_by_id(id+7);319 break;320 case 5:321 turn_on_by_id(id+1);322 turn_on_by_id(id+2);323 turn_off_by_id(id+3);324 turn_on_by_id(id+4);325 turn_off_by_id(id+5);326 turn_on_by_id(id+6);327 turn_on_by_id(id+7);328 break;329 case 6:330 turn_on_by_id(id+1);331 turn_on_by_id(id+2);332 turn_off_by_id(id+3);333 turn_on_by_id(id+4);334 turn_on_by_id(id+5);335 turn_on_by_id(id+6);336 turn_on_by_id(id+7);337 break;338 case 7:339 turn_on_by_id(id+1);340 turn_off_by_id(id+2);341 turn_on_by_id(id+3);342 turn_off_by_id(id+4);343 turn_off_by_id(id+5);344 turn_on_by_id(id+6);345 turn_off_by_id(id+7);346 break;347 case 8:348 turn_on_by_id(id+1);349 turn_on_by_id(id+2);350 turn_on_by_id(id+3);351 turn_on_by_id(id+4);352 turn_on_by_id(id+5);353 turn_on_by_id(id+6);354 turn_on_by_id(id+7);355 break;356 case 9:357 turn_on_by_id(id+1);358 turn_on_by_id(id+2);359 turn_on_by_id(id+3);360 turn_on_by_id(id+4);361 turn_off_by_id(id+5);362 turn_on_by_id(id+6);363 turn_on_by_id(id+7);364 break;365 case 10: //means void366 turn_off_by_id(id+1);367 turn_off_by_id(id+2);368 turn_off_by_id(id+3);369 turn_off_by_id(id+4);370 turn_off_by_id(id+5);371 turn_off_by_id(id+6);372 turn_off_by_id(id+7);373 break;374 }375}376var share_k;377//FLASH = 10;378function display_share(){379 gnu_share = hit/(hit+share_k*miss);380 //Market share bar:381 for (i=1;i<=23;i++){382 if (i<23*gnu_share)383 turn_on_by_id("gnu-share-"+i);384 else385 turn_off_by_id("gnu-share-"+i);386 }387 set_digit("MS1_", Math.floor(10*gnu_share));388 set_digit("MS0_", Math.floor(100*gnu_share)%10);389/*390 //Blinking GNU logo391 if (count_ticks%(Math.floor(FLASH * gnu_share))==0)392 turn_on_by_id("gnu");393 else394 turn_off_by_id("gnu");395 //Blinking MS-Windows(r) logo396 if (count_ticks%(Math.floor(FLASH*(1 - gnu_share)))==0)397 turn_on_by_id("win");398 else399 turn_off_by_id("win");400*/401 402}403function display_time(){404 set_digit("TMin1_", Math.floor(time/600)%10);405 set_digit("TMin0_", Math.floor(time/60)%10);406 set_digit("TSec1_", Math.floor(time/10)%6);407 set_digit("TSec0_", Math.floor(time%10));408}409POINTS_NEEDED_IN_ORDER_TO_INCREASE_LEVEL = 50410var score;411function set_score(val){412 if (Math.floor(val / (level * POINTS_NEEDED_IN_ORDER_TO_INCREASE_LEVEL)) != 413 Math.floor(score / (level * POINTS_NEEDED_IN_ORDER_TO_INCREASE_LEVEL)) && level <9)414 set_level(level+1);415 score = val;416 417 var i=0;418 while(i < 5){419 if (val==0 && i > 0) set_digit("S"+i+"_", 10);420 else set_digit("S"+i+"_", val%10);421 val = Math.floor(val/10);422 i++;423 }424}425var level;426function set_level(n){427 level = n;428 set_digit("L", n%10);429}430function clear_sprites(){431 for (i=0;i<NUM_SPRITES;i++){432 turn_off(i);433 }434 turn_sprite_on("tux", position);435 turn_sprite_on("down", position);436 turn_on_by_id("share_label");437 turn_on_by_id("gnu");438 turn_on_by_id("win");439 turn_off_by_id("game-over");440 turn_off_by_id("paused");441}442function turn_sprite_on(id, i){443// O=event.target;444// svgDocument=O.ownerDocument;445 switch(i){446 case 0: i="A"; break;447 case 1: i="B"; break;448 case 2: i="C"; break;449 case 3: i="D"; break;450 case 4: i="E"; break;451 }452 turn_on_by_id(id+i);453}454function turn_sprite_off(id, i){455// O=event.target;456// svgDocument=O.ownerDocument;457 switch(i){458 case 0: i="A"; break;459 case 1: i="B"; break;460 case 2: i="C"; break;461 case 3: i="D"; break;462 case 4: i="E"; break;463 }464 turn_off_by_id(id+i)465}466function turn_on(i){467 if (sprites[i]){468 sprites[parseInt(i)].setAttribute("visibility", "visible");469 }470}471function turn_off(i){472 if (sprites[i])473 sprites[parseInt(i)].setAttribute("visibility", "hidden");474}475function random_light(){476 for (i=0;i<20;i++){477 turn_on(Math.floor(Math.random()*NUM_SPRITES));478 turn_off(Math.floor(Math.random()*NUM_SPRITES));479 }480}481var current_lamp = 0;482function sequential_light(){483 turn_on(current_lamp%NUM_SPRITES);484 turn_off((current_lamp + Math.floor(NUM_SPRITES/2))%NUM_SPRITES);485 current_lamp=(current_lamp+1)%NUM_SPRITES;486}487var position = 2;488function tux_right(){489 if (is_paused || !game_is_running) return;490 tux_wing_down();491 if (position < 4){492 turn_sprite_off("tux", position);493 turn_sprite_off("down", position);494 position++;495 turn_sprite_on("tux", position);496 turn_sprite_on("down", position);497 }498}499function tux_left(){500 if (is_paused || !game_is_running) return;501 tux_wing_down();502 if (position > 0){503 turn_sprite_off("tux", position);504 turn_sprite_off("down", position);505 position--;506 turn_sprite_on("tux", position);507 turn_sprite_on("down", position);508 }509}510function tux_hit(){511 if (is_paused || !game_is_running) return;512 turn_sprite_off("down", position);513 turn_sprite_on("up", position);514 if (butterfly[4][position]){515 turn_sprite_on("hit", position);516 set_score(score+level);517 hit++;518 boop();519 } else {520 turn_sprite_on("miss", position);521 beep();522 }523}524function tux_wing_down(){525 if (is_paused || !game_is_running) return;526 turn_sprite_on("down", position);527 turn_sprite_off("up", position);528 turn_sprite_off("hit", position);529 turn_sprite_off("miss", position);530 if (butterfly[4][position]){531 butterfly[4][position]=0;532 turn_sprite_off("msn4", position);533 }534}535function start(){536 if (game_is_running == false){537 init_game();538 }539}540RIGHT_KEY = 39541LEFT_KEY = 37542SPACEBAR_KEY = 32543ENTER_KEY = 13544PAUSE_KEY = 19545H_KEY = 72546P_KEY = 80547Q_KEY = 81548R_KEY = 82549S_KEY = 83550ESC_KEY = 27551function keydown(event){552 O=event.target;553 svgDocument=O.ownerDocument;554 switch(event.which){555 case LEFT_KEY:556 tux_left();557 break;558 case RIGHT_KEY:559 tux_right();560 break;561 case ENTER_KEY:562 case S_KEY:563 start();564 break;565 case PAUSE_KEY:566 case P_KEY:567 pause();568 break;569 case R_KEY:570 show_rules();571 break;572 case SPACEBAR_KEY:573 case H_KEY:574 tux_hit();575 break;576 case ESC_KEY:577 case Q_KEY:578 game_over();579// default:580// alert(event.which)581 }582}583function keyup(event){584 O=event.target;585 svgDocument=O.ownerDocument;586 switch(event.which){587 case SPACEBAR_KEY:588 tux_wing_down();589 break;590 }...

Full Screen

Full Screen

chart.js

Source:chart.js Github

copy

Full Screen

1 2 StyleArray = new Array("pie1", 3 "pie2", 4 "pie3", 5 "pie4", 6 "pie5", 7 "pie6", 8 "pie7", 9 "pie8", 10 "pie9", 11 "pie10", 12 "pie11") 13 14 ActiveSegment = "Pie"15 16 CurrentStyle = 0;17 18 SVGDocument = null19 20 BarChartHeight = 15021 BarChartWidth = 25022 23 PieChartSize = 14024 25 MoveDistance = 4026 27 Values = new Array()28 Names = new Array()29 PieElements = new Array()30 BarElements = new Array()31 BarTexts = new Array()32 DeleteList = new Array()33 34 PieLabels = new Array()35 PieBox = new Array()36 DrillData = new Array()37 38 PieTotalSize = 0;39 BarTotalSize = 0;40 MaxSize = 0;41 42 AngleFactor = Math.pow(2, .5)43 44 Removed = true45 46 function ClearChart()47 {48 for (var I = 0; I < PieElements.length; I++)49 {50 ParentGroup1.removeChild(PieElements[I])51 ParentGroup2.removeChild(BarElements[I])52 SVGDocument.getElementById("labels").removeChild(Names[I])53 SVGDocument.getElementById("pielabels").removeChild(Names[I])54 }55 56 PieElements = new Array()57 BarElements = new Array()58 BarTexts = new Array()59 Values = new Array()60 Names = new Array()61 PieLabels = new Array()62 PieBox = new Array()63 DrillData = new Array()64 65 PieTotalSize = 0;66 BarTotalSize = 0;67 MaxSize = 0;68 if (!(Removed))69 {70 Grandparent1.removeChild(ParentGroup1)71 Grandparent2.removeChild(ParentGroup2)72 }73 Removed = true74 75 }76 77 function Initialize(LoadEvent)78 {79 SVGDocument = LoadEvent.target.ownerDocument;80 ParentGroup1 = SVGDocument.getElementById("slices")81 Grandparent1 = SVGDocument.getElementById("piechart")82 ParentGroup2 = SVGDocument.getElementById("bars")83 Grandparent2 = SVGDocument.getElementById("barchart")84 }85 86 function AddChartValue(Value, Name, Repress)87 {88 Value = Value * 189 if ((Value <= 0) || (isNaN(Value)))90 {91 // I cant handle non-numeric or negative data here, so just get out.92 return;93 }94 95 Style = StyleArray[CurrentStyle]96 // Increment the style, and loop back to 0 if we have bust the limit.97 CurrentStyle++98 if (CurrentStyle >= StyleArray.length) CurrentStyle = 0 99 100 if (!(Removed))101 {102 Grandparent1.removeChild(ParentGroup1)103 Grandparent2.removeChild(ParentGroup2)104 }105 DeleteList[DeleteList.length] = false106 107 Values[Values.length] = Value * 1108 PieLabels[PieLabels.length] = SVGDocument.createElementNS("http://www.w3.org/2000/svg","text")109 Names[Names.length] = SVGDocument.createElementNS("http://www.w3.org/2000/svg","text")110 111 PieElements[PieElements.length] = SVGDocument.createElementNS("http://www.w3.org/2000/svg","path")112 113 PieElements[PieElements.length - 1].setAttributeNS(null,"class", Style)114 PieElements[PieElements.length - 1].setAttributeNS(null,"onmouseover", "DisplayInfo('" + Name + "', '" + Value + "')")115 PieElements[PieElements.length - 1].setAttributeNS(null,"onmouseout", "DisplayInfo(' ', ' ')")116 ParentGroup1.appendChild(PieElements[PieElements.length - 1])117 118 BarElements[BarElements.length] = SVGDocument.createElementNS("http://www.w3.org/2000/svg","path")119 BarTexts[BarTexts.length] = SVGDocument.createElementNS("http://www.w3.org/2000/svg","text")120 121 BarElements[BarElements.length - 1].setAttributeNS(null,"class",Style)122 123 BarElements[BarElements.length - 1].setAttributeNS(null,"onmouseover", "BarTexts[" + (BarTexts.length - 1) + "].style.setProperty('visibility', 'visible','')")124 BarElements[BarElements.length - 1].setAttributeNS(null,"onmouseout", "BarTexts[" + (BarTexts.length - 1) + "].style.setProperty('visibility', 'hidden')")125 ParentGroup2.appendChild(BarElements[BarElements.length - 1])126 127 BarTexts[BarTexts.length - 1].setAttributeNS(null,"style", "text-anchor:end;font-weight:bold;font-size:13;visibility:hidden")128 BarTexts[BarTexts.length - 1].setAttributeNS(null,"x", "40")129 BarTexts[BarTexts.length - 1].appendChild(SVGDocument.createTextNode(Value))130 SVGDocument.getElementById("barsidetext").appendChild(BarTexts[BarTexts.length - 1])131 Names[Names.length - 1].appendChild(SVGDocument.createTextNode(Name + ""))132 Names[Names.length - 1].setAttributeNS(null,"transform", "rotate(45)")133 134 PieLabels[PieLabels.length-1].appendChild(SVGDocument.createTextNode(Name + ""))135 SVGDocument.getElementById("pielabels").appendChild(PieLabels[PieLabels.length - 1])136 PieBox[PieBox.length] = SVGDocument.createElementNS("http://www.w3.org/2000/svg","path")137 SVGDocument.getElementById("pielabels").appendChild(PieBox[PieBox.length - 1])138 PieBox[PieBox.length - 1].setAttributeNS(null,"class",Style)139 140 SVGDocument.getElementById("labels").appendChild(Names[Names.length - 1])141 }142// All done so add the items and display the chart143function Complete(){144 Refresh(); // Draw it!145 Grandparent1.appendChild(ParentGroup1)146 Grandparent2.appendChild(ParentGroup2)147}148// Add drilldata for enquiry drill downs149function AddDrill(Drill) {150 DrillData[DrillData.length]=Drill;151} 152// Actually draw the whole nine yards....153 function Refresh()154 {155 PieTotalSize = 0156 BarTotalSize = 0157 MaxSize = 0158 159 for (var I = 0; I < Values.length; I++)160 {161 PieTotalSize += Values[I]162 BarTotalSize++163 if (Values[I] > MaxSize)164 MaxSize = Values[I]165 }166 167 PieStart = 0168 BarStart = 0169 yStart = 0170 boxHeight = 10171 172 if (PieTotalSize > 0)173 for (var I = 0; I < Values.length; I++)174 {175 PieStart = DrawPieSegment(PieStart, Values[I] / PieTotalSize, PieElements[I], I)176 BarStart = DrawBarSegment(BarStart, Values[I] / MaxSize, BarElements[I], BarTexts[I], Names[I], I)177 178 PieLabels[I].setAttributeNS(null,"y",yStart +10 + (15* I))179 PieLabels[I].setAttributeNS(null,"x",15)180 // Draw the chart legend boxes181 PathData = "M 0 "+ (yStart + (15* I))+" L 0 "+ (boxHeight+yStart + (15* I))+" L 10 "+ (boxHeight+yStart + (15* I))+" L 10 "+ (yStart + (15* I))+"Z"182 PieBox[I].setAttributeNS(null,"d", PathData)183 }184 185 SVGDocument.getElementById("max").replaceChild(SVGDocument.createTextNode(MaxSize + ""), SVGDocument.getElementById("max").firstChild)186 SVGDocument.getElementById("min").replaceChild(SVGDocument.createTextNode("0"), SVGDocument.getElementById("min").firstChild)187 }188 189 190 191 function DrawBarSegment(Start, Height, Element, Text, Label, ID)192 {193 XOffset3D = 10194 YOffset3D = 5195 196 PathData = "M" + (Start + (BarChartWidth / BarTotalSize)) + ",0"197 PathData = PathData + "h" + (BarChartWidth / BarTotalSize * -1)198 PathData = PathData + "v" + (Height * BarChartHeight * -1)199 PathData = PathData + "l" + XOffset3D + ",-" + YOffset3D200 PathData = PathData + "h" + (BarChartWidth / BarTotalSize)201 PathData = PathData + "v" + (Height * BarChartHeight)202 PathData = PathData + "l-" + XOffset3D + "," + YOffset3D203 PathData = PathData + "v" + (Height * BarChartHeight * -1)204 PathData = PathData + "h" + (BarChartWidth / BarTotalSize * -1)205 PathData = PathData + "h" + (BarChartWidth / BarTotalSize)206 PathData = PathData + "l" + XOffset3D + ",-" + YOffset3D207 PathData = PathData + "l-" + XOffset3D + "," + YOffset3D208 209 Element.setAttributeNS(null,"d", PathData)210 Element.setAttributeNS(null,"onclick", "doDrill(" + ID + ")")211 Label.setAttributeNS(null,"x", Start / AngleFactor)212 Label.setAttributeNS(null,"y", Start * -1 / AngleFactor)213 214 Text.setAttributeNS(null,"y", (200 - BarChartHeight * Height))215 216 return Start + BarChartWidth / BarTotalSize217 }218 219 function DrawPieSegment(Start, Size, Element, ID)220 {221 if (Size == 1) {222 PathData = "M-" + PieChartSize + " 0 a " + PieChartSize + " " + PieChartSize + " 0 1 0 " + 2*PieChartSize + " 0 a " + PieChartSize + " " + PieChartSize + " 0 1 0 -" + 2*PieChartSize + " 0"223 } else {224 PathData = "M0,0L" 225 PathData = PathData + PieChartSize * Math.sin(Start * Math.PI * 2) + "," + PieChartSize * Math.cos(Start * Math.PI * 2)226 if (Size >= .5) {227 PathData = PathData + "A" + PieChartSize + " " + PieChartSize + " 1 1 0 " + PieChartSize * Math.sin((Start + Size) * Math.PI * 2) + "," + PieChartSize * Math.cos((Start + Size) * Math.PI * 2)228 } else {229 PathData = PathData + "A" + PieChartSize + " " + PieChartSize + " 0 0 0 " + PieChartSize * Math.sin((Start + Size) * Math.PI * 2) + "," + PieChartSize * Math.cos((Start + Size) * Math.PI * 2)230 }231 PathData = PathData + "z"232 }233 Element.setAttributeNS(null,"d", PathData)234 Element.setAttributeNS(null,"onclick", "MoveSegment(evt, " + (Start + Size / 2) + ", true, " + ID + ")")235 if (Start > 0) {236// Element.setAttributeNS(null,"onclick", "MoveSegment(evt, " + (Start + Size / 2) + ", true, " + ID + ")")237 } else 238 {239 DeleteList[ID] = true;240// Angle = Start + Size / 2241 // X = MoveDistance * Math.sin(Angle * 2 * Math.PI)242 // Y = MoveDistance * Math.cos(Angle * 2 * Math.PI)243 // Element.setAttributeNS(null,"transform", "translate(" + X + "," + Y + ")")244 // Element.setAttributeNS(null,"onclick", "MoveSegment(evt, " + ((Start + Size / 2) * -1) + ", false, " + ID + ")")245 }246 247 return Start + Size248 }249 250 function doDrill(ID){251 parent.chartdrill(DrillData[ID])252 }253 254 function MoveSegment(MouseEvent, Angle, CanBeDeleted, ID)255 {256 Element = MouseEvent.target257 if (Angle < 0)258 {259 X = 0260 Y = 0261 }262 else263 {264 X = MoveDistance * Math.sin(Angle * 2 * Math.PI)265 Y = MoveDistance * Math.cos(Angle * 2 * Math.PI)266 }267 268 DeleteList[ID] = CanBeDeleted269 270 Element.setAttributeNS(null,"transform", "translate(" + X + "," + Y + ")")271 Element.setAttributeNS(null,"onclick", "MoveSegment(evt, " + (Angle * -1) + ", " + (!CanBeDeleted) + ", " + ID + ")")272 parent.chartdrill(DrillData[ID])273 }274 275 function DisplayInfo(Text, Value)276 {277 if (Text != " ") {278 Text = Text + " : "279 Percent = " (" + Math.round(Value / PieTotalSize * 10000) / 100 + "%)"280 }281 else282 {283 Percent = ""284 }285 NewItem = SVGDocument.createTextNode(Text +Value + Percent)286 firstChild = SVGDocument.getElementById("labelamount").firstChild287 if (firstChild==null){288 SVGDocument.getElementById("labelamount").appendChild(NewItem)289 }290 SVGDocument.getElementById("labelamount").replaceChild(NewItem, SVGDocument.getElementById("labelamount").firstChild)291 }292 293 function SetTitle(Text)294 {295 NewItem = SVGDocument.createTextNode(Text + "")296 firstChild = SVGDocument.getElementById("title").firstChild297 if (firstChild==null){298 SVGDocument.getElementById("title").appendChild(NewItem)299 }300 SVGDocument.getElementById("title").replaceChild(NewItem, SVGDocument.getElementById("title").firstChild)301 }302 303 function SetAxis(Text)304 {305 NewItem = SVGDocument.createTextNode(Text + "")306 firstChild = SVGDocument.getElementById("axis").firstChild307 if (firstChild==null){308 SVGDocument.getElementById("axis").appendChild(NewItem)309 }310 SVGDocument.getElementById("axis").replaceChild(NewItem, SVGDocument.getElementById("axis").firstChild)311 NewItem = SVGDocument.createTextNode(Text + "")312 firstChild = SVGDocument.getElementById("subtitle").firstChild313 if (firstChild==null){314 SVGDocument.getElementById("subtitle").appendChild(NewItem)315 }316 SVGDocument.getElementById("subtitle").replaceChild(NewItem, SVGDocument.getElementById("subtitle").firstChild)317 }318 319 function ShowPie()320 {321 ActiveSegment = "Pie"322 SVGDocument.getElementById("barchart").style.setProperty("visibility", "hidden","");323 SVGDocument.getElementById("subtitle").style.setProperty("visibility", "visible","");324 SVGDocument.getElementById("piechart").style.setProperty("visibility", "visible","");325 SVGDocument.getElementById("pieitemlabel").style.setProperty("visibility", "visible","");326 SVGDocument.getElementById("barsidetext").style.setProperty("visibility", "hidden","");327 }328 329 function ShowBar()330 {331 ActiveSegment = "Bar" 332 SVGDocument.getElementById("barchart").style.setProperty("visibility", "visible","");333 SVGDocument.getElementById("subtitle").style.setProperty("visibility", "hidden","");334 SVGDocument.getElementById("piechart").style.setProperty("visibility", "hidden","");335 SVGDocument.getElementById("pieitemlabel").style.setProperty("visibility", "hidden","");336 SVGDocument.getElementById("barsidetext").style.setProperty("visibility", "visible","");337 }338 339 parent.clearChart = ClearChart340 parent.addChartValue = AddChartValue341 parent.setTitle = SetTitle342 parent.setAxis = SetAxis343 parent.showBar = ShowBar344 parent.showPie = ShowPie 345 parent.addDrill = AddDrill346parent.complete = Complete...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3}, function (err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 var run = data.data.runs[1];9 var testId = data.data.testId;10 console.log(run.firstView.svgDocument);11 wpt.getTestResults(testId, function (err, data) {12 if (err) {13 console.log(err);14 } else {15 console.log(data);16 }17 });18 }19});20{ data: 21 { testId: '150925_9C_5d6f5e6c5f6d2e6e5c5b5f6b5c6e5d6d',

Full Screen

Using AI Code Generation

copy

Full Screen

1var svgDoc = wpt.svgDocument();2var svgRoot = svgDoc.documentElement;3var svgNS = svgRoot.namespaceURI;4var rect = svgDoc.createElementNS(svgNS, "rect");5rect.setAttributeNS(null, "x", 100);6rect.setAttributeNS(null, "y", 100);7rect.setAttributeNS(null, "width", 100);8rect.setAttributeNS(null, "height", 100);9rect.setAttributeNS(null, "fill", "red");10svgRoot.appendChild(rect);11var svgDoc = wpt.svgDocument();12var svgRoot = svgDoc.documentElement;13var svgNS = svgRoot.namespaceURI;14var rect = svgDoc.createElementNS(svgNS, "rect");15rect.setAttributeNS(null, "x", 100);16rect.setAttributeNS(null, "y", 100);17rect.setAttributeNS(null, "width", 100);18rect.setAttributeNS(null, "height", 100);19rect.setAttributeNS(null, "fill", "red");20svgRoot.appendChild(rect);21var svgDoc = wpt.svgDocument();22var svgRoot = svgDoc.documentElement;23var svgNS = svgRoot.namespaceURI;24var rect = svgDoc.createElementNS(svgNS, "rect");25rect.setAttributeNS(null, "x", 100);26rect.setAttributeNS(null, "y", 100);27rect.setAttributeNS(null, "width", 100);28rect.setAttributeNS(null, "height", 100);29rect.setAttributeNS(null, "fill", "red");30svgRoot.appendChild(rect);31var svgDoc = wpt.svgDocument();32var svgRoot = svgDoc.documentElement;33var svgNS = svgRoot.namespaceURI;34var rect = svgDoc.createElementNS(svgNS, "rect");35rect.setAttributeNS(null, "x", 100);36rect.setAttributeNS(null, "y", 100);37rect.setAttributeNS(null, "width", 100);38rect.setAttributeNS(null, "height", 100);39rect.setAttributeNS(null, "fill", "red");40svgRoot.appendChild(rect);41var svgDoc = wpt.svgDocument();42var svgRoot = svgDoc.documentElement;43var svgNS = svgRoot.namespaceURI;44var rect = svgDoc.createElementNS(svgNS, "rect");45rect.setAttributeNS(null, "x

Full Screen

Using AI Code Generation

copy

Full Screen

1var svgDoc = wptdriver.svgDocument();2var svg = svgDoc.getElementById("svg");3var rect = svgDoc.getElementById("rect");4var text = svgDoc.getElementById("text");5var circle = svgDoc.getElementById("circle");6var line = svgDoc.getElementById("line");7var path = svgDoc.getElementById("path");8var polyline = svgDoc.getElementById("polyline");9var polygon = svgDoc.getElementById("polygon");10var g = svgDoc.getElementById("g");11var use = svgDoc.getElementById("use");12var defs = svgDoc.getElementById("defs");13var symbol = svgDoc.getElementById("symbol");14var clipPath = svgDoc.getElementById("clipPath");15var marker = svgDoc.getElementById("marker");16var linearGradient = svgDoc.getElementById("linearGradient");17var radialGradient = svgDoc.getElementById("radialGradient");18var stop = svgDoc.getElementById("stop");19var filter = svgDoc.getElementById("filter");20var feGaussianBlur = svgDoc.getElementById("feGaussianBlur");21var title = svgDoc.getElementById("title");22var desc = svgDoc.getElementById("desc");23var a = svgDoc.getElementById("a");24var image = svgDoc.getElementById("image");25var foreignObject = svgDoc.getElementById("foreignObject");26var textPath = svgDoc.getElementById("textPath");27var tspan = svgDoc.getElementById("tspan");28var altGlyph = svgDoc.getElementById("altGlyph");29var altGlyphDef = svgDoc.getElementById("altGlyphDef");30var altGlyphItem = svgDoc.getElementById("altGlyphItem");31var glyphRef = svgDoc.getElementById("glyphRef");32var glyph = svgDoc.getElementById("glyph");33var missingGlyph = svgDoc.getElementById("missingGlyph");34var pattern = svgDoc.getElementById("pattern");35var view = svgDoc.getElementById("view");36assert_equals(svg.nodeName, "svg");37assert_equals(rect.nodeName, "rect");38assert_equals(text.nodeName, "text");39assert_equals(circle.nodeName, "circle");40assert_equals(line.nodeName, "line");41assert_equals(path.nodeName, "path");42assert_equals(polyline.nodeName, "polyline");43assert_equals(polygon.nodeName, "polygon");44assert_equals(g.nodeName, "g");45assert_equals(use.nodeName, "use");46assert_equals(defs.nodeName, "defs");47assert_equals(symbol.nodeName, "symbol");48assert_equals(clipPath.nodeName, "clipPath");49assert_equals(marker.nodeName, "marker");50assert_equals(linearGradient.nodeName, "linearGradient");51assert_equals(radialGradient.nodeName, "radialGradient");

Full Screen

Using AI Code Generation

copy

Full Screen

1function test() {2 var svgDoc = wpt.svgDocument();3 return svgDoc;4}5function test() {6 var svgDoc = wpt.svgDocument();7 return svgDoc;8}9function test() {10 var svgDoc = wpt.svgDocument();11 return svgDoc;12}13function test() {14 var svgDoc = wpt.svgDocument();15 return svgDoc;16}17function test() {18 var svgDoc = wpt.svgDocument();19 return svgDoc;20}

Full Screen

Using AI Code Generation

copy

Full Screen

1var svg = wptdriver.svgDocument();2svg.getElementById("test").innerHTML = "Hello World!";3var svg = wptdriver.svgDocument();4var script = "svg.getElementById('test').innerHTML = 'Hello World!';";5wptdriver.evaluate(script);6var svg = wptdriver.svgDocument();7var script = "svg.getElementById('test').innerHTML = 'Hello World!';";8wptdriver.evaluate(script);9var svg = wptdriver.svgDocument();10var script = "svg.getElementById('test').innerHTML = 'Hello World!';";11wptdriver.evaluate(script);

Full Screen

Using AI Code Generation

copy

Full Screen

1var svgDoc = wptDriver.svgDocument();2var svgElement = svgDoc.documentElement;3var svgElementWidth = svgElement.getAttribute("width");4var svgElementHeight = svgElement.getAttribute("height");5var svgElementViewBox = svgElement.getAttribute("viewBox");6console.log("SVG Element Width: " + svgElementWidth);7console.log("SVG Element Height: " + svgElementHeight);8console.log("SVG Element ViewBox: " + svgElementViewBox);9var svgDoc = wptDriver.svgDocument();10var svgElement = svgDoc.documentElement;11var svgElementWidth = svgElement.getAttribute("width");12var svgElementHeight = svgElement.getAttribute("height");13var svgElementViewBox = svgElement.getAttribute("viewBox");14console.log("SVG Element Width: " + svgElementWidth);15console.log("SVG Element Height: " + svgElementHeight);16console.log("SVG Element ViewBox: " + svgElementViewBox);17var svgDoc = wptDriver.svgDocument();18var svgElement = svgDoc.documentElement;19var svgElementWidth = svgElement.getAttribute("width");20var svgElementHeight = svgElement.getAttribute("height");21var svgElementViewBox = svgElement.getAttribute("viewBox");22console.log("SVG Element Width: " + svgElementWidth);23console.log("SVG Element Height: " + svgElementHeight);24console.log("SVG Element ViewBox: " + svgElementViewBox);25var svgDoc = wptDriver.svgDocument();26var svgElement = svgDoc.documentElement;27var svgElementWidth = svgElement.getAttribute("width");28var svgElementHeight = svgElement.getAttribute("height");29var svgElementViewBox = svgElement.getAttribute("viewBox");30console.log("SVG Element Width: " + svgElementWidth);31console.log("SVG Element Height: " + svgElementHeight);32console.log("SVG Element ViewBox: " + svgElementViewBox);

Full Screen

Using AI Code Generation

copy

Full Screen

1var svgDoc = document.svgDocument;2var svgRoot = svgDoc.rootElement;3var rect = svgRoot.getElementById('rect1');4var svgtext = svgRoot.getElementById('text1');5var wptextarea = svgtext.svgDocument;6var svgtext2 = svgRoot.getElementById('text2');7var wptextarea2 = svgtext2.svgDocument;8var svgDoc = rect.svgDocument;9var svgRoot = svgDoc.rootElement;10var svgtext = svgRoot.getElementById('text1');11var wptextarea = svgtext.svgDocument;12var svgtext2 = svgRoot.getElementById('text2');13var wptextarea2 = svgtext2.svgDocument;14var svgDoc = svgtext.svgDocument;15var svgRoot = svgDoc.rootElement;16var rect = svgRoot.getElementById('rect1');17var wptextarea = svgtext.svgDocument;18var svgtext2 = svgRoot.getElementById('text2');19var wptextarea2 = svgtext2.svgDocument;20var svgDoc = wptextarea.svgDocument;21var svgRoot = svgDoc.rootElement;22var rect = svgRoot.getElementById('rect1');23var svgtext = svgRoot.getElementById('text1');24var svgtext2 = svgRoot.getElementById('text2');25var wptextarea2 = svgtext2.svgDocument;26var svgDoc = svgtext2.svgDocument;27var svgRoot = svgDoc.rootElement;28var rect = svgRoot.getElementById('rect1');29var svgtext = svgRoot.getElementById('text1');30var wptextarea = svgtext.svgDocument;31var wptextarea2 = svgtext2.svgDocument;32var svgDoc = wptextarea2.svgDocument;33var svgRoot = svgDoc.rootElement;34var rect = svgRoot.getElementById('rect1');35var svgtext = svgRoot.getElementById('text1');36var wptextarea = svgtext.svgDocument;37var svgtext2 = svgRoot.getElementById('text2');38var svgDoc = svgRoot.svgDocument;39var rect = svgRoot.getElementById('rect1');40var svgtext = svgRoot.getElementById('text

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptext = require('wptext');2var wp = new wptext();3wp.setWiki('en.wikipedia.org');4wp.getWikiText('Wikipedia:WikiProject Text/Word cloud', function(err, data){5 if (err) {6 console.log(err);7 }8 else {9 console.log(data);10 }11});12var wptext = require('wptext');13var wp = new wptext();14wp.setWiki('en.wikipedia.org');15wp.getWikiText('Wikipedia:WikiProject Text/Word cloud', function(err, data){16 if (err) {17 console.log(err);18 }19 else {20 console.log(data);21 }22});

Full Screen

Using AI Code Generation

copy

Full Screen

1var svgDoc = wptdriver.svgDocument("svgObject");2var svgElement = svgDoc.getElementById("rect");3var bbox = svgElement.getBBox();4var x = wptdriver.getAttribute("svgObject", "rect", "x");5var y = wptdriver.getAttribute("svgObject", "rect", "y");6var width = wptdriver.getAttribute("svgObject", "rect", "width");7var height = wptdriver.getAttribute("svgObject", "rect", "height");8var stroke = wptdriver.getStyleAttribute("svgObject", "rect", "stroke");9var strokeWidth = wptdriver.getStyleAttribute("svgObject", "rect", "stroke-width");10var fill = wptdriver.getStyleAttribute("svgObject", "rect", "fill");11var opacity = wptdriver.getStyleAttribute("svgObject", "rect", "opacity");12var transform = wptdriver.getTransformAttribute("svgObject", "rect");13var viewBox = wptdriver.getAttribute("svgObject", "svg", "viewBox");14var x = 0;15var y = 0;16var width = 100;17var height = 100;18var stroke = "black";19var strokeWidth = 1;20var fill = "none";21var opacity = 1;22var transform = "matrix(1,0,0,

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful