Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server side rendering? #2195

Open
rosek86 opened this issue Dec 8, 2024 · 0 comments
Open

Server side rendering? #2195

rosek86 opened this issue Dec 8, 2024 · 0 comments

Comments

@rosek86
Copy link

rosek86 commented Dec 8, 2024

Is it possible to render in node.js using canvas/skia-canvas? I'm trying to do something like this but it complains about missing 'window':

main.mjs

import { Network } from 'vis-network';
import { DataSet } from 'vis-data';
import { Canvas } from 'skia-canvas';

const nodes = new DataSet([
  { id: 1, label: "Node 1" },
  { id: 2, label: "Node 2" },
  { id: 3, label: "Node 3" },
  { id: 4, label: "Node 4" },
  { id: 5, label: "Node 5" },
]);

// create an array with edges
const edges = new DataSet([
  { from: 1, to: 3 },
  { from: 1, to: 2 },
  { from: 2, to: 4 },
  { from: 2, to: 5 },
  { from: 3, to: 3 },
]);

// create a network
const container = new Canvas(400, 400);
const data = {
  nodes: nodes,
  edges: edges,
};
const options = {};
new Network(container, data, options);
await canvas.saveAs("graph.png", {density:2})
node_modules/vis-network/peer/umd/vis-network.js:26803
          if (window !== undefined) {
          ^

ReferenceError: window is not defined
(...)

Node.js v22.12.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant