owid / owid-grapher

A platform for creating interactive data visualizations
https://ourworldindata.org
MIT License
1.37k stars 230 forks source link

Faceted stacked bar chart chooses colors differently than unfaceted one #3697

Open marcelgerber opened 3 months ago

marcelgerber commented 3 months ago

Description

The logic for choosing bar colors is different for faceted and unfaceted stacked bar charts, leading to inconsistent colors between page reloads.

Steps to reproduce

Steps to reproduce the behavior:

  1. Go to https://ourworldindata.org/grapher/covid-vaccine-willingness-and-people-vaccinated-by-month
  2. Select another country (such that two are selected)
  3. Reload the page
  4. Observe that the chart colors are clearly different

Screenshots

https://github.com/owid/owid-grapher/assets/2641501/c97b6af7-e3cf-4356-ac8c-065849a84416

Additional context

In this chart, there are not explicit colors assigned to the indicators.

Instead, it's using the Red-Blue color scale (see the Customize tab in Admin)

marcelgerber commented 3 months ago

Arguably, this could also be fixed by assigning fixed colors to the chart dimensions, which in fact is what we do in most Stacked bar charts with non-default colors.

It is a bit of an open question how often we have this case, where we are using a non-default color scheme to assign colors to a stacked chart - if it's not happening often, then the above is an absolutely valid workaround.