# Advent of Code, Day 5: Form Components

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

Day 5! I didn’t think I’d make this much progress today, but I’m happy I did.

#### Today’s progress

 * Built reusable form components (button, input, form, label) with the help of 
   [EmberMap](https://embermap.com/topics/forms)
 * Updated the chart
 * Integrated a color picker addon [ember-pickr](https://astronomersiva.github.io/ember-pickr/)
 * Discovered and fixed a bug with the way I was calculating the scale.
 * I didn’t realize how much stuff I thought was just regular Ember in our app is
   actually addons. A bunch of things I use at Crash every day didn’t work at first
   in plant-gantt until I tracked it back to an addon. For example: `ember-truth-
   helpers` and `ember-decorators`

The scale bug: ⌊the scale bug⌉ You see here that blueberries are going off the right
side. This is because I was calculating the scale based on the last plant in the
list, which isn’t always the one that will be _harvested_ last, only the one that
will be _planted_ last.

Instead, I had to use d3.max and offset to create a custom function to look at all
of the plants and see which one would be harvested last:

    ```highlight
    let lastToHarvest = maxIndex(sortedData, d =>   timeDay.offset(new Date(d.start), d.daysToMaturity) ); 
    ```

Today’s commits:

 1. [upgrade ember, add form components, add some helpers](https://github.com/cagrimmett/plant-gantt/commit/562ad652c4f20fc4021aaccc3073cb67ee215789)
 2. [updates to chart with form data](https://github.com/cagrimmett/plant-gantt/commit/b682a4db98d7d0ab0434613fc912f14a72931511)
 3. [get the color picker working](https://github.com/cagrimmett/plant-gantt/commit/c986674656a3dbf3cc5fbe82fad31265afd467c5)
 4. [fixed end data calculation bug](https://github.com/cagrimmett/plant-gantt/commit/8341a8e45b2829542fe28346f73b0ebbcab11e8e)

Here’s how it works so far!

![plant gantt with forms](https://i0.wp.com/cagrimmett.com/wp-content/uploads/2020/
09/plant-gantt-form.gif?ssl=1)

#### Tomorrow’s goal:

 * Improve the form UI
 * Use D3’s `update()` to update the chart instead of destroying and redrawing it
 * Show a different screen on the first time you land instead of showing the mocked
   out chart
 * Break the components apart
