简体   繁体   中英

JointJS: how do you get the new scale factor after a scaleContentToFit?

I understand how to set a scale number, then increase or decrease that value and do a paper.scale() to implement zoom in and out on a graph. The issue comes when the user resizes the browser window small enough that my graph calls scaleContentToFit. Now the paper's actual scale factor differs from the value I'm manipulating, and zoom is broken unless I can get the newly-calculated factor and refresh the variable zoom is working with.

I've done a lot of digging in the API and the values in "paper" looking for where the value is stored so I can retrieve it but thus far I'm unsuccessful. Can some kind soul point me to where I can get that information?

Many thanks in advance!

Well, guess I gave up too quickly. I did more searching and found the answer in the related Google Groups forum at this link:

Google Groups thread

In sum, the answer lies in all those nifty V functions. In this case the code to get the desired value is:

var scale = V(paper.viewport).scale();       //// scale = { sx: 0.4, sy: 0.4 }

Credit to Roman Bruckner for the information.

I tried Mark's answer but It didn't work. I ended up using the following

var scale = paper.scale(); // scale = { sx: 0.4, sy: 0.4 };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM