Skip to content

Instantly share code, notes, and snippets.

@matthiasak
Created August 23, 2012 17:19
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 matthiasak/3438934 to your computer and use it in GitHub Desktop.
Save matthiasak/3438934 to your computer and use it in GitHub Desktop.
// text coords
texts.push({x: Building.width/2, y:Building.length/2, obj: {name:Building.name}, attr:{'font-size':'15px'} });
texts.push({x: Building.width/2, y:Building.length, obj: _.find(Building.surfaces, function(el){ return el.swa; }), attr:{'font-size':'10px'} });
texts.push({x: 0, y:Building.length/2, obj: _.find(Building.surfaces, function(el){ return el.ewb; }), attr:{'font-size':'10px', rotate:-90} });
texts.push({x: Building.width/2, y:0, obj: _.find(Building.surfaces, function(el){ return el.swc; }), attr:{'font-size':'10px'} });
texts.push({x: Building.width, y:Building.length/2, obj: _.find(Building.surfaces, function(el){ return el.ewd; }), attr:{'font-size':'10px', rotate:90} });
/// later used in
_.forEach(polygonCollection.texts, function(text){
var path = raphael.text(text.x, text.y, text.obj.name).attr(text.attr || {}),
_minX = text.x - padding,
_maxX = text.x + padding,
_minY = text.y - padding,
_maxY = text.x + padding;
if(text.attr.rotate){
path.rotate(text.attr.rotate);
}
bounds.minX = _minX < bounds.minX ? _minX : bounds.minX;
bounds.maxX = _maxX > bounds.maxX ? _maxX : bounds.maxX;
bounds.minY = _minY < bounds.minY ? _minY : bounds.minY;
bounds.maxY = _maxY > bounds.maxY ? _maxY : bounds.maxY;
set.push(path);
})
var width = Math.abs(bounds.maxX - bounds.minX),
height = Math.abs(bounds.maxY - bounds.minY),
scale = (canvasWidth*0.99)/width,
newWidth = width * scale,
newHeight = height * scale,
transform = {
x : (newWidth - width)/2 + width,
y : (newHeight - height)/2 + height
},
transformString = "s"+scale+","+scale+",0,0t1,1";
set.transform(transformString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment