99 <a title =" @visx/shape npm downloads " href =" https://www.npmjs.com/package/@visx/shape " >
1010 <img src="https://img.shields.io/npm/dm/@visx/shape.svg?style=flat-square" />
1111 </a >
12- <a href =" https://lerna.js.org/ " alt =" lerna " >
13- <img src="https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg"/>
14- </a >
1512</p >
1613
1714### visx
1815
1916visx is a collection of reusable low-level visualization components. visx combines the power of d3
2017to generate your visualization with the benefits of react for updating the DOM.
2118
19+ > [ !IMPORTANT]
20+ > ** visx v4 is in alpha** with React 19 support. Install with the ` @next ` tag:
21+ >
22+ > ``` bash
23+ > npm install @visx/shape@next
24+ > ` ` `
25+ >
26+ > v3 remains the ` latest` stable release. See the [migration guide](./MIGRATION.md) and [changelog](./CHANGELOG.md) for details.
27+
2228< br />
2329
2430< p align=" center" >
@@ -30,25 +36,13 @@ to generate your visualization with the benefits of react for updating the DOM.
3036 < a href=" https://airbnb.io/visx/gallery" > Gallery< /a>
3137 < /strong>
3238 & bull;
33- <strong >
34- <a href="https://medium.com/vx-code/getting-started-with-vx-1756bb661410">Blog</a>
35- </strong >
36- &bull ;
37- <strong >
38- <a href="https://github.com/airbnb/visx/discussions">Discussions</a>
39- </strong >
40- &bull ;
4139 < strong>
4240 < a href=" ./CHANGELOG.md" > Changelog< /a>
4341 < /strong>
4442 & bull;
4543 < strong>
4644 < a href=" ./MIGRATION.md" > Migration< /a>
4745 < /strong>
48- &bull ;
49- <strong >
50- <a href="https://medium.com/vx-code/getting-started-with-vx-1756bb661410">Getting started tutorial</a>
51- </strong >
5246< /p>
5347
5448< p align=" center" >
@@ -88,38 +82,34 @@ const margin = { top: 20, bottom: 20, left: 20, right: 20 };
8882const xMax = width - margin .left - margin .right ;
8983const yMax = height - margin .top - margin .bottom ;
9084
91- // We'll make some helpers to get at the data we want
92- const x = (d ) => d .letter ;
93- const y = (d ) => + d .frequency * 100 ;
85+ // Accessors
86+ const getLetter = (d ) => d .letter ;
87+ const getFrequency = (d ) => d .frequency * 100 ;
9488
9589// And then scale the graph by our data
9690const xScale = scaleBand ({
9791 range: [0 , xMax],
9892 round: true ,
99- domain: data .map (x ),
93+ domain: data .map (getLetter ),
10094 padding: 0.4 ,
10195});
10296const yScale = scaleLinear ({
10397 range: [yMax, 0 ],
10498 round: true ,
105- domain: [0 , Math .max (... data .map (y ))],
99+ domain: [0 , Math .max (... data .map (getFrequency ))],
106100});
107101
108- // Compose together the scale and accessor functions to get point functions
109- const compose = (scale , accessor ) => (data ) => scale (accessor (data));
110- const xPoint = compose (xScale, x);
111- const yPoint = compose (yScale, y);
112-
113102// Finally we'll embed it all in an SVG
114- function BarGraph (props ) {
103+ function BarGraph () {
115104 return (
116105 < svg width= {width} height= {height}>
117- {data .map ((d , i ) => {
118- const barHeight = yMax - yPoint (d);
106+ {data .map ((d ) => {
107+ const letter = getLetter (d);
108+ const barHeight = yMax - (yScale (getFrequency (d)) ?? 0 );
119109 return (
120- < Group key= {` bar-${ i } ` }>
110+ < Group key= {` bar-${ letter } ` }>
121111 < Bar
122- x= {xPoint (d )}
112+ x= {xScale (letter )}
123113 y= {yMax - barHeight}
124114 height= {barHeight}
125115 width= {xScale .bandwidth ()}
@@ -131,9 +121,6 @@ function BarGraph(props) {
131121 < / svg>
132122 );
133123}
134-
135- // ... somewhere else, render it ...
136- // <BarGraph />
137124` ` `
138125
139126For more examples using ` visx` , check out the [gallery](https://airbnb.io/visx/gallery).
@@ -155,75 +142,10 @@ your team could create charts as easily as using reusable react components.
155142**But why?**
156143
157144Mixing two mental models for updating the DOM is never a good time. Copy and pasting d3 code into
158- ` componentDidMount ()` is just that. This collection of components lets you easily build your own
159- reusable visualization charts or library without having to learn d3. No more selections or
145+ ` useEffect ()` is just that. This collection of components lets you easily build your own reusable
146+ visualization charts or library without having to learn d3. No more selections or
160147` enter ()` /` exit ()` /` update ()` .
161148
162- ## In the wild
163-
164- - [ williaster/data-ui] ( https://github.com/williaster/data-ui )
165- ([ Demo] ( https://williaster.github.io/data-ui/ ) )
166- - [ dylanmoz/trello] ( https://github.com/DylanMoz/dylanmoz.github.io/blob/source/src/pages/trello/TrelloGraph.js )
167- ([ Demo] ( http://dylanmoz.github.io/trello/ ) )
168- ([ How to Make Beautiful Graphs With vx and React-Motion] ( https://devblog.classy.org/how-to-make-beautiful-graphs-with-vx-and-react-motion-6ffe7aecf6f3 ) )
169- - [ gkunthara/Crypto-Chart] ( https://github.com/gkunthara/Crypto-Chart )
170- ([ Tutorial] ( https://medium.com/@georgekunthara/after-the-tutorial-the-first-react-app-4dce6645634e ) )
171- - Collapsible tree with [ ` react-move ` ] ( https://github.com/react-tools/react-move ) by
172- [ @techniq ] ( https://github.com/techniq ) ([ Demo] ( https://codesandbox.io/s/n3w687vmqj ) )
173- ([ Radial demo] ( https://codesandbox.io/s/vmqwrkl395 ) )
174- ([ More info] ( https://github.com/airbnb/visx/issues/162#issuecomment-335029517 ) )
175- - Bitcoin 30-day price by [ @hshoff ] ( https://github.com/hshoff )
176- ([ Github] ( https://github.com/hshoff/viewsource#1-bitcoin-price-chart ) )
177- ([ YouTube] ( https://www.youtube.com/watch?v=oeE2tuspdHg ) )
178- - Ethereum candlestick chart by [ @hshoff ] ( https://github.com/hshoff )
179- ([ Github] ( https://github.com/hshoff/viewsource#2-ethereum-candlestick-chart ) )
180- - Song data visualization through spotify by [ @bother7 ] ( https://github.com/bother7 )
181- ([ Github] ( https://github.com/bother7/spotalyzer_frontend ) )
182- - Investment Calculator ([ website] ( https://investmentcalculator.io/ ) )
183- - Animation with [ ` react-spring ` ] ( https://github.com/drcmda/react-spring/ ) by
184- [ @drcmda ] ( https://github.com/drcmda ) ([ Demo] ( https://codesandbox.io/embed/j3x61vjz5v ) )
185- - Code Coverage Dashboard by [ @ezy ] ( https://github.com/ezy )
186- ([ Github] ( https://github.com/ezy/code-coverage-dashboard ) )
187- - Ethereum Portfolio Toolkit by [ @JayWelsh ] ( https://github.com/JayWelsh )
188- ([ Demo] ( https://cryptocape.com/ ) ) ([ Github] ( https://github.com/JayWelsh/CryptoCape ) )
189- - Family tree by [ @vkallore ] ( https://github.com/vkallore )
190- ([ Github] ( https://github.com/vkallore/d3-vx-family-tree ) )
191- - South African Coronavirus Data Visuals by [ @JayWelsh ] ( https://github.com/JayWelsh )
192- ([ Demo] ( https://coronamap.co.za/ ) ) ([ Github] ( https://github.com/JayWelsh/coronamap ) )
193- - [ CNN: Tracking America's Recovery] ( https://www.cnn.com/business/us-economic-recovery-coronavirus )
194- - [ Wall Street Journal: Americans Familiarize Themselves with the Word ‘Forbearance’] ( https://blogs.wsj.com/dailyshot/2020/04/13/the-daily-shot-americans-familiarize-themselves-with-the-word-forbearance/ )
195- by [ @rayshan ] ( https://github.com/rayshan )
196- ([ Demo] ( https://finance.shan.io/recessions-bear-markets-compared ) )
197- - Dollar to food emoji caculator by [ @gmlwo530 ] ( https://github.com/gmlwo530 )
198- ([ Demo] ( https://dollar-to-food-emoji.web.app/ ) )
199- ([ Github] ( https://github.com/gmlwo530/dollar-to-food-emoji ) )
200- - [ zh-TW] Taiwan Real-time Air Quality Index by
201- [ @ArvinH ] ( https://github.com/ArvinH ) ([ Demo] ( https://codesandbox.io/s/simpleradar-aqi-with-tooltip-select-data-react-spring-item3?file=/Radar.tsx ) )([ Tutorial] ( https://blog.arvinh.info/tech/datavis-visx ) )
202- - tokenized BTC on ethereum stacked chart with brush by [ @sakulstra ] ( https://github.com/sakulstra )
203- - [ Escape From Tarkov Ammo Chart] ( https://eft.monster/ ) by
204- [ @codenomial ] ( https://github.com/codenomial )
205- - [ Pry] ( https://pry.co ) Finance for Founders (dashboard by [ @valtism ] ( https://github.com/valtism ) )
206- - [ Data 2 the People] ( https://www.data2thepeople.org/ ) Donation Efficacy Analysis for Downballot
207- Races ([ Demo] ( https://donate.data2thepeople.org/ ) )
208- ([ Github] ( https://github.com/Data-2-the-People/skyfall/blob/master/components/Scatterplot.jsx ) )
209- - [ Augora] ( https://augora.fr ) Display information of french deputies
210- ([ Demo] ( https://augora.fr/statistiques ) )([ Github] ( https://github.com/Augora/Augora ) )
211- - WHO Coronavirus (COVID-19) Dashboard is built on top of ` vx ` , earlier version of ` visx ` .
212- ([ Demo] ( https://covid19.who.int/ ) )
213- - [ Fig Stats] ( https://fig-stats.com ) - Figma community plugin & widget analytics
214- - [ Physician.FYI] ( https://physician.fyi ) - Explore physicians' disciplinary history
215- - [ Index by Superstardle] ( https://index.superstardle.com ) ,
216- [ Salaries by Superstardle] ( https://salaries.superstardle.com ) , &
217- [ Pack'Em by Superstardle] ( https://playoffs.superstardle.com ) - Explore professional sports teams
218- and superstars in the world of underdogs, salaries, and playoff performances.
219- - Ridgeline chart visualizing shuffling probabilities by [ @jmssnr ] ( https://github.com/jmssnr )
220- ([ Demo] ( https://shuffling-probability.vercel.app/ ) )
221- ([ Github] ( https://github.com/jmssnr/shuffling-probability ) )
222- - [ UCSF Data Library] ( https://datalibrary.ucsf.edu ) - Landing page for disease research tools
223- ([ Github] ( https://github.com/mountetna/monoetna/tree/master/vesta/ui ) )
224-
225- Have a project that's using ` visx ` ? Open a pull request and we'll add it to the list.
226-
227149## FAQ
228150
2291511. What does ` visx` stand for?
@@ -243,15 +165,7 @@ Have a project that's using `visx`? Open a pull request and we'll add it to the
243165 >
244166 > visx makes this easier for everyone. No need to reinvent the wheel each time.
245167 >
246- > more info: https://github.com/airbnb/visx/issues/6
247- >
248- > examples:
249- >
250- > - Collapsible tree with [ ` react-move ` ] ( https://github.com/react-tools/react-move ) by
251- > [ @techniq ] ( https://github.com/techniq ) ([ Demo] ( https://codesandbox.io/s/n3w687vmqj ) )
252- > ([ Radial demo] ( https://codesandbox.io/s/vmqwrkl395 ) )
253- > - Animation with ` react-spring ` by [ @drcmda ] ( https://github.com/drcmda )
254- > ([ Demo] ( https://codesandbox.io/embed/j3x61vjz5v ) )
168+ > more info: <https://github.com/airbnb/visx/issues/6>
255169
2561701. Do I have to use every package to make a chart?
257171
@@ -263,7 +177,7 @@ Have a project that's using `visx`? Open a pull request and we'll add it to the
263177
2641781. Does visx work with [preact](https://preactjs.com/)?
265179
266- > yup! need to alias ` react ` + ` react-dom ` and use ` preact- compat ` .
180+ > yup! need to alias ` react` + ` react- dom` and use ` preact/ compat` .
267181
2681821. I like using d3.
269183
0 commit comments