Created
July 11, 2012 05:23
-
-
Save roundrobin/3088163 to your computer and use it in GitHub Desktop.
just another inlet to tributary
This file contains 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 Baushaus = function(){ | |
this.svg = g; | |
} | |
//datatelling.com | |
Baushaus.prototype.mergeOptions = function(element, options){ for(option in options){ element.attr(option,options[option]); } }; | |
Baushaus.prototype.circle = function(r,x,y,options){ | |
var elem = this.svg.append('circle').attr('r',r); | |
elem.attr('cx',x) | |
elem.attr('cy',y) | |
if(options) this.mergeOptions(elem,options); | |
return elem; | |
}; | |
Baushaus.prototype.rect = function(w,h,options){ return this.svg.append('rect').attr('width',w).attr('height',h) }; | |
Baushaus.prototype.square = function(s,options){ return this.svg.append('rect').attr('width',s).attr('height',s)}; | |
var b = new Baushaus(); | |
b.circle(54,167,147) | |
b.circle(113,374,147) | |
var fo = g.append("foreignObject") | |
.attr("width", 100) | |
.attr("height", 14) | |
.append("xhtml:body") | |
fo.append('input').attr('id','content') | |
g.append('rect') | |
.attr('width',49) | |
.attr('height',55) | |
.attr('fill','red') | |
.on('click', function(){ | |
var val = $('#content').val() | |
parseCommand(val) | |
$('#content').val('') | |
}) | |
var drag = d3.behavior.drag().on("drag", function(d,i){ | |
d.x += d3.event.dx; | |
d.y += d3.event.dy; | |
d3.select(this).attr("transform", "translate(" + d.x + "," + d.y + ")");}) | |
function parseCommand(val){ | |
var split = val.split(' ') // Split the input | |
var command = split[0] // Get Command | |
if(command=='rect'){ | |
var rect = g.append('rect').attr('width',50).attr('height',50).attr('x',100).attr('y',100).attr('class','drag').data([{x: 0, y: 0}]) | |
rect.call(drag) | |
if(rect && split[1]) rect.attr('width',split[1]) | |
if(rect && split[2]) rect.attr('height',split[2]) | |
} | |
if(command=='circle'){ | |
var circle = g.append('circle').attr('r',50).attr('cx',100).attr('cy',100).attr('class','drag').data([{x: 0, y: 0}]) | |
circle.call(drag) | |
if(circle && split[1]) circle.attr('r',split[1]) | |
if(circle && split[2]) circle.attr('fill',split[2]) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment