Skip to content

Commit

Permalink
single module (#3773)
Browse files Browse the repository at this point in the history
* add an example of how to load from a single module (using the recommended ESM method & destructuring)

* apply suggestions from review
  • Loading branch information
Fil committed Oct 5, 2023
1 parent 356b826 commit e4682f1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/getting-started.md
Expand Up @@ -210,6 +210,22 @@ container.append(svg.node());
```
:::

You can also import and destructure individual D3 modules like so:

```html
<script type="module">
import {forceSimulation, forceCollide, forceX} from "https://cdn.jsdelivr.net/npm/d3-force@3/+esm";
const nodes = [{}, {}];
const simulation = forceSimulation(nodes)
.force("x", forceX())
.force("collide", forceCollide(5))
.on("tick", () => console.log(nodes[0].x));
</script>
```

If you’d prefer to run D3 locally (or offline), you can download the UMD bundles of D3 here:

- <a href="./d3.v7.js" download>d3.v7.js</a>
Expand Down

0 comments on commit e4682f1

Please sign in to comment.