Skip to content

Instantly share code, notes, and snippets.

@roundrobin
Created July 13, 2012 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roundrobin/3101989 to your computer and use it in GitHub Desktop.
Save roundrobin/3101989 to your computer and use it in GitHub Desktop.
just another inlet to tributary
width = 446
height = 221
x = 100
y= 100
rect = g.append("g").attr("width",width).attr("height",height).attr("fill","red").attr('x',x).attr('y',y)
rect.append("rect").attr("width",width).attr("height",height).attr("fill","red").attr('x',x).attr('y',y)
text = g.append("text").text("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.")
.attr("dominant-baseline","text-before-edge")
.attr('y',0).attr('x',x).attr('y',y)
wrapGroupInMaskWidthFadeOut = (box,selection) =>
height = parseInt(box.attr("height"))
defs = d3.select("svg").append("defs")
gradient = defs.append('linearGradient')
.attr('id','fadeout')
.attr('gradientUnits','userSpaceOnUse')
.attr('x1','0%')
.attr('x2','0%')
.attr('y1','0%')
.attr('y2',height)
gradient.append('stop')
.attr('stop-color',"#FFFFFF")
.attr('offset',80+'%')
gradient.append('stop')
.attr('stop-color',"#FFFFFF")
.attr('offset',85+'%')
gradient.append('stop')
.attr('stop-color',"#000000")
.attr('offset',100+'%')
mask = defs.append("mask").attr("id","fadeOutMask")
mask.append("rect").attr("width",width).attr("height",height).attr("fill","url(#fadeout)")
new_group = g.append("g").attr("mask","url(#fadeOutMask)")
elem = selection.node().cloneNode(true)
selection.remove()
new_group.node().appendChild(elem)
return new_group
wrapTextToBoxWidth = (box,text,line_height = 22,padding=70) =>
width = parseInt(box.attr("width"))
height = parseInt(box.attr("height"))
text_string = text.text()
text.text("") #Empty the old text
test_text_container = box.append("text")
textArray = text_string.split(" ")
tspan = text.append("tspan").attr("dy", line_height).attr("x", x)
tspan_copy = test_text_container.append("tspan").attr("dy", line_height).attr("x", x)
textSoFar = undefined
console.log(textArray)
for pText in textArray
textSoFar = tspan_copy.text()
tspan_copy.text(textSoFar + '' + pText)
textLength = tspan_copy.node().getComputedTextLength()
if textLength >= (width - padding)
tspan = text.append("tspan").attr("dy", line_height).attr("x", x)
tspan_copy.text('')
textSoFar = tspan.text()
space = if(tspan.text() == '') then '' else ' '
tspan.text textSoFar + space + pText
test_text_container.remove()
return text
text = wrapTextToBoxWidth(rect, text)
#wrapGroupInMaskWidthFadeOut(rect,text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment