mdaines / viz-js

Graphviz in your browser
https://viz-js.com/
MIT License
4.1k stars 353 forks source link

Having trouble with new image support - can't use same image URL in two different places #237

Closed Neriderc closed 9 months ago

Neriderc commented 9 months ago

I have code that I have been running with the previous version until now because of a lack of image support. This is being used to generate family trees. So I'm very excited that the latest version now includes image support! However, ...

For some reason, in this new version, if the same person is displayed twice (e.g. as a partner in two different marriages), then I get an ErrnoError: FS error. When logging object to console, it looks like this: image of error object text

Note that I am using HTML-like tags to make tables in labels, and tags to show the images.

If FS error refers to file system, I have no idea why that would be an issue. The image is not actually loaded by GraphViz, right?

It seems if I change the URL, it will work.

Any ideas on troubleshooting this further?

mdaines commented 9 months ago

What does the images array you're using look like?

if the same person is displayed twice

Does this mean that there are two entries in the array with the same image name?

Assuming this, I was able to get a similar error with this call:

 viz.render("graph { a[image=\"test.png\"] }", {
  images: [
    { name: "test.png", width: 300, height: 200 },
    { name: "test.png", width: 300, height: 200 }
  ]
});

The images feature uses Emscripten's in-memory file system to write a simple SVG file with the requested width and height, which Graphviz will then read to find the size of the image. After rendering, Viz.js will delete these files. My guess is that the error you're seeing is because Viz.js is trying to delete a file that was already deleted.

If this is actually the issue, a workaround would be to avoid using the same image name twice.

A simple fix in Viz.js would be to only try to delete one of these virtual files if it actually exists. See #238.

Neriderc commented 9 months ago

Yes, that sounds like the same issue! The image URLs (and therefore the "name" in the array) will be the same. Unfortunately because of where I'm using it I'm not able to change the URLs (not even to add a junk parameter), but it sounds like it's not too hard to fix on the Viz.js end so I'll just wait for that pull request to make it into a release.

Thanks :slightly_smiling_face:

mdaines commented 9 months ago

Released in 3.3.1.