@buildcanada/charts 0.1.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/components/Button/Button.scss +17 -17
- package/src/components/Button/Button.tsx +4 -4
- package/src/components/MarkdownTextWrap/MarkdownTextWrap.tsx +1 -1
- package/src/components/index.ts +1 -1
- package/src/components/stubs/DataCitation.tsx +1 -1
- package/src/components/stubs/IndicatorKeyData.tsx +1 -1
- package/src/components/stubs/IndicatorProcessing.tsx +1 -1
- package/src/components/stubs/IndicatorSources.tsx +1 -1
- package/src/components/styles/colors.scss +1 -1
- package/src/components/styles/mixins.scss +5 -5
- package/src/core-table/{OwidTable.ts → ChartsTable.ts} +31 -31
- package/src/core-table/CoreTable.ts +12 -12
- package/src/core-table/CoreTableColumns.ts +24 -24
- package/src/core-table/CoreTableUtils.ts +7 -7
- package/src/core-table/{OwidTableSynthesizers.ts → TableSynthesizers.ts} +24 -24
- package/src/core-table/{OwidTableUtil.ts → TableUtil.ts} +5 -5
- package/src/core-table/index.ts +3 -3
- package/src/explorer/ColumnGrammar.ts +1 -1
- package/src/explorer/Explorer.sample.ts +7 -7
- package/src/explorer/Explorer.scss +1 -1
- package/src/explorer/Explorer.tsx +23 -23
- package/src/explorer/ExplorerConstants.ts +2 -2
- package/src/explorer/ExplorerGrammar.ts +3 -3
- package/src/explorer/ExplorerProgram.ts +21 -18
- package/src/explorer/ExplorerUtils.ts +1 -1
- package/src/explorer/gridLang/readme.md +1 -1
- package/src/grapher/axis/Axis.ts +3 -3
- package/src/grapher/barCharts/DiscreteBarChart.tsx +2 -2
- package/src/grapher/barCharts/DiscreteBarChartState.ts +8 -8
- package/src/grapher/captionedChart/Logos.tsx +11 -13
- package/src/grapher/captionedChart/LogosSVG.tsx +2 -2
- package/src/grapher/chart/ChartAreaContent.tsx +1 -1
- package/src/grapher/chart/ChartDimension.ts +15 -15
- package/src/grapher/chart/ChartInterface.ts +6 -6
- package/src/grapher/chart/ChartManager.ts +3 -3
- package/src/grapher/chart/ChartUtils.tsx +3 -3
- package/src/grapher/color/ColorConstants.ts +2 -2
- package/src/grapher/color/ColorScale.ts +4 -4
- package/src/grapher/color/ColorSchemes.ts +26 -26
- package/src/grapher/color/CustomSchemes.ts +227 -227
- package/src/grapher/controls/DataTableFilterDropdown.tsx +2 -2
- package/src/grapher/controls/MapZoomDropdown.tsx +3 -3
- package/src/grapher/controls/ShareMenu.tsx +1 -1
- package/src/grapher/controls/entityPicker/EntityPicker.tsx +8 -8
- package/src/grapher/controls/entityPicker/EntityPickerConstants.ts +3 -3
- package/src/grapher/controls/globalEntitySelector/GlobalEntitySelector.tsx +1 -1
- package/src/grapher/core/EntitiesByRegionType.ts +4 -4
- package/src/grapher/core/EntityUrlBuilder.ts +2 -2
- package/src/grapher/core/FetchingGrapher.tsx +4 -4
- package/src/grapher/core/Grapher.tsx +10 -10
- package/src/grapher/core/GrapherState.tsx +46 -46
- package/src/grapher/core/GrapherUseHelpers.tsx +4 -4
- package/src/grapher/core/{LegacyToOwidTable.ts → LegacyToChartsTable.ts} +100 -100
- package/src/grapher/core/loadGrapherTableHelpers.ts +13 -13
- package/src/grapher/core/loadVariable.ts +5 -5
- package/src/grapher/dataTable/DataTable.sample.ts +12 -12
- package/src/grapher/dataTable/DataTable.tsx +22 -22
- package/src/grapher/dataTable/DataTableConstants.ts +9 -9
- package/src/grapher/entitySelector/EntitySelector.tsx +12 -12
- package/src/grapher/facet/FacetChart.tsx +4 -4
- package/src/grapher/facet/FacetMap.tsx +6 -6
- package/src/grapher/footer/Footer.tsx +4 -4
- package/src/grapher/footer/FooterManager.ts +2 -2
- package/src/grapher/header/Header.tsx +5 -5
- package/src/grapher/header/HeaderManager.ts +1 -1
- package/src/grapher/index.ts +8 -8
- package/src/grapher/lineCharts/LineChartHelpers.ts +3 -3
- package/src/grapher/lineCharts/LineChartState.ts +9 -9
- package/src/grapher/mapCharts/ChoroplethGlobe.tsx +1 -1
- package/src/grapher/mapCharts/GlobeController.ts +9 -9
- package/src/grapher/mapCharts/MapChartState.ts +16 -16
- package/src/grapher/mapCharts/MapSparkline.tsx +5 -5
- package/src/grapher/mapCharts/MapTooltip.tsx +13 -13
- package/src/grapher/modal/DownloadModal.scss +3 -3
- package/src/grapher/modal/DownloadModal.tsx +24 -29
- package/src/grapher/modal/SourcesDescriptions.scss +1 -1
- package/src/grapher/modal/SourcesKeyDataTable.tsx +2 -2
- package/src/grapher/modal/SourcesModal.tsx +15 -15
- package/src/grapher/scatterCharts/ScatterPlotChart.tsx +2 -2
- package/src/grapher/scatterCharts/ScatterPlotChartConstants.ts +2 -2
- package/src/grapher/scatterCharts/ScatterPlotChartState.ts +8 -8
- package/src/grapher/scatterCharts/ScatterSizeLegend.tsx +2 -2
- package/src/grapher/scatterCharts/ScatterUtils.ts +2 -2
- package/src/grapher/schema/grapher-schema.009.yaml +18 -18
- package/src/grapher/schema/migrations/migrations.ts +4 -4
- package/src/grapher/selection/MapSelectionArray.ts +1 -1
- package/src/grapher/selection/readme.md +1 -1
- package/src/grapher/slopeCharts/SlopeChartConstants.ts +3 -3
- package/src/grapher/slopeCharts/SlopeChartState.ts +10 -10
- package/src/grapher/stackedCharts/AbstractStackedChartState.ts +8 -8
- package/src/grapher/stackedCharts/MarimekkoChart.tsx +5 -5
- package/src/grapher/stackedCharts/MarimekkoChartConstants.ts +2 -2
- package/src/grapher/stackedCharts/MarimekkoChartState.ts +12 -12
- package/src/grapher/stackedCharts/StackedBarChartState.ts +1 -1
- package/src/grapher/stackedCharts/StackedConstants.ts +2 -2
- package/src/grapher/stackedCharts/StackedDiscreteBarChartState.ts +12 -12
- package/src/grapher/stackedCharts/StackedDiscreteBars.tsx +2 -2
- package/src/grapher/testData/{OwidTestData.sample.ts → TestData.sample.ts} +7 -7
- package/src/grapher/testData/{OwidTestData.ts → TestData.ts} +5 -5
- package/src/index.ts +7 -7
- package/src/types/{OwidOrigin.ts → Origin.ts} +3 -3
- package/src/types/{OwidSource.ts → Source.ts} +1 -1
- package/src/types/Variable.ts +133 -0
- package/src/types/{OwidVariableDisplayConfigInterface.ts → VariableDisplayConfigInterface.ts} +11 -11
- package/src/types/domainTypes/ContentGraph.ts +2 -2
- package/src/types/domainTypes/CoreTableTypes.ts +29 -29
- package/src/types/domainTypes/Posts.ts +2 -2
- package/src/types/domainTypes/Search.ts +6 -6
- package/src/types/domainTypes/Various.ts +1 -1
- package/src/types/gdocTypes/Gdoc.ts +42 -42
- package/src/types/grapherTypes/GrapherTypes.ts +21 -21
- package/src/types/index.ts +50 -50
- package/src/utils/MultiDimDataPageConfig.ts +1 -1
- package/src/utils/Util.ts +61 -55
- package/src/utils/{OwidVariable.ts → Variable.ts} +15 -15
- package/src/utils/formatValue.ts +12 -12
- package/src/utils/image.ts +12 -12
- package/src/utils/index.ts +5 -5
- package/src/utils/metadataHelpers.ts +19 -19
- package/src/utils/regions.ts +9 -9
- package/src/types/OwidVariable.ts +0 -133
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
// todo: Remove this file when we've migrated
|
|
1
|
+
// todo: Remove this file when we've migrated legacy data and charts to next version
|
|
2
2
|
|
|
3
3
|
import * as _ from "lodash-es"
|
|
4
4
|
import {
|
|
5
5
|
ColumnTypeNames,
|
|
6
6
|
CoreColumnDef,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
StandardColumnDefs,
|
|
8
|
+
ChartsTableSlugs,
|
|
9
|
+
ColumnDef,
|
|
10
|
+
VariableDimensions,
|
|
11
|
+
VariableDataMetadataDimensions,
|
|
12
12
|
ErrorValue,
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
ChartDimensionInterfaceWithMandatorySlug,
|
|
14
|
+
ChartDimensionInterface,
|
|
15
15
|
EntityName,
|
|
16
16
|
} from "../../types/index.js"
|
|
17
17
|
import {
|
|
18
|
-
|
|
18
|
+
ChartsTable,
|
|
19
19
|
ErrorValueTypes,
|
|
20
20
|
makeKeyFn,
|
|
21
21
|
} from "../../core-table/index.js"
|
|
@@ -25,59 +25,59 @@ import {
|
|
|
25
25
|
intersection,
|
|
26
26
|
makeAnnotationsSlug,
|
|
27
27
|
trimObject,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
EntityKey,
|
|
29
|
+
MultipleVariableDataDimensionsMap,
|
|
30
|
+
VariableWithSource,
|
|
31
|
+
VariableMixedData,
|
|
32
|
+
VariableWithSourceAndDimension,
|
|
33
33
|
ColumnSlug,
|
|
34
34
|
EPOCH_DATE,
|
|
35
|
-
|
|
35
|
+
VariableType,
|
|
36
36
|
} from "../../utils/index.js"
|
|
37
37
|
import { isContinentsVariableId } from "./GrapherConstants"
|
|
38
38
|
import * as R from "remeda"
|
|
39
39
|
import { getDimensionColumnSlug } from "../chart/ChartDimension.js"
|
|
40
40
|
|
|
41
|
-
export const
|
|
42
|
-
json:
|
|
43
|
-
dimensions:
|
|
41
|
+
export const legacyToChartsTableAndDimensionsWithMandatorySlug = (
|
|
42
|
+
json: MultipleVariableDataDimensionsMap,
|
|
43
|
+
dimensions: ChartDimensionInterface[],
|
|
44
44
|
selectedEntityColors:
|
|
45
45
|
| { [entityName: string]: string | undefined }
|
|
46
46
|
| undefined
|
|
47
|
-
):
|
|
47
|
+
): ChartsTable => {
|
|
48
48
|
const dimensionsWithSlug = dimensions?.map((dimension) => ({
|
|
49
49
|
...dimension,
|
|
50
50
|
slug:
|
|
51
51
|
dimension.slug ??
|
|
52
52
|
getDimensionColumnSlug(dimension.variableId, dimension.targetYear),
|
|
53
53
|
}))
|
|
54
|
-
return
|
|
54
|
+
return legacyToChartsTableAndDimensions(
|
|
55
55
|
json,
|
|
56
56
|
dimensionsWithSlug,
|
|
57
57
|
selectedEntityColors
|
|
58
58
|
)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
export const
|
|
62
|
-
json:
|
|
63
|
-
dimensions:
|
|
61
|
+
export const legacyToChartsTableAndDimensions = (
|
|
62
|
+
json: MultipleVariableDataDimensionsMap,
|
|
63
|
+
dimensions: ChartDimensionInterfaceWithMandatorySlug[],
|
|
64
64
|
selectedEntityColors:
|
|
65
65
|
| { [entityName: string]: string | undefined }
|
|
66
66
|
| undefined
|
|
67
|
-
):
|
|
67
|
+
): ChartsTable => {
|
|
68
68
|
// Entity meta map
|
|
69
69
|
|
|
70
70
|
const entityMeta = [...json.values()].flatMap(
|
|
71
71
|
(value) => value.metadata.dimensions.entities.values
|
|
72
72
|
)
|
|
73
|
-
const entityMetaById:
|
|
73
|
+
const entityMetaById: EntityKey = Object.fromEntries(
|
|
74
74
|
entityMeta.map((entity) => [entity.id.toString(), entity])
|
|
75
75
|
)
|
|
76
76
|
|
|
77
77
|
// Base column defs, shared by all variable tables
|
|
78
78
|
|
|
79
79
|
const baseColumnDefs: Map<ColumnSlug, CoreColumnDef> = new Map()
|
|
80
|
-
|
|
80
|
+
StandardColumnDefs.forEach((def) => {
|
|
81
81
|
baseColumnDefs.set(def.slug, def)
|
|
82
82
|
})
|
|
83
83
|
|
|
@@ -85,9 +85,9 @@ export const legacyToOwidTableAndDimensions = (
|
|
|
85
85
|
// multiple columns for a single variable.
|
|
86
86
|
const dimensionColumns = _.uniqBy(dimensions, (dim) => dim.slug)
|
|
87
87
|
|
|
88
|
-
const variableTablesToJoinByYear:
|
|
89
|
-
const variableTablesToJoinByDay:
|
|
90
|
-
const variableTablesWithYearToJoinByEntityOnly:
|
|
88
|
+
const variableTablesToJoinByYear: ChartsTable[] = []
|
|
89
|
+
const variableTablesToJoinByDay: ChartsTable[] = []
|
|
90
|
+
const variableTablesWithYearToJoinByEntityOnly: ChartsTable[] = []
|
|
91
91
|
for (const dimension of dimensionColumns) {
|
|
92
92
|
const variable = json.get(dimension.variableId)
|
|
93
93
|
|
|
@@ -99,11 +99,11 @@ export const legacyToOwidTableAndDimensions = (
|
|
|
99
99
|
const columnDefs = new Map(baseColumnDefs)
|
|
100
100
|
|
|
101
101
|
// Time column
|
|
102
|
-
const timeColumnDef =
|
|
102
|
+
const timeColumnDef = timeColumnDefFromVariable(variable.metadata)
|
|
103
103
|
columnDefs.set(timeColumnDef.slug, timeColumnDef)
|
|
104
104
|
|
|
105
105
|
// Value column
|
|
106
|
-
const valueColumnDef =
|
|
106
|
+
const valueColumnDef = columnDefFromVariable(variable.metadata)
|
|
107
107
|
const valueColumnColor = dimension.display?.color
|
|
108
108
|
// Ensure the column slug is unique by copying it from the dimensions
|
|
109
109
|
// (there can be two columns of the same variable with different targetTimes)
|
|
@@ -127,11 +127,11 @@ export const legacyToOwidTableAndDimensions = (
|
|
|
127
127
|
|
|
128
128
|
// Annotations column
|
|
129
129
|
const [annotationMap, annotationColumnDef] =
|
|
130
|
-
|
|
130
|
+
annotationMapAndDefFromVariable(variable.metadata)
|
|
131
131
|
|
|
132
132
|
// Column values
|
|
133
133
|
|
|
134
|
-
const times =
|
|
134
|
+
const times = timeColumnValuesFromVariable(
|
|
135
135
|
variable.metadata,
|
|
136
136
|
variable.data
|
|
137
137
|
)
|
|
@@ -164,9 +164,9 @@ export const legacyToOwidTableAndDimensions = (
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
const columnStore: { [key: string]: any[] } = {
|
|
167
|
-
[
|
|
168
|
-
[
|
|
169
|
-
[
|
|
167
|
+
[ChartsTableSlugs.entityId]: entityIds,
|
|
168
|
+
[ChartsTableSlugs.entityCode]: entityCodes,
|
|
169
|
+
[ChartsTableSlugs.entityName]: entityNames,
|
|
170
170
|
[timeColumnDef.slug]: times,
|
|
171
171
|
[valueColumnDef.slug]: values,
|
|
172
172
|
}
|
|
@@ -179,7 +179,7 @@ export const legacyToOwidTableAndDimensions = (
|
|
|
179
179
|
}
|
|
180
180
|
// Build the tables
|
|
181
181
|
|
|
182
|
-
let variableTable = new
|
|
182
|
+
let variableTable = new ChartsTable(
|
|
183
183
|
columnStore,
|
|
184
184
|
Array.from(columnDefs.values())
|
|
185
185
|
)
|
|
@@ -241,11 +241,11 @@ export const legacyToOwidTableAndDimensions = (
|
|
|
241
241
|
|
|
242
242
|
// Merge all day based variables together (returns an empty table if there are none)
|
|
243
243
|
const variablesJoinedByDay = fullJoinTables(variableTablesToJoinByDay, [
|
|
244
|
-
|
|
245
|
-
|
|
244
|
+
ChartsTableSlugs.day,
|
|
245
|
+
ChartsTableSlugs.entityId,
|
|
246
246
|
])
|
|
247
247
|
|
|
248
|
-
let joinedVariablesTable:
|
|
248
|
+
let joinedVariablesTable: ChartsTable
|
|
249
249
|
// If we have both day and year based variables we need to do some special logic as described above
|
|
250
250
|
if (
|
|
251
251
|
variableTablesToJoinByYear.length > 0 &&
|
|
@@ -253,7 +253,7 @@ export const legacyToOwidTableAndDimensions = (
|
|
|
253
253
|
) {
|
|
254
254
|
// Derive the year from the day column and add it to the joined days table
|
|
255
255
|
const daysColumn = variablesJoinedByDay.getColumns([
|
|
256
|
-
|
|
256
|
+
ChartsTableSlugs.day,
|
|
257
257
|
])[0]
|
|
258
258
|
const getYearFromISOStringMemoized = _.memoize((dayValue: number) =>
|
|
259
259
|
getYearFromISOStringAndDayOffset(EPOCH_DATE, dayValue)
|
|
@@ -264,10 +264,10 @@ export const legacyToOwidTableAndDimensions = (
|
|
|
264
264
|
|
|
265
265
|
const newYearColumn = {
|
|
266
266
|
...daysColumn,
|
|
267
|
-
slug:
|
|
268
|
-
name:
|
|
267
|
+
slug: ChartsTableSlugs.year,
|
|
268
|
+
name: ChartsTableSlugs.year,
|
|
269
269
|
values: yearsForDaysValues,
|
|
270
|
-
} as
|
|
270
|
+
} as ColumnDef
|
|
271
271
|
const variablesJoinedByDayWithYearFilled =
|
|
272
272
|
variablesJoinedByDay.appendColumns([newYearColumn])
|
|
273
273
|
|
|
@@ -278,10 +278,10 @@ export const legacyToOwidTableAndDimensions = (
|
|
|
278
278
|
// trying to merge first by day+entity, then year+entity and finally entity only
|
|
279
279
|
joinedVariablesTable = fullJoinTables(
|
|
280
280
|
[variablesJoinedByDayWithYearFilled, ...variableTablesToJoinByYear],
|
|
281
|
-
[
|
|
281
|
+
[ChartsTableSlugs.day, ChartsTableSlugs.entityId],
|
|
282
282
|
[
|
|
283
|
-
[
|
|
284
|
-
[
|
|
283
|
+
[ChartsTableSlugs.year, ChartsTableSlugs.entityId],
|
|
284
|
+
[ChartsTableSlugs.entityId],
|
|
285
285
|
]
|
|
286
286
|
)
|
|
287
287
|
// If we have scatter/marimekko variables that had a targetTime set
|
|
@@ -292,15 +292,15 @@ export const legacyToOwidTableAndDimensions = (
|
|
|
292
292
|
joinedVariablesTable,
|
|
293
293
|
...variableTablesWithYearToJoinByEntityOnly,
|
|
294
294
|
],
|
|
295
|
-
[
|
|
296
|
-
[[
|
|
295
|
+
[ChartsTableSlugs.day, ChartsTableSlugs.entityId],
|
|
296
|
+
[[ChartsTableSlugs.entityId]]
|
|
297
297
|
)
|
|
298
298
|
} else if (variableTablesToJoinByYear.length > 0) {
|
|
299
299
|
// If we only have year based variables then life is easy and we just join
|
|
300
300
|
// those together without any special cases
|
|
301
301
|
joinedVariablesTable = fullJoinTables(variableTablesToJoinByYear, [
|
|
302
|
-
|
|
303
|
-
|
|
302
|
+
ChartsTableSlugs.year,
|
|
303
|
+
ChartsTableSlugs.entityId,
|
|
304
304
|
])
|
|
305
305
|
|
|
306
306
|
// If we have scatter/marimekko variables that had a targetTime set
|
|
@@ -311,8 +311,8 @@ export const legacyToOwidTableAndDimensions = (
|
|
|
311
311
|
joinedVariablesTable,
|
|
312
312
|
...variableTablesWithYearToJoinByEntityOnly,
|
|
313
313
|
],
|
|
314
|
-
[
|
|
315
|
-
[[
|
|
314
|
+
[ChartsTableSlugs.year, ChartsTableSlugs.entityId],
|
|
315
|
+
[[ChartsTableSlugs.entityId]]
|
|
316
316
|
)
|
|
317
317
|
} else {
|
|
318
318
|
// If we only have day variables life is also easy but this case is rare
|
|
@@ -326,20 +326,20 @@ export const legacyToOwidTableAndDimensions = (
|
|
|
326
326
|
joinedVariablesTable,
|
|
327
327
|
...variableTablesWithYearToJoinByEntityOnly,
|
|
328
328
|
],
|
|
329
|
-
[
|
|
330
|
-
[[
|
|
329
|
+
[ChartsTableSlugs.day, ChartsTableSlugs.entityId],
|
|
330
|
+
[[ChartsTableSlugs.entityId]]
|
|
331
331
|
)
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
// Inject a common "time" column that is used as the main time column for the table
|
|
335
335
|
// e.g. for the timeline.
|
|
336
|
-
for (const dayOrYearSlug of [
|
|
336
|
+
for (const dayOrYearSlug of [ChartsTableSlugs.day, ChartsTableSlugs.year]) {
|
|
337
337
|
if (joinedVariablesTable.columnSlugs.includes(dayOrYearSlug)) {
|
|
338
338
|
joinedVariablesTable = joinedVariablesTable.duplicateColumn(
|
|
339
339
|
dayOrYearSlug,
|
|
340
340
|
{
|
|
341
|
-
slug:
|
|
342
|
-
name:
|
|
341
|
+
slug: ChartsTableSlugs.time,
|
|
342
|
+
name: ChartsTableSlugs.time,
|
|
343
343
|
}
|
|
344
344
|
)
|
|
345
345
|
// Do not inject multiple columns, terminate after one is successful
|
|
@@ -349,7 +349,7 @@ export const legacyToOwidTableAndDimensions = (
|
|
|
349
349
|
|
|
350
350
|
// Append the entity color column if we have selected entity colors
|
|
351
351
|
if (!_.isEmpty(selectedEntityColors)) {
|
|
352
|
-
const entityColorColumnSlug =
|
|
352
|
+
const entityColorColumnSlug = ChartsTableSlugs.entityColor
|
|
353
353
|
|
|
354
354
|
const valueFn = (
|
|
355
355
|
entityName: EntityName | undefined
|
|
@@ -379,11 +379,11 @@ export const legacyToOwidTableAndDimensions = (
|
|
|
379
379
|
}
|
|
380
380
|
|
|
381
381
|
const fullJoinTables = (
|
|
382
|
-
tables:
|
|
383
|
-
indexColumnNames:
|
|
384
|
-
mergeFallbackLookupColumns?:
|
|
385
|
-
):
|
|
386
|
-
// This function merges a number of
|
|
382
|
+
tables: ChartsTable[],
|
|
383
|
+
indexColumnNames: ChartsTableSlugs[],
|
|
384
|
+
mergeFallbackLookupColumns?: ChartsTableSlugs[][]
|
|
385
|
+
): ChartsTable => {
|
|
386
|
+
// This function merges a number of ChartsTables together using a given list of columns
|
|
387
387
|
// to be used as the merge key. The merge key columns are used to construct a full set
|
|
388
388
|
// of index values from the various tables - all tables are enumerated, we create
|
|
389
389
|
// a merged string value from the index column values for each row and then we create
|
|
@@ -403,7 +403,7 @@ const fullJoinTables = (
|
|
|
403
403
|
// matching the day from the population variable (year+entity lookup) but for variables that don't
|
|
404
404
|
// have overlapping years (e.g. continents that only has 2015 as the single year) we want to fall back
|
|
405
405
|
// to merging by entity alone as a last resort
|
|
406
|
-
if (tables.length === 0) return new
|
|
406
|
+
if (tables.length === 0) return new ChartsTable()
|
|
407
407
|
else if (tables.length === 1) return tables[0]
|
|
408
408
|
|
|
409
409
|
// Get all the index values per table and then figure out the full set of all stringified index values
|
|
@@ -451,7 +451,7 @@ const fullJoinTables = (
|
|
|
451
451
|
// try other tables for these shared columns if the given row index does
|
|
452
452
|
// not exist in the first table
|
|
453
453
|
const firstTableDuplicateForIndices: [
|
|
454
|
-
|
|
454
|
+
ChartsTable | undefined,
|
|
455
455
|
string[] | undefined,
|
|
456
456
|
] = [tables[0], sharedColumnNames]
|
|
457
457
|
const defsToAddPerTable = [firstTableDuplicateForIndices]
|
|
@@ -464,7 +464,7 @@ const fullJoinTables = (
|
|
|
464
464
|
const def = { ...col.def }
|
|
465
465
|
def.values = []
|
|
466
466
|
return def
|
|
467
|
-
}) as
|
|
467
|
+
}) as ColumnDef[]
|
|
468
468
|
)
|
|
469
469
|
// Now loop over all unique index values and for each assemble as full a row as we can manage by looking
|
|
470
470
|
// up the values in the different source tables
|
|
@@ -572,13 +572,13 @@ const fullJoinTables = (
|
|
|
572
572
|
}
|
|
573
573
|
}
|
|
574
574
|
}
|
|
575
|
-
return new
|
|
575
|
+
return new ChartsTable(
|
|
576
576
|
[],
|
|
577
577
|
defsToAddPerTable.flatMap((defs) => defs)
|
|
578
578
|
)
|
|
579
579
|
}
|
|
580
580
|
|
|
581
|
-
const variableTypeToColumnType = (type:
|
|
581
|
+
const variableTypeToColumnType = (type: VariableType): ColumnTypeNames => {
|
|
582
582
|
switch (type) {
|
|
583
583
|
case "ordinal":
|
|
584
584
|
return ColumnTypeNames.Ordinal
|
|
@@ -595,7 +595,7 @@ const variableTypeToColumnType = (type: OwidVariableType): ColumnTypeNames => {
|
|
|
595
595
|
}
|
|
596
596
|
|
|
597
597
|
const getSortFromDimensions = (
|
|
598
|
-
dimensions:
|
|
598
|
+
dimensions: VariableDimensions
|
|
599
599
|
): string[] | undefined => {
|
|
600
600
|
const values = dimensions.values?.values
|
|
601
601
|
if (!values) return
|
|
@@ -609,9 +609,9 @@ const getSortFromDimensions = (
|
|
|
609
609
|
return sort
|
|
610
610
|
}
|
|
611
611
|
|
|
612
|
-
const
|
|
613
|
-
variable:
|
|
614
|
-
):
|
|
612
|
+
const columnDefFromVariable = (
|
|
613
|
+
variable: VariableWithSourceAndDimension
|
|
614
|
+
): ColumnDef => {
|
|
615
615
|
const slug = variable.id.toString() // For now, the variableId will be the column slug
|
|
616
616
|
const {
|
|
617
617
|
unit,
|
|
@@ -682,34 +682,34 @@ const columnDefFromOwidVariable = (
|
|
|
682
682
|
presentation,
|
|
683
683
|
catalogPath,
|
|
684
684
|
updatePeriodDays,
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
685
|
+
variableId: variable.id,
|
|
686
|
+
processingLevel: variable.processingLevel,
|
|
687
|
+
schemaVersion: variable.schemaVersion,
|
|
688
688
|
type,
|
|
689
689
|
sort,
|
|
690
690
|
shortName,
|
|
691
691
|
}
|
|
692
692
|
}
|
|
693
693
|
|
|
694
|
-
const
|
|
695
|
-
variableMetadata:
|
|
696
|
-
):
|
|
694
|
+
const timeColumnDefFromVariable = (
|
|
695
|
+
variableMetadata: VariableWithSource
|
|
696
|
+
): ColumnDef => {
|
|
697
697
|
return variableMetadata.display?.yearIsDay
|
|
698
698
|
? {
|
|
699
|
-
slug:
|
|
699
|
+
slug: ChartsTableSlugs.day,
|
|
700
700
|
type: ColumnTypeNames.Day,
|
|
701
701
|
name: "Day",
|
|
702
702
|
}
|
|
703
703
|
: {
|
|
704
|
-
slug:
|
|
704
|
+
slug: ChartsTableSlugs.year,
|
|
705
705
|
type: ColumnTypeNames.Year,
|
|
706
706
|
name: "Year",
|
|
707
707
|
}
|
|
708
708
|
}
|
|
709
709
|
|
|
710
|
-
const
|
|
711
|
-
variableMetadata:
|
|
712
|
-
variableData:
|
|
710
|
+
const timeColumnValuesFromVariable = (
|
|
711
|
+
variableMetadata: VariableWithSource,
|
|
712
|
+
variableData: VariableMixedData
|
|
713
713
|
): number[] => {
|
|
714
714
|
const { display } = variableMetadata
|
|
715
715
|
const { years } = variableData
|
|
@@ -734,9 +734,9 @@ const convertLegacyYears = (years: number[], zeroDay: string): number[] => {
|
|
|
734
734
|
return years.map((y) => y + diff)
|
|
735
735
|
}
|
|
736
736
|
|
|
737
|
-
const
|
|
738
|
-
variable:
|
|
739
|
-
): [Map<string, string>,
|
|
737
|
+
const annotationMapAndDefFromVariable = (
|
|
738
|
+
variable: VariableWithSourceAndDimension
|
|
739
|
+
): [Map<string, string>, ColumnDef] | [] => {
|
|
740
740
|
if (variable.display?.entityAnnotationsMap) {
|
|
741
741
|
const slug = makeAnnotationsSlug(variable.id.toString())
|
|
742
742
|
const annotationMap = annotationsToMap(
|
|
@@ -767,29 +767,29 @@ const annotationsToMap = (annotations: string): Map<string, string> => {
|
|
|
767
767
|
}
|
|
768
768
|
|
|
769
769
|
/**
|
|
770
|
-
* Loads a single variable into an
|
|
770
|
+
* Loads a single variable into an ChartsTable.
|
|
771
771
|
*/
|
|
772
772
|
export function buildVariableTable(
|
|
773
|
-
variable:
|
|
774
|
-
):
|
|
773
|
+
variable: VariableDataMetadataDimensions
|
|
774
|
+
): ChartsTable {
|
|
775
775
|
const entityMeta = variable.metadata.dimensions.entities.values
|
|
776
|
-
const entityMetaById:
|
|
776
|
+
const entityMetaById: EntityKey = Object.fromEntries(
|
|
777
777
|
entityMeta.map((entity) => [entity.id.toString(), entity])
|
|
778
778
|
)
|
|
779
779
|
|
|
780
|
-
// Base column defs, present in all
|
|
780
|
+
// Base column defs, present in all ChartsTables
|
|
781
781
|
const baseColumnDefs: Map<ColumnSlug, CoreColumnDef> = new Map(
|
|
782
|
-
|
|
782
|
+
StandardColumnDefs.map((def) => [def.slug, def])
|
|
783
783
|
)
|
|
784
784
|
|
|
785
785
|
const columnDefs = new Map(baseColumnDefs)
|
|
786
786
|
|
|
787
787
|
// Time column
|
|
788
|
-
const timeColumnDef =
|
|
788
|
+
const timeColumnDef = timeColumnDefFromVariable(variable.metadata)
|
|
789
789
|
columnDefs.set(timeColumnDef.slug, timeColumnDef)
|
|
790
790
|
|
|
791
791
|
// Value column
|
|
792
|
-
const valueColumnDef =
|
|
792
|
+
const valueColumnDef = columnDefFromVariable(variable.metadata)
|
|
793
793
|
// Because database columns can contain mixed types, we want to avoid
|
|
794
794
|
// parsing for Grapher data until we fix that.
|
|
795
795
|
valueColumnDef.skipParsing = true
|
|
@@ -797,7 +797,7 @@ export function buildVariableTable(
|
|
|
797
797
|
|
|
798
798
|
// Column values
|
|
799
799
|
|
|
800
|
-
const times =
|
|
800
|
+
const times = timeColumnValuesFromVariable(
|
|
801
801
|
variable.metadata,
|
|
802
802
|
variable.data
|
|
803
803
|
)
|
|
@@ -830,12 +830,12 @@ export function buildVariableTable(
|
|
|
830
830
|
}
|
|
831
831
|
|
|
832
832
|
const columnStore: { [key: string]: any[] } = {
|
|
833
|
-
[
|
|
834
|
-
[
|
|
835
|
-
[
|
|
833
|
+
[ChartsTableSlugs.entityId]: entityIds,
|
|
834
|
+
[ChartsTableSlugs.entityCode]: entityCodes,
|
|
835
|
+
[ChartsTableSlugs.entityName]: entityNames,
|
|
836
836
|
[timeColumnDef.slug]: times,
|
|
837
837
|
[valueColumnDef.slug]: values,
|
|
838
838
|
}
|
|
839
839
|
|
|
840
|
-
return new
|
|
840
|
+
return new ChartsTable(columnStore, Array.from(columnDefs.values()))
|
|
841
841
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as _ from "lodash-es"
|
|
2
|
-
import {
|
|
2
|
+
import { ChartsTable } from "../../core-table/index.js"
|
|
3
3
|
import {
|
|
4
4
|
ArchiveContext,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
ChartDimensionInterface,
|
|
6
|
+
VariableDataMetadataDimensions,
|
|
7
7
|
} from "../../utils/index.js"
|
|
8
|
-
import {
|
|
8
|
+
import { legacyToChartsTableAndDimensionsWithMandatorySlug } from "./LegacyToChartsTable.js"
|
|
9
9
|
import {
|
|
10
10
|
loadVariablesDataSite,
|
|
11
11
|
loadVariableDataAndMetadata,
|
|
@@ -13,13 +13,13 @@ import {
|
|
|
13
13
|
import { toJS } from "mobx"
|
|
14
14
|
|
|
15
15
|
export type FetchInputTableForConfigFn = (args: {
|
|
16
|
-
dimensions?:
|
|
16
|
+
dimensions?: ChartDimensionInterface[]
|
|
17
17
|
selectedEntityColors?: { [entityName: string]: string | undefined }
|
|
18
18
|
dataApiUrl: string
|
|
19
19
|
archiveContext?: ArchiveContext
|
|
20
20
|
noCache?: boolean
|
|
21
21
|
loadMetadataOnly?: boolean
|
|
22
|
-
}) => Promise<
|
|
22
|
+
}) => Promise<ChartsTable | undefined>
|
|
23
23
|
|
|
24
24
|
export const fetchInputTableForConfig: FetchInputTableForConfigFn = async (
|
|
25
25
|
args
|
|
@@ -33,7 +33,7 @@ export const fetchInputTableForConfig: FetchInputTableForConfigFn = async (
|
|
|
33
33
|
args.noCache,
|
|
34
34
|
args.loadMetadataOnly
|
|
35
35
|
)
|
|
36
|
-
const inputTable =
|
|
36
|
+
const inputTable = legacyToChartsTableAndDimensionsWithMandatorySlug(
|
|
37
37
|
variablesDataMap,
|
|
38
38
|
args.dimensions,
|
|
39
39
|
args.selectedEntityColors
|
|
@@ -48,13 +48,13 @@ export function getCachingInputTableFetcher(
|
|
|
48
48
|
noCache?: boolean,
|
|
49
49
|
loadMetadataOnly?: boolean
|
|
50
50
|
): (
|
|
51
|
-
dimensions:
|
|
51
|
+
dimensions: ChartDimensionInterface[],
|
|
52
52
|
selectedEntityColors:
|
|
53
53
|
| { [entityName: string]: string | undefined }
|
|
54
54
|
| undefined
|
|
55
|
-
) => Promise<
|
|
56
|
-
const cache: Map<number,
|
|
57
|
-
let previousDimensions:
|
|
55
|
+
) => Promise<ChartsTable | undefined> {
|
|
56
|
+
const cache: Map<number, VariableDataMetadataDimensions> = new Map()
|
|
57
|
+
let previousDimensions: ChartDimensionInterface[] = []
|
|
58
58
|
let previousSelectedEntityColors:
|
|
59
59
|
| {
|
|
60
60
|
[entityName: string]: string | undefined
|
|
@@ -62,7 +62,7 @@ export function getCachingInputTableFetcher(
|
|
|
62
62
|
| undefined = undefined
|
|
63
63
|
|
|
64
64
|
return async (
|
|
65
|
-
dimensionsMobx:
|
|
65
|
+
dimensionsMobx: ChartDimensionInterface[],
|
|
66
66
|
selectedEntityColorsMobx:
|
|
67
67
|
| { [entityName: string]: string | undefined }
|
|
68
68
|
| undefined
|
|
@@ -105,7 +105,7 @@ export function getCachingInputTableFetcher(
|
|
|
105
105
|
variables.map((v) => [v, cache.get(v)!])
|
|
106
106
|
)
|
|
107
107
|
|
|
108
|
-
const inputTable =
|
|
108
|
+
const inputTable = legacyToChartsTableAndDimensionsWithMandatorySlug(
|
|
109
109
|
variablesDataMap,
|
|
110
110
|
dimensions,
|
|
111
111
|
selectedEntityColors
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ArchiveContext,
|
|
3
3
|
AssetMap,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
MultipleVariableDataDimensionsMap,
|
|
5
|
+
VariableDataMetadataDimensions,
|
|
6
6
|
} from "../../types/index.js"
|
|
7
7
|
import { fetchWithRetry, readFromAssetMap } from "../../utils/index.js"
|
|
8
8
|
import urljoin from "url-join"
|
|
@@ -51,7 +51,7 @@ export async function loadVariableDataAndMetadata(
|
|
|
51
51
|
noCache?: boolean
|
|
52
52
|
loadMetadataOnly?: boolean
|
|
53
53
|
}
|
|
54
|
-
): Promise<
|
|
54
|
+
): Promise<VariableDataMetadataDimensions> {
|
|
55
55
|
const metadataPromise = fetchWithRetry(
|
|
56
56
|
getVariableMetadataRoute(dataApiUrl, variableId, options)
|
|
57
57
|
)
|
|
@@ -84,7 +84,7 @@ export async function loadVariablesDataSite(
|
|
|
84
84
|
archiveContext: ArchiveContext | undefined,
|
|
85
85
|
noCache?: boolean,
|
|
86
86
|
loadMetadataOnly?: boolean
|
|
87
|
-
): Promise<
|
|
87
|
+
): Promise<MultipleVariableDataDimensionsMap> {
|
|
88
88
|
const loadVariableDataPromises = variableIds.map((variableId) =>
|
|
89
89
|
loadVariableDataAndMetadata(variableId, dataApiUrl, {
|
|
90
90
|
assetMap:
|
|
@@ -95,7 +95,7 @@ export async function loadVariablesDataSite(
|
|
|
95
95
|
loadMetadataOnly,
|
|
96
96
|
})
|
|
97
97
|
)
|
|
98
|
-
const variablesData:
|
|
98
|
+
const variablesData: VariableDataMetadataDimensions[] =
|
|
99
99
|
await Promise.all(loadVariableDataPromises)
|
|
100
100
|
const variablesDataMap = new Map(
|
|
101
101
|
variablesData.map((data) => [data.metadata.id, data])
|
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
} from "../../types/index.js"
|
|
7
7
|
import {
|
|
8
8
|
TestMetadata,
|
|
9
|
-
|
|
9
|
+
createTestDataset,
|
|
10
10
|
fakeEntities,
|
|
11
|
-
} from "../testData/
|
|
12
|
-
import {
|
|
11
|
+
} from "../testData/TestData"
|
|
12
|
+
import { legacyToChartsTableAndDimensionsWithMandatorySlug } from "../core/LegacyToChartsTable.js"
|
|
13
13
|
|
|
14
14
|
export const childMortalityGrapher = (
|
|
15
15
|
props: Partial<GrapherInterface> = {}
|
|
@@ -40,7 +40,7 @@ export const childMortalityGrapher = (
|
|
|
40
40
|
property: DimensionProperty.y,
|
|
41
41
|
},
|
|
42
42
|
]
|
|
43
|
-
const
|
|
43
|
+
const dataset = createTestDataset([
|
|
44
44
|
{
|
|
45
45
|
metadata: childMortalityMetadata,
|
|
46
46
|
data: childMortalityData,
|
|
@@ -52,8 +52,8 @@ export const childMortalityGrapher = (
|
|
|
52
52
|
dimensions,
|
|
53
53
|
...props,
|
|
54
54
|
})
|
|
55
|
-
state.inputTable =
|
|
56
|
-
|
|
55
|
+
state.inputTable = legacyToChartsTableAndDimensionsWithMandatorySlug(
|
|
56
|
+
dataset,
|
|
57
57
|
dimensions,
|
|
58
58
|
{}
|
|
59
59
|
)
|
|
@@ -94,8 +94,8 @@ export const GrapherWithIncompleteData = (
|
|
|
94
94
|
},
|
|
95
95
|
},
|
|
96
96
|
]
|
|
97
|
-
const inputTable =
|
|
98
|
-
|
|
97
|
+
const inputTable = legacyToChartsTableAndDimensionsWithMandatorySlug(
|
|
98
|
+
createTestDataset([{ metadata, data }]),
|
|
99
99
|
dimensions,
|
|
100
100
|
{}
|
|
101
101
|
)
|
|
@@ -140,8 +140,8 @@ export const GrapherWithAggregates = (
|
|
|
140
140
|
property: DimensionProperty.y,
|
|
141
141
|
},
|
|
142
142
|
]
|
|
143
|
-
const inputTable =
|
|
144
|
-
|
|
143
|
+
const inputTable = legacyToChartsTableAndDimensionsWithMandatorySlug(
|
|
144
|
+
createTestDataset([
|
|
145
145
|
{ metadata: childMortalityMetadata, data: childMortalityData },
|
|
146
146
|
]),
|
|
147
147
|
dimensions,
|
|
@@ -189,8 +189,8 @@ export const GrapherWithMultipleVariablesAndMultipleYears = (
|
|
|
189
189
|
{ year: 2019, entity: fakeEntities.World, value: 10 },
|
|
190
190
|
],
|
|
191
191
|
}
|
|
192
|
-
const inputTable =
|
|
193
|
-
|
|
192
|
+
const inputTable = legacyToChartsTableAndDimensionsWithMandatorySlug(
|
|
193
|
+
createTestDataset([
|
|
194
194
|
abovePovertyLineDataset,
|
|
195
195
|
belowPovertyLineDataset,
|
|
196
196
|
]),
|