# Advent of Code, Day 4: Responsive D3 Chart in an Ember Component

- Link: https://cagrimmett.com/2019/12/05/advent-day-4/
- Published: 2019-12-05T02:15:00-05:00
- Author: Chuck Grimmett

Day 4!

#### Today’s progress

 * Sorted vegetables by start date
 * Updated the data model to calculate the harvest date by the days to maturity
 * Changed the scale to start 15 days before the first planting and end 15 days 
   after the last harvest to save space on screen. This also allows things to start
   before January and end after December.
 * Made the chart responsive

Making the chart responsive took me down a weird rabbit hole. I tried using a computed
property and then a bunch of different addons, but none of that worked. So I went
the old-school route and wrapped the chart drawing in a function and then added 
an event listener to remove the chart and redraw it. There is probably a more elegant
way to handle it, but I don’t know what it is.

    ```highlight
    window.addEventListener('resize', function() {   selectAll('svg').remove();   drawChart(); }); 
    ```

Today’s commits:

 1. [change tick format to months and sort data](https://github.com/cagrimmett/plant-gantt/commit/fb21a94e8a0bc7be868221e7163ac57b89b96abb)
 2. [move to relative scales](https://github.com/cagrimmett/plant-gantt/commit/f4d363d7dbe7e809779bfabeba5b7063d15b9f13)
 3. [responsive chart](https://github.com/cagrimmett/plant-gantt/commit/fc188dba51b779dfe7a2abbae5a9696a346a9858)

#### Tomorrow’s goal:

 * Add a form to add new elements and update the chart
