Skip to content

Instantly share code, notes, and snippets.

@kiinlam
Created December 29, 2014 02:57
Show Gist options
  • Save kiinlam/8d7786c38019dd0272c2 to your computer and use it in GitHub Desktop.
Save kiinlam/8d7786c38019dd0272c2 to your computer and use it in GitHub Desktop.
dynashow-demo
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);
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment