@buildcanada/charts 0.1.0 → 0.2.0
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 +9 -24
- 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/ContentSwitchers.tsx +1 -1
- 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 +47 -50
- 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 +13 -13
- 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 +4 -4
- 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/SlopeChartHelpers.ts +1 -1
- 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/tabs/Tabs.tsx +1 -1
- 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 +3 -3
- 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 +51 -51
- 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/LICENSE.md +0 -8
- package/README.md +0 -113
- package/src/types/OwidVariable.ts +0 -133
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Stub types for Google Docs integration.
|
|
3
|
-
* These are simplified versions of the full
|
|
3
|
+
* These are simplified versions of the full gdocTypes.
|
|
4
4
|
* Most Google Docs CMS functionality is not needed for the standalone charts library,
|
|
5
5
|
* but the types are required for compilation.
|
|
6
6
|
*/
|
|
@@ -9,9 +9,9 @@ import { QueryParams } from "../domainTypes/Various.js"
|
|
|
9
9
|
import { ArchivedPageVersion } from "../domainTypes/Archive.js"
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Document types in the
|
|
12
|
+
* Document types in the CMS.
|
|
13
13
|
*/
|
|
14
|
-
export enum
|
|
14
|
+
export enum GdocType {
|
|
15
15
|
Article = "article",
|
|
16
16
|
TopicPage = "topic-page",
|
|
17
17
|
LinearTopicPage = "linear-topic-page",
|
|
@@ -69,10 +69,10 @@ export interface UserCountryInformation {
|
|
|
69
69
|
/**
|
|
70
70
|
* Base interface for Gdoc content.
|
|
71
71
|
*/
|
|
72
|
-
export interface
|
|
72
|
+
export interface GdocBaseInterface {
|
|
73
73
|
id: string
|
|
74
74
|
slug: string
|
|
75
|
-
content:
|
|
75
|
+
content: GdocContent
|
|
76
76
|
published: boolean
|
|
77
77
|
createdAt: Date
|
|
78
78
|
publishedAt: Date | null
|
|
@@ -100,30 +100,30 @@ export interface OwidGdocBaseInterface {
|
|
|
100
100
|
/**
|
|
101
101
|
* Gdoc content type.
|
|
102
102
|
*/
|
|
103
|
-
export interface
|
|
104
|
-
type:
|
|
103
|
+
export interface GdocContent {
|
|
104
|
+
type: GdocType
|
|
105
105
|
title?: string
|
|
106
|
-
body?:
|
|
106
|
+
body?: EnrichedGdocBlock[]
|
|
107
107
|
[key: string]: unknown
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
111
|
* Generic Gdoc interface.
|
|
112
112
|
*/
|
|
113
|
-
export type
|
|
114
|
-
|
|
|
115
|
-
|
|
|
116
|
-
|
|
|
117
|
-
|
|
|
118
|
-
|
|
|
113
|
+
export type Gdoc =
|
|
114
|
+
| GdocPostInterface
|
|
115
|
+
| GdocDataInsightInterface
|
|
116
|
+
| GdocAuthorInterface
|
|
117
|
+
| GdocAboutInterface
|
|
118
|
+
| GdocHomepageInterface
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
121
|
* JSON representation of a Gdoc.
|
|
122
122
|
*/
|
|
123
|
-
export interface
|
|
123
|
+
export interface GdocJSON {
|
|
124
124
|
id: string
|
|
125
125
|
slug: string
|
|
126
|
-
content:
|
|
126
|
+
content: GdocContent
|
|
127
127
|
published: boolean
|
|
128
128
|
createdAt: string
|
|
129
129
|
publishedAt: string | null
|
|
@@ -134,61 +134,61 @@ export interface OwidGdocJSON {
|
|
|
134
134
|
/**
|
|
135
135
|
* Post (article/topic page) interface.
|
|
136
136
|
*/
|
|
137
|
-
export interface
|
|
138
|
-
content:
|
|
137
|
+
export interface GdocPostInterface extends GdocBaseInterface {
|
|
138
|
+
content: GdocPostContent
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
export interface
|
|
141
|
+
export interface GdocPostContent extends GdocContent {
|
|
142
142
|
type:
|
|
143
|
-
|
|
|
144
|
-
|
|
|
145
|
-
|
|
|
146
|
-
|
|
|
147
|
-
|
|
|
143
|
+
| GdocType.Article
|
|
144
|
+
| GdocType.TopicPage
|
|
145
|
+
| GdocType.LinearTopicPage
|
|
146
|
+
| GdocType.Fragment
|
|
147
|
+
| GdocType.AboutPage
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
/**
|
|
151
151
|
* Data insight interface.
|
|
152
152
|
*/
|
|
153
|
-
export interface
|
|
154
|
-
content:
|
|
153
|
+
export interface GdocDataInsightInterface extends GdocBaseInterface {
|
|
154
|
+
content: GdocDataInsightContent
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
export interface
|
|
158
|
-
type:
|
|
157
|
+
export interface GdocDataInsightContent extends GdocContent {
|
|
158
|
+
type: GdocType.DataInsight
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
162
|
* Author interface.
|
|
163
163
|
*/
|
|
164
|
-
export interface
|
|
165
|
-
content:
|
|
164
|
+
export interface GdocAuthorInterface extends GdocBaseInterface {
|
|
165
|
+
content: GdocAuthorContent
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
export interface
|
|
169
|
-
type:
|
|
168
|
+
export interface GdocAuthorContent extends GdocContent {
|
|
169
|
+
type: GdocType.Author
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
/**
|
|
173
173
|
* About page interface.
|
|
174
174
|
*/
|
|
175
|
-
export interface
|
|
176
|
-
content:
|
|
175
|
+
export interface GdocAboutInterface extends GdocBaseInterface {
|
|
176
|
+
content: GdocAboutContent
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
export interface
|
|
180
|
-
type:
|
|
179
|
+
export interface GdocAboutContent extends GdocContent {
|
|
180
|
+
type: GdocType.AboutPage
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
/**
|
|
184
184
|
* Homepage interface.
|
|
185
185
|
*/
|
|
186
|
-
export interface
|
|
187
|
-
content:
|
|
186
|
+
export interface GdocHomepageInterface extends GdocBaseInterface {
|
|
187
|
+
content: GdocHomepageContent
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
export interface
|
|
191
|
-
type:
|
|
190
|
+
export interface GdocHomepageContent extends GdocContent {
|
|
191
|
+
type: GdocType.Homepage
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
// =====================================================
|
|
@@ -198,7 +198,7 @@ export interface OwidGdocHomepageContent extends OwidGdocContent {
|
|
|
198
198
|
/**
|
|
199
199
|
* Base interface for enriched Gdoc blocks.
|
|
200
200
|
*/
|
|
201
|
-
export interface
|
|
201
|
+
export interface EnrichedGdocBlock {
|
|
202
202
|
type: string
|
|
203
203
|
parseErrors?: unknown[]
|
|
204
204
|
[key: string]: unknown
|
|
@@ -216,7 +216,7 @@ export interface Span {
|
|
|
216
216
|
/**
|
|
217
217
|
* Key insights slide block.
|
|
218
218
|
*/
|
|
219
|
-
export interface EnrichedBlockKeyInsightsSlide extends
|
|
219
|
+
export interface EnrichedBlockKeyInsightsSlide extends EnrichedGdocBlock {
|
|
220
220
|
type: "key-insights-slide"
|
|
221
221
|
title?: string
|
|
222
222
|
[key: string]: unknown
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "../
|
|
2
|
+
ChartDimensionInterface,
|
|
3
|
+
VariableRoundingMode,
|
|
4
|
+
} from "../VariableDisplayConfigInterface.js"
|
|
5
5
|
import { ColumnSlugs, EntityName } from "../domainTypes/CoreTableTypes.js"
|
|
6
6
|
import { AxisAlign, Position } from "../domainTypes/Layout.js"
|
|
7
|
-
import { Integer,
|
|
7
|
+
import { Integer, VariableId } from "../domainTypes/Various.js"
|
|
8
8
|
import { DetailDictionary } from "../gdocTypes/Gdoc.js"
|
|
9
9
|
import {
|
|
10
10
|
GRAPHER_CHART_TYPES,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
GRAPHER_TAB_CONFIG_OPTIONS,
|
|
14
14
|
GRAPHER_TAB_QUERY_PARAMS,
|
|
15
15
|
} from "./GrapherConstants.js"
|
|
16
|
-
import {
|
|
16
|
+
import { VariableDataMetadataDimensions } from "../Variable.js"
|
|
17
17
|
import { ArchiveContext } from "../domainTypes/Archive.js"
|
|
18
18
|
import {
|
|
19
19
|
BinningStrategyIncludingManual,
|
|
@@ -233,7 +233,7 @@ export interface Tickmark {
|
|
|
233
233
|
solid?: boolean // mostly for labelling domain start (e.g. 0)
|
|
234
234
|
}
|
|
235
235
|
export interface TickFormattingOptions {
|
|
236
|
-
roundingMode?:
|
|
236
|
+
roundingMode?: VariableRoundingMode
|
|
237
237
|
numDecimalPlaces?: number
|
|
238
238
|
numSignificantFigures?: number
|
|
239
239
|
unit?: string
|
|
@@ -339,9 +339,9 @@ export type ComparisonLineConfig =
|
|
|
339
339
|
| CustomComparisonLineConfig
|
|
340
340
|
|
|
341
341
|
export enum LogoOption {
|
|
342
|
-
|
|
343
|
-
"core+
|
|
344
|
-
"gv+
|
|
342
|
+
legacy = "legacy",
|
|
343
|
+
"core+legacy" = "core+legacy",
|
|
344
|
+
"gv+legacy" = "gv+legacy",
|
|
345
345
|
buildcanada = "buildcanada",
|
|
346
346
|
"buildcanada-wide" = "buildcanada-wide",
|
|
347
347
|
canadaspends = "canadaspends",
|
|
@@ -441,20 +441,20 @@ export enum ColorSchemeName {
|
|
|
441
441
|
Viridis = "Viridis",
|
|
442
442
|
continents = "continents",
|
|
443
443
|
stackedAreaDefault = "stackedAreaDefault",
|
|
444
|
-
"
|
|
444
|
+
"distinct" = "distinct",
|
|
445
445
|
SingleColorDenim = "SingleColorDenim",
|
|
446
446
|
SingleColorTeal = "SingleColorTeal",
|
|
447
447
|
SingleColorPurple = "SingleColorPurple",
|
|
448
448
|
SingleColorDustyCoral = "SingleColorDustyCoral",
|
|
449
449
|
SingleColorDarkCopper = "SingleColorDarkCopper",
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
450
|
+
CategoricalA = "CategoricalA",
|
|
451
|
+
CategoricalB = "CategoricalB",
|
|
452
|
+
CategoricalC = "CategoricalC",
|
|
453
|
+
CategoricalD = "CategoricalD",
|
|
454
|
+
CategoricalE = "CategoricalE",
|
|
455
|
+
Energy = "Energy",
|
|
456
|
+
EnergyLines = "EnergyLines",
|
|
457
|
+
DistinctLines = "DistinctLines",
|
|
458
458
|
BinaryMapPaletteA = "BinaryMapPaletteA",
|
|
459
459
|
BinaryMapPaletteB = "BinaryMapPaletteB",
|
|
460
460
|
BinaryMapPaletteC = "BinaryMapPaletteC",
|
|
@@ -520,7 +520,7 @@ export interface GrapherInterface extends SortConfig {
|
|
|
520
520
|
maxTime?: TimeBound | TimeBoundValueStr
|
|
521
521
|
timelineMinTime?: Time | TimeBoundValueStr
|
|
522
522
|
timelineMaxTime?: Time | TimeBoundValueStr
|
|
523
|
-
dimensions?:
|
|
523
|
+
dimensions?: ChartDimensionInterface[]
|
|
524
524
|
addCountryMode?: EntitySelectionMode
|
|
525
525
|
comparisonLines?: ComparisonLineConfig[]
|
|
526
526
|
stackMode?: StackMode
|
|
@@ -736,8 +736,8 @@ export enum GrapherWindowType {
|
|
|
736
736
|
}
|
|
737
737
|
|
|
738
738
|
export type AdditionalGrapherDataFetchFn = (
|
|
739
|
-
varId:
|
|
739
|
+
varId: VariableId,
|
|
740
740
|
loadMetadataOnly?: boolean
|
|
741
|
-
) => Promise<
|
|
741
|
+
) => Promise<VariableDataMetadataDimensions>
|
|
742
742
|
|
|
743
743
|
export type GrapherTrendArrowDirection = "up" | "right" | "down"
|
package/src/types/index.ts
CHANGED
|
@@ -14,7 +14,7 @@ export {
|
|
|
14
14
|
JsonError,
|
|
15
15
|
type JsonString,
|
|
16
16
|
type SerializedGridProgram,
|
|
17
|
-
type
|
|
17
|
+
type VariableId,
|
|
18
18
|
type QueryParams,
|
|
19
19
|
} from "./domainTypes/Various.js"
|
|
20
20
|
|
|
@@ -41,18 +41,18 @@ export {
|
|
|
41
41
|
type CoreTableInputOption,
|
|
42
42
|
type CoreQuery,
|
|
43
43
|
type CoreMatrix,
|
|
44
|
-
|
|
44
|
+
ChartsTableSlugs,
|
|
45
45
|
type EntityName,
|
|
46
46
|
type EntityCode,
|
|
47
47
|
type EntityId,
|
|
48
48
|
type Entity,
|
|
49
|
-
type
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
type
|
|
55
|
-
type
|
|
49
|
+
type ColumnDef,
|
|
50
|
+
EntityNameColumnDef,
|
|
51
|
+
EntityIdColumnDef,
|
|
52
|
+
EntityCodeColumnDef,
|
|
53
|
+
StandardColumnDefs,
|
|
54
|
+
type Row,
|
|
55
|
+
type VariableRow,
|
|
56
56
|
ColumnTypeNames,
|
|
57
57
|
type ColumnColorScale,
|
|
58
58
|
type CoreColumnDef,
|
|
@@ -158,36 +158,36 @@ export {
|
|
|
158
158
|
|
|
159
159
|
// Variable types
|
|
160
160
|
export {
|
|
161
|
-
type
|
|
162
|
-
type
|
|
163
|
-
type
|
|
164
|
-
type
|
|
165
|
-
type
|
|
166
|
-
type
|
|
167
|
-
type
|
|
168
|
-
type
|
|
169
|
-
type
|
|
170
|
-
type
|
|
171
|
-
type
|
|
172
|
-
type
|
|
173
|
-
type
|
|
174
|
-
type
|
|
175
|
-
type
|
|
161
|
+
type VariableWithSource,
|
|
162
|
+
type VariableWithSourceAndDimension,
|
|
163
|
+
type VariableWithSourceAndDimensionWithoutId,
|
|
164
|
+
type VariableMixedData,
|
|
165
|
+
type VariableWithDataAndSource,
|
|
166
|
+
type VariableDimension,
|
|
167
|
+
type VariableDimensions,
|
|
168
|
+
type VariableDataMetadataDimensions,
|
|
169
|
+
type MultipleVariableDataDimensionsMap,
|
|
170
|
+
type VariableDimensionValuePartial,
|
|
171
|
+
type VariableDimensionValueFull,
|
|
172
|
+
type VariablePresentation,
|
|
173
|
+
type EntityKey,
|
|
174
|
+
type License,
|
|
175
|
+
type ProcessingLevel,
|
|
176
176
|
type IndicatorTitleWithFragments,
|
|
177
177
|
joinTitleFragments,
|
|
178
|
-
type
|
|
179
|
-
} from "./
|
|
178
|
+
type VariableType,
|
|
179
|
+
} from "./Variable.js"
|
|
180
180
|
|
|
181
|
-
export type {
|
|
182
|
-
export type {
|
|
181
|
+
export type { Source } from "./Source.js"
|
|
182
|
+
export type { Origin } from "./Origin.js"
|
|
183
183
|
|
|
184
184
|
export {
|
|
185
|
-
type
|
|
186
|
-
type
|
|
187
|
-
|
|
188
|
-
type
|
|
189
|
-
type
|
|
190
|
-
} from "./
|
|
185
|
+
type VariableDisplayConfigInterface,
|
|
186
|
+
type VariableDataTableConfigInterface,
|
|
187
|
+
VariableRoundingMode,
|
|
188
|
+
type ChartDimensionInterface,
|
|
189
|
+
type ChartDimensionInterfaceWithMandatorySlug,
|
|
190
|
+
} from "./VariableDisplayConfigInterface.js"
|
|
191
191
|
|
|
192
192
|
export { type Nominal, wrap, unwrap } from "./NominalType.js"
|
|
193
193
|
|
|
@@ -202,26 +202,26 @@ export {
|
|
|
202
202
|
|
|
203
203
|
// Gdoc types (stubs for type compatibility)
|
|
204
204
|
export {
|
|
205
|
-
|
|
205
|
+
GdocType,
|
|
206
206
|
type NarrativeChartInfo,
|
|
207
207
|
type DetailDictionary,
|
|
208
208
|
type EnrichedDetail,
|
|
209
209
|
type UserCountryInformation,
|
|
210
|
-
type
|
|
211
|
-
type
|
|
212
|
-
type
|
|
213
|
-
type
|
|
214
|
-
type
|
|
215
|
-
type
|
|
216
|
-
type
|
|
217
|
-
type
|
|
218
|
-
type
|
|
219
|
-
type
|
|
220
|
-
type
|
|
221
|
-
type
|
|
222
|
-
type
|
|
223
|
-
type
|
|
224
|
-
type
|
|
210
|
+
type GdocBaseInterface,
|
|
211
|
+
type GdocContent,
|
|
212
|
+
type Gdoc,
|
|
213
|
+
type GdocJSON,
|
|
214
|
+
type GdocPostInterface,
|
|
215
|
+
type GdocPostContent,
|
|
216
|
+
type GdocDataInsightInterface,
|
|
217
|
+
type GdocDataInsightContent,
|
|
218
|
+
type GdocAuthorInterface,
|
|
219
|
+
type GdocAuthorContent,
|
|
220
|
+
type GdocAboutInterface,
|
|
221
|
+
type GdocAboutContent,
|
|
222
|
+
type GdocHomepageInterface,
|
|
223
|
+
type GdocHomepageContent,
|
|
224
|
+
type EnrichedGdocBlock,
|
|
225
225
|
type Span,
|
|
226
226
|
type EnrichedBlockKeyInsightsSlide,
|
|
227
227
|
type EnrichedTopicPageIntroRelatedTopic,
|
|
@@ -300,7 +300,7 @@ export interface TagGraphNode {
|
|
|
300
300
|
|
|
301
301
|
export const TagGraphRootName = "tag-graph-root" as const
|
|
302
302
|
|
|
303
|
-
export
|
|
303
|
+
export interface TagGraphRoot {
|
|
304
304
|
children: TagGraphNode[]
|
|
305
305
|
id: number
|
|
306
306
|
isTopic: false
|
package/src/utils/Util.ts
CHANGED
|
@@ -17,17 +17,17 @@ import {
|
|
|
17
17
|
VerticalAlign,
|
|
18
18
|
type GridParameters,
|
|
19
19
|
HorizontalAlign,
|
|
20
|
-
type
|
|
20
|
+
type EnrichedGdocBlock,
|
|
21
21
|
type EnrichedBlockKeyInsightsSlide,
|
|
22
22
|
type EnrichedTopicPageIntroRelatedTopic,
|
|
23
23
|
type EnrichedTopicPageIntroDownloadButton,
|
|
24
24
|
type EnrichedHybridLink,
|
|
25
|
-
type
|
|
26
|
-
type
|
|
27
|
-
type
|
|
28
|
-
type
|
|
29
|
-
|
|
30
|
-
type
|
|
25
|
+
type GdocPostInterface,
|
|
26
|
+
type GdocDataInsightInterface,
|
|
27
|
+
type GdocAuthorInterface,
|
|
28
|
+
type Gdoc,
|
|
29
|
+
GdocType,
|
|
30
|
+
type GdocJSON,
|
|
31
31
|
type Span,
|
|
32
32
|
UserCountryInformation,
|
|
33
33
|
Time,
|
|
@@ -40,8 +40,8 @@ import {
|
|
|
40
40
|
GRAPHER_CHART_TYPES,
|
|
41
41
|
DbPlainTag,
|
|
42
42
|
AssetMap,
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
GdocAboutInterface,
|
|
44
|
+
GdocHomepageInterface,
|
|
45
45
|
PrimitiveType,
|
|
46
46
|
GrapherTrendArrowDirection,
|
|
47
47
|
TocHeadingWithTitleSupertitle,
|
|
@@ -533,10 +533,16 @@ export async function fetchWithTimeout(
|
|
|
533
533
|
})
|
|
534
534
|
}
|
|
535
535
|
|
|
536
|
+
// Country detection service URL - can be configured for custom deployments
|
|
537
|
+
// This service should return JSON with a "country" object containing "code" and "name"
|
|
538
|
+
const COUNTRY_DETECTION_URL =
|
|
539
|
+
(typeof process !== "undefined" && process.env?.COUNTRY_DETECTION_URL) ||
|
|
540
|
+
"https://detect-country.example.com"
|
|
541
|
+
|
|
536
542
|
const _getUserCountryInformation = async (): Promise<
|
|
537
543
|
UserCountryInformation | undefined
|
|
538
544
|
> =>
|
|
539
|
-
await fetchWithRetry(
|
|
545
|
+
await fetchWithRetry(COUNTRY_DETECTION_URL)
|
|
540
546
|
.then((res) => res.json())
|
|
541
547
|
.then((res) => res.country)
|
|
542
548
|
.catch(() => undefined)
|
|
@@ -1251,7 +1257,7 @@ export const formatDate = (date: Date): string => {
|
|
|
1251
1257
|
* write a custom JSON parser to handle that automatically for all keys. At this
|
|
1252
1258
|
* stage, the manual approach is probably simpler.
|
|
1253
1259
|
*/
|
|
1254
|
-
export const
|
|
1260
|
+
export const getGdocFromJSON = (json: GdocJSON): Gdoc => {
|
|
1255
1261
|
return {
|
|
1256
1262
|
...json,
|
|
1257
1263
|
createdAt: new Date(json.createdAt),
|
|
@@ -1263,7 +1269,7 @@ export const getOwidGdocFromJSON = (json: OwidGdocJSON): OwidGdoc => {
|
|
|
1263
1269
|
// We want to infer the return type from the existing types instead of having to
|
|
1264
1270
|
// manually specify it.
|
|
1265
1271
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/explicit-module-boundary-types
|
|
1266
|
-
export function extractGdocPageData(gdoc:
|
|
1272
|
+
export function extractGdocPageData(gdoc: Gdoc) {
|
|
1267
1273
|
// Generic properties every gdoc has
|
|
1268
1274
|
const gdocProps = R.pick(gdoc, [
|
|
1269
1275
|
"id",
|
|
@@ -1327,10 +1333,10 @@ export function extractGdocPageData(gdoc: OwidGdoc) {
|
|
|
1327
1333
|
.otherwise(() => commonProps)
|
|
1328
1334
|
}
|
|
1329
1335
|
|
|
1330
|
-
export type
|
|
1336
|
+
export type GdocPageProps = ReturnType<typeof extractGdocPageData>
|
|
1331
1337
|
|
|
1332
|
-
export type
|
|
1333
|
-
|
|
1338
|
+
export type GdocPageData = Omit<
|
|
1339
|
+
GdocPageProps,
|
|
1334
1340
|
"createdAt" | "publishedAt" | "updatedAt"
|
|
1335
1341
|
> & {
|
|
1336
1342
|
createdAt: string
|
|
@@ -1338,11 +1344,11 @@ export type OwidGdocPageData = Omit<
|
|
|
1338
1344
|
updatedAt: string | null
|
|
1339
1345
|
}
|
|
1340
1346
|
|
|
1341
|
-
export function
|
|
1342
|
-
json:
|
|
1343
|
-
):
|
|
1347
|
+
export function deserializeGdocPageData(
|
|
1348
|
+
json: GdocPageData
|
|
1349
|
+
): GdocPageProps {
|
|
1344
1350
|
// NOTE: We have to do manual type casting around the content.type property
|
|
1345
|
-
// because it can be undefined in
|
|
1351
|
+
// because it can be undefined in GdocPostContent. That makes sense
|
|
1346
1352
|
// during the gdoc creation, where we do manual validation for various
|
|
1347
1353
|
// properties. But at some point we should only pass around a valid gdoc
|
|
1348
1354
|
// where content.type can't be undefined anymore. So we should likely create
|
|
@@ -1353,7 +1359,7 @@ export function deserializeOwidGdocPageData(
|
|
|
1353
1359
|
createdAt: new Date(json.createdAt),
|
|
1354
1360
|
publishedAt: json.publishedAt ? new Date(json.publishedAt) : null,
|
|
1355
1361
|
updatedAt: json.updatedAt ? new Date(json.updatedAt) : null,
|
|
1356
|
-
} as
|
|
1362
|
+
} as GdocPageProps
|
|
1357
1363
|
}
|
|
1358
1364
|
|
|
1359
1365
|
// Checking whether we have clipboard write access is surprisingly complicated.
|
|
@@ -1516,7 +1522,7 @@ export function bind<This, Args extends any[], Return>(
|
|
|
1516
1522
|
// It's more than just the EnrichedBlocks and Spans, because some EnrichedBlocks have nested children
|
|
1517
1523
|
// that contain URLs/filenames
|
|
1518
1524
|
export type NodeWithUrl =
|
|
1519
|
-
|
|
|
1525
|
+
| EnrichedGdocBlock
|
|
1520
1526
|
| Span
|
|
1521
1527
|
| EnrichedHybridLink
|
|
1522
1528
|
| EnrichedTopicPageIntroRelatedTopic
|
|
@@ -1593,13 +1599,13 @@ export function traverseEnrichedSpan(
|
|
|
1593
1599
|
.exhaustive()
|
|
1594
1600
|
}
|
|
1595
1601
|
|
|
1596
|
-
// If your node is a
|
|
1602
|
+
// If your node is a EnrichedGdocBlock, the callback will apply to it
|
|
1597
1603
|
// If your node has children that are Spans, the spanCallback will apply to them
|
|
1598
|
-
// If your node has children that aren't
|
|
1604
|
+
// If your node has children that aren't EnrichedGdocBlocks or Spans
|
|
1599
1605
|
// you'll have to handle those children yourself in your callback
|
|
1600
1606
|
export function traverseEnrichedBlock(
|
|
1601
|
-
node:
|
|
1602
|
-
callback: (x:
|
|
1607
|
+
node: EnrichedGdocBlock,
|
|
1608
|
+
callback: (x: EnrichedGdocBlock) => void,
|
|
1603
1609
|
spanCallback?: (x: Span) => void
|
|
1604
1610
|
): void {
|
|
1605
1611
|
match(node)
|
|
@@ -1860,7 +1866,7 @@ export function spansToUnformattedPlainText(spans: Span[]): string {
|
|
|
1860
1866
|
}
|
|
1861
1867
|
|
|
1862
1868
|
export function generateToc(
|
|
1863
|
-
body:
|
|
1869
|
+
body: EnrichedGdocBlock[] | undefined,
|
|
1864
1870
|
isTocForLinearTopicPage: boolean = false
|
|
1865
1871
|
): TocHeadingWithTitleSupertitle[] {
|
|
1866
1872
|
if (!body) return []
|
|
@@ -1930,10 +1936,10 @@ export function generateToc(
|
|
|
1930
1936
|
return toc
|
|
1931
1937
|
}
|
|
1932
1938
|
|
|
1933
|
-
export function
|
|
1939
|
+
export function checkIsGdocType(
|
|
1934
1940
|
gdocType: unknown
|
|
1935
|
-
): gdocType is
|
|
1936
|
-
return Object.values(
|
|
1941
|
+
): gdocType is GdocType {
|
|
1942
|
+
return Object.values(GdocType).includes(gdocType as any)
|
|
1937
1943
|
}
|
|
1938
1944
|
|
|
1939
1945
|
export function isArrayOfNumbers(arr: unknown[]): arr is number[] {
|
|
@@ -1977,16 +1983,16 @@ export function extractDetailsFromSyntax(str: string): string[] {
|
|
|
1977
1983
|
|
|
1978
1984
|
/**
|
|
1979
1985
|
* If you're using this type guard, make sure you're okay with Fragments
|
|
1980
|
-
* See
|
|
1986
|
+
* See # legacy issue 3426
|
|
1981
1987
|
*/
|
|
1982
|
-
export function checkIsGdocPost(x: unknown): x is
|
|
1983
|
-
const type = _.get(x, "content.type") as
|
|
1988
|
+
export function checkIsGdocPost(x: unknown): x is GdocPostInterface {
|
|
1989
|
+
const type = _.get(x, "content.type") as GdocType | undefined
|
|
1984
1990
|
return [
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1991
|
+
GdocType.Article,
|
|
1992
|
+
GdocType.TopicPage,
|
|
1993
|
+
GdocType.LinearTopicPage,
|
|
1994
|
+
GdocType.Fragment,
|
|
1995
|
+
GdocType.AboutPage,
|
|
1990
1996
|
].includes(type as any)
|
|
1991
1997
|
}
|
|
1992
1998
|
|
|
@@ -1994,40 +2000,40 @@ export function checkIsGdocPost(x: unknown): x is OwidGdocPostInterface {
|
|
|
1994
2000
|
* Fragments were developed before we had a robust gdoc type system in place
|
|
1995
2001
|
* Use this function when you want to be sure you're dealing with published editorial content
|
|
1996
2002
|
* and not just content that has the right shape
|
|
1997
|
-
* See
|
|
2003
|
+
* See # legacy issue 3426
|
|
1998
2004
|
*/
|
|
1999
2005
|
export function checkIsGdocPostExcludingFragments(
|
|
2000
2006
|
x: unknown
|
|
2001
|
-
): x is
|
|
2002
|
-
const type = _.get(x, "content.type") as
|
|
2007
|
+
): x is GdocPostInterface {
|
|
2008
|
+
const type = _.get(x, "content.type") as GdocType | undefined
|
|
2003
2009
|
return [
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2010
|
+
GdocType.Article,
|
|
2011
|
+
GdocType.TopicPage,
|
|
2012
|
+
GdocType.LinearTopicPage,
|
|
2013
|
+
GdocType.AboutPage,
|
|
2008
2014
|
].includes(type as any)
|
|
2009
2015
|
}
|
|
2010
2016
|
|
|
2011
2017
|
export function checkIsDataInsight(
|
|
2012
|
-
gdoc:
|
|
2013
|
-
): gdoc is
|
|
2014
|
-
return gdoc.content.type ===
|
|
2018
|
+
gdoc: Gdoc
|
|
2019
|
+
): gdoc is GdocDataInsightInterface {
|
|
2020
|
+
return gdoc.content.type === GdocType.DataInsight
|
|
2015
2021
|
}
|
|
2016
2022
|
|
|
2017
2023
|
export function checkIsAboutPage(
|
|
2018
|
-
gdoc:
|
|
2019
|
-
): gdoc is
|
|
2020
|
-
return gdoc.content.type ===
|
|
2024
|
+
gdoc: Gdoc
|
|
2025
|
+
): gdoc is GdocAboutInterface {
|
|
2026
|
+
return gdoc.content.type === GdocType.AboutPage
|
|
2021
2027
|
}
|
|
2022
2028
|
|
|
2023
|
-
export function checkIsAuthor(gdoc:
|
|
2024
|
-
return gdoc.content.type ===
|
|
2029
|
+
export function checkIsAuthor(gdoc: Gdoc): gdoc is GdocAuthorInterface {
|
|
2030
|
+
return gdoc.content.type === GdocType.Author
|
|
2025
2031
|
}
|
|
2026
2032
|
|
|
2027
2033
|
export function checkIsHomepage(
|
|
2028
|
-
gdoc:
|
|
2029
|
-
): gdoc is
|
|
2030
|
-
return gdoc.content.type ===
|
|
2034
|
+
gdoc: Gdoc
|
|
2035
|
+
): gdoc is GdocHomepageInterface {
|
|
2036
|
+
return gdoc.content.type === GdocType.Homepage
|
|
2031
2037
|
}
|
|
2032
2038
|
|
|
2033
2039
|
/**
|