cosmograph-org / cosmos

GPU-accelerated force graph layout and rendering
Other
790 stars 52 forks source link

Can't get basic setup to work on a Vue application #99

Closed marcodarko closed 4 months ago

marcodarko commented 4 months ago

I don't know what is wrong because no errors occur also, here's a codebox of the basic setup: https://codesandbox.io/p/devbox/gallant-forest-7vgq4z?file=%2Fsrc%2Fcomponents%2FHelloWorld.vue

If you spot any errors or have any tips it would be much appreciated.

rokotyan commented 4 months ago

Can you please check if your example works, I'm getting this error when trying to open it

image
marcodarko commented 4 months ago

@rokotyan sorry about that, I forgot to make it public, here's a new link

rokotyan commented 4 months ago

@marcodarko I think there might be a problem with the application setup itself. Even if I comment out all the Cosmograph-related code, it still doesn't work.

marcodarko commented 4 months ago

I think that site is having issues, let's try CodePen: https://codepen.io/marcodarko/pen/poYXWNj

rokotyan commented 4 months ago

Thanks @marcodarko

Try changing canvas to div here:

image

Looks like there is a typo in our docs. Thanks for bringing this to our attention.

marcodarko commented 4 months ago

Ah! perfect yeah I see the graph now! thanks!

marcodarko commented 4 months ago

@rokotyan one more question: initialZoomLevel seems to have no effect, I see it resize for a split second then goes back to default. How can I make it stick? I've tried different values but can't get it to scale bigger.

config = {
initialZoomLevel: 5
}
cosmograph.setZoomLevel(5) //1
console.log(cosmograph.getZoomLevel()) // always 1 no matter what I do
Stukova commented 4 months ago

@marcodarko

If the fitViewOnInit property is set to true (which is true by default), the initialZoomLevel value will be overridden. Additionally, if you call cosmograph.setZoomLevel(5) followed by console.log(cosmograph.getZoomLevel()), the zoom level displayed in the console will not be 5 because the zoom animation using d3's transition function will complete before the getZoomLevel() method reads the updated zoom level, even if the animation duration is 0.

For initialZoomLevel to have an effect, try to disable fitViewOnInit in the config.

marcodarko commented 4 months ago

@Stukova thank you so much for this info! Works great now! Really appreciate your help. Perhaps I would suggest I would prefer the opposite the behavior, that my user setting would override the default, but it's a minor suggestion for consideration.