Forum Discussion

ewaghabi's avatar
ewaghabi
Frequent Visitor
5 years ago
Solved

measureSvgTextWidth giving wrong results?

I'm using measureSvgTextWidth, from textMeasurementService ("powerbi-visuals-utils-formattingutils") - and getting lower values than I think it should give, based on actual svg element. On the other ...
  • ewaghabi's avatar
    ewaghabi
    5 years ago

    Hi, Henry, thank you for you answer!

     

    I didn't say the problem was with getTailoredTextOrDefault. The problem seem to be with measureSvgTextWidth, that returned the wrong size. 

     

    I just now figured out what is wrong, so I'll just put here for further reference: one must inform the fontsize unit, either in points (pt) or pixels (px). If only the number is used, although anything else works fine, this function calculates the wrong width (which breaks getTailoredTextOrDefault as well).

     

    So, to further exemplify:

    let textProperties = {
       text: "Microsoft PowerBI!",
       fontFamily: "sans-serif",
       fontSize: "24"        
    };
                   
    console.log(tms.getTailoredTextOrDefault(textProperties, 100));  // Microsoft PowerBI!

     

    Here's a little experiment I've made:

     

    I didn't see any reference to this behaviour in the official document, nor any mention of what is the default unit (if any).