Created
December 29, 2014 02:57
-
-
Save kiinlam/8d7786c38019dd0272c2 to your computer and use it in GitHub Desktop.
dynashow-demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SVG_NS = "http://www.w3.org/2000/svg"; | |
var XLINK_NS = "http://www.w3.org/1999/xlink"; | |
var ATTR_MAP = { | |
"className": "class", | |
"svgHref": "href" | |
}; | |
var NS_MAP = { | |
"svgHref": XLINK_NS | |
}; | |
function makeSVG(tag, attributes){ | |
var elem = document.createElementNS(SVG_NS, tag); | |
for (var attribute in attributes) { | |
var name = (attribute in ATTR_MAP ? ATTR_MAP[attribute] : attribute); | |
var value = attributes[attribute]; | |
if (attribute in NS_MAP) | |
elem.setAttributeNS(NS_MAP[attribute], name, value); | |
else | |
elem.setAttribute(name, value); | |
} | |
return elem; | |
} | |
//var lab1 = {x: "10", y: "10", width: "100", height: "35", label: "Good Moring!"}; | |
function createMySharp(sharpData) { | |
var svgdoc = document.documentElement; | |
var group = makeSVG("g", {x: "0", y: "0", transform: "translate("+sharpData.x+", "+sharpData.y+")"}); | |
var rect = makeSVG("rect", {x: "0", y: "0", width: sharpData.width, height: sharpData.height}); | |
group.appendChild(rect); | |
var text = makeSVG("text", {x: "0", y: "25"}); | |
text.textContent = sharpData.label; | |
group.appendChild(text); | |
svgdoc.appendChild(group); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment