3

Simple question that I can't find a simple answer to.

How do I look up the complete current human-readable (non-matrix) transform state of a Raphael element, regardless of whether or how that element's transform state was set?


For example, using element.transform() doesn't give you a complete transform state:

1: If something has been set by matrix, it doesn't give you the non-matrix state. E.g. here the element has been scaled equivalent to s2,2 but there's no s data when we parse the result:

circ = paper.circle(50,50,50);
circ.transform('m2 0 0 2 0 0');
console.log(circ.transform(''));

2: If something hasn't been set, it's undefined rather than giving us the default numeric value. E.g. here there's no s data, whereas I'm hoping for something that would tell us the scale state is equivalent to applying s1,1:

circ = paper.circle(50,50,50);
circ.transform('t100,100');
console.log(circ.transform(''));
4

1 回答 1

3

这是我能找到的最接近的 - 在这里记录它,因为它并不明显。在路径、圆、椭圆、矩形上进行了测试。不适用于集合(因为集合不直接转换,它们只是将转换应用于其内容的美化数组)。


将 Raphael 元素的完整当前变换状态作为对象获取:

element.matrix.split();

该对象的内容是(显示未转换元素的默认值):

dx: 0
dy: 0
isSimple: true
isSuperSimple: true
noRotation: true
rotate: 0
scalex: 1
scaley: 1
shear: 0

因此,要查找 Raphael 元素的 x 比例条件,您可以使用element.matrix.split().scalex;. 要独立于设置它的方法来查找元素的旋转状态,您可以使用element.matrix.split().rotate;etc.dx并且dy等效于 translate 值。

circle = paper.circle(5,5,5).attr('transform','s2,2');
alert(circle.matrix.split().scalex);   // alerts 2
alert(circle.matrix.split().dx);       // alerts 0

circle = paper.circle(5,5,5).attr('transform','m2 0 0 2 0 0');
alert(circle.matrix.split().scalex);   // alerts 2
alert(circle.matrix.split().dx);       // alerts 0

circle = paper.circle(5,5,5).attr('transform','t100,100');
alert(circle.matrix.split().scalex);   // alerts 1
alert(circle.matrix.split().dx);       // alerts 100

要将 Raphael 元素的当前变换状态作为变换字符串,最接近的似乎是:

element.matrix.toTransformString();

...但是,这仅包括已应用的转换。例如,如果没有缩放,则s字符串中没有段,而不是任何默认缩放转换字符串,如s1,1,0,0.

同样,如果你这样做...

Raphael.parseTransformString( element.matrix.toTransformString() );

...您会得到一个缺少未设置值的数组,而不是一个包含所有值的对象。

似乎没有任何方便的功能来打开 element.matrix.split(); 的输出;转换成一个转换字符串(尽管它可能不需要)。

于 2013-10-14T16:31:06.657 回答