-
-
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.
✨ (line chart) set y-axis min default to 0
- Loading branch information
1 parent
a3b1e38
commit 7e9094f
Showing
9 changed files
with
117 additions
and
20 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
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,76 @@ | ||
import { defaultGrapherConfig } from "@ourworldindata/grapher" | ||
import { mergeGrapherConfigs } from "@ourworldindata/utils" | ||
import { MigrationInterface, QueryRunner } from "typeorm" | ||
|
||
export class SetYAxisMinDefaultToZero1729763649580 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
// set yAxis.min explicitly to "auto" for line charts | ||
// that used to rely on "auto" being the default. | ||
// this is the case for charts where neither the patch config | ||
// of the chart itself nor the indicator config have a yAxis.min set | ||
await queryRunner.query(` | ||
-- sql | ||
UPDATE chart_configs cc | ||
JOIN charts c ON cc.id = c.configId | ||
LEFT JOIN charts_x_parents cxp ON cxp.chartId = c.id | ||
LEFT JOIN variables v ON v.id = cxp.variableId | ||
LEFT JOIN chart_configs cc_admin ON cc_admin.id = v.grapherConfigIdAdmin | ||
SET | ||
-- using JSON_MERGE_PATCH instead of JSON_SET in case yAxis doesn't exist | ||
cc.patch = JSON_MERGE_PATCH(cc.patch, '{"yAxis":{"min":"auto"}}') | ||
WHERE | ||
cc.full ->> '$.type' = 'LineChart' | ||
AND cc.patch ->> '$.yAxis.min' IS NULL | ||
AND ( | ||
cc_admin.full IS NULL | ||
OR cc_admin.full ->> '$.yAxis.min' IS NULL | ||
) | ||
`) | ||
|
||
// recompute all full configs | ||
// (necessary since we changed the defaultGrapherConfig) | ||
const charts = await queryRunner.query(` | ||
-- sql | ||
SELECT | ||
cc.id AS configId, | ||
cc.patch AS patchConfig, | ||
cc_etl.patch AS etlConfig, | ||
cc_admin.patch AS adminConfig | ||
FROM charts c | ||
JOIN chart_configs cc ON cc.id = c.configId | ||
LEFT JOIN charts_x_parents cxp ON cxp.chartId = c.id | ||
LEFT JOIN variables v ON v.id = cxp.variableId | ||
LEFT JOIN chart_configs cc_etl ON cc_etl.id = v.grapherConfigIdETL | ||
LEFT JOIN chart_configs cc_admin ON cc_admin.id = v.grapherConfigIdAdmin | ||
`) | ||
for (const chart of charts) { | ||
const patchConfig = JSON.parse(chart.patchConfig) | ||
const etlConfig = chart.etlConfig ? JSON.parse(chart.etlConfig) : {} | ||
const adminConfig = chart.adminConfig | ||
? JSON.parse(chart.adminConfig) | ||
: {} | ||
|
||
const fullConfig = mergeGrapherConfigs( | ||
defaultGrapherConfig, | ||
etlConfig, | ||
adminConfig, | ||
patchConfig | ||
) | ||
|
||
await queryRunner.query( | ||
` | ||
-- sql | ||
UPDATE chart_configs cc | ||
SET cc.full = ? | ||
WHERE cc.id = ? | ||
`, | ||
[JSON.stringify(fullConfig), chart.configId] | ||
) | ||
} | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
public async down(): Promise<void> {} | ||
} |
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
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