example-d3-react

D3.js + React 集成示例。「Example D3.js + React integration」

Github星跟蹤圖

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.

主要指標

概覽
名稱與所有者nicolashery/example-d3-react
主編程語言JavaScript
編程語言JavaScript (語言數: 3)
平台
許可證
所有者活动
創建於2014-08-12 23:25:32
推送於2016-05-18 12:28:10
最后一次提交2016-05-18 08:27:55
發布數0
用户参与
星數225
關注者數11
派生數57
提交數14
已啟用問題?
問題數3
打開的問題數1
拉請求數0
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?