act-now-coalition / act-now-packages

NPM Packages for Act Now Coalition
https://act-now-packages.web.app/
MIT License
4 stars 1 forks source link

MetricLegendThrshold width weirdness #563

Open mikelehen opened 1 year ago

mikelehen commented 1 year ago

I tried to drop a map and a legend into my app with:

          <MetricUSNationalMap
            regionDB={regions}
            metric={MetricId.OPIOID_DEATHS}
          />
          <MetricLegendThreshold metric={MetricId.OPIOID_DEATHS} orientation="horizontal"/>

and got:

Image

That is ridiculously wide, so I added width={300} and lost centering:

Image

I think:

  1. Setting the width explicitly should preserve centering.
  2. We might want a default width that's not full-width so you don't have to explicitly set it.
  3. We might want to consider having the map include a legend by default (with a good default width) and let you pass includeLegend={false} if you want to disable it.
chasulin commented 1 year ago

I originally wrapped the legend in AutoWidth so that it would always grow to the size of whatever parent container it is wrapped in (in this case, it didn't have a wrapper of its own so it grew to the width of the wrapper it shares with the map assumedly).

In this PR, I add a wrapper in LegendThresholdHorizontal that applies the passed with as the legend's maxWidth (similar to our vax thermometer in CAN).

Im not 100% sold on the idea of making it centered by default -- I kind of feel like alignment should be set in the context of implementing (in the case of your demo homepage, a wrapper that centers all of the items it contains). what do you think @mikelehen?

chasulin commented 1 year ago

re: your 3rd point, do you think this might call for a MetricMapBlock component? 😁

mikelehen commented 1 year ago

@chasulin Thanks, Chelsi! I think that sounds good though I'm not 100% sure without trying it. Mostly I just want to minimize the steps and fiddling necessary to get a map onto a homepage. 😁 So yeah, on that note a MetricMapBlock component does seem appealing as well!