Created
July 10, 2012 05:57
-
-
Save roundrobin/3081443 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 width = 381 | |
var height = 205 | |
var font_size = 88 | |
var precise = 4 | |
var x = 230 | |
var y = 119 | |
var rect = g.append("rect") | |
.attr("width",width) | |
.attr("height",height) | |
.attr("fill","black") | |
.attr("x",x) | |
.attr("y",y) | |
var text1 = g.append("text") | |
.attr("fill","red") | |
.attr("x",x) | |
.attr("y",y) | |
.attr("font-size",font_size) | |
.text("Helllll yeeeahhhhhh") | |
.style('dominant-baseline','text-before-edge') | |
.style('font-family','Times') | |
text = fitTextToBox(rect,text1) | |
var textHeight = text.node().getBBox().height | |
var middle = (height/2) | |
text.attr("dy", middle - (textHeight / 2) ) | |
function fitTextToBox(box,text){ | |
var boxHeight = parseInt(box.attr("height")) | |
var boxWidth = parseInt(box.attr("width")) | |
var textWidth = text.node().getComputedTextLength(); | |
var textHeight = text.node().getBBox().height; | |
var currentFZ = text.attr("font-size") | |
var aspectRatioBox = boxWidth / boxHeight; | |
var aspectRatioText = textWidth / textHeight; | |
var maxWidth = (boxWidth /textWidth ) | |
var maxHeight = (boxHeight /textHeight) | |
var max = Math.min(maxWidth, maxHeight) | |
var fontsize = (currentFZ * max) | |
text.attr("font-size", fontsize) | |
return text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment