Closed jorgens closed 6 years ago
@jorgens thanks for reaching out. I haven't specifically tested d3-force-3d
with requireJS
, but if it can work with d3-force as a stand-alone module, than it should work seamlessly with d3-force-3d
.
I can imagine just replacing the d3 bundle (if you are using it solely for d3-force
), with d3-force-3d
, something like:
require(['//unpkg.com/d3-force-3d'], function(d3) { ... })
If you're using the 3D mode of it, you may need to import the d3-octree module as well.
Let me know if you can get it working!
@vasturiano sorry for the late reply and thanks for the pointers.
I ended up using ES6 and babel.js to get it working cleanly and handle the needed Micromodules. So now I just have something like:
import { forceSimulation, forceLink, forceManyBody, forceX, forceY, forceZ } from "../node_modules/d3-force-3d";
import { select, event } from "../node_modules/d3-selection"
import { drag } from "../node_modules/d3-drag"
import { zoom } from "../node_modules/d3-zoom"
...
let simulation = forceSimulation(graph.nodes)
.force("link", forceLink(graph.links).distance(20).strength(.7))
.force("charge", forceManyBody().strength(-400))
.force('centerX', forceX(width / 2))
.force('centerY', forceY(height / 2))
.force('centerZ', forceZ(height / 2))
.on("tick", ticked);
Thanks a lot for all your work!
Nice! Btw, quick tip, you don't need to specify node_modules
in your imports. Just do import { ... } from 'd3-selection'
should work. :)
Thx, indeed it does! :)
Sorry, for this probably stupid question, but you write that d3-force-3d can be used as a drop-in to replace d3-force. How would I go about using require to drop in d3-force-3d into the following code: