Giter Club home page Giter Club logo

d3-wasm-force's Introduction

d3-wasm-force

A re-implementation of d3-force in WebAssembly with the AssemblyScript compiler. Read more about the project in the accompanying blog post, and see the code in action in this bl.ock.

Overview

The goal of this project is to create a drop-in replacement for d3-force, using WebAssembly. Rather than implement the full d3-force API, I am aiming to re-create the following example:

https://bl.ocks.org/mbostock/4062045

To build the project run:

npm install
npm run build

This will run the TypeScript compiler and rollup to create a bundle, and the AssemblyScript compiler to create a separate wasm file.

The resulting output is namespaces as d3wasm, and can be used in exactly the same way as the d3 counterpart:

const simulation = d3wasm.forceSimulation(graph.nodes, true)
  .force('charge', d3wasm.forceManyBody())
  .force('center', d3wasm.forceCenter(width / 2, height / 2))
  .force('link', d3wasm.forceLink().links(graph.links).id(d => d.id))
  .stop();

Switching between WebAssembly and JavaScript

One of the really interesting features of AssemblyScript is that it compiles TypeScript to JavaScript. As a result, the TypeScript source of the WebAssembly module can also be compiled to TypeScript, giving the option of running it either as WebAssembly or JavaScript!

The second argument passed to forceSimulation allows you to choose whether to use the WebAssembly or JavaScript build. Passing false uses the JavaScript version:

const simulation = d3wasm.forceSimulation(graph.nodes, false)

TODO

  • Create multiple typescript configurations
  • Inline the code (note, could use rollup-plugin-wasm), although inline code is still async
  • Resolve build-wasm warnings
  • Find a better way to read / write WASM buffers
  • Make use of d3-force typing
  • ensure the code behaves exactly the same as d3-force
  • implement the fx / fy properties of force layout

d3-wasm-force's People

Contributors

colineberhardt avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.