@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,142 @@
|
|
|
1
|
+
import * as R from "remeda"
|
|
2
|
+
import * as _ from "lodash-es"
|
|
3
|
+
import {
|
|
4
|
+
sortNumeric,
|
|
5
|
+
isArrayOfNumbers,
|
|
6
|
+
findGreatestCommonDivisorOfArray,
|
|
7
|
+
rollingMap,
|
|
8
|
+
omitUndefinedValues,
|
|
9
|
+
AxisConfigInterface,
|
|
10
|
+
} from "../../utils/index.js"
|
|
11
|
+
import { StackedPointPositionType, StackedSeries } from "./StackedConstants"
|
|
12
|
+
import { StackedBarChartState } from "./StackedBarChartState.js"
|
|
13
|
+
|
|
14
|
+
// This method shift up the Y Values of a Series with Points in place.
|
|
15
|
+
export const stackSeries = <PositionType extends StackedPointPositionType>(
|
|
16
|
+
seriesArr: readonly StackedSeries<PositionType>[]
|
|
17
|
+
): readonly StackedSeries<PositionType>[] => {
|
|
18
|
+
seriesArr.forEach((series, seriesIndex) => {
|
|
19
|
+
if (!seriesIndex) return // The first series does not need to be shifted
|
|
20
|
+
series.points.forEach((point, pointIndex) => {
|
|
21
|
+
const pointBelowThisOne =
|
|
22
|
+
seriesArr[seriesIndex - 1].points[pointIndex]
|
|
23
|
+
point.valueOffset =
|
|
24
|
+
pointBelowThisOne.value + pointBelowThisOne.valueOffset
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
return seriesArr
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// This method shifts up positive y values and shifts down negative y values of a Series with Points in place.
|
|
31
|
+
export const stackSeriesInBothDirections = <
|
|
32
|
+
PositionType extends StackedPointPositionType,
|
|
33
|
+
>(
|
|
34
|
+
seriesArr: readonly StackedSeries<PositionType>[]
|
|
35
|
+
): readonly StackedSeries<PositionType>[] => {
|
|
36
|
+
seriesArr.forEach((series, seriesIndex) => {
|
|
37
|
+
if (!seriesIndex) return // The first series does not need to be shifted
|
|
38
|
+
series.points.forEach((point, pointIndex) => {
|
|
39
|
+
const pointsBelowThisOne = seriesArr
|
|
40
|
+
.slice(0, seriesIndex)
|
|
41
|
+
.map((s) => s.points[pointIndex])
|
|
42
|
+
const pointBelowThisOne =
|
|
43
|
+
point.value < 0
|
|
44
|
+
? pointsBelowThisOne.findLast((p) => p.value < 0)
|
|
45
|
+
: pointsBelowThisOne.findLast((p) => p.value >= 0)
|
|
46
|
+
point.valueOffset = pointBelowThisOne
|
|
47
|
+
? pointBelowThisOne.value + pointBelowThisOne.valueOffset
|
|
48
|
+
: 0
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
return seriesArr
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Makes sure that values are evenly spaced
|
|
55
|
+
export function withUniformSpacing(values: number[]): number[] {
|
|
56
|
+
const deltas = rollingMap(values, (a, b) => b - a)
|
|
57
|
+
const gcd = findGreatestCommonDivisorOfArray(deltas)
|
|
58
|
+
if (gcd === null) return values
|
|
59
|
+
return _.range(values[0], values[values.length - 1] + gcd, gcd)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Adds a Y = 0 value for each missing x value (where X is usually Time)
|
|
63
|
+
export const withMissingValuesAsZeroes = <
|
|
64
|
+
PositionType extends StackedPointPositionType,
|
|
65
|
+
>(
|
|
66
|
+
seriesArr: readonly StackedSeries<PositionType>[],
|
|
67
|
+
{ enforceUniformSpacing = false }: { enforceUniformSpacing?: boolean } = {}
|
|
68
|
+
): StackedSeries<PositionType>[] => {
|
|
69
|
+
let allXValuesSorted = sortNumeric(
|
|
70
|
+
_.uniq(
|
|
71
|
+
seriesArr
|
|
72
|
+
.flatMap((series) => series.points)
|
|
73
|
+
.map((point) => point.position)
|
|
74
|
+
)
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
if (enforceUniformSpacing && isArrayOfNumbers(allXValuesSorted)) {
|
|
78
|
+
allXValuesSorted = withUniformSpacing(
|
|
79
|
+
allXValuesSorted
|
|
80
|
+
) as PositionType[]
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return seriesArr.map((series) => {
|
|
84
|
+
const pointsByPosition = _.keyBy(series.points, "position")
|
|
85
|
+
return {
|
|
86
|
+
...series,
|
|
87
|
+
points: allXValuesSorted.map((position) => {
|
|
88
|
+
const point = pointsByPosition[position]
|
|
89
|
+
const value = point?.value ?? 0
|
|
90
|
+
const time = point?.time ?? 0
|
|
91
|
+
return omitUndefinedValues({
|
|
92
|
+
time,
|
|
93
|
+
position,
|
|
94
|
+
value,
|
|
95
|
+
valueOffset: 0,
|
|
96
|
+
interpolated: point?.interpolated,
|
|
97
|
+
fake: !point || !!point.interpolated,
|
|
98
|
+
color: point?.color,
|
|
99
|
+
})
|
|
100
|
+
}),
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function resolveCollision(
|
|
106
|
+
s1: StackedSeries<number>,
|
|
107
|
+
s2: StackedSeries<number>
|
|
108
|
+
): StackedSeries<number> | undefined {
|
|
109
|
+
// Early return if one series is all zeroes
|
|
110
|
+
if (s1.isAllZeros && !s2.isAllZeros) return s2
|
|
111
|
+
if (s2.isAllZeros && !s1.isAllZeros) return s1
|
|
112
|
+
|
|
113
|
+
// Prefer series with a higher maximum value
|
|
114
|
+
const yMax1 = _.maxBy(s1.points, (p) => p.value)?.value ?? 0
|
|
115
|
+
const yMax2 = _.maxBy(s2.points, (p) => p.value)?.value ?? 0
|
|
116
|
+
if (yMax1 > yMax2) return s1
|
|
117
|
+
if (yMax2 > yMax1) return s2
|
|
118
|
+
|
|
119
|
+
// Prefer series with a higher last value
|
|
120
|
+
const yLast1 = R.last(s1.points)?.value ?? 0
|
|
121
|
+
const yLast2 = R.last(s2.points)?.value ?? 0
|
|
122
|
+
if (yLast1 > yLast2) return s1
|
|
123
|
+
if (yLast2 > yLast1) return s2
|
|
124
|
+
|
|
125
|
+
// Prefer series with a higher total area
|
|
126
|
+
const area1 = _.sumBy(s1.points, (p) => p.value)
|
|
127
|
+
const area2 = _.sumBy(s2.points, (p) => p.value)
|
|
128
|
+
if (area1 > area2) return s1
|
|
129
|
+
if (area2 > area1) return s2
|
|
130
|
+
|
|
131
|
+
return undefined // no preference
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function getXAxisConfigDefaultsForStackedBar(
|
|
135
|
+
chartState: StackedBarChartState
|
|
136
|
+
): AxisConfigInterface {
|
|
137
|
+
return {
|
|
138
|
+
hideGridlines: true,
|
|
139
|
+
domainValues: chartState.xValues,
|
|
140
|
+
ticks: chartState.xValues.map((value) => ({ value, priority: 2 })),
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
.Tabs {
|
|
2
|
+
position: relative;
|
|
3
|
+
|
|
4
|
+
&::-webkit-scrollbar {
|
|
5
|
+
display: none;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Variant: default
|
|
9
|
+
&.Tabs--variant-default,
|
|
10
|
+
&.Tabs--variant-scroll {
|
|
11
|
+
margin: 16px 0;
|
|
12
|
+
display: flex;
|
|
13
|
+
|
|
14
|
+
.Tabs__Tab {
|
|
15
|
+
@include grapher_label-2-medium;
|
|
16
|
+
flex-shrink: 0;
|
|
17
|
+
display: inline-block;
|
|
18
|
+
margin: 0 8px 8px 0;
|
|
19
|
+
padding: 8px;
|
|
20
|
+
border: 1px solid $blue-10;
|
|
21
|
+
background: #fff;
|
|
22
|
+
color: $dark-text;
|
|
23
|
+
white-space: normal;
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
text-wrap: balance;
|
|
26
|
+
|
|
27
|
+
&[data-hovered] {
|
|
28
|
+
background-color: $gray-10;
|
|
29
|
+
border-color: $gray-10;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&[data-selected] {
|
|
33
|
+
background: $accent-pale-blue;
|
|
34
|
+
border-color: $accent-pale-blue;
|
|
35
|
+
color: $blue-90;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Variant: horizontal scroll
|
|
41
|
+
&.Tabs--variant-scroll {
|
|
42
|
+
overflow-x: auto;
|
|
43
|
+
white-space: nowrap;
|
|
44
|
+
-webkit-overflow-scrolling: touch;
|
|
45
|
+
scrollbar-width: none;
|
|
46
|
+
|
|
47
|
+
$fade-out-width: 40px;
|
|
48
|
+
padding-right: $fade-out-width;
|
|
49
|
+
mask-image: linear-gradient(
|
|
50
|
+
to right,
|
|
51
|
+
black calc(100% - #{$fade-out-width}),
|
|
52
|
+
transparent 100%
|
|
53
|
+
);
|
|
54
|
+
-webkit-mask-image: linear-gradient(
|
|
55
|
+
to right,
|
|
56
|
+
black calc(100% - #{$fade-out-width}),
|
|
57
|
+
transparent 100%
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Variant: slim
|
|
62
|
+
&.Tabs--variant-slim {
|
|
63
|
+
$font-size: var(--tabs-font-size, 13px);
|
|
64
|
+
--tab-padding: 16px;
|
|
65
|
+
|
|
66
|
+
$light-stroke: $gray-20;
|
|
67
|
+
|
|
68
|
+
$hover-fill: $gray-10;
|
|
69
|
+
$active-fill: $blue-20;
|
|
70
|
+
|
|
71
|
+
$border-radius: 4px;
|
|
72
|
+
$visual-gap: 2px;
|
|
73
|
+
|
|
74
|
+
display: flex;
|
|
75
|
+
height: $controlRowHeight;
|
|
76
|
+
margin: 0;
|
|
77
|
+
padding: $visual-gap;
|
|
78
|
+
// using a box-shadow instead of a border fixes a bug
|
|
79
|
+
// where the tab items weren't centered when zoomed in or out
|
|
80
|
+
box-shadow: inset 0 0 0 1px $light-stroke;
|
|
81
|
+
border-radius: $border-radius;
|
|
82
|
+
|
|
83
|
+
.Tabs__Tab {
|
|
84
|
+
position: relative;
|
|
85
|
+
|
|
86
|
+
$height: $controlRowHeight - 2 * $visual-gap;
|
|
87
|
+
|
|
88
|
+
display: block;
|
|
89
|
+
text-transform: capitalize;
|
|
90
|
+
color: $light-text;
|
|
91
|
+
font-size: $font-size;
|
|
92
|
+
font-weight: 500;
|
|
93
|
+
height: $height;
|
|
94
|
+
line-height: $height;
|
|
95
|
+
border-radius: $border-radius - $visual-gap;
|
|
96
|
+
padding: 0 var(--tab-padding);
|
|
97
|
+
cursor: pointer;
|
|
98
|
+
letter-spacing: 0.01em;
|
|
99
|
+
white-space: nowrap;
|
|
100
|
+
user-select: none;
|
|
101
|
+
text-align: center;
|
|
102
|
+
text-overflow: ellipsis;
|
|
103
|
+
overflow: hidden;
|
|
104
|
+
|
|
105
|
+
&[data-hovered] {
|
|
106
|
+
background-color: $hover-fill;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
&[data-selected] {
|
|
110
|
+
color: $active-text;
|
|
111
|
+
background-color: $active-fill;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// separators between tabs
|
|
116
|
+
.Tabs__Tab + .Tabs__Tab::before {
|
|
117
|
+
content: "";
|
|
118
|
+
display: block;
|
|
119
|
+
width: 1px;
|
|
120
|
+
height: calc(100% - 12px);
|
|
121
|
+
position: absolute;
|
|
122
|
+
top: 6px;
|
|
123
|
+
background-color: $light-stroke;
|
|
124
|
+
left: -0.5px;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// hide separators when a tab is hovered over or when a tab is active
|
|
128
|
+
.Tabs__Tab[data-selected]::before,
|
|
129
|
+
.Tabs__Tab[data-hovered]::before,
|
|
130
|
+
.Tabs__Tab[data-selected] + .Tabs__Tab::before,
|
|
131
|
+
.Tabs__Tab[data-hovered] + .Tabs__Tab::before {
|
|
132
|
+
display: none;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Variant: stretch
|
|
137
|
+
&.Tabs--variant-stretch {
|
|
138
|
+
display: flex;
|
|
139
|
+
gap: 8px;
|
|
140
|
+
|
|
141
|
+
$hover-fill: $gray-10;
|
|
142
|
+
$active-fill: $accent-pale-blue;
|
|
143
|
+
|
|
144
|
+
.Tabs__Tab {
|
|
145
|
+
flex-grow: 1;
|
|
146
|
+
flex-shrink: 1;
|
|
147
|
+
|
|
148
|
+
@include grapher_label-2-medium;
|
|
149
|
+
display: inline-block;
|
|
150
|
+
padding: 8px;
|
|
151
|
+
border: 1px solid $blue-10;
|
|
152
|
+
background: #fff;
|
|
153
|
+
color: $dark-text;
|
|
154
|
+
cursor: pointer;
|
|
155
|
+
text-wrap: balance;
|
|
156
|
+
|
|
157
|
+
&[data-hovered] {
|
|
158
|
+
background-color: $hover-fill;
|
|
159
|
+
border-color: $hover-fill;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
&[data-selected] {
|
|
163
|
+
background: $active-fill;
|
|
164
|
+
border-color: $active-fill;
|
|
165
|
+
color: $blue-90;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import cx from "classnames"
|
|
3
|
+
import { Tabs as AriaTabs, TabList, Tab } from "react-aria-components"
|
|
4
|
+
|
|
5
|
+
export interface TabItem<TabKey extends string = string> {
|
|
6
|
+
key: TabKey
|
|
7
|
+
element: React.ReactElement
|
|
8
|
+
buttonProps?: {
|
|
9
|
+
className?: string
|
|
10
|
+
ariaLabel?: string
|
|
11
|
+
dataTrackNote?: string
|
|
12
|
+
ref?: React.RefObject<HTMLButtonElement | null>
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const Tabs = <TabKey extends string = string>({
|
|
17
|
+
items,
|
|
18
|
+
selectedKey,
|
|
19
|
+
onChange,
|
|
20
|
+
className,
|
|
21
|
+
variant = "default",
|
|
22
|
+
}: {
|
|
23
|
+
items: TabItem<TabKey>[]
|
|
24
|
+
selectedKey: TabKey
|
|
25
|
+
onChange: (key: TabKey) => void
|
|
26
|
+
className?: string
|
|
27
|
+
variant?: "default" | "slim" | "stretch" | "scroll"
|
|
28
|
+
}) => {
|
|
29
|
+
return (
|
|
30
|
+
<AriaTabs
|
|
31
|
+
selectedKey={selectedKey}
|
|
32
|
+
onSelectionChange={(key) => {
|
|
33
|
+
if (typeof key === "string") onChange(key as TabKey)
|
|
34
|
+
}}
|
|
35
|
+
>
|
|
36
|
+
<TabList
|
|
37
|
+
className={cx("Tabs", "Tabs--variant-" + variant, className)}
|
|
38
|
+
>
|
|
39
|
+
{items.map((item) => (
|
|
40
|
+
<Tab
|
|
41
|
+
key={item.key}
|
|
42
|
+
id={item.key}
|
|
43
|
+
data-track-note={item.buttonProps?.dataTrackNote}
|
|
44
|
+
aria-label={item.buttonProps?.ariaLabel}
|
|
45
|
+
className={cx("Tabs__Tab", item.buttonProps?.className)}
|
|
46
|
+
ref={item.buttonProps?.ref}
|
|
47
|
+
>
|
|
48
|
+
{item.element}
|
|
49
|
+
</Tab>
|
|
50
|
+
))}
|
|
51
|
+
</TabList>
|
|
52
|
+
</AriaTabs>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
.TabsWithDropdown {
|
|
2
|
+
position: relative;
|
|
3
|
+
|
|
4
|
+
.TabsWithDropdown__Row {
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: stretch;
|
|
7
|
+
gap: 8px;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.TabsWithDropdown__MoreButton {
|
|
11
|
+
@include grapher_label-2-medium;
|
|
12
|
+
flex: 0 0 auto; // Fixed size
|
|
13
|
+
display: inline-flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
justify-content: center;
|
|
16
|
+
gap: 8px;
|
|
17
|
+
padding: 8px 16px;
|
|
18
|
+
background: $gray-10;
|
|
19
|
+
color: $gray-80;
|
|
20
|
+
white-space: nowrap;
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
|
|
23
|
+
&[data-hovered] {
|
|
24
|
+
background: $blue-20;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&[data-open] {
|
|
28
|
+
background: $accent-pale-blue;
|
|
29
|
+
color: $blue-90;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@at-root .TabsWithDropdown__Popover {
|
|
35
|
+
border-radius: 4px;
|
|
36
|
+
background-color: #fff;
|
|
37
|
+
box-shadow: 0px 4px 40px 0px rgba(0, 0, 0, 0.06);
|
|
38
|
+
max-width: 400px;
|
|
39
|
+
max-height: 400px;
|
|
40
|
+
overflow: hidden;
|
|
41
|
+
|
|
42
|
+
.TabsWithDropdown__Menu {
|
|
43
|
+
max-height: 400px;
|
|
44
|
+
overflow-y: auto;
|
|
45
|
+
padding: 4px 0;
|
|
46
|
+
outline: none;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.TabsWithDropdown__MenuItem {
|
|
50
|
+
@include grapher_label-2-regular;
|
|
51
|
+
|
|
52
|
+
padding: 8px 16px;
|
|
53
|
+
color: $gray-80;
|
|
54
|
+
cursor: pointer;
|
|
55
|
+
text-wrap: balance;
|
|
56
|
+
|
|
57
|
+
&[data-hovered],
|
|
58
|
+
&[data-focused] {
|
|
59
|
+
background-color: $gray-10;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import * as R from "remeda"
|
|
2
|
+
import cx from "classnames"
|
|
3
|
+
import { useState } from "react"
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
MenuTrigger,
|
|
7
|
+
Popover,
|
|
8
|
+
Menu,
|
|
9
|
+
MenuItem,
|
|
10
|
+
} from "react-aria-components"
|
|
11
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
|
|
12
|
+
import { faEllipsisVertical } from "@fortawesome/free-solid-svg-icons"
|
|
13
|
+
import { TabItem, Tabs } from "./Tabs"
|
|
14
|
+
|
|
15
|
+
export const TabsWithDropdown = <TabKey extends string = string>({
|
|
16
|
+
items,
|
|
17
|
+
selectedKey,
|
|
18
|
+
onChange,
|
|
19
|
+
numVisibleTabs,
|
|
20
|
+
className,
|
|
21
|
+
portalContainer,
|
|
22
|
+
}: {
|
|
23
|
+
items: TabItem<TabKey>[]
|
|
24
|
+
selectedKey: TabKey
|
|
25
|
+
onChange: (key: TabKey) => void
|
|
26
|
+
numVisibleTabs: number
|
|
27
|
+
className?: string
|
|
28
|
+
portalContainer?: HTMLElement
|
|
29
|
+
}) => {
|
|
30
|
+
const [isOpen, setIsOpen] = useState(false)
|
|
31
|
+
|
|
32
|
+
let visibleItems = R.take(items, numVisibleTabs)
|
|
33
|
+
let hiddenItems = items.filter(
|
|
34
|
+
(item) => !visibleItems.find((v) => v.key === item.key)
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
// If a hidden item is selected, swap it with the last visible item
|
|
38
|
+
const selectedHiddenItem = hiddenItems.find(
|
|
39
|
+
(item) => item.key === selectedKey
|
|
40
|
+
)
|
|
41
|
+
if (selectedHiddenItem && visibleItems.length > 0) {
|
|
42
|
+
const lastVisibleItem = visibleItems[visibleItems.length - 1]
|
|
43
|
+
visibleItems = R.pipe(
|
|
44
|
+
visibleItems,
|
|
45
|
+
R.dropLast(1),
|
|
46
|
+
R.concat([selectedHiddenItem])
|
|
47
|
+
)
|
|
48
|
+
hiddenItems = hiddenItems
|
|
49
|
+
.filter((item) => item.key !== selectedKey)
|
|
50
|
+
.concat(lastVisibleItem)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const handleSelect = (key: React.Key) => {
|
|
54
|
+
if (typeof key === "string") onChange(key as TabKey)
|
|
55
|
+
setIsOpen(false)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div className={cx("TabsWithDropdown", className)}>
|
|
60
|
+
<div className="TabsWithDropdown__Row">
|
|
61
|
+
<Tabs
|
|
62
|
+
className="TabsWithDropdown__Tabs"
|
|
63
|
+
items={visibleItems}
|
|
64
|
+
selectedKey={selectedKey}
|
|
65
|
+
onChange={onChange}
|
|
66
|
+
variant="stretch"
|
|
67
|
+
/>
|
|
68
|
+
{hiddenItems.length > 0 && (
|
|
69
|
+
<MenuTrigger isOpen={isOpen} onOpenChange={setIsOpen}>
|
|
70
|
+
<Button
|
|
71
|
+
className="TabsWithDropdown__MoreButton"
|
|
72
|
+
aria-label="Show more tabs"
|
|
73
|
+
data-open={isOpen || undefined}
|
|
74
|
+
>
|
|
75
|
+
<FontAwesomeIcon
|
|
76
|
+
icon={faEllipsisVertical}
|
|
77
|
+
aria-hidden="true"
|
|
78
|
+
/>
|
|
79
|
+
<span>More</span>
|
|
80
|
+
</Button>
|
|
81
|
+
<Popover
|
|
82
|
+
className="TabsWithDropdown__Popover"
|
|
83
|
+
placement="bottom end"
|
|
84
|
+
UNSTABLE_portalContainer={portalContainer}
|
|
85
|
+
>
|
|
86
|
+
<Menu
|
|
87
|
+
className="TabsWithDropdown__Menu"
|
|
88
|
+
onAction={handleSelect}
|
|
89
|
+
>
|
|
90
|
+
{hiddenItems.map((item) => (
|
|
91
|
+
<MenuItem
|
|
92
|
+
key={item.key}
|
|
93
|
+
id={item.key}
|
|
94
|
+
className={cx(
|
|
95
|
+
"TabsWithDropdown__MenuItem",
|
|
96
|
+
item.buttonProps?.className
|
|
97
|
+
)}
|
|
98
|
+
data-track-note={
|
|
99
|
+
item.buttonProps?.dataTrackNote
|
|
100
|
+
}
|
|
101
|
+
aria-label={item.buttonProps?.ariaLabel}
|
|
102
|
+
ref={item.buttonProps?.ref}
|
|
103
|
+
>
|
|
104
|
+
{item.element}
|
|
105
|
+
</MenuItem>
|
|
106
|
+
))}
|
|
107
|
+
</Menu>
|
|
108
|
+
</Popover>
|
|
109
|
+
</MenuTrigger>
|
|
110
|
+
)}
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
)
|
|
114
|
+
}
|