10bestdesign / jqvmap

jQuery Vector Map Library
https://www.10bestdesign.com/jqvmap/
Other
1.82k stars 681 forks source link

Bug: jquery.vmap.min.js:10 Error: <g> attribute transform: Trailing garbage, "…0) translate(0, Infinity)". #333

Open ghost opened 6 years ago

ghost commented 6 years ago

Hi, I found a bug when JQVMap is initialized in a canvas with height or width whoch is 0px

Overview:

In some case, the map can be initialised in a 0px canvas. The JQVMap throws an exception like this:

jquery.vmap.min.js:10 Error: <g> attribute transform: Trailing garbage, "…0) translate(0, Infinity)".

When it is initialised in a 0px canvas, the scale calculus provides a scale of 0. When the scale of 0 is applyed on SVG, it perform a divide by 0 which returns infinite. The SVG translate attribute expect number. It receives "Infinity".

Fix:

I proposes the attached patch which check scale == 0 and force 1. I tested it and it work, and I check grunt build.

0001-Bug-Minor-revent-divide-by-0.patch.txt

Thierry