Reputation: 55
I have a Node.js project which uses jsdom and Raphael Js to generate SVG markup on my server, all was going well until I started to get missing values when calling getBBox() on Raphael text elements.
var paper = window.Raphael(10, 50, 320, 200);
var txt = paper.text(10, 10, 'hello world!');
console.log( txt.getBBox().toString() ); // Returns: NaN NaN NaN × NaN
whereas ...
var rect = paper.rect(10, 10, 10, 10);
console.log( rect.getBBox().toString() ); // Returns: 10 10 10 × 10
What would be the cause of this and more importantly is there a fix?
Upvotes: 1
Views: 1852
Reputation: 25381
TextElement.getBBox() only work in browsers, it should not be used in server side.
Upvotes: 1
Reputation: 55
You should use the print()
method of RaphaelJs, which produces an array of paths. You can use getBBox()
on the array to get the bounding box.
Upvotes: 1