Search code examples
typescriptgraphfrontendsigma.js

How can I set a font for a graph on Sigma.js?


Documentation for Sigma.js only specifies a Setting for a graph labelFont that receives a string. But I can't make it work because there no options for this string. Is it a source path for a .woff? Is it a browser default like Arial ? Tried all of them and can't make it work.


Solution

  • This labelFont setting basically works as the CSS font-family property. You first need to load the font the way you want (using @font-face for instance). Then, you set labelFont with the name of the variable, with fallbacks separated with commas if needed (like Lato, sans-serif for instance).

    To be a bit more precise, sigma assembles its settings labelFont, labelSize and labelWeight into the Canvas font property. The code is visible here.