Pivot __setAutoWidth function takes too long on Firefox


#1

So I had a problem with Pivot widget where a large dataset would cause Firefox to slow down or even crash.

I investigated the problem and found that the function getStrWidth, called by _setAutoWidth, takes long only on Firefox.

The problem seems to be that Firefox has an 8 year old bug with repeatedly calling Canvas.getContext function:

Here is your function code:

    function getStrWidth(str, font) {
        if (font === void 0) { font = "14px Arial"; }
        var canvas = document.createElement("canvas");
        var ctx = canvas.getContext("2d");
        ctx.font = font;
        return Math.round(ctx.measureText(str).width);
    }

I fixed it by creating a global canvas and ctx variables and using them inside getStrWidth.

Just wanted to tell you so you can fix it.

BR