@buildcanada/charts 0.1.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/LICENSE.md +8 -0
- package/README.md +113 -0
- package/package.json +137 -0
- package/src/components/BodyPortal/BodyPortal.tsx +40 -0
- package/src/components/Button/Button.scss +110 -0
- package/src/components/Button/Button.tsx +101 -0
- package/src/components/Checkbox.scss +93 -0
- package/src/components/Checkbox.tsx +47 -0
- package/src/components/ExpandableToggle/ExpandableToggle.scss +123 -0
- package/src/components/ExpandableToggle/ExpandableToggle.tsx +60 -0
- package/src/components/GrapherTabIcon.tsx +156 -0
- package/src/components/GrapherTrendArrow.scss +16 -0
- package/src/components/GrapherTrendArrow.tsx +30 -0
- package/src/components/Halo/Halo.tsx +44 -0
- package/src/components/LabeledSwitch/LabeledSwitch.scss +109 -0
- package/src/components/LabeledSwitch/LabeledSwitch.tsx +62 -0
- package/src/components/MarkdownTextWrap/MarkdownTextWrap.tsx +1173 -0
- package/src/components/OverlayHeader.scss +18 -0
- package/src/components/OverlayHeader.tsx +29 -0
- package/src/components/RadioButton.scss +69 -0
- package/src/components/RadioButton.tsx +42 -0
- package/src/components/SimpleMarkdownText.tsx +89 -0
- package/src/components/TextInput.scss +17 -0
- package/src/components/TextInput.tsx +19 -0
- package/src/components/TextWrap/TextWrap.tsx +361 -0
- package/src/components/TextWrap/TextWrapUtils.ts +32 -0
- package/src/components/closeButton/CloseButton.scss +40 -0
- package/src/components/closeButton/CloseButton.tsx +27 -0
- package/src/components/index.ts +70 -0
- package/src/components/loadingIndicator/LoadingIndicator.scss +40 -0
- package/src/components/loadingIndicator/LoadingIndicator.tsx +28 -0
- package/src/components/markdown/remarkPlainLinks.ts +36 -0
- package/src/components/reactUtil.ts +20 -0
- package/src/components/stubs/CodeSnippet.tsx +19 -0
- package/src/components/stubs/DataCitation.tsx +16 -0
- package/src/components/stubs/IndicatorKeyData.tsx +45 -0
- package/src/components/stubs/IndicatorProcessing.tsx +15 -0
- package/src/components/stubs/IndicatorSources.tsx +15 -0
- package/src/components/styles/colors.scss +113 -0
- package/src/components/styles/mixins.scss +630 -0
- package/src/components/styles/typography.scss +579 -0
- package/src/components/styles/util.scss +89 -0
- package/src/components/styles/variables.scss +208 -0
- package/src/config/ChartsConfig.ts +163 -0
- package/src/config/ChartsProvider.tsx +157 -0
- package/src/config/index.ts +20 -0
- package/src/core-table/CoreTable.ts +1355 -0
- package/src/core-table/CoreTableColumns.ts +973 -0
- package/src/core-table/CoreTableUtils.ts +793 -0
- package/src/core-table/ErrorValues.ts +73 -0
- package/src/core-table/OwidTable.ts +1175 -0
- package/src/core-table/OwidTableSynthesizers.ts +272 -0
- package/src/core-table/OwidTableUtil.ts +76 -0
- package/src/core-table/Transforms.ts +484 -0
- package/src/core-table/index.ts +82 -0
- package/src/explorer/ColumnGrammar.ts +217 -0
- package/src/explorer/Explorer.sample.ts +212 -0
- package/src/explorer/Explorer.scss +148 -0
- package/src/explorer/Explorer.tsx +1283 -0
- package/src/explorer/ExplorerConstants.ts +85 -0
- package/src/explorer/ExplorerControls.scss +156 -0
- package/src/explorer/ExplorerControls.tsx +210 -0
- package/src/explorer/ExplorerDecisionMatrix.ts +471 -0
- package/src/explorer/ExplorerGrammar.ts +161 -0
- package/src/explorer/ExplorerProgram.ts +568 -0
- package/src/explorer/ExplorerUtils.ts +59 -0
- package/src/explorer/GrapherGrammar.ts +387 -0
- package/src/explorer/gridLang/GrammarUtils.ts +121 -0
- package/src/explorer/gridLang/GridCell.ts +298 -0
- package/src/explorer/gridLang/GridLangConstants.ts +255 -0
- package/src/explorer/gridLang/GridProgram.ts +311 -0
- package/src/explorer/gridLang/readme.md +17 -0
- package/src/explorer/index.ts +69 -0
- package/src/explorer/readme.md +19 -0
- package/src/explorer/urlMigrations/CO2UrlMigration.ts +46 -0
- package/src/explorer/urlMigrations/CovidUrlMigration.ts +37 -0
- package/src/explorer/urlMigrations/EnergyUrlMigration.ts +41 -0
- package/src/explorer/urlMigrations/ExplorerPageUrlMigrationSpec.ts +12 -0
- package/src/explorer/urlMigrations/ExplorerUrlMigrationUtils.ts +45 -0
- package/src/explorer/urlMigrations/ExplorerUrlMigrations.ts +33 -0
- package/src/explorer/urlMigrations/LegacyCovidUrlMigration.ts +144 -0
- package/src/explorer/urlMigrations/readme.md +39 -0
- package/src/grapher/axis/Axis.ts +973 -0
- package/src/grapher/axis/AxisConfig.ts +179 -0
- package/src/grapher/axis/AxisViews.tsx +597 -0
- package/src/grapher/barCharts/DiscreteBarChart.tsx +728 -0
- package/src/grapher/barCharts/DiscreteBarChartConstants.ts +60 -0
- package/src/grapher/barCharts/DiscreteBarChartHelpers.ts +338 -0
- package/src/grapher/barCharts/DiscreteBarChartState.ts +354 -0
- package/src/grapher/barCharts/DiscreteBarChartThumbnail.tsx +34 -0
- package/src/grapher/captionedChart/CaptionedChart.scss +61 -0
- package/src/grapher/captionedChart/CaptionedChart.tsx +523 -0
- package/src/grapher/captionedChart/Logos.tsx +141 -0
- package/src/grapher/captionedChart/LogosSVG.tsx +16 -0
- package/src/grapher/captionedChart/StaticChartRasterizer.tsx +178 -0
- package/src/grapher/captionedChart/assets/buildcanada-logo-square.svg +15 -0
- package/src/grapher/captionedChart/assets/buildcanada-logo.svg +15 -0
- package/src/grapher/captionedChart/assets/canadaspends.svg +7 -0
- package/src/grapher/captionedChart/readme.md +14 -0
- package/src/grapher/chart/Chart.tsx +62 -0
- package/src/grapher/chart/ChartAreaContent.tsx +172 -0
- package/src/grapher/chart/ChartDimension.ts +121 -0
- package/src/grapher/chart/ChartInterface.ts +83 -0
- package/src/grapher/chart/ChartManager.ts +113 -0
- package/src/grapher/chart/ChartTabs.ts +178 -0
- package/src/grapher/chart/ChartTypeMap.tsx +158 -0
- package/src/grapher/chart/ChartTypeSwitcher.tsx +26 -0
- package/src/grapher/chart/ChartUtils.tsx +364 -0
- package/src/grapher/chart/DimensionSlot.ts +45 -0
- package/src/grapher/chart/StaticChartWrapper.tsx +94 -0
- package/src/grapher/chart/guidedChartUtils.ts +82 -0
- package/src/grapher/color/BinningStrategies.ts +484 -0
- package/src/grapher/color/BinningStrategyEqualSizeBins.ts +132 -0
- package/src/grapher/color/BinningStrategyLogarithmic.ts +121 -0
- package/src/grapher/color/CategoricalColorAssigner.ts +97 -0
- package/src/grapher/color/ColorBrewerSchemes.ts +80 -0
- package/src/grapher/color/ColorConstants.ts +20 -0
- package/src/grapher/color/ColorScale.ts +339 -0
- package/src/grapher/color/ColorScaleBin.ts +147 -0
- package/src/grapher/color/ColorScaleConfig.ts +204 -0
- package/src/grapher/color/ColorScheme.ts +137 -0
- package/src/grapher/color/ColorSchemes.ts +149 -0
- package/src/grapher/color/ColorUtils.ts +86 -0
- package/src/grapher/color/CustomSchemes.ts +1772 -0
- package/src/grapher/color/readme.md +84 -0
- package/src/grapher/comparisonLine/ComparisonLine.tsx +31 -0
- package/src/grapher/comparisonLine/ComparisonLineConstants.ts +11 -0
- package/src/grapher/comparisonLine/ComparisonLineGenerator.ts +60 -0
- package/src/grapher/comparisonLine/ComparisonLineHelpers.ts +10 -0
- package/src/grapher/comparisonLine/CustomComparisonLine.tsx +159 -0
- package/src/grapher/comparisonLine/VerticalComparisonLine.tsx +208 -0
- package/src/grapher/controls/ActionButtons.scss +97 -0
- package/src/grapher/controls/ActionButtons.tsx +453 -0
- package/src/grapher/controls/CommandPalette.scss +50 -0
- package/src/grapher/controls/CommandPalette.tsx +74 -0
- package/src/grapher/controls/ContentSwitchers.scss +93 -0
- package/src/grapher/controls/ContentSwitchers.tsx +238 -0
- package/src/grapher/controls/Controls.scss +158 -0
- package/src/grapher/controls/DataTableFilterDropdown.scss +7 -0
- package/src/grapher/controls/DataTableFilterDropdown.tsx +168 -0
- package/src/grapher/controls/DataTableSearchField.scss +3 -0
- package/src/grapher/controls/DataTableSearchField.tsx +76 -0
- package/src/grapher/controls/Dropdown.scss +252 -0
- package/src/grapher/controls/Dropdown.tsx +235 -0
- package/src/grapher/controls/EntitySelectionToggle.tsx +135 -0
- package/src/grapher/controls/MapRegionDropdown.scss +3 -0
- package/src/grapher/controls/MapRegionDropdown.tsx +104 -0
- package/src/grapher/controls/MapResetButton.tsx +115 -0
- package/src/grapher/controls/MapZoomDropdown.scss +9 -0
- package/src/grapher/controls/MapZoomDropdown.tsx +270 -0
- package/src/grapher/controls/MapZoomToSelectionButton.tsx +87 -0
- package/src/grapher/controls/SearchField.scss +78 -0
- package/src/grapher/controls/SearchField.tsx +63 -0
- package/src/grapher/controls/SettingsMenu.scss +191 -0
- package/src/grapher/controls/SettingsMenu.tsx +399 -0
- package/src/grapher/controls/ShareMenu.scss +58 -0
- package/src/grapher/controls/ShareMenu.tsx +304 -0
- package/src/grapher/controls/SortIcon.tsx +39 -0
- package/src/grapher/controls/VerticalScrollContainer.tsx +263 -0
- package/src/grapher/controls/controlsRow/ControlsRow.tsx +168 -0
- package/src/grapher/controls/dropdown-icons.scss +4 -0
- package/src/grapher/controls/entityPicker/EntityPicker.scss +255 -0
- package/src/grapher/controls/entityPicker/EntityPicker.tsx +816 -0
- package/src/grapher/controls/entityPicker/EntityPickerConstants.ts +23 -0
- package/src/grapher/controls/globalEntitySelector/GlobalEntitySelector.scss +129 -0
- package/src/grapher/controls/globalEntitySelector/GlobalEntitySelector.tsx +463 -0
- package/src/grapher/controls/globalEntitySelector/GlobalEntitySelectorConstants.ts +3 -0
- package/src/grapher/controls/globalEntitySelector/readme.md +17 -0
- package/src/grapher/controls/settings/AbsRelToggle.tsx +64 -0
- package/src/grapher/controls/settings/AxisScaleToggle.tsx +53 -0
- package/src/grapher/controls/settings/FacetStrategySelector.tsx +110 -0
- package/src/grapher/controls/settings/FacetYDomainToggle.tsx +51 -0
- package/src/grapher/controls/settings/NoDataAreaToggle.tsx +38 -0
- package/src/grapher/controls/settings/ZoomToggle.tsx +36 -0
- package/src/grapher/core/EntitiesByRegionType.ts +174 -0
- package/src/grapher/core/EntityCodes.ts +19 -0
- package/src/grapher/core/EntityUrlBuilder.ts +200 -0
- package/src/grapher/core/FetchingGrapher.tsx +156 -0
- package/src/grapher/core/Grapher.tsx +760 -0
- package/src/grapher/core/GrapherAnalytics.ts +229 -0
- package/src/grapher/core/GrapherConstants.ts +173 -0
- package/src/grapher/core/GrapherState.tsx +3659 -0
- package/src/grapher/core/GrapherUrl.ts +184 -0
- package/src/grapher/core/GrapherUrlMigrations.ts +29 -0
- package/src/grapher/core/GrapherUseHelpers.tsx +147 -0
- package/src/grapher/core/LegacyToOwidTable.ts +841 -0
- package/src/grapher/core/grapher.entry.ts +5 -0
- package/src/grapher/core/grapher.scss +257 -0
- package/src/grapher/core/loadGrapherTableHelpers.ts +116 -0
- package/src/grapher/core/loadVariable.ts +104 -0
- package/src/grapher/core/relatedQuestion.ts +12 -0
- package/src/grapher/core/typography.scss +206 -0
- package/src/grapher/dataTable/DataTable.sample.ts +206 -0
- package/src/grapher/dataTable/DataTable.scss +249 -0
- package/src/grapher/dataTable/DataTable.tsx +1332 -0
- package/src/grapher/dataTable/DataTableConstants.ts +186 -0
- package/src/grapher/entitySelector/EntitySelector.scss +255 -0
- package/src/grapher/entitySelector/EntitySelector.tsx +1838 -0
- package/src/grapher/facet/FacetChart.tsx +943 -0
- package/src/grapher/facet/FacetChartConstants.ts +24 -0
- package/src/grapher/facet/FacetChartUtils.ts +51 -0
- package/src/grapher/facet/FacetMap.tsx +604 -0
- package/src/grapher/facet/FacetMapConstants.ts +23 -0
- package/src/grapher/facet/readme.md +13 -0
- package/src/grapher/focus/FocusArray.ts +79 -0
- package/src/grapher/footer/Footer.scss +63 -0
- package/src/grapher/footer/Footer.tsx +809 -0
- package/src/grapher/footer/FooterManager.ts +44 -0
- package/src/grapher/fullScreen/FullScreen.scss +11 -0
- package/src/grapher/fullScreen/FullScreen.tsx +61 -0
- package/src/grapher/header/Header.scss +35 -0
- package/src/grapher/header/Header.tsx +372 -0
- package/src/grapher/header/HeaderManager.ts +28 -0
- package/src/grapher/index.ts +157 -0
- package/src/grapher/interaction/InteractionState.ts +60 -0
- package/src/grapher/legend/HorizontalColorLegends.tsx +923 -0
- package/src/grapher/legend/LegendInteractionState.ts +40 -0
- package/src/grapher/legend/VerticalColorLegend.tsx +295 -0
- package/src/grapher/lineCharts/LineChart.tsx +968 -0
- package/src/grapher/lineCharts/LineChartConstants.ts +89 -0
- package/src/grapher/lineCharts/LineChartHelpers.ts +184 -0
- package/src/grapher/lineCharts/LineChartState.ts +394 -0
- package/src/grapher/lineCharts/LineChartThumbnail.tsx +437 -0
- package/src/grapher/lineCharts/Lines.tsx +258 -0
- package/src/grapher/lineLegend/LineLegend.tsx +723 -0
- package/src/grapher/lineLegend/LineLegendConstants.ts +9 -0
- package/src/grapher/lineLegend/LineLegendFilterAlgorithms.ts +143 -0
- package/src/grapher/lineLegend/LineLegendHelpers.ts +253 -0
- package/src/grapher/lineLegend/LineLegendTypes.ts +32 -0
- package/src/grapher/mapCharts/CanadaTopology.ts +17922 -0
- package/src/grapher/mapCharts/ChoroplethGlobe.tsx +949 -0
- package/src/grapher/mapCharts/ChoroplethMap.tsx +662 -0
- package/src/grapher/mapCharts/GeoFeatures.ts +184 -0
- package/src/grapher/mapCharts/GlobeController.ts +496 -0
- package/src/grapher/mapCharts/MapAnnotationPlacements.json +1040 -0
- package/src/grapher/mapCharts/MapAnnotationPlacements.ts +31 -0
- package/src/grapher/mapCharts/MapAnnotations.ts +723 -0
- package/src/grapher/mapCharts/MapChart.sample.ts +59 -0
- package/src/grapher/mapCharts/MapChart.scss +5 -0
- package/src/grapher/mapCharts/MapChart.tsx +720 -0
- package/src/grapher/mapCharts/MapChartConstants.ts +260 -0
- package/src/grapher/mapCharts/MapChartState.ts +416 -0
- package/src/grapher/mapCharts/MapChartThumbnail.tsx +25 -0
- package/src/grapher/mapCharts/MapComponents.tsx +338 -0
- package/src/grapher/mapCharts/MapConfig.ts +156 -0
- package/src/grapher/mapCharts/MapHelpers.ts +181 -0
- package/src/grapher/mapCharts/MapProjections.ts +49 -0
- package/src/grapher/mapCharts/MapSparkline.tsx +257 -0
- package/src/grapher/mapCharts/MapTooltip.scss +49 -0
- package/src/grapher/mapCharts/MapTooltip.tsx +409 -0
- package/src/grapher/mapCharts/MapTopology.ts +1766 -0
- package/src/grapher/mapCharts/d3-bboxCollide.js +204 -0
- package/src/grapher/mapCharts/d3-geo-projection.ts +198 -0
- package/src/grapher/modal/DownloadIcons.tsx +39 -0
- package/src/grapher/modal/DownloadModal.scss +300 -0
- package/src/grapher/modal/DownloadModal.tsx +1226 -0
- package/src/grapher/modal/EmbedModal.scss +40 -0
- package/src/grapher/modal/EmbedModal.tsx +160 -0
- package/src/grapher/modal/EntitySelectorModal.tsx +59 -0
- package/src/grapher/modal/Modal.scss +31 -0
- package/src/grapher/modal/Modal.tsx +90 -0
- package/src/grapher/modal/ModalHeader.scss +12 -0
- package/src/grapher/modal/ModalHeader.tsx +16 -0
- package/src/grapher/modal/SourcesDescriptions.scss +87 -0
- package/src/grapher/modal/SourcesDescriptions.tsx +89 -0
- package/src/grapher/modal/SourcesKeyDataTable.scss +49 -0
- package/src/grapher/modal/SourcesKeyDataTable.tsx +87 -0
- package/src/grapher/modal/SourcesModal.scss +301 -0
- package/src/grapher/modal/SourcesModal.tsx +568 -0
- package/src/grapher/noDataModal/NoDataModal.tsx +125 -0
- package/src/grapher/scatterCharts/ConnectedScatterLegend.tsx +143 -0
- package/src/grapher/scatterCharts/MultiColorPolyline.tsx +129 -0
- package/src/grapher/scatterCharts/NoDataSection.scss +14 -0
- package/src/grapher/scatterCharts/NoDataSection.tsx +56 -0
- package/src/grapher/scatterCharts/ScatterPlotChart.tsx +792 -0
- package/src/grapher/scatterCharts/ScatterPlotChartConstants.ts +157 -0
- package/src/grapher/scatterCharts/ScatterPlotChartState.ts +678 -0
- package/src/grapher/scatterCharts/ScatterPlotChartThumbnail.tsx +155 -0
- package/src/grapher/scatterCharts/ScatterPlotTooltip.tsx +560 -0
- package/src/grapher/scatterCharts/ScatterPoints.tsx +153 -0
- package/src/grapher/scatterCharts/ScatterPointsWithLabels.tsx +708 -0
- package/src/grapher/scatterCharts/ScatterSizeLegend.tsx +327 -0
- package/src/grapher/scatterCharts/ScatterUtils.ts +265 -0
- package/src/grapher/scatterCharts/Triangle.tsx +41 -0
- package/src/grapher/schema/README.md +33 -0
- package/src/grapher/schema/defaultGrapherConfig.ts +100 -0
- package/src/grapher/schema/grapher-schema.009.yaml +781 -0
- package/src/grapher/schema/migrations/helpers.ts +58 -0
- package/src/grapher/schema/migrations/migrate.ts +75 -0
- package/src/grapher/schema/migrations/migrations.ts +158 -0
- package/src/grapher/selection/MapSelectionArray.ts +99 -0
- package/src/grapher/selection/SelectionArray.ts +71 -0
- package/src/grapher/selection/readme.md +16 -0
- package/src/grapher/sidePanel/SidePanel.scss +10 -0
- package/src/grapher/sidePanel/SidePanel.tsx +23 -0
- package/src/grapher/slideInDrawer/SlideInDrawer.scss +57 -0
- package/src/grapher/slideInDrawer/SlideInDrawer.tsx +125 -0
- package/src/grapher/slideshowController/SlideShowController.tsx +43 -0
- package/src/grapher/slideshowController/readme.md +7 -0
- package/src/grapher/slopeCharts/MarkX.tsx +45 -0
- package/src/grapher/slopeCharts/Slope.tsx +102 -0
- package/src/grapher/slopeCharts/SlopeChart.tsx +1152 -0
- package/src/grapher/slopeCharts/SlopeChartConstants.ts +33 -0
- package/src/grapher/slopeCharts/SlopeChartHelpers.ts +73 -0
- package/src/grapher/slopeCharts/SlopeChartState.ts +392 -0
- package/src/grapher/slopeCharts/SlopeChartThumbnail.tsx +368 -0
- package/src/grapher/stackedCharts/AbstractStackedChartState.ts +370 -0
- package/src/grapher/stackedCharts/MarimekkoBars.tsx +190 -0
- package/src/grapher/stackedCharts/MarimekkoBarsForOneEntity.tsx +168 -0
- package/src/grapher/stackedCharts/MarimekkoChart.tsx +1144 -0
- package/src/grapher/stackedCharts/MarimekkoChartConstants.ts +112 -0
- package/src/grapher/stackedCharts/MarimekkoChartHelpers.ts +21 -0
- package/src/grapher/stackedCharts/MarimekkoChartState.ts +465 -0
- package/src/grapher/stackedCharts/MarimekkoChartThumbnail.tsx +168 -0
- package/src/grapher/stackedCharts/MarimekkoInternalLabels.tsx +124 -0
- package/src/grapher/stackedCharts/StackedAreaChart.tsx +678 -0
- package/src/grapher/stackedCharts/StackedAreaChartState.ts +34 -0
- package/src/grapher/stackedCharts/StackedAreaChartThumbnail.tsx +215 -0
- package/src/grapher/stackedCharts/StackedAreas.tsx +223 -0
- package/src/grapher/stackedCharts/StackedBarChart.tsx +619 -0
- package/src/grapher/stackedCharts/StackedBarChartState.ts +80 -0
- package/src/grapher/stackedCharts/StackedBarChartThumbnail.tsx +220 -0
- package/src/grapher/stackedCharts/StackedBarSegment.tsx +87 -0
- package/src/grapher/stackedCharts/StackedBars.tsx +102 -0
- package/src/grapher/stackedCharts/StackedConstants.ts +109 -0
- package/src/grapher/stackedCharts/StackedDiscreteBarChart.tsx +270 -0
- package/src/grapher/stackedCharts/StackedDiscreteBarChartState.ts +296 -0
- package/src/grapher/stackedCharts/StackedDiscreteBarChartThumbnail.tsx +27 -0
- package/src/grapher/stackedCharts/StackedDiscreteBars.tsx +648 -0
- package/src/grapher/stackedCharts/StackedUtils.ts +142 -0
- package/src/grapher/tabs/Tabs.scss +169 -0
- package/src/grapher/tabs/Tabs.tsx +54 -0
- package/src/grapher/tabs/TabsWithDropdown.scss +62 -0
- package/src/grapher/tabs/TabsWithDropdown.tsx +114 -0
- package/src/grapher/testData/OwidTestData.sample.ts +273 -0
- package/src/grapher/testData/OwidTestData.ts +64 -0
- package/src/grapher/timeline/TimelineComponent.scss +139 -0
- package/src/grapher/timeline/TimelineComponent.tsx +658 -0
- package/src/grapher/timeline/TimelineController.ts +368 -0
- package/src/grapher/timeline/readme.md +7 -0
- package/src/grapher/tooltip/Tooltip.scss +510 -0
- package/src/grapher/tooltip/Tooltip.tsx +294 -0
- package/src/grapher/tooltip/TooltipContents.tsx +383 -0
- package/src/grapher/tooltip/TooltipProps.ts +123 -0
- package/src/grapher/tooltip/TooltipState.ts +81 -0
- package/src/grapher/verticalLabels/VerticalLabels.tsx +31 -0
- package/src/grapher/verticalLabels/VerticalLabelsState.ts +154 -0
- package/src/index.ts +226 -0
- package/src/styles/charts.scss +15 -0
- package/src/types/NominalType.ts +30 -0
- package/src/types/OwidOrigin.ts +18 -0
- package/src/types/OwidSource.ts +9 -0
- package/src/types/OwidVariable.ts +133 -0
- package/src/types/OwidVariableDisplayConfigInterface.ts +49 -0
- package/src/types/analyticsTypes.ts +54 -0
- package/src/types/dbTypes/Tags.ts +11 -0
- package/src/types/domainTypes/Archive.ts +139 -0
- package/src/types/domainTypes/Author.ts +28 -0
- package/src/types/domainTypes/ContentGraph.ts +76 -0
- package/src/types/domainTypes/CoreTableTypes.ts +305 -0
- package/src/types/domainTypes/DeployStatus.ts +23 -0
- package/src/types/domainTypes/Layout.ts +34 -0
- package/src/types/domainTypes/Posts.ts +34 -0
- package/src/types/domainTypes/Search.ts +299 -0
- package/src/types/domainTypes/Site.ts +8 -0
- package/src/types/domainTypes/StaticViz.ts +64 -0
- package/src/types/domainTypes/Toc.ts +11 -0
- package/src/types/domainTypes/Tombstone.ts +19 -0
- package/src/types/domainTypes/Various.ts +79 -0
- package/src/types/gdocTypes/Gdoc.ts +280 -0
- package/src/types/grapherTypes/BinningStrategyTypes.ts +46 -0
- package/src/types/grapherTypes/GrapherConstants.ts +53 -0
- package/src/types/grapherTypes/GrapherTypes.ts +743 -0
- package/src/types/index.ts +316 -0
- package/src/types/wordpressTypes/WordpressTypes.ts +9 -0
- package/src/utils/Bounds.ts +439 -0
- package/src/utils/BrowserUtils.ts +12 -0
- package/src/utils/FuzzySearch.ts +74 -0
- package/src/utils/MultiDimDataPageConfig.ts +31 -0
- package/src/utils/OwidVariable.ts +82 -0
- package/src/utils/PointVector.ts +97 -0
- package/src/utils/PromiseCache.ts +36 -0
- package/src/utils/PromiseSwitcher.ts +52 -0
- package/src/utils/TimeBounds.ts +130 -0
- package/src/utils/Tippy.tsx +57 -0
- package/src/utils/Util.ts +2369 -0
- package/src/utils/archival/archivalDate.ts +48 -0
- package/src/utils/dayjs.ts +32 -0
- package/src/utils/formatValue.ts +242 -0
- package/src/utils/grapherConfigUtils.ts +81 -0
- package/src/utils/image.ts +225 -0
- package/src/utils/index.ts +318 -0
- package/src/utils/isPresent.ts +5 -0
- package/src/utils/metadataHelpers.ts +329 -0
- package/src/utils/persistable/Persistable.ts +82 -0
- package/src/utils/persistable/readme.md +50 -0
- package/src/utils/regions.json +5635 -0
- package/src/utils/regions.ts +463 -0
- package/src/utils/serializers.ts +16 -0
- package/src/utils/string.ts +42 -0
- package/src/utils/urls/Url.ts +195 -0
- package/src/utils/urls/UrlMigration.ts +10 -0
- package/src/utils/urls/UrlUtils.ts +54 -0
- package/src/utils/urls/readme.md +90 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import {
|
|
3
|
+
GrapherTooltipAnchor,
|
|
4
|
+
GrapherTrendArrowDirection,
|
|
5
|
+
} from "../../utils/index.js"
|
|
6
|
+
import { IObservableValue } from "mobx"
|
|
7
|
+
|
|
8
|
+
export interface TooltipManager {
|
|
9
|
+
// We can't pass the property directly because we need it to be observable
|
|
10
|
+
tooltip?: IObservableValue<TooltipProps | undefined>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Controls the fade transition behavior for tooltips.
|
|
15
|
+
* - "delayed": Good for charts with gaps between targetable areas
|
|
16
|
+
* - "immediate": Better if the tooltip is displayed for all points in the chart's bounds
|
|
17
|
+
* - "none": Disables the fade transition altogether
|
|
18
|
+
*/
|
|
19
|
+
export type TooltipFadeMode = "delayed" | "immediate" | "none"
|
|
20
|
+
|
|
21
|
+
export enum TooltipFooterIcon {
|
|
22
|
+
Notice = "notice",
|
|
23
|
+
Stripes = "stripes",
|
|
24
|
+
Significance = "significance",
|
|
25
|
+
None = "none",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface FooterItem {
|
|
29
|
+
icon: TooltipFooterIcon
|
|
30
|
+
text: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface TooltipProps {
|
|
34
|
+
id: number | string
|
|
35
|
+
x?: number
|
|
36
|
+
y?: number
|
|
37
|
+
offsetX?: number
|
|
38
|
+
offsetY?: number
|
|
39
|
+
offsetXDirection?: "left" | "right"
|
|
40
|
+
offsetYDirection?: "upward" | "downward"
|
|
41
|
+
title?: string | number // header text
|
|
42
|
+
titleAnnotation?: string // rendered next to the title, but muted
|
|
43
|
+
subtitle?: string | number // header deck
|
|
44
|
+
subtitleFormat?: "notice" | "unit" // optional postprocessing for subtitle
|
|
45
|
+
footer?: FooterItem[]
|
|
46
|
+
style?: React.CSSProperties // css overrides (particularly width/maxWidth)
|
|
47
|
+
dissolve?: TooltipFadeMode // flag that the tooltip should begin fading out
|
|
48
|
+
children?: React.ReactNode
|
|
49
|
+
dismiss?: () => void
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface TooltipValueProps {
|
|
53
|
+
label?: string
|
|
54
|
+
unit?: string
|
|
55
|
+
value?: string
|
|
56
|
+
color?: string
|
|
57
|
+
isProjection?: boolean
|
|
58
|
+
originalTime?: string // actual year data was drawn from (when ≠ target year)
|
|
59
|
+
isRoundedToSignificantFigures?: boolean
|
|
60
|
+
showSignificanceSuperscript?: boolean // show significance-s superscript if applicable
|
|
61
|
+
labelVariant?: "label+unit" | "unit-only"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface TooltipValueRangeProps {
|
|
65
|
+
label?: string
|
|
66
|
+
unit?: string
|
|
67
|
+
values: [string | undefined, string | undefined]
|
|
68
|
+
trend?: GrapherTrendArrowDirection
|
|
69
|
+
colors?: string[] // value colors, matched by indices
|
|
70
|
+
originalTimes?: (string | undefined)[] // actual year data was drawn from (when ≠ target year)
|
|
71
|
+
isRoundedToSignificantFigures?: boolean
|
|
72
|
+
showSignificanceSuperscript?: boolean // show significance-s superscript if applicable
|
|
73
|
+
labelVariant?: "label+unit" | "unit-only"
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface TooltipTableProps {
|
|
77
|
+
columns: TooltipTableColumn[]
|
|
78
|
+
rows: TooltipTableRow[]
|
|
79
|
+
totals?: (number | undefined)[]
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface TooltipTableColumn {
|
|
83
|
+
label: string
|
|
84
|
+
formatValue: (value: unknown) => string
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface TooltipTableRow {
|
|
88
|
+
name: string
|
|
89
|
+
annotation?: string
|
|
90
|
+
swatch?: {
|
|
91
|
+
color?: string // css color string for the series's swatch
|
|
92
|
+
opacity?: number
|
|
93
|
+
}
|
|
94
|
+
focused?: boolean // highlighted (based on hovered series in chart)
|
|
95
|
+
blurred?: boolean // greyed out (typically due to missing data)
|
|
96
|
+
striped?: boolean // use textured swatch (to show data is extrapolated)
|
|
97
|
+
originalTime?: string // actual year data was drawn (when ≠ target year)
|
|
98
|
+
values: (string | number | undefined)[]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface TooltipVariableProps {
|
|
102
|
+
label?: string
|
|
103
|
+
unit?: string
|
|
104
|
+
color?: string
|
|
105
|
+
isProjection?: boolean
|
|
106
|
+
originalTimes?: (string | undefined)[]
|
|
107
|
+
labelVariant?: "label+unit" | "unit-only"
|
|
108
|
+
children?: React.ReactNode
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface TooltipTableData {
|
|
112
|
+
value: number
|
|
113
|
+
fake?: boolean
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface TooltipContainerProps {
|
|
117
|
+
containerBounds?: { width: number; height: number }
|
|
118
|
+
anchor?: GrapherTooltipAnchor
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export const TooltipContext = React.createContext<
|
|
122
|
+
Pick<TooltipContainerProps, "anchor">
|
|
123
|
+
>({})
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { observable, computed, action, makeObservable } from "mobx"
|
|
2
|
+
import { PointVector } from "../../utils/index.js"
|
|
3
|
+
import { TooltipFadeMode } from "./TooltipProps"
|
|
4
|
+
|
|
5
|
+
const TOOLTIP_FADE_DURATION = 400 // $fade-time + $fade-delay in scss
|
|
6
|
+
|
|
7
|
+
interface TooltipStateArgs {
|
|
8
|
+
fade?: TooltipFadeMode
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class PlainTooltipState<T> {
|
|
12
|
+
position = new PointVector(0, 0)
|
|
13
|
+
|
|
14
|
+
protected _target: T | undefined = undefined
|
|
15
|
+
protected _timer: number | undefined = undefined
|
|
16
|
+
protected _fade: TooltipFadeMode
|
|
17
|
+
|
|
18
|
+
constructor({ fade }: TooltipStateArgs = {}) {
|
|
19
|
+
this._fade = fade ?? "delayed"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get target(): T | undefined {
|
|
23
|
+
return this._target
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
set target(newTarget: T | null) {
|
|
27
|
+
this.setTarget(newTarget)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get fading(): TooltipFadeMode | undefined {
|
|
31
|
+
// returns "delayed"|"immediate" during the timeout after clearing the target
|
|
32
|
+
return !!this._timer && !!this._target ? this._fade : undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
protected setTarget(newTarget: T | null): void {
|
|
36
|
+
// delay clearing the target (and hiding the tooltip) for a bit to prevent
|
|
37
|
+
// flicker when frobbing between neighboring elements and allow an opacity
|
|
38
|
+
// transition to smoothly fade the tooltip out
|
|
39
|
+
clearTimeout(this._timer)
|
|
40
|
+
|
|
41
|
+
if (newTarget === null) {
|
|
42
|
+
const speed = { delayed: 1, immediate: 0.5, none: 0 }[this._fade]
|
|
43
|
+
this._timer = window.setTimeout(
|
|
44
|
+
() => this.resetTarget(),
|
|
45
|
+
speed * TOOLTIP_FADE_DURATION
|
|
46
|
+
)
|
|
47
|
+
} else {
|
|
48
|
+
this._target = newTarget
|
|
49
|
+
this._timer = undefined
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected resetTarget(): void {
|
|
54
|
+
this._target = undefined
|
|
55
|
+
this._timer = undefined
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class TooltipState<T> extends PlainTooltipState<T> {
|
|
60
|
+
constructor(args?: TooltipStateArgs) {
|
|
61
|
+
super(args)
|
|
62
|
+
|
|
63
|
+
makeObservable<
|
|
64
|
+
this,
|
|
65
|
+
"_target" | "_timer" | "setTarget" | "resetTarget"
|
|
66
|
+
>(this, {
|
|
67
|
+
// observables
|
|
68
|
+
position: observable,
|
|
69
|
+
_target: observable,
|
|
70
|
+
_timer: observable,
|
|
71
|
+
|
|
72
|
+
// computed (getters)
|
|
73
|
+
target: computed,
|
|
74
|
+
fading: computed,
|
|
75
|
+
|
|
76
|
+
// actions
|
|
77
|
+
setTarget: action.bound,
|
|
78
|
+
resetTarget: action.bound,
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import { VerticalAxis } from "../axis/Axis"
|
|
3
|
+
import { VerticalLabelsState } from "./VerticalLabelsState"
|
|
4
|
+
import { darkenColorForText } from "../color/ColorUtils.js"
|
|
5
|
+
|
|
6
|
+
export function VerticalLabels({
|
|
7
|
+
state,
|
|
8
|
+
yAxis,
|
|
9
|
+
x = 0,
|
|
10
|
+
xAnchor = "start",
|
|
11
|
+
}: {
|
|
12
|
+
state: VerticalLabelsState
|
|
13
|
+
yAxis: VerticalAxis
|
|
14
|
+
x?: number
|
|
15
|
+
xAnchor?: "start" | "end"
|
|
16
|
+
}): React.ReactElement {
|
|
17
|
+
return (
|
|
18
|
+
<g>
|
|
19
|
+
{state.series.map((series) => (
|
|
20
|
+
<React.Fragment key={series.yPosition}>
|
|
21
|
+
{series.textWrap.renderSVG(x, yAxis.place(series.value), {
|
|
22
|
+
textProps: {
|
|
23
|
+
textAnchor: xAnchor,
|
|
24
|
+
fill: darkenColorForText(series.color),
|
|
25
|
+
},
|
|
26
|
+
})}
|
|
27
|
+
</React.Fragment>
|
|
28
|
+
))}
|
|
29
|
+
</g>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import * as R from "remeda"
|
|
2
|
+
import { computed } from "mobx"
|
|
3
|
+
import { Bounds, RequiredBy, VerticalAlign } from "../../utils/index.js"
|
|
4
|
+
import { TextWrap } from "../../components/index.js"
|
|
5
|
+
|
|
6
|
+
interface VerticalLabelsOptions {
|
|
7
|
+
/** Font size for the labels */
|
|
8
|
+
fontSize: number
|
|
9
|
+
|
|
10
|
+
/** Font weight for the labels */
|
|
11
|
+
fontWeight?: number
|
|
12
|
+
|
|
13
|
+
/** Line height multiplier for multi-line labels (defaults to 1) */
|
|
14
|
+
lineHeight?: number
|
|
15
|
+
|
|
16
|
+
/** Maximum width for labels (no restriction by default) */
|
|
17
|
+
maxWidth?: number
|
|
18
|
+
|
|
19
|
+
/** Labels outside of this range are hidden */
|
|
20
|
+
yRange?: [number, number]
|
|
21
|
+
|
|
22
|
+
/** Minimum space between labels in pixels to prevent overlap */
|
|
23
|
+
minSpacing?: number
|
|
24
|
+
|
|
25
|
+
/** Controls how the label is aligned relative to the y-position */
|
|
26
|
+
verticalAlign?: VerticalAlign
|
|
27
|
+
|
|
28
|
+
/** Function to resolve collisions between two overlapping labels by choosing which one to keep */
|
|
29
|
+
resolveCollision?: (
|
|
30
|
+
s1: InitialVerticalLabelsSeries,
|
|
31
|
+
s2: InitialVerticalLabelsSeries
|
|
32
|
+
) => InitialVerticalLabelsSeries
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface InitialVerticalLabelsSeries {
|
|
36
|
+
seriesName: string
|
|
37
|
+
value: number
|
|
38
|
+
label: string
|
|
39
|
+
yPosition: number
|
|
40
|
+
color: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface SizedVerticalLabelsSeries extends InitialVerticalLabelsSeries {
|
|
44
|
+
textWrap: TextWrap
|
|
45
|
+
bounds: Bounds
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type VerticalLabelsSeries = SizedVerticalLabelsSeries
|
|
49
|
+
|
|
50
|
+
export class VerticalLabelsState {
|
|
51
|
+
private initialSeries: InitialVerticalLabelsSeries[]
|
|
52
|
+
private initialOptions: VerticalLabelsOptions
|
|
53
|
+
|
|
54
|
+
private defaultOptions = {
|
|
55
|
+
lineHeight: 1,
|
|
56
|
+
maxWidth: Infinity,
|
|
57
|
+
minSpacing: 5,
|
|
58
|
+
verticalAlign: VerticalAlign.middle,
|
|
59
|
+
fontWeight: 400,
|
|
60
|
+
} as const satisfies Partial<VerticalLabelsOptions>
|
|
61
|
+
|
|
62
|
+
constructor(
|
|
63
|
+
series: InitialVerticalLabelsSeries[],
|
|
64
|
+
options: VerticalLabelsOptions
|
|
65
|
+
) {
|
|
66
|
+
this.initialSeries = series
|
|
67
|
+
this.initialOptions = options
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@computed private get options(): RequiredBy<
|
|
71
|
+
VerticalLabelsOptions,
|
|
72
|
+
keyof typeof this.defaultOptions
|
|
73
|
+
> {
|
|
74
|
+
return { ...this.defaultOptions, ...this.initialOptions }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@computed
|
|
78
|
+
private get sizedSeries(): SizedVerticalLabelsSeries[] {
|
|
79
|
+
const { fontSize, fontWeight, maxWidth, verticalAlign, lineHeight } =
|
|
80
|
+
this.options
|
|
81
|
+
|
|
82
|
+
return this.initialSeries.map((series) => {
|
|
83
|
+
const { label, yPosition } = series
|
|
84
|
+
|
|
85
|
+
const textWrap = new TextWrap({
|
|
86
|
+
text: label,
|
|
87
|
+
maxWidth,
|
|
88
|
+
fontSize,
|
|
89
|
+
fontWeight,
|
|
90
|
+
lineHeight,
|
|
91
|
+
verticalAlign,
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
const [x, y] = textWrap.getPositionForSvgRendering(0, yPosition)
|
|
95
|
+
const bounds = new Bounds(x, y, textWrap.width, textWrap.height)
|
|
96
|
+
|
|
97
|
+
return { ...series, textWrap, bounds }
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@computed get series(): VerticalLabelsSeries[] {
|
|
102
|
+
const { minSpacing, resolveCollision, yRange } = this.options
|
|
103
|
+
|
|
104
|
+
const margin = minSpacing > 0 ? minSpacing / 2 : 0
|
|
105
|
+
const margins = { top: margin, bottom: margin }
|
|
106
|
+
|
|
107
|
+
const series = this.sizedSeries.map((series) => ({
|
|
108
|
+
...series,
|
|
109
|
+
// Bounds used to detect collisions. They're a bit larger than the
|
|
110
|
+
// text bounds to account for the minimum spacing between labels.
|
|
111
|
+
collisionBounds: series.bounds.expand(margins),
|
|
112
|
+
// None of the series are initially hidden
|
|
113
|
+
isHidden: false,
|
|
114
|
+
}))
|
|
115
|
+
|
|
116
|
+
// Hide labels that are overlapping or too close to each other
|
|
117
|
+
for (let i = 0; i < series.length; i++) {
|
|
118
|
+
const s1 = series[i]
|
|
119
|
+
if (s1.isHidden) continue
|
|
120
|
+
|
|
121
|
+
// Check if the label is out of bounds
|
|
122
|
+
if (
|
|
123
|
+
yRange &&
|
|
124
|
+
(s1.bounds.top < yRange[1] || s1.bounds.bottom > yRange[0])
|
|
125
|
+
) {
|
|
126
|
+
s1.isHidden = true
|
|
127
|
+
continue
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Check if the label is overlapping with any other label
|
|
131
|
+
for (let j = i + 1; j < series.length; j++) {
|
|
132
|
+
const s2 = series[j]
|
|
133
|
+
if (s2.isHidden) continue
|
|
134
|
+
|
|
135
|
+
if (s1.collisionBounds.hasVerticalOverlap(s2.collisionBounds)) {
|
|
136
|
+
const picked = resolveCollision?.(s1, s2) ?? s1
|
|
137
|
+
|
|
138
|
+
if (picked === s1) s2.isHidden = true
|
|
139
|
+
else s1.isHidden = true
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return series
|
|
145
|
+
.filter((series) => !series.isHidden)
|
|
146
|
+
.map((series) => R.omit(series, ["isHidden", "collisionBounds"]))
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@computed get width(): number {
|
|
150
|
+
const labelWidths = this.series.map((series) => series.textWrap.width)
|
|
151
|
+
const maxLabelWidth = R.firstBy(labelWidths, [R.identity(), "desc"])
|
|
152
|
+
return maxLabelWidth ?? 0
|
|
153
|
+
}
|
|
154
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @buildcanada/charts
|
|
3
|
+
*
|
|
4
|
+
* A configurable data visualization library for creating interactive charts.
|
|
5
|
+
* Extracted from Our World in Data's Grapher library.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { ChartsProvider, Grapher, GrapherState } from '@buildcanada/charts'
|
|
10
|
+
* import '@buildcanada/charts/styles.css'
|
|
11
|
+
*
|
|
12
|
+
* const config = {
|
|
13
|
+
* branding: { poweredByText: 'My Organization' },
|
|
14
|
+
* dataApi: { baseUrl: 'https://api.example.com/v1/indicators/' }
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* function App() {
|
|
18
|
+
* return (
|
|
19
|
+
* <ChartsProvider config={config}>
|
|
20
|
+
* <Grapher {...chartProps} />
|
|
21
|
+
* </ChartsProvider>
|
|
22
|
+
* )
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
// Configuration
|
|
28
|
+
export {
|
|
29
|
+
type ChartsConfig,
|
|
30
|
+
type ChartsBranding,
|
|
31
|
+
type ChartsDataApi,
|
|
32
|
+
type ChartsErrorReporting,
|
|
33
|
+
type ChartsAnalytics,
|
|
34
|
+
type LogoConfig,
|
|
35
|
+
defaultChartsConfig,
|
|
36
|
+
mergeWithDefaults,
|
|
37
|
+
ChartsProvider,
|
|
38
|
+
type ChartsProviderProps,
|
|
39
|
+
useChartsConfig,
|
|
40
|
+
useMaybeChartsConfig,
|
|
41
|
+
createFallbackConfig,
|
|
42
|
+
reportError,
|
|
43
|
+
trackEvent,
|
|
44
|
+
} from "./config/index.js"
|
|
45
|
+
|
|
46
|
+
// Re-export grapher components
|
|
47
|
+
export {
|
|
48
|
+
Grapher,
|
|
49
|
+
type GrapherProgrammaticInterface,
|
|
50
|
+
type GrapherManager,
|
|
51
|
+
} from "./grapher/core/Grapher.js"
|
|
52
|
+
|
|
53
|
+
export { GrapherState } from "./grapher/core/GrapherState.js"
|
|
54
|
+
export { FetchingGrapher } from "./grapher/core/FetchingGrapher.js"
|
|
55
|
+
|
|
56
|
+
// Explorer
|
|
57
|
+
export { Explorer } from "./explorer/Explorer.js"
|
|
58
|
+
export type { ExplorerProps } from "./explorer/Explorer.js"
|
|
59
|
+
|
|
60
|
+
// Chart State types
|
|
61
|
+
export type { ChartState, ChartSeries } from "./grapher/chart/ChartInterface.js"
|
|
62
|
+
export type { LineChartState } from "./grapher/lineCharts/LineChartState.js"
|
|
63
|
+
export type { SlopeChartState } from "./grapher/slopeCharts/SlopeChartState.js"
|
|
64
|
+
export type { DiscreteBarChartState } from "./grapher/barCharts/DiscreteBarChartState.js"
|
|
65
|
+
export type { StackedAreaChartState } from "./grapher/stackedCharts/StackedAreaChartState.js"
|
|
66
|
+
export type { StackedBarChartState } from "./grapher/stackedCharts/StackedBarChartState.js"
|
|
67
|
+
export type { StackedDiscreteBarChartState } from "./grapher/stackedCharts/StackedDiscreteBarChartState.js"
|
|
68
|
+
export type { ScatterPlotChartState } from "./grapher/scatterCharts/ScatterPlotChartState.js"
|
|
69
|
+
export type { MarimekkoChartState } from "./grapher/stackedCharts/MarimekkoChartState.js"
|
|
70
|
+
export { MapChartState } from "./grapher/mapCharts/MapChartState.js"
|
|
71
|
+
export { MapConfig } from "./grapher/mapCharts/MapConfig.js"
|
|
72
|
+
|
|
73
|
+
// Data loading
|
|
74
|
+
export {
|
|
75
|
+
fetchInputTableForConfig,
|
|
76
|
+
getCachingInputTableFetcher,
|
|
77
|
+
type FetchInputTableForConfigFn,
|
|
78
|
+
} from "./grapher/core/loadGrapherTableHelpers.js"
|
|
79
|
+
|
|
80
|
+
export { loadVariableDataAndMetadata } from "./grapher/core/loadVariable.js"
|
|
81
|
+
|
|
82
|
+
// Color system
|
|
83
|
+
export { ColorScale } from "./grapher/color/ColorScale.js"
|
|
84
|
+
export { ColorScaleConfig } from "./grapher/color/ColorScaleConfig.js"
|
|
85
|
+
export { ColorScheme } from "./grapher/color/ColorScheme.js"
|
|
86
|
+
export { ColorSchemes, getColorSchemeForChartType } from "./grapher/color/ColorSchemes.js"
|
|
87
|
+
export {
|
|
88
|
+
NumericBin,
|
|
89
|
+
CategoricalBin,
|
|
90
|
+
type ColorScaleBin,
|
|
91
|
+
isCategoricalBin,
|
|
92
|
+
isNumericBin,
|
|
93
|
+
isNoDataBin,
|
|
94
|
+
isProjectedDataBin,
|
|
95
|
+
} from "./grapher/color/ColorScaleBin.js"
|
|
96
|
+
|
|
97
|
+
// Selection and Focus
|
|
98
|
+
export { SelectionArray } from "./grapher/selection/SelectionArray.js"
|
|
99
|
+
export { FocusArray } from "./grapher/focus/FocusArray.js"
|
|
100
|
+
|
|
101
|
+
// Constants
|
|
102
|
+
export {
|
|
103
|
+
DEFAULT_GRAPHER_WIDTH,
|
|
104
|
+
DEFAULT_GRAPHER_HEIGHT,
|
|
105
|
+
GRAPHER_THUMBNAIL_WIDTH,
|
|
106
|
+
GRAPHER_THUMBNAIL_HEIGHT,
|
|
107
|
+
DEFAULT_GRAPHER_BOUNDS,
|
|
108
|
+
BASE_FONT_SIZE,
|
|
109
|
+
Patterns,
|
|
110
|
+
latestGrapherConfigSchema,
|
|
111
|
+
} from "./grapher/core/GrapherConstants.js"
|
|
112
|
+
|
|
113
|
+
// Controls
|
|
114
|
+
export { EntityPicker } from "./grapher/controls/entityPicker/EntityPicker.js"
|
|
115
|
+
export type { EntityPickerManager } from "./grapher/controls/entityPicker/EntityPickerConstants.js"
|
|
116
|
+
export { GlobalEntitySelector } from "./grapher/controls/globalEntitySelector/GlobalEntitySelector.js"
|
|
117
|
+
export { Dropdown } from "./grapher/controls/Dropdown.js"
|
|
118
|
+
|
|
119
|
+
// Schema and migrations
|
|
120
|
+
export { defaultGrapherConfig } from "./grapher/schema/defaultGrapherConfig.js"
|
|
121
|
+
export {
|
|
122
|
+
migrateGrapherConfigToLatestVersion,
|
|
123
|
+
migrateGrapherConfigToLatestVersionAndFailOnError,
|
|
124
|
+
} from "./grapher/schema/migrations/migrate.js"
|
|
125
|
+
|
|
126
|
+
// URL utilities
|
|
127
|
+
export {
|
|
128
|
+
setSelectedEntityNamesParam,
|
|
129
|
+
migrateSelectedEntityNamesParam,
|
|
130
|
+
getSelectedEntityNamesParam,
|
|
131
|
+
generateSelectedEntityNamesParam,
|
|
132
|
+
generateFocusedSeriesNamesParam,
|
|
133
|
+
getEntityNamesParam,
|
|
134
|
+
} from "./grapher/core/EntityUrlBuilder.js"
|
|
135
|
+
|
|
136
|
+
export { grapherConfigToQueryParams } from "./grapher/core/GrapherUrl.js"
|
|
137
|
+
|
|
138
|
+
// Chart utilities
|
|
139
|
+
export { ChartDimension } from "./grapher/chart/ChartDimension.js"
|
|
140
|
+
export { DimensionSlot } from "./grapher/chart/DimensionSlot.js"
|
|
141
|
+
export { makeChartState } from "./grapher/chart/ChartTypeMap.js"
|
|
142
|
+
export { generateGrapherImageSrcSet } from "./grapher/chart/ChartUtils.js"
|
|
143
|
+
|
|
144
|
+
// Slideshow
|
|
145
|
+
export {
|
|
146
|
+
type SlideShowManager,
|
|
147
|
+
SlideShowController,
|
|
148
|
+
} from "./grapher/slideshowController/SlideShowController.js"
|
|
149
|
+
|
|
150
|
+
// Analytics
|
|
151
|
+
export { GrapherAnalytics } from "./grapher/core/GrapherAnalytics.js"
|
|
152
|
+
|
|
153
|
+
// Rendering helpers
|
|
154
|
+
export {
|
|
155
|
+
renderGrapherIntoContainer,
|
|
156
|
+
renderSingleGrapherOnGrapherPage,
|
|
157
|
+
} from "./grapher/core/GrapherUseHelpers.js"
|
|
158
|
+
|
|
159
|
+
// Map features
|
|
160
|
+
export { GeoFeatures } from "./grapher/mapCharts/GeoFeatures.js"
|
|
161
|
+
export {
|
|
162
|
+
MAP_REGION_LABELS,
|
|
163
|
+
type GeoFeature,
|
|
164
|
+
type Direction,
|
|
165
|
+
type Ellipse,
|
|
166
|
+
type EllipseCoords,
|
|
167
|
+
} from "./grapher/mapCharts/MapChartConstants.js"
|
|
168
|
+
|
|
169
|
+
// Comparison lines
|
|
170
|
+
export { isValidVerticalComparisonLineConfig } from "./grapher/comparisonLine/ComparisonLineHelpers.js"
|
|
171
|
+
|
|
172
|
+
// Binning strategies
|
|
173
|
+
export { hasValidConfigForBinningStrategy } from "./grapher/color/BinningStrategies.js"
|
|
174
|
+
|
|
175
|
+
// Chart tabs
|
|
176
|
+
export {
|
|
177
|
+
isChartTypeName,
|
|
178
|
+
isValidTabQueryParam,
|
|
179
|
+
findPotentialChartTypeSiblings,
|
|
180
|
+
mapGrapherTabNameToQueryParam,
|
|
181
|
+
mapGrapherTabNameToConfigOption,
|
|
182
|
+
makeLabelForGrapherTab,
|
|
183
|
+
} from "./grapher/chart/ChartTabs.js"
|
|
184
|
+
|
|
185
|
+
// Guided chart utilities
|
|
186
|
+
export {
|
|
187
|
+
useMaybeGlobalGrapherStateRef,
|
|
188
|
+
useGuidedChartLinkHandler,
|
|
189
|
+
GuidedChartContext,
|
|
190
|
+
type GuidedChartContextValue,
|
|
191
|
+
type ArchiveGuidedChartRegistration,
|
|
192
|
+
buildArchiveGuidedChartSrc,
|
|
193
|
+
} from "./grapher/chart/guidedChartUtils.js"
|
|
194
|
+
|
|
195
|
+
// Legacy conversion
|
|
196
|
+
export {
|
|
197
|
+
legacyToOwidTableAndDimensions,
|
|
198
|
+
legacyToOwidTableAndDimensionsWithMandatorySlug,
|
|
199
|
+
} from "./grapher/core/LegacyToOwidTable.js"
|
|
200
|
+
|
|
201
|
+
export { legacyToCurrentGrapherUrl } from "./grapher/core/GrapherUrlMigrations.js"
|
|
202
|
+
|
|
203
|
+
// Test data helpers (useful for demos and testing)
|
|
204
|
+
export {
|
|
205
|
+
fakeEntities,
|
|
206
|
+
createOwidTestDataset,
|
|
207
|
+
type TestData,
|
|
208
|
+
type TestMetadata,
|
|
209
|
+
} from "./grapher/testData/OwidTestData.js"
|
|
210
|
+
export { LifeExpectancyGrapher } from "./grapher/testData/OwidTestData.sample.js"
|
|
211
|
+
|
|
212
|
+
// Types commonly needed for data loading
|
|
213
|
+
export {
|
|
214
|
+
DimensionProperty,
|
|
215
|
+
GRAPHER_CHART_TYPES,
|
|
216
|
+
ALL_GRAPHER_CHART_TYPES,
|
|
217
|
+
ColorSchemeName,
|
|
218
|
+
MapRegionName,
|
|
219
|
+
type EntityName,
|
|
220
|
+
type EntityId,
|
|
221
|
+
type EntityCode,
|
|
222
|
+
} from "./types/index.js"
|
|
223
|
+
|
|
224
|
+
// Utilities for data loading
|
|
225
|
+
export { Bounds } from "./utils/index.js"
|
|
226
|
+
export { parseDelimited, OwidTable, BlankOwidTable } from "./core-table/index.js"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @buildcanada/charts - Main Stylesheet
|
|
3
|
+
*
|
|
4
|
+
* This file imports all necessary styles for the charts library.
|
|
5
|
+
* Import this in your application:
|
|
6
|
+
*
|
|
7
|
+
* import '@buildcanada/charts/styles.css'
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Import the main grapher styles which include all component styles
|
|
11
|
+
@import "../grapher/core/grapher.scss";
|
|
12
|
+
|
|
13
|
+
// Explorer styles
|
|
14
|
+
@import "../explorer/Explorer.scss";
|
|
15
|
+
@import "../explorer/ExplorerControls.scss";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare const __nominal__type: unique symbol
|
|
2
|
+
/** Typescript is structurally typed, not nominally typed. This means that
|
|
3
|
+
* two types are considered equivalent if their members are equivalent.
|
|
4
|
+
* This is often useful but sometimes you want to distingish types based on their
|
|
5
|
+
* name alone - e.g. if you have an identifier that is just a string but you'd like
|
|
6
|
+
* some type safety when using it. This is where this nominal type comes in.
|
|
7
|
+
* @example
|
|
8
|
+
* type UserName = Nominal<string, "UserName">
|
|
9
|
+
* type UserId = Nominal<string, "UserId">
|
|
10
|
+
*
|
|
11
|
+
* function getUserName(name: UserName) {
|
|
12
|
+
* return name
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* const name = getUserName("123" as UserName) // OK
|
|
16
|
+
* const name2 = getUserName("123") // Error
|
|
17
|
+
* const name3 = getUserName("123" as UserId) // Error
|
|
18
|
+
* // of course the main benefit comes when the UserName and UserId types are used in a more complex call hierarchy
|
|
19
|
+
*/
|
|
20
|
+
export type Nominal<Type, Identifier> = Type & {
|
|
21
|
+
readonly [__nominal__type]: Identifier
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function wrap<T, I>(obj: T): Nominal<T, I> {
|
|
25
|
+
return obj as Nominal<T, I>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function unwrap<T, I>(obj: Nominal<T, I>): T {
|
|
29
|
+
return obj
|
|
30
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { OwidLicense } from "./OwidVariable.js"
|
|
2
|
+
export interface OwidOrigin {
|
|
3
|
+
id?: number
|
|
4
|
+
title?: string
|
|
5
|
+
titleSnapshot?: string
|
|
6
|
+
attribution?: string
|
|
7
|
+
attributionShort?: string
|
|
8
|
+
versionProducer?: string
|
|
9
|
+
license?: OwidLicense
|
|
10
|
+
descriptionSnapshot?: string
|
|
11
|
+
description?: string
|
|
12
|
+
producer?: string
|
|
13
|
+
citationFull?: string
|
|
14
|
+
urlMain?: string
|
|
15
|
+
urlDownload?: string
|
|
16
|
+
dateAccessed?: string
|
|
17
|
+
datePublished?: string
|
|
18
|
+
}
|