In https://mcmap.net/q/871573/-export-visjs-network-to-jpeg-png-image, the essence of the code is:
network.on("afterDrawing", function (ctx) {
var dataURL = ctx.canvas.toDataURL();
document.getElementById('canvasImg').src = dataURL;
});
How can it run? ctx
isn't defined anywhere. In the Vis.js' documentation, the afterDrawing
event has this description:
Name | Properties | Description |
---|---|---|
afterDrawing | canvas context | Fired after drawing on the canvas has been completed. Can be used to draw on top of the network. |
afterDrawing
event provides thectx
to the passed callback. see the docs – Pamulapancallback functions
, once.on
is done doing it's thing, it will return a valuectx
which you can use in your code. – Fillisterfunction
. – IlluminationafterDrawing
event in the docs (though this is confusing language). – Pamulapanctx
is short forcanvas context
. So when the methodon()
completes, it will return the canvas context so thefunction
can pick up? – Menagerie