GithubHelp home page GithubHelp logo

olihawkins / vis-template Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 495 KB

A template for developing interactive data visualisations with D3 using modern JavaScript.

License: BSD 3-Clause "New" or "Revised" License

JavaScript 100.00%

vis-template's Introduction

Visualisation template

This repository is a simple template and workflow for developing interactive data visualisations with modern JavaScript using Node.js, Babel, rollup and D3. The aim is to be able to use the latest features of JavaScript, while generating code that works across a wide range of browsers. You will need to have Node.js installed.

D3 support

The template now supports D3 version 7. As D3 has fully adopted ES2015, D3 modules in the node_modules folder are now transpiled along with your own source code when you build the production bundle. If you are using D3 version 5 or earlier and don't need to transpile D3, you should change the regular expression that is used as the exclusion rule for babel-loader on line 26 of rollup.config.js to the following:

/node_modules\/(?!(?!(whatwg-fetch)\/).*/

Quick setup

The easiest way of using the template is to clone this repository into a new project directory and install the required modules using the pre-defined package.json.

1. Clone the repository into a project directory.

git clone https://github.com/olihawkins/vis-template my-project

2. Change into the project directory.

cd my-project

3. Remove the git files.

rm -rf .git .gitignore LICENSE readme.md

4. Install from package.json.

npm install

Manual setup

An alternative method involves manually downloading the latest versions of the packages. This may be useful if you want to upgrade to newer versions of the packages, or customise the setup in other ways.

1. Clone the repository into a project directory.

git clone https://github.com/olihawkins/vis-template my-project

2. Change into the project directory.

cd my-project

4. Remove the git files and the existing package.json files.

rm -rf .git .gitignore LICENSE readme.md package.json package-lock.json

5. Initialise the project folder with npm to create a new package.json.

npm init

6. Install the development dependencies.

npm install --save-dev @babel/core @babel/plugin-transform-runtime @babel/preset-env rollup @rollup/plugin-babel rollup-plugin-terser @rollup/plugin-commonjs @rollup/plugin-node-resolve rollup-plugin-serve eslint

7. Install the package dependencies.

npm install --save @babel/runtime @babel/runtime-corejs3 whatwg-fetch d3

8. Open package.json and add the following entries to scripts (above the entry for test).

"build": "rollup -c --watch",

Development

The src directory contains the input JavaScript source file index.js, while the dist directory contains the index.html webpage. Once you have set up the workflow you can edit src/index.js and dist/index.html to develop your visualisation.

To begin development, start rollup and navigate to localhost:10001 in your browser.

npm run build

Rollup transpiles and bundles src/index.js as dist/index.min.js, including any modules index.js imports.

In its initial state, index.js contains some example code, which checks that rollup, Babel and D3 are working correctly. Replace this with your visualisation code.

Note that D3 needs the whatwg-fetch polyfill for d3-fetch functions to work in older browsers. All other polyfills are handled automatically by Babel and core-js.

You can optionally create a .eslintrc for the project if you use linting in your text editor.

./node_modules/.bin/eslint --init

Technologies

This is a simple setup. You can configure rollup to do a lot more than this. More information on the technologies used for this workflow can be found in the documentation.

vis-template's People

Contributors

olihawkins avatar

Stargazers

James Scott-Brown avatar Azad Amir-Ghassemi avatar Henry Lau avatar

Watchers

James Cloos avatar  avatar

Forkers

mind3str

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.