DmitryBaranovskiy / raphael

JavaScript Vector Library
https://dmitrybaranovskiy.github.io/raphael/
MIT License
11.26k stars 1.67k forks source link

Bug: getBBox() works incorrect for VML after settings View Box on canvas #811

Open isadovskiy opened 10 years ago

isadovskiy commented 10 years ago

Hello.

There is an issue with VML implementation of getBBox(). If paper.setViewBox() was called first, it affects el.matrix property internally in transform() method implementation for VML:

R._extractTransform(this, vbt + tstr);

New matrix is calculated as a sum for viewBox and current transformation string. Later matrix property is used for getBBox() calculations for element and as a result returns values, different from SVG implementation.

The fix is to restore matrix at the end of the VML transform method (as it's currently done for _transform property):

    if (oldt != null) {
        this._.transform = oldt;
        R._extractTransform(this, oldt);
    }

Please note, explicit (oldt != null) comparison is required, since transform/matrix should also be restored if no transformation was set to element explicitly. "oldt" will be empty string in this case and should be restored as well.

This fix helped me to resolve the issue. However I'm not sure - probably it could break something else in the code. So need for approval from someone, who knows the internal code architecture better.

Regards, Igor

TheCloudlessSky commented 10 years ago

This is most likely related to #731. Check out my comment that has more detail. I really think the whole transform() method needs a re-write for VML because there are a lot of bugs creeping up.

tomasAlabes commented 10 years ago

@isadovskiy could you provide a pull request with your fix? @TheCloudlessSky do you think that this would fix this issue and 731?

TheCloudlessSky commented 10 years ago

@tomasAlabes Unfortunately, that didn't fix it.

isadovskiy commented 10 years ago

I will create pull request soon

isadovskiy commented 10 years ago

This commit fixes the issue for me: https://github.com/isadovskiy/raphael/commit/4f244b4329d083b465cc1623a0867cd76d7b9707

tomasAlabes commented 10 years ago

Pushed to v2.1.2, any feedback before merging to master is appreciated.