8000 How to build · Issue #465 · graphology/graphology · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

How to build #465

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

Open
NicolasWinsten opened this issue Apr 26, 2023 · 8 comments
Open

How to build #465

NicolasWinsten opened this issue Apr 26, 2023 · 8 comments
Labels

Comments

@NicolasWinsten
Copy link

npm run build produces this error

> graphology:build

> graphology@0.26.0-alpha1 build
> npm run clean && rollup -c && babel tests --out-dir specs && cp src/endpoint.esm.d.ts dist/graphology.d.ts
> graphology@0.26.0-alpha1 clean
> rimraf dist specs
(node:18220) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
[!] RollupError: Node tried to load your configuration file as CommonJS even though it is likely an ES module. To resolve this, change the extension of your configuration to ".mjs", set "type": "module" in your package.json file or pass the "--bundleConfigAsCjs" flag.
Original error: Cannot use import statement outside a module
https://rollupjs.org/command-line-interface/#bundleconfigascjs
/home/nicol/projects/graphology/src/graphology/rollup.config.js:1
import pkg from './package.json';
^^^^^^
SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1187:20)
    at Module._compile (node:internal/modules/cjs/loader:1231:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1321:10)
    at Module.load (node:internal/modules/cjs/loader:1125:32)
    at Module._load (node:internal/modules/cjs/loader:965:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:165:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)

 ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  Lerna (powered by Nx)   Ran target build for project graphology (551ms)
 
    ✖    1/1 failed
    ✔    0/1 succeeded [0 read from cache]

I don't know a lot about the differences between ESM and CommonJS.

How should I be building this project?

@Yomguithereal
Copy link
Member

Hello @NicolasWinsten, what are you trying to achieve here? Why build graphology from the repo itself? Aren't the builds found in releases sufficient for your use case?

@NicolasWinsten
Copy link
Author

Thank you for the quick response!

That's a good question, I should have been more clear.

I wanted to make a quick change to forceAtlas2 to expose the iterate function inside. I want to be able to step through the algorithm rather than have it run off for some number of iterations. Is there a way to do this? I wasn't sure how to accomplish it with the webworker version if that's possible.

@Yomguithereal
Copy link
Member

What is your version of node & npm? I just ran the build on node v16 with npm v8 and I don't have your issue. I have been trying recently to port the lib to ESM-first so this might be what's causing your problem on very recent node versions. If so, can you try using an older version (v16 for instance) by switching with something like nvm (in which case don't forget to reinstall dependencies).

@NicolasWinsten
Copy link
Author
NicolasWinsten commented Apr 26, 2023

Thanks that seemed to be the issue. I was using the latest node v20

Again, sorry for the bother. Can I ask if there's a reason why stepping functionality isn't provided with the layouts? Is it just too weird a use case?

@Yomguithereal
Copy link
Member

Again, sorry for the bother. Can I ask if there's a reason why stepping functionality isn't provided with the layouts? Is it just too weird a use case?

People tend to either use the layout by asking for some fixed amount of iterations or use the web worker to animate the steps live. They tend not to need running the steps one by one themselves which can be tedious since you need to track some state between said steps (this state is held within the node data matrix used by the iteration).

Can you describe your use case a little bit more so I understand what you are trying to do here?

@NicolasWinsten
Copy link
Author

I'm writing a small project that compares force-directed layout algorithms side by side, and I want to be able to compare them step-by-step:
image

I want to be able to track what each algorithm is at on iteration X. It's slightly unscientific, I know. I seem to get what I want by making these minimal changes to the source, but I'd like to know if you think I'm misunderstanding something here:

I basically shoved this code into abstractSynchronousLayout of layout-forceatlas2/index.js:

  let iterator = {settings:settings}
  iterator.step = () => {
    iterate(iterator.settings, matrices.nodes, matrices.edges)
    helpers.assignLayoutChanges(graph, matrices.nodes, outputReducer)
  }
  return iterator

@Yomguithereal
Copy link
Member

@NicolasWinsten thanks I understand better now. Your use-case makes sense of course. I could create some kind of helper class to make this easier. I just need to think a little bit more how it can relate to some other use-case people have where they need to run one step by animation frame in a setInterval when they cannot rely on webworkers at all. Also, your code does not include the iteration state matrices initialization but I guess you have it above somehow?

As a side note, your screenshot shows what I would call a FA2 layout with bad settings, though. FA2 can produce a large variety of results and somehow is a superset of typical Fruchterman Reingold/Force Vector at least. Did you try the inferSettings to have a result closer to what the algorithm's author recommends?

@NicolasWinsten
Copy link
Author

As a side note, your screenshot shows what I would call a FA2 layout with bad settings,

I plan to give the user the option to modify the algorithm parameters. The screenshot was just to help understanding.

If you think this stepping functionality should be added in a more friendly way, I'd be happy to help.

Thanks for your help

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

No branches or pull requests

2 participants
0