• Stars
    star
    225
  • Rank 177,187 (Top 4 %)
  • Language
    JavaScript
  • Created over 10 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Example D3.js + React integration

Example D3.js + React integration

A small example exploring how to integrate D3.js data visualization components into a React app.

Demo: http://nicolashery.github.io/example-d3-react

Explanation

Context: React allows you to manipulate SVG, so you could probably re-write this repo in "pure React". Here, I assume that you might already have some D3 components you want to re-use, and/or you would rather write the data visualization parts of your app in D3.

I find that making D3 components play nice inside a React app becomes easier when you follow these simple rules:

(1) "One Source Of Truth": The D3 visualization should get all of the data it needs to render passed down to it. In this example, the single source of truth is in the main <App> React component's state, and is used by the D3 component (d3Chart) and React components (for example <Stats>).

(2) "Stateless All The Things": Related to (1), D3 and React components alike should be as stateless as possible, i.e. they shouldn't hide/encapsulate something that makes them render differently given the same "input". In this example, if you call d3Chart.update() at anytime with the same arguments, you always get the same result on screen.

(3) "Don't Make Too Many Assumptions": Related to (1) and (2), components shouldn't make too many assumptions about how they will be used. In this example, d3Chart doesn't prescribe when tooltips should show, it only shows whatever it receives in the tooltips array. This allows us to show tooltips on hover, but also to easily create a "show/hide all tooltips" toggle.

Quick start

Clone this repo, then:

$ npm install
$ npm start

Open http://localhost:8080 in your browser.

More Repositories

1

mac-dev-setup

A beginner's guide to setting up a development environment on macOS
Shell
5,581
star
2

markdownpad-github

GitHub stylesheet for MarkdownPad
CSS
114
star
3

example-isomorphic-one

Code for the blog post "Exploring Isomorphic JavaScript"
JavaScript
56
star
4

example-stream-parser

An example Node.js streaming data file parser
JavaScript
45
star
5

example-ui-as-data

Code for the blog post "Describing UI state with data"
JavaScript
32
star
6

nicolashery.com

My personal website
CSS
25
star
7

cjs-umd

Bundle CommonJS source files into a single UMD file
JavaScript
10
star
8

example-react-app

Exploring ways to organize an app built with React
JavaScript
10
star
9

resumee

My resume
HTML
8
star
10

excesiv

Application component to generate and read Excel files using Apache POI
JavaScript
8
star
11

explore-marko-typescript

Explore using Marko with TypeScript
TypeScript
7
star
12

example-handlers-haskell

Example of non-trivial web handlers in Haskell web frameworks Scotty, Yesod, and Servant
Haskell
6
star
13

messenger-react

Example mobile web app for conversations, built with React
JavaScript
6
star
14

router-lib

Build your own client-side router with this set of utility functions
JavaScript
4
star
15

example-marvel-app

Example Node.js app using the Marvel API
JavaScript
4
star
16

example-build-workflow

Example web app development workflow and build tools
JavaScript
4
star
17

example-js-csp-game

An example JavaScript game using CSP
JavaScript
3
star
18

webdev

Tools to build your own local development server
JavaScript
3
star
19

excesiv-worker

Worker module of Excesiv, Excel file generator and reader
Ruby
3
star
20

stackato-worker

Trying to get a simple worker process working on Stackato
Ruby
2
star
21

example-react-architecture

Example architecture of a web app built with React
JavaScript
2
star
22

elm-yelp-app

Small app built with Elm, PostgreSQL, and the Yelp API
JavaScript
2
star
23

cis194

My solutions to the CIS 194 Haskell course
Haskell
2
star
24

haskellbook

Exercises in "Haskell Programming from first principles"
Haskell
2
star
25

example-angular-flux

Example app with Angular 1.4, Angular New Router, Flux
JavaScript
1
star
26

adventofcode-2018

My solutions in Haskell to the puzzles in Advent of Code
Haskell
1
star
27

mini-spot

A small example web app combining React, Mori, and Flux-like patterns
JavaScript
1
star
28

vscode-language-yesod

Syntax highlighting for the Haskell Yesod web framework
1
star
29

motherboard

A simple real-time dashboard for internal metrics.
JavaScript
1
star
30

example-upload-ajax

Exploration of how to upload a file using different transports
JavaScript
1
star
31

outfolio

Small app to keep a list of bars and restaurants, built with Backbone and Node.js
CoffeeScript
1
star
32

example-typescript-prototype

Example of prototyping and data modeling in the browser using TypeScript, React, and Redux
TypeScript
1
star
33

example-marvel-haskell

Example Haskell app using the Marvel API
Haskell
1
star
34

functional-ui

Functional programming concepts applied to web app UIs
JavaScript
1
star