owid / owid-grapher

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

Add overriding of the display settings of indicators so that colors, the display name etc could be set #4040

Open danyx23 opened 1 month ago

danyx23 commented 1 month ago

In the ETL every indicator has a few settings that are called the display settings (see the ETL docs). These are very old (they predate the metadata we have for indicators) but still used. One thing they do is e.g. that if you set the display.name of an indicator, this is what Grapher will use to label that indicator in a multi-indicator line chart. Similarly, you can set a color this way.

The display settings make their way into the dimensions object of a grapher config, but the dimensions array is the one part of the grapher config that we can't override with the partial grapher config of an MDim view (since it references indicators by id and is constructed only late in the process).

To make this work well, we'd like to be able to set the various display settings from the mdim yaml file. It's probably the nicest if, in addition to the current way of mapping the dimension to an array of etl path strings, we could also map the dimensions to an array of objects with an id for the etl path string and then a display setting, like so:

views:
  - dimensions:
      source: overview
      metric: per_capita
    indicators:
      y:
        - "grapher/energy/2024-06-20/energy_mix/energy_mix#coal_per_capita__kwh" # current use
        - id: "grapher/energy/2024-06-20/energy_mix/energy_mix#oil_per_capita__kwh" # new use
          display: 
            name: "Oil"
            color: "111111"
      $schema: https://files.ourworldindata.org/schemas/grapher-schema.005.json
      type: StackedArea

Doing things this way would also allow us in the future to add more indicator level overrides per view (e.g. if we want to support data tranform functions in the future or similar).

rakyi commented 3 weeks ago

We are still not sure if using the view.config.dimensions instead of the proposed solution wouldn't be better.

rakyi commented 2 weeks ago

This is blocking moving Covid charts to mdims, since we need to override color of indicators.