-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 (grapher) let chart configs inherit default values / TAS-565 (#3782)
## Summary Implements chart config inheritance and makes all chart configs inherit values from a parent config with default values. ## Details - For all standalone charts, the `full` config is the `patch` config merged with the default layer - Whenever we save a new chart or update the existing one, we first compute the patch config by diffing against the parent/default config and then compute the full config by merging the patch with the parent - We usually operate on the full config, but we're baking the full config without defaults so that we're not baking the defaults again and again and again (makes a difference on explorer pages where we potentially bake tens/hundreds of configs) - We use the ~full~ patch config for version history. The way we currently do revisions doesn't always work[^1]. ~Using the full config for version history fixes this, but has the disadvantage that "old" default values (that have since been updated) are copied over when a config is restored.~ - The default grapher config is derived from the schema and lives in the codebase. It can be generated by running the `generate-default-object-from-schema.ts` with the `--save-ts` flag - Whenever Grapher defaults are updated, the default config should be regenerated, and all `full` configs of stand-alone charts should be recomputed - We could have also stored the default layer in the database, but it's convenient to have it at hand in the codebase (where it's also type-checked). If some external entity needs the default config, they can access https://files.ourworldindata.org/schemas/grapher-schema.default.latest.json - Two new functions operate on chart configs and implement inheritance: - `mergeGrapherConfigs`: merges two or more patch configs - Some keys are excluded from inheritance ($schema, id, slug, version, isPublished) - Configs with different schema versions can't be merged - `diffGrapherConfigs`: diffs a given config against some reference config, where only values that are different in both configs are kept ## Caveats - ~I left the chart revisions as is but now store the full config in the chart revisions table whenever a chart is saved – this could be a bit confusing~ - ~As I said above, storing the full config in version history comes at the cost of copying over old default values when a chart is restored – how big of a problem is that?~ ## SVG tester I dumped two new set of configs and reference charts for the SVG tester: - [Patch configs](https://github.com/owid/owid-grapher-svgs/compare/configs-2024-july...configs-july-2024-defaults?short_path=4814afd#diff-4814afdf72df1537e0f28ca29966dde09611474e3ed214d1609754491faa83e0) - The config changes are due to diffing against the default layer (meaning, default values are removed) - There is one chart that is rendered differently, but it seems to be unrelated to the changes in this PR. - [Full configs](owid/owid-grapher-svgs@configs-2024-08-20...configs-2024-08-20-defaults-2) - Few charts are added and removed, probably because I refreshed the database in between - Other than that, no changes ## To do - ~Add some real-world tests~ it's ok as is - [x] Add a GitHub workflow that re-generates the default config and checks if the diff is clean - [x] Delete `DEFAULT_GRAPHER_CONFIG_SCHEMA` [^1]: When restoring a config from version history, we re-apply an old config version. But that doesn't take default values into account. For example, let's say the v1 version of a chart relies on the default value for `hasMapTab` and has thus no map tab. In v2, a map tab is added (the config now contains `{..., hasMapTab: true}`. Restoring v1 doesn't switch `hasMapTab` back to `false` since `hasMapTab` isn't contained in the v1 version of the config (since we were relying on the default).
- Loading branch information
1 parent
6c3057a
commit 3cc05db
Showing
30 changed files
with
1,035 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Check default grapher config | ||
on: | ||
push: | ||
branches: | ||
- "**" | ||
- "!master" | ||
paths: | ||
- "packages/@ourworldindata/grapher/src/schema/**" | ||
|
||
jobs: | ||
commit-default-config: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Clone repository | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
|
||
- uses: ./.github/actions/setup-node-yarn-deps | ||
- uses: ./.github/actions/build-tsc | ||
|
||
- uses: hustcer/setup-nu@v3 | ||
with: | ||
version: "0.80" # Don't use 0.80 here, as it was a float number and will be convert to 0.8, you can use v0.80/0.80.0 or '0.80' | ||
|
||
# Turn all yaml files in the schema directory into json (should only be one) | ||
- name: Convert yaml schema to json | ||
run: | | ||
(ls packages/@ourworldindata/grapher/src/schema/*.yaml | ||
| each {|yaml| | ||
open $yaml.name | ||
| to json | ||
| save -f ($yaml.name | ||
| path parse | ||
| upsert extension "json" | ||
| path join) }) | ||
shell: nu {0} | ||
|
||
# Construct default config objects for all grapher schemas in the schema directory (should only be one) | ||
- name: Generate default grapher config | ||
run: | | ||
(ls packages/@ourworldindata/grapher/src/schema/grapher-schema.*.json | ||
| each {|json| | ||
node itsJustJavascript/devTools/schema/generate-default-object-from-schema.js $json.name --save-ts packages/@ourworldindata/grapher/src/schema/defaultGrapherConfig.ts }) | ||
shell: nu {0} | ||
|
||
- name: Run prettier | ||
run: yarn fixPrettierAll | ||
|
||
- uses: stefanzweifel/git-auto-commit-action@v5 | ||
with: | ||
commit_message: "🤖 update default grapher config" | ||
file_pattern: "packages/@ourworldindata/grapher/src/schema/defaultGrapherConfig.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.