@buildcanada/charts 0.1.1 → 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 +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
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buildcanada/charts",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A configurable data visualization library for creating interactive charts.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A configurable data visualization library for creating interactive charts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"types": "src/index.ts",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.
|
|
1
|
+
.charts-btn {
|
|
2
2
|
@include body-3-medium;
|
|
3
3
|
padding: 8.5px 24px;
|
|
4
4
|
border: 1px solid transparent;
|
|
@@ -7,23 +7,23 @@
|
|
|
7
7
|
display: block;
|
|
8
8
|
cursor: pointer;
|
|
9
9
|
|
|
10
|
-
&.
|
|
10
|
+
&.charts-btn--icon-only {
|
|
11
11
|
padding: 4.5px 9px;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
&:disabled {
|
|
15
15
|
cursor: default;
|
|
16
16
|
|
|
17
|
-
&.
|
|
18
|
-
&.
|
|
19
|
-
&.
|
|
20
|
-
&.
|
|
17
|
+
&.charts-btn--solid-blue,
|
|
18
|
+
&.charts-btn--solid-dark-blue,
|
|
19
|
+
&.charts-btn--solid-light-blue,
|
|
20
|
+
&.charts-btn--solid-vermillion {
|
|
21
21
|
color: $blue-50;
|
|
22
22
|
background-color: $blue-10;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
&.
|
|
26
|
-
&.
|
|
25
|
+
&.charts-btn--outline-vermillion,
|
|
26
|
+
&.charts-btn--outline-white {
|
|
27
27
|
color: $blue-40;
|
|
28
28
|
border-color: $blue-40;
|
|
29
29
|
}
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
.
|
|
37
|
+
.charts-btn--icon-right {
|
|
38
38
|
margin-left: 0.5rem;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
.
|
|
41
|
+
.charts-btn--icon-left {
|
|
42
42
|
margin-right: 0.5rem;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
.
|
|
45
|
+
.charts-btn--solid-vermillion {
|
|
46
46
|
background-color: $vermillion;
|
|
47
47
|
color: #fff;
|
|
48
48
|
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
.
|
|
54
|
+
.charts-btn--outline-vermillion {
|
|
55
55
|
border-color: $vermillion;
|
|
56
56
|
color: $vermillion;
|
|
57
57
|
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
.
|
|
64
|
+
.charts-btn--solid-blue {
|
|
65
65
|
background-color: $blue-60;
|
|
66
66
|
color: #fff;
|
|
67
67
|
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
.
|
|
73
|
+
.charts-btn--solid-dark-blue {
|
|
74
74
|
background-color: $blue-95;
|
|
75
75
|
color: #fff;
|
|
76
76
|
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
.
|
|
82
|
+
.charts-btn--solid-light-blue {
|
|
83
83
|
background-color: $blue-20;
|
|
84
84
|
color: $blue-90;
|
|
85
85
|
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
.
|
|
91
|
+
.charts-btn--outline-white {
|
|
92
92
|
background-color: transparent;
|
|
93
93
|
border-color: $white;
|
|
94
94
|
color: $white;
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
.
|
|
102
|
+
.charts-btn--outline-light-blue {
|
|
103
103
|
border-color: $blue-20;
|
|
104
104
|
color: $blue-90;
|
|
105
105
|
|
|
@@ -52,21 +52,21 @@ export const Button = ({
|
|
|
52
52
|
dataTrackNote,
|
|
53
53
|
disabled,
|
|
54
54
|
}: ButtonProps) => {
|
|
55
|
-
const classes = cx("
|
|
56
|
-
"
|
|
55
|
+
const classes = cx("charts-btn", `charts-btn--${theme}`, className, {
|
|
56
|
+
"charts-btn--icon-only": icon && !text,
|
|
57
57
|
})
|
|
58
58
|
const content = (
|
|
59
59
|
<>
|
|
60
60
|
{iconPosition === "left" && icon && (
|
|
61
61
|
<FontAwesomeIcon
|
|
62
|
-
className={cx({ "
|
|
62
|
+
className={cx({ "charts-btn--icon-left": text })}
|
|
63
63
|
icon={icon}
|
|
64
64
|
/>
|
|
65
65
|
)}
|
|
66
66
|
{text && <span>{text}</span>}
|
|
67
67
|
{iconPosition !== "left" && icon && (
|
|
68
68
|
<FontAwesomeIcon
|
|
69
|
-
className={cx({ "
|
|
69
|
+
className={cx({ "charts-btn--icon-right": text })}
|
|
70
70
|
icon={icon}
|
|
71
71
|
/>
|
|
72
72
|
)}
|
|
@@ -427,7 +427,7 @@ export const isTextToken = (token: IRToken): token is IRText | IRWhitespace =>
|
|
|
427
427
|
* translated.
|
|
428
428
|
* This is to be run _just before_ rendering to HTML, because it loses some
|
|
429
429
|
* information and is not easily reversible.
|
|
430
|
-
* See also
|
|
430
|
+
* See also # legacy issue 1785
|
|
431
431
|
*/
|
|
432
432
|
export const recursiveMergeTextTokens = (
|
|
433
433
|
tokens: IRToken[],
|
package/src/components/index.ts
CHANGED
|
@@ -47,7 +47,7 @@ export { reactRenderToStringClientOnly } from "./reactUtil.js"
|
|
|
47
47
|
export { GrapherTabIcon } from "./GrapherTabIcon.js"
|
|
48
48
|
export { GrapherTrendArrow } from "./GrapherTrendArrow.js"
|
|
49
49
|
|
|
50
|
-
// Stub components for
|
|
50
|
+
// Stub components for data page features
|
|
51
51
|
export { CodeSnippet } from "./stubs/CodeSnippet.js"
|
|
52
52
|
export {
|
|
53
53
|
makeSource,
|
|
@@ -105,7 +105,7 @@ $sdgColors: (
|
|
|
105
105
|
);
|
|
106
106
|
|
|
107
107
|
:root {
|
|
108
|
-
// See also
|
|
108
|
+
// See also gdocTypes/Gdoc.ts > GdocPostContent > cover-color
|
|
109
109
|
--amber: #{$amber};
|
|
110
110
|
@each $i, $sdgColor in $sdgColors {
|
|
111
111
|
--sdg-color-#{$i}: #{$sdgColor};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
@use "sass:math";
|
|
2
2
|
|
|
3
|
-
@mixin
|
|
3
|
+
@mixin link-90 {
|
|
4
4
|
color: $blue-90;
|
|
5
5
|
text-decoration: underline;
|
|
6
6
|
text-underline-offset: 4px;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
@mixin
|
|
16
|
+
@mixin link-60 {
|
|
17
17
|
color: $blue-60;
|
|
18
18
|
text-decoration: underline;
|
|
19
19
|
text-underline-offset: 4px;
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
@mixin
|
|
29
|
+
@mixin link-40 {
|
|
30
30
|
color: $blue-40;
|
|
31
31
|
text-decoration: underline;
|
|
32
32
|
text-underline-offset: 4px;
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
a {
|
|
73
|
-
@include
|
|
73
|
+
@include link-90;
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -517,7 +517,7 @@
|
|
|
517
517
|
}
|
|
518
518
|
}
|
|
519
519
|
|
|
520
|
-
@mixin
|
|
520
|
+
@mixin charts-checkbox {
|
|
521
521
|
background: #fff;
|
|
522
522
|
appearance: none;
|
|
523
523
|
width: 16px;
|
|
@@ -24,9 +24,9 @@ import {
|
|
|
24
24
|
CoreValueType,
|
|
25
25
|
ColumnTypeNames,
|
|
26
26
|
EntityName,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
ColumnDef,
|
|
28
|
+
Row,
|
|
29
|
+
ChartsTableSlugs,
|
|
30
30
|
ErrorValue,
|
|
31
31
|
ToleranceOptions,
|
|
32
32
|
} from "../types/index.js"
|
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
makeOriginalStartTimeSlugFromColumnSlug,
|
|
40
40
|
timeColumnSlugFromColumnDef,
|
|
41
41
|
toPercentageColumnDef,
|
|
42
|
-
} from "./
|
|
42
|
+
} from "./TableUtil.js"
|
|
43
43
|
import {
|
|
44
44
|
linearInterpolation,
|
|
45
45
|
toleranceInterpolation,
|
|
@@ -49,10 +49,10 @@ import {
|
|
|
49
49
|
} from "./CoreTableUtils.js"
|
|
50
50
|
import { CoreColumn, ColumnTypeMap } from "./CoreTableColumns.js"
|
|
51
51
|
|
|
52
|
-
// An
|
|
52
|
+
// An ChartsTable is a subset of Table. An ChartsTable always has EntityName, EntityCode, EntityId, and Time columns,
|
|
53
53
|
// and value column(s). Whether or not we need in the long run is uncertain and it may just be a stepping stone
|
|
54
54
|
// to go from our Variables paradigm to the Table paradigm.
|
|
55
|
-
export class
|
|
55
|
+
export class ChartsTable extends CoreTable<Row, ColumnDef> {
|
|
56
56
|
@imemo get availableEntityNames(): any[] {
|
|
57
57
|
return Array.from(this.availableEntityNameSet)
|
|
58
58
|
}
|
|
@@ -64,7 +64,7 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> {
|
|
|
64
64
|
@imemo override get entityNameColumn(): CoreColumn {
|
|
65
65
|
return (
|
|
66
66
|
this.getFirstColumnWithType(ColumnTypeNames.EntityName) ??
|
|
67
|
-
this.get(
|
|
67
|
+
this.get(ChartsTableSlugs.entityName)
|
|
68
68
|
)
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -84,7 +84,7 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> {
|
|
|
84
84
|
return this.rowIndex([this.entityNameSlug])
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
getAnnotationColumnSlug(columnDef:
|
|
87
|
+
getAnnotationColumnSlug(columnDef: ColumnDef): string | undefined {
|
|
88
88
|
return _.isEmpty(columnDef?.annotationsColumnSlug)
|
|
89
89
|
? makeAnnotationsSlug(columnDef.slug)
|
|
90
90
|
: columnDef.annotationsColumnSlug
|
|
@@ -92,7 +92,7 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> {
|
|
|
92
92
|
|
|
93
93
|
// todo: instead of this we should probably make annotations another property on charts—something like "annotationsColumnSlugs"
|
|
94
94
|
getAnnotationColumnForColumn(columnSlug: ColumnSlug): CoreColumn {
|
|
95
|
-
const def = this.get(columnSlug).def as
|
|
95
|
+
const def = this.get(columnSlug).def as ColumnDef
|
|
96
96
|
const slug = this.getAnnotationColumnSlug(def)
|
|
97
97
|
return this.get(slug)
|
|
98
98
|
}
|
|
@@ -179,7 +179,7 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> {
|
|
|
179
179
|
const adjustedStart = start === Infinity ? this.maxTime! : start
|
|
180
180
|
const adjustedEnd = end === -Infinity ? this.minTime! : end
|
|
181
181
|
// todo: we should set a time column onload so we don't have to worry about it again.
|
|
182
|
-
const timeColumnSlug = this.timeColumn?.slug ||
|
|
182
|
+
const timeColumnSlug = this.timeColumn?.slug || ChartsTableSlugs.time
|
|
183
183
|
|
|
184
184
|
const description = `Keep only rows with Time between ${adjustedStart} - ${adjustedEnd}`
|
|
185
185
|
|
|
@@ -543,7 +543,7 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> {
|
|
|
543
543
|
columnSlugs.forEach((valueSlug) => {
|
|
544
544
|
let comparisonValue: number
|
|
545
545
|
rowsForSingleEntity = rowsForSingleEntity.map(
|
|
546
|
-
(row: Readonly<
|
|
546
|
+
(row: Readonly<Row>) => {
|
|
547
547
|
const newRow = {
|
|
548
548
|
...row,
|
|
549
549
|
}
|
|
@@ -658,11 +658,11 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> {
|
|
|
658
658
|
this.getAverageAnnualChangeIndicesByEntity(columnSlugs)
|
|
659
659
|
|
|
660
660
|
// Overwrite table rows
|
|
661
|
-
const rows:
|
|
661
|
+
const rows: Row[] = []
|
|
662
662
|
entityNameToIndices.forEach((indices) => {
|
|
663
663
|
const [startRow, endRow] = this.rowsAt(indices)
|
|
664
664
|
|
|
665
|
-
const newRow:
|
|
665
|
+
const newRow: Row = { ...endRow }
|
|
666
666
|
columns.forEach((col) => {
|
|
667
667
|
const timeSlug = col.originalTimeColumnSlug
|
|
668
668
|
|
|
@@ -712,7 +712,7 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> {
|
|
|
712
712
|
)
|
|
713
713
|
}
|
|
714
714
|
|
|
715
|
-
// Give our users a clean CSV of each Grapher. Assumes
|
|
715
|
+
// Give our users a clean CSV of each Grapher. Assumes a ChartsTable with entityName.
|
|
716
716
|
toPrettyCsv(
|
|
717
717
|
useShortNames: boolean = false,
|
|
718
718
|
activeColumnSlugs: string[] | undefined = undefined
|
|
@@ -720,8 +720,8 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> {
|
|
|
720
720
|
let table
|
|
721
721
|
if (activeColumnSlugs?.length) {
|
|
722
722
|
const timeColumnToInclude = [
|
|
723
|
-
|
|
724
|
-
|
|
723
|
+
ChartsTableSlugs.year,
|
|
724
|
+
ChartsTableSlugs.day,
|
|
725
725
|
this.timeColumn.slug, // needed for explorers, where the time column may be called anything
|
|
726
726
|
].find((colSlug) => this.has(colSlug))
|
|
727
727
|
|
|
@@ -737,9 +737,9 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> {
|
|
|
737
737
|
])
|
|
738
738
|
} else {
|
|
739
739
|
table = this.dropColumns([
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
740
|
+
ChartsTableSlugs.entityId,
|
|
741
|
+
ChartsTableSlugs.time,
|
|
742
|
+
ChartsTableSlugs.entityColor,
|
|
743
743
|
])
|
|
744
744
|
}
|
|
745
745
|
return table
|
|
@@ -750,7 +750,7 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> {
|
|
|
750
750
|
@imemo get entityNameColorIndex(): Map<EntityName, Color> {
|
|
751
751
|
return this.valueIndex(
|
|
752
752
|
this.entityNameSlug,
|
|
753
|
-
|
|
753
|
+
ChartsTableSlugs.entityColor
|
|
754
754
|
) as Map<EntityName, Color>
|
|
755
755
|
}
|
|
756
756
|
|
|
@@ -836,7 +836,7 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> {
|
|
|
836
836
|
if (!this.has(columnSlug)) return this
|
|
837
837
|
|
|
838
838
|
const column = this.get(columnSlug)
|
|
839
|
-
const columnDef = column.def as
|
|
839
|
+
const columnDef = column.def as ColumnDef
|
|
840
840
|
const tolerance = toleranceOverride ?? column.tolerance ?? 0
|
|
841
841
|
const toleranceStrategy =
|
|
842
842
|
toleranceStrategyOverride ??
|
|
@@ -846,7 +846,7 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> {
|
|
|
846
846
|
const timeColumnOfTable = !this.timeColumn.isMissing
|
|
847
847
|
? this.timeColumn
|
|
848
848
|
: // CovidTable does not have a day or year column so we need to use time.
|
|
849
|
-
(this.get(
|
|
849
|
+
(this.get(ChartsTableSlugs.time) as CoreColumn)
|
|
850
850
|
|
|
851
851
|
const maybeTimeColumnOfValue =
|
|
852
852
|
getOriginalTimeColumnSlug(this, columnSlug) ??
|
|
@@ -923,14 +923,14 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> {
|
|
|
923
923
|
if (!this.has(columnSlug)) return this
|
|
924
924
|
|
|
925
925
|
const column = this.get(columnSlug)
|
|
926
|
-
const columnDef = column?.def as
|
|
926
|
+
const columnDef = column?.def as ColumnDef
|
|
927
927
|
|
|
928
928
|
const maybeTimeColumnSlug =
|
|
929
929
|
getOriginalTimeColumnSlug(this, columnSlug) ??
|
|
930
930
|
timeColumnSlugFromColumnDef(columnDef)
|
|
931
931
|
const timeColumn =
|
|
932
932
|
this.get(maybeTimeColumnSlug) ??
|
|
933
|
-
(this.get(
|
|
933
|
+
(this.get(ChartsTableSlugs.time) as CoreColumn) // CovidTable does not have a day or year column so we need to use time.
|
|
934
934
|
|
|
935
935
|
const originalColumnSlug =
|
|
936
936
|
makeOriginalValueSlugFromColumnSlug(columnSlug)
|
|
@@ -1157,16 +1157,16 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> {
|
|
|
1157
1157
|
|
|
1158
1158
|
const BLANK_TABLE_MESSAGE = `Table is empty.`
|
|
1159
1159
|
|
|
1160
|
-
// This just assures that even an emtpty
|
|
1161
|
-
export const
|
|
1162
|
-
tableSlug = `
|
|
1160
|
+
// This just assures that even an emtpty ChartsTable will have an entityName column. Probably a cleaner way to do this pattern (add a defaultColumns prop??)
|
|
1161
|
+
export const BlankChartsTable = (
|
|
1162
|
+
tableSlug = `blankChartsTable`,
|
|
1163
1163
|
extraTableDescription = ""
|
|
1164
|
-
):
|
|
1165
|
-
new
|
|
1164
|
+
): ChartsTable =>
|
|
1165
|
+
new ChartsTable(
|
|
1166
1166
|
undefined,
|
|
1167
1167
|
[
|
|
1168
|
-
{ slug:
|
|
1169
|
-
{ slug:
|
|
1168
|
+
{ slug: ChartsTableSlugs.entityName },
|
|
1169
|
+
{ slug: ChartsTableSlugs.year, type: ColumnTypeNames.Year },
|
|
1170
1170
|
],
|
|
1171
1171
|
{
|
|
1172
1172
|
tableDescription: BLANK_TABLE_MESSAGE + extraTableDescription,
|
|
@@ -28,8 +28,8 @@ import {
|
|
|
28
28
|
ColumnTypeNames,
|
|
29
29
|
CoreColumnDef,
|
|
30
30
|
JsTypes,
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
ChartsTableSlugs,
|
|
32
|
+
ColumnDef,
|
|
33
33
|
} from "../types/index.js"
|
|
34
34
|
import {
|
|
35
35
|
makeAutoTypeFn,
|
|
@@ -65,7 +65,7 @@ interface AdvancedOptions {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// The complex generic with default here just enables you to optionally specify a more
|
|
68
|
-
// narrow interface for the input rows. This is helpful for
|
|
68
|
+
// narrow interface for the input rows. This is helpful for ChartsTable.
|
|
69
69
|
export class CoreTable<
|
|
70
70
|
ROW_TYPE extends CoreRow = CoreRow,
|
|
71
71
|
COL_DEF_TYPE extends CoreColumnDef = CoreColumnDef,
|
|
@@ -232,7 +232,7 @@ export class CoreTable<
|
|
|
232
232
|
// If we ever pass Mobx observable arrays, we need to convert them to regular arrays.
|
|
233
233
|
// Otherwise, operations like `.concat()` will break in unexpected ways.
|
|
234
234
|
// See https://github.com/mobxjs/mobx/blob/mobx4and5/docs/best/pitfalls.md
|
|
235
|
-
// Also, see
|
|
235
|
+
// Also, see # legacy issue 2948 for an issue caused by this problem.
|
|
236
236
|
type CoreValueArrayThatMayBeMobxProxy = CoreValueType[] & {
|
|
237
237
|
toJS?: () => CoreValueType[]
|
|
238
238
|
}
|
|
@@ -468,14 +468,14 @@ export class CoreTable<
|
|
|
468
468
|
)
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
-
// todo: move this. time methods should not be in CoreTable, in
|
|
471
|
+
// todo: move this. time methods should not be in CoreTable, in ChartsTable instead (which is really TimeSeriesTable).
|
|
472
472
|
// TODO: remove this. Currently we use this to get the right day/year time formatting. For now a chart is either a "day chart" or a "year chart".
|
|
473
473
|
// But we can have charts with multiple time columns. Ideally each place that needs access to the timeColumn, would get the specific column
|
|
474
474
|
// and not the first time column from the table.
|
|
475
475
|
@imemo get timeColumn(): TimeColumn | MissingColumn {
|
|
476
476
|
// "time" is the canonical time column slug.
|
|
477
|
-
// See
|
|
478
|
-
const maybeTimeColumn = this.get(
|
|
477
|
+
// See LegacyToChartsTable where this column is injected for all Graphers.
|
|
478
|
+
const maybeTimeColumn = this.get(ChartsTableSlugs.time)
|
|
479
479
|
if (maybeTimeColumn instanceof ColumnTypeMap.Time)
|
|
480
480
|
return maybeTimeColumn
|
|
481
481
|
// If a valid "time" column doesn't exist, find _some_ time column to use.
|
|
@@ -496,15 +496,15 @@ export class CoreTable<
|
|
|
496
496
|
maybeTimeColumn) as TimeColumn | MissingColumn
|
|
497
497
|
}
|
|
498
498
|
|
|
499
|
-
// todo: should be on
|
|
499
|
+
// todo: should be on ChartsTable
|
|
500
500
|
@imemo get entityNameColumn(): CoreColumn {
|
|
501
501
|
return (
|
|
502
502
|
this.getFirstColumnWithType(ColumnTypeNames.EntityName) ??
|
|
503
|
-
this.get(
|
|
503
|
+
this.get(ChartsTableSlugs.entityName)
|
|
504
504
|
)
|
|
505
505
|
}
|
|
506
506
|
|
|
507
|
-
// todo: should be on
|
|
507
|
+
// todo: should be on ChartsTable
|
|
508
508
|
@imemo get entityNameSlug(): string {
|
|
509
509
|
return this.entityNameColumn.slug
|
|
510
510
|
}
|
|
@@ -854,8 +854,8 @@ export class CoreTable<
|
|
|
854
854
|
this.columnsAsArray
|
|
855
855
|
.map((col) =>
|
|
856
856
|
csvEscape(
|
|
857
|
-
useShortNames && (col.def as
|
|
858
|
-
? (col.def as
|
|
857
|
+
useShortNames && (col.def as ColumnDef).shortName
|
|
858
|
+
? (col.def as ColumnDef).shortName
|
|
859
859
|
: col.name
|
|
860
860
|
)
|
|
861
861
|
)
|
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
omitUndefinedValues,
|
|
10
10
|
isPresent,
|
|
11
11
|
dayjs,
|
|
12
|
-
|
|
12
|
+
Source,
|
|
13
13
|
formatValue,
|
|
14
14
|
checkIsVeryShortUnit,
|
|
15
15
|
TickFormattingOptions,
|
|
16
|
-
|
|
16
|
+
VariableDisplayConfigInterface,
|
|
17
17
|
ColumnSlug,
|
|
18
18
|
PrimitiveType,
|
|
19
19
|
imemo,
|
|
@@ -29,16 +29,16 @@ import {
|
|
|
29
29
|
ColumnTypeNames,
|
|
30
30
|
CoreColumnDef,
|
|
31
31
|
EntityName,
|
|
32
|
-
|
|
32
|
+
VariableRow,
|
|
33
33
|
ErrorValue,
|
|
34
|
-
|
|
34
|
+
VariableRoundingMode,
|
|
35
35
|
} from "../types/index.js"
|
|
36
36
|
import { ErrorValueTypes, isNotErrorValue } from "./ErrorValues.js"
|
|
37
37
|
import {
|
|
38
38
|
getOriginalStartTimeColumnSlug,
|
|
39
39
|
getOriginalTimeColumnSlug,
|
|
40
40
|
getOriginalValueColumnSlug,
|
|
41
|
-
} from "./
|
|
41
|
+
} from "./TableUtil.js"
|
|
42
42
|
import * as R from "remeda"
|
|
43
43
|
|
|
44
44
|
export abstract class AbstractCoreColumn<JS_TYPE extends PrimitiveType> {
|
|
@@ -86,7 +86,7 @@ export abstract class AbstractCoreColumn<JS_TYPE extends PrimitiveType> {
|
|
|
86
86
|
return this.def.toleranceStrategy
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
@imemo get display():
|
|
89
|
+
@imemo get display(): VariableDisplayConfigInterface | undefined {
|
|
90
90
|
return this.def.display
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -130,18 +130,18 @@ export abstract class AbstractCoreColumn<JS_TYPE extends PrimitiveType> {
|
|
|
130
130
|
return this.originalTimeColumn.formatValue(time)
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
@imemo get roundingMode():
|
|
133
|
+
@imemo get roundingMode(): VariableRoundingMode {
|
|
134
134
|
return (
|
|
135
|
-
this.display?.roundingMode ??
|
|
135
|
+
this.display?.roundingMode ?? VariableRoundingMode.decimalPlaces
|
|
136
136
|
)
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
@imemo get roundsToFixedDecimals(): boolean {
|
|
140
|
-
return this.roundingMode ===
|
|
140
|
+
return this.roundingMode === VariableRoundingMode.decimalPlaces
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
@imemo get roundsToSignificantFigures(): boolean {
|
|
144
|
-
return this.roundingMode ===
|
|
144
|
+
return this.roundingMode === VariableRoundingMode.significantFigures
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
@imemo get numDecimalPlaces(): number {
|
|
@@ -418,7 +418,7 @@ export abstract class AbstractCoreColumn<JS_TYPE extends PrimitiveType> {
|
|
|
418
418
|
return this.jsType === "string" ? values.sort() : sortNumeric(values)
|
|
419
419
|
}
|
|
420
420
|
|
|
421
|
-
get source():
|
|
421
|
+
get source(): Source {
|
|
422
422
|
const { def } = this
|
|
423
423
|
return {
|
|
424
424
|
name: def.sourceName,
|
|
@@ -465,7 +465,7 @@ export abstract class AbstractCoreColumn<JS_TYPE extends PrimitiveType> {
|
|
|
465
465
|
|
|
466
466
|
// todo: remove? Should not be on CoreTable
|
|
467
467
|
// assumes table is sorted by time
|
|
468
|
-
@imemo get
|
|
468
|
+
@imemo get dataRows(): VariableRow<JS_TYPE>[] {
|
|
469
469
|
const entities = this.allEntityNames
|
|
470
470
|
const times = this.allTimes
|
|
471
471
|
const values = this.values
|
|
@@ -483,12 +483,12 @@ export abstract class AbstractCoreColumn<JS_TYPE extends PrimitiveType> {
|
|
|
483
483
|
}
|
|
484
484
|
|
|
485
485
|
// todo: remove? Should not be on CoreTable
|
|
486
|
-
@imemo get
|
|
486
|
+
@imemo get dataRowsByEntityName(): Map<
|
|
487
487
|
EntityName,
|
|
488
|
-
|
|
488
|
+
VariableRow<JS_TYPE>[]
|
|
489
489
|
> {
|
|
490
|
-
const map = new Map<EntityName,
|
|
491
|
-
this.
|
|
490
|
+
const map = new Map<EntityName, VariableRow<JS_TYPE>[]>()
|
|
491
|
+
this.dataRows.forEach((row) => {
|
|
492
492
|
if (!map.has(row.entityName)) map.set(row.entityName, [])
|
|
493
493
|
map.get(row.entityName)!.push(row)
|
|
494
494
|
})
|
|
@@ -496,15 +496,15 @@ export abstract class AbstractCoreColumn<JS_TYPE extends PrimitiveType> {
|
|
|
496
496
|
}
|
|
497
497
|
|
|
498
498
|
// todo: remove? Should not be on CoreTable
|
|
499
|
-
@imemo get
|
|
499
|
+
@imemo get dataRowByEntityNameAndTime(): Map<
|
|
500
500
|
EntityName,
|
|
501
|
-
Map<Time,
|
|
501
|
+
Map<Time, VariableRow<JS_TYPE>>
|
|
502
502
|
> {
|
|
503
503
|
const valueByEntityNameAndTime = new Map<
|
|
504
504
|
EntityName,
|
|
505
|
-
Map<Time,
|
|
505
|
+
Map<Time, VariableRow<JS_TYPE>>
|
|
506
506
|
>()
|
|
507
|
-
this.
|
|
507
|
+
this.dataRows.forEach((row) => {
|
|
508
508
|
if (!valueByEntityNameAndTime.has(row.entityName))
|
|
509
509
|
valueByEntityNameAndTime.set(row.entityName, new Map())
|
|
510
510
|
valueByEntityNameAndTime.get(row.entityName)!.set(row.time, row)
|
|
@@ -515,7 +515,7 @@ export abstract class AbstractCoreColumn<JS_TYPE extends PrimitiveType> {
|
|
|
515
515
|
// todo: remove? Should not be on CoreTable
|
|
516
516
|
@imemo get valuesByTime(): Map<Time, JS_TYPE[]> {
|
|
517
517
|
const map = new Map<Time, JS_TYPE[]>()
|
|
518
|
-
this.
|
|
518
|
+
this.dataRows.forEach((row) => {
|
|
519
519
|
if (!map.has(row.time)) map.set(row.time, [])
|
|
520
520
|
map.get(row.time)!.push(row.value)
|
|
521
521
|
})
|
|
@@ -528,7 +528,7 @@ export abstract class AbstractCoreColumn<JS_TYPE extends PrimitiveType> {
|
|
|
528
528
|
Time,
|
|
529
529
|
Map<EntityName, JS_TYPE>
|
|
530
530
|
>()
|
|
531
|
-
this.
|
|
531
|
+
this.dataRows.forEach((row) => {
|
|
532
532
|
if (!valueByTimeAndEntityName.has(row.time))
|
|
533
533
|
valueByTimeAndEntityName.set(row.time, new Map())
|
|
534
534
|
valueByTimeAndEntityName
|
|
@@ -548,7 +548,7 @@ export abstract class AbstractCoreColumn<JS_TYPE extends PrimitiveType> {
|
|
|
548
548
|
EntityName,
|
|
549
549
|
Map<Time, JS_TYPE>
|
|
550
550
|
>()
|
|
551
|
-
this.
|
|
551
|
+
this.dataRows.forEach((row) => {
|
|
552
552
|
if (!valueByEntityNameAndTime.has(row.entityName))
|
|
553
553
|
valueByEntityNameAndTime.set(row.entityName, new Map())
|
|
554
554
|
valueByEntityNameAndTime
|
|
@@ -758,7 +758,7 @@ class CurrencyColumn extends NumericColumn {
|
|
|
758
758
|
options?: TickFormattingOptions
|
|
759
759
|
): string {
|
|
760
760
|
return super.formatValue(value, {
|
|
761
|
-
roundingMode:
|
|
761
|
+
roundingMode: VariableRoundingMode.decimalPlaces,
|
|
762
762
|
numDecimalPlaces: 0,
|
|
763
763
|
unit: this.shortUnit,
|
|
764
764
|
...options,
|