/*******************************************************************************
AToMPM - A Tool for Multi-Paradigm Modelling
Copyright (c) 2011 Raphael Mannadiar (raphael.mannadiar@mail.mcgill.ca)
This file is part of AToMPM.
AToMPM is free software: you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
AToMPM is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with AToMPM. If not, see .
*******************************************************************************/
/* inspired by https://github.com/rhyolight/Raphael-Plugins (raphael.group.js) */
Raphael.fn.group = function() {
var r = this;
function Group()
{
var inst,
set = r.set(),
group = r.raphael.vml ?
document.createElement("group") :
document.createElementNS("http://www.w3.org/2000/svg", "g"),
overlay = r.raphael.vml ?
document.createElement("group") :
document.createElementNS("http://www.w3.org/2000/svg", "g");
/* transform a series of translate|rotate|scale commands into t|r|s
NOTE :: the parameters for 'SVG.scale()' are not exactly the same
as those for 'Raphael.scale()'... this because the former
scales wrt. (0,0) while the latter defaults to scaling wrt.
the center of the element... for consistency, we force Raphael
transform() to scale around (0,0)
NOTE :: the same goes for SVG.rotate() and Raphael.rotate() */
function svg2raphaelTransformString()
{
var rT = '';
group.getAttribute('transform').split(' ').forEach(
function(svgt)
{
if( (args = svgt.match(/translate\((.*),(.*)\)/)) )
rT += 't'+args[1]+','+args[2];
else if( (args = svgt.match(/rotate\((.*),(.*),(.*)\)/)) )
rT += 'r'+args[1]+','+args[2]+','+args[3];
else if( (args = svgt.match(/rotate\((.*)\)/)) )
rT += 'r'+args[1]+',0,0';
else if( (args = svgt.match(/scale\((.*),(.*)\)/)) )
rT += 's'+args[1]+','+args[2]+',0,0';
else if( (args = svgt.match(/scale\((.*)\)/)) )
rT += 's'+args[1]+','+args[1]+',0,0';
else if( (args = svgt.match(
/matrix\((.*),(.*),(.*),(.*),(.*),(.*)\)/)) )
rT += 'm'+args[1]+','+args[2]+','+args[3]+','+
args[4]+','+args[5]+','+args[6];
});
return rT;
}
r.canvas.appendChild(group);
group.setAttribute('transform','');
inst =
{'forEach':
function(callback)
{
for( var i=0; i=0; i-- )
if( overlay.childNodes[i].hasAttribute('__tag') )
overlay.removeChild(overlay.childNodes[i]);
}
else
{
for( var i=0; i