Project Update: COVID-19 World Tracker
Tags: react, d3, javascript
Published: 2020-05-16 22:08:06

Last week I shared my project plan for [building out a project while balancing homeschooling for my kids](https://dev.to/jessesbyers/balancing-covid-19-homeschooling-and-post-bootcamp-goals-5ghc). Despite being computer-less for 3 days after an unfortunate coffee-on-laptop incident, I am continuing to work through my goal of learning D3 data visualization and incorporating my visualizations as components in a react application. 

##Weekly Update

This week's work focused on integrating D3.js into my existing react.js app. After a bit of research, I decided to use Leigh Steiner's approach described in her article [React + D3 : The Macaroni and Cheese of the Data Visualization World](https://towardsdatascience.com/react-d3-the-macaroni-and-cheese-of-the-data-visualization-world-12bafde1f922). Aside from the amazing title, I appreciated the simplicity of her approach, which was to completely separate the concerns of React and D3 apart from one another so that each could interact with the DOM independently and without interference. Following this structure, I organized my react components around user interactions, as well as fetching and parsing the COVID-19 data, and kept my data visualization work confined to one file (Draw.js).
![Imgur](https://i.imgur.com/TUGW8qM.png)

The basic flow of data entails a user choosing countries from a dropdown menu (CountryDropdown.js), which renders and passes props to a collection container (Collection.js), which renders a collection of individual country components (Country.js). 

```
const Country = (props) => {
  
  // Code to parse data into correct format for D3

    return (
        <Viz countryName={countryName} totalCases={totalCases()} dailyData={parseData(dailyData, array)}/>
    )
}

export default Country
```


This component is responsible for parsing the fetched data into a format that will be used by D3, and renders a Viz component (Viz.js). 

```
const Viz = (props) => {

    useEffect( () => {
        Draw(props.countryName, props.totalCases, props.dailyData)
    }, [props])

    return <div className="viz"></div>
}

export default Viz

```

The sole purpose of the Viz component is to call the Draw() function, which ultimately will render the data visualization. However, it also needs to render an empty div that D3 will use as a node to attach the data visualization to.

Finally, with the .viz node available, we can write and execute the Draw() function to render the data visualizations. While there is more to be done in terms of formatting, I now have dynamically-generated bar charts showing COVID-19 data from any country (or any collection of countries) chosen by the user. You can view my D3 code-in-progress [here](https://github.com/jessesbyers/covid19_world_tracker_frontend/blob/master/src/d3/Draw.js).

![Imgur](https://i.imgur.com/EyDYYSs.png)

##Next Steps

This coming week, I hope to explore and add the following features:

1. Continue styling and formatting the chart
2. Make the user interface and charts more responsive
2. Add conditional logic to account for countries with 0 cases
3. Add stacked bars to show all data (total, recovered, active, deaths)
4. Use Bootstrap styling to create cards to build a dashboard of charts
5. Add a map visualization to the home page
6. And eventually...Add a show page for each country, with multiple data visualizations

##Resources

I've used a ton of excellent resources to learn D3 from scratch, and I recommend the following if you're interested in creating a similar data visualization project:

1. [Free Code Camp Data Visualization Certification Course](https://www.freecodecamp.org/learn)
2. [Curran Kelleher's 13-hour Data Visualization with D3.js - Full Tutorial Course](https://www.youtube.com/watch?v=_8V5o2UHG0E)
3. [React + D3 : The Macaroni and Cheese of the Data Visualization World](https://towardsdatascience.com/react-d3-the-macaroni-and-cheese-of-the-data-visualization-world-12bafde1f922)
4. [D3 documentation](https://d3js.org/)
5. [CoronaVirus Covid19 API](https://documenter.getpostman.com/view/10808728/SzS8rjbc?version=latest#00030720-fae3-4c72-8aea-ad01ba17adf8)
6. [Using d3-tip to add tooltips to a d3 bar chart](http://bl.ocks.org/caged/6476579)
7. [D3-tip documentation](https://github.com/caged/d3-tip/blob/517b14761d5a7a2d4b188941e26bb6a8f76d7c43/examples/bars.html)
8. [D3 Chart Examples on Observable](https://observablehq.com/@d3/gallery)