Skip to content

Instantly share code, notes, and snippets.

@roundrobin
Created July 10, 2012 23:53
Show Gist options
  • Select an option

  • Save roundrobin/3087025 to your computer and use it in GitHub Desktop.

Select an option

Save roundrobin/3087025 to your computer and use it in GitHub Desktop.
just another inlet to tributary
var width = 677;
var text = "Das ist einn schon lange text und der soll assdfsdf sdlfksdf bla bla bla der ist auch so coooooll auch noch viel langer werden verstanden???";
g.append("text").text(text).attr("y",200).attr("x",30)
g.append("rect").attr("width",width).attr("height",200).attr("y",200).attr("x",30).attr("fill","red")
var mothership = g.append("text").attr("height",200).attr("y",354).attr("x",30).attr("fill","green")
var textArray = text.split(" ")
var tspan = mothership.append("tspan")
var i = 0
for(i in textArray){
var textLength = mothership.node().getComputedTextLength()
if(textLength >= width){
i++;
tspan = mothership.append("tspan").attr("dy",22)
}
tspan.text(tspan.text()+" "+textArray[i])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment