I have created code to zoom my SVG area when I double-click on the area. I used the transform scale attribute to achive this, multiplying the current scale by a factor ( such as 1.2 to give 20% of zooming ).
I can do the same acting on the viewbox attribute's 2nd and 3rd parameter. Decreasing them will cause the area elements to zoom, and vice versa.
Any observations on pros and cons of these two different approaches ?
I think viewbox is actually going to be faster in a real world application while a performance bench mark will indicate the opposite information.
I created a jsPerf: http://jsperf.com/transform-scale-vs-viewbox-scale
jsPerf seems to give me incorrect numbers for how long the tests took therefore skewing the results, but this much is certain: the code for the transform test is shorter, has 0 string manipulations and ran more times in less time.
Clearly, transform scale is faster. The code looks faster, the test is broken but observing the test runs indicates more runs for transform. However, I still have a feeling viewbox is faster in a real world application.
Conclusion: computers are fast; use viewbox; its less work; optimizing here is probably not going to give you huge gains in performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With