@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,387 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ALL_GRAPHER_CHART_TYPES,
|
|
3
|
+
ColorSchemeName,
|
|
4
|
+
FacetAxisDomain,
|
|
5
|
+
FacetStrategy,
|
|
6
|
+
GRAPHER_CHART_TYPES,
|
|
7
|
+
GRAPHER_TAB_CONFIG_OPTIONS,
|
|
8
|
+
GrapherChartType,
|
|
9
|
+
MissingDataStrategy,
|
|
10
|
+
StackMode,
|
|
11
|
+
} from "../types/index.js"
|
|
12
|
+
import { SortBy, SortOrder } from "../utils/index.js"
|
|
13
|
+
import {
|
|
14
|
+
GridBoolean,
|
|
15
|
+
BooleanCellDef,
|
|
16
|
+
CellDef,
|
|
17
|
+
EnumCellDef,
|
|
18
|
+
Grammar,
|
|
19
|
+
IntegerCellDef,
|
|
20
|
+
NumericOrAutoCellDef,
|
|
21
|
+
SlugDeclarationCellDef,
|
|
22
|
+
SlugsDeclarationCellDef,
|
|
23
|
+
StringCellDef,
|
|
24
|
+
UrlCellDef,
|
|
25
|
+
IndicatorIdsOrEtlPathsCellDef,
|
|
26
|
+
IndicatorIdOrEtlPathCellDef,
|
|
27
|
+
SlugOrIndicatorIdOrEtlPathCellDef,
|
|
28
|
+
GrapherCellDef,
|
|
29
|
+
} from "./gridLang/GridLangConstants.js"
|
|
30
|
+
import * as R from "remeda"
|
|
31
|
+
const toTerminalOptions = (keywords: string[]): CellDef[] => {
|
|
32
|
+
return keywords.map((keyword) => ({
|
|
33
|
+
keyword,
|
|
34
|
+
cssClass: "",
|
|
35
|
+
description: "",
|
|
36
|
+
}))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const GrapherGrammar: Grammar<GrapherCellDef> = {
|
|
40
|
+
title: {
|
|
41
|
+
...StringCellDef,
|
|
42
|
+
keyword: "title",
|
|
43
|
+
description: "Chart title",
|
|
44
|
+
valuePlaceholder: "Life Expectancy around the world.",
|
|
45
|
+
toGrapherObject: (parsedValue) =>
|
|
46
|
+
omitEmptyStringValues({ title: parsedValue }),
|
|
47
|
+
},
|
|
48
|
+
subtitle: {
|
|
49
|
+
...StringCellDef,
|
|
50
|
+
keyword: "subtitle",
|
|
51
|
+
description: "Chart subtitle",
|
|
52
|
+
valuePlaceholder: "Life Expectancy has risen over time.",
|
|
53
|
+
toGrapherObject: (parsedValue) =>
|
|
54
|
+
omitEmptyStringValues({ subtitle: parsedValue }),
|
|
55
|
+
},
|
|
56
|
+
ySlugs: {
|
|
57
|
+
...SlugsDeclarationCellDef,
|
|
58
|
+
description: "ColumnSlug(s) for the yAxis",
|
|
59
|
+
keyword: "ySlugs",
|
|
60
|
+
toGrapherObject: (parsedValue) =>
|
|
61
|
+
omitEmptyStringValues({ ySlugs: parsedValue }),
|
|
62
|
+
},
|
|
63
|
+
yVariableIds: {
|
|
64
|
+
...IndicatorIdsOrEtlPathsCellDef,
|
|
65
|
+
keyword: "yVariableIds",
|
|
66
|
+
description: "Variable ID(s) or ETL path(s) for the yAxis",
|
|
67
|
+
toGrapherObject: () => ({}), // explorer-specific, not used in grapher config
|
|
68
|
+
},
|
|
69
|
+
type: {
|
|
70
|
+
...StringCellDef,
|
|
71
|
+
keyword: "type",
|
|
72
|
+
description: `The type of chart to show such as LineChart or ScatterPlot. If set to None, then the chart tab is hidden.`,
|
|
73
|
+
terminalOptions: toTerminalOptions([
|
|
74
|
+
...ALL_GRAPHER_CHART_TYPES,
|
|
75
|
+
`${GRAPHER_CHART_TYPES.LineChart} ${GRAPHER_CHART_TYPES.SlopeChart}`,
|
|
76
|
+
`${GRAPHER_CHART_TYPES.LineChart} ${GRAPHER_CHART_TYPES.DiscreteBar}`,
|
|
77
|
+
`${GRAPHER_CHART_TYPES.SlopeChart} ${GRAPHER_CHART_TYPES.DiscreteBar}`,
|
|
78
|
+
`${GRAPHER_CHART_TYPES.LineChart} ${GRAPHER_CHART_TYPES.SlopeChart} ${GRAPHER_CHART_TYPES.DiscreteBar}`,
|
|
79
|
+
"None",
|
|
80
|
+
]),
|
|
81
|
+
toGrapherObject: (parsedValue) => {
|
|
82
|
+
if (parsedValue === "None") return { chartTypes: [] }
|
|
83
|
+
if (parsedValue)
|
|
84
|
+
return {
|
|
85
|
+
chartTypes: parsedValue.split(" ") as GrapherChartType[],
|
|
86
|
+
}
|
|
87
|
+
return {}
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
grapherId: {
|
|
91
|
+
...IntegerCellDef,
|
|
92
|
+
description: "ID of a legacy Grapher to load",
|
|
93
|
+
keyword: "grapherId",
|
|
94
|
+
toGrapherObject: (parsedValue) =>
|
|
95
|
+
omitEmptyStringValues({ id: parsedValue }),
|
|
96
|
+
},
|
|
97
|
+
tableSlug: {
|
|
98
|
+
...SlugDeclarationCellDef,
|
|
99
|
+
description:
|
|
100
|
+
"Slug of the explorer table (i.e. csv file) to use for this row. All variables used in this row must be present in the table/file.",
|
|
101
|
+
keyword: "tableSlug",
|
|
102
|
+
toGrapherObject: () => ({}), // explorer-specific, not used in grapher config
|
|
103
|
+
},
|
|
104
|
+
hasMapTab: {
|
|
105
|
+
...BooleanCellDef,
|
|
106
|
+
keyword: "hasMapTab",
|
|
107
|
+
description: "Show the map tab?",
|
|
108
|
+
toGrapherObject: (parsedValue) =>
|
|
109
|
+
omitEmptyStringValues({ hasMapTab: parsedValue }),
|
|
110
|
+
},
|
|
111
|
+
tab: {
|
|
112
|
+
...EnumCellDef,
|
|
113
|
+
keyword: "tab",
|
|
114
|
+
description: "Which tab to show by default",
|
|
115
|
+
terminalOptions: toTerminalOptions(
|
|
116
|
+
Object.values(GRAPHER_TAB_CONFIG_OPTIONS)
|
|
117
|
+
),
|
|
118
|
+
toGrapherObject: (parsedValue) =>
|
|
119
|
+
omitEmptyStringValues({ tab: parsedValue }),
|
|
120
|
+
},
|
|
121
|
+
xSlug: {
|
|
122
|
+
...SlugDeclarationCellDef,
|
|
123
|
+
description: "ColumnSlug for the xAxis",
|
|
124
|
+
keyword: "xSlug",
|
|
125
|
+
toGrapherObject: (parsedValue) =>
|
|
126
|
+
omitEmptyStringValues({ xSlug: parsedValue }),
|
|
127
|
+
},
|
|
128
|
+
xVariableId: {
|
|
129
|
+
...IndicatorIdOrEtlPathCellDef,
|
|
130
|
+
keyword: "xVariableId",
|
|
131
|
+
description: "Variable ID or ETL path for the xAxis",
|
|
132
|
+
toGrapherObject: () => ({}), // explorer-specific, not used in grapher config
|
|
133
|
+
},
|
|
134
|
+
colorSlug: {
|
|
135
|
+
...SlugDeclarationCellDef,
|
|
136
|
+
description: "ColumnSlug for the color",
|
|
137
|
+
keyword: "colorSlug",
|
|
138
|
+
toGrapherObject: (parsedValue) =>
|
|
139
|
+
omitEmptyStringValues({ colorSlug: parsedValue }),
|
|
140
|
+
},
|
|
141
|
+
colorVariableId: {
|
|
142
|
+
...IndicatorIdOrEtlPathCellDef,
|
|
143
|
+
keyword: "colorVariableId",
|
|
144
|
+
description: "Variable ID or ETL path for the color",
|
|
145
|
+
toGrapherObject: () => ({}), // explorer-specific, not used in grapher config
|
|
146
|
+
},
|
|
147
|
+
sizeSlug: {
|
|
148
|
+
...SlugDeclarationCellDef,
|
|
149
|
+
description: "ColumnSlug for the size of points on scatters",
|
|
150
|
+
keyword: "sizeSlug",
|
|
151
|
+
toGrapherObject: (parsedValue) =>
|
|
152
|
+
omitEmptyStringValues({ sizeSlug: parsedValue }),
|
|
153
|
+
},
|
|
154
|
+
sizeVariableId: {
|
|
155
|
+
...IndicatorIdOrEtlPathCellDef,
|
|
156
|
+
keyword: "sizeVariableId",
|
|
157
|
+
description:
|
|
158
|
+
"Variable ID or ETL path for the size of points on scatters",
|
|
159
|
+
toGrapherObject: () => ({}), // explorer-specific, not used in grapher config
|
|
160
|
+
},
|
|
161
|
+
tableSlugs: {
|
|
162
|
+
...SlugsDeclarationCellDef,
|
|
163
|
+
description:
|
|
164
|
+
"Columns to show in the Table tab of the chart. If not specified all active slugs will be used.",
|
|
165
|
+
keyword: "tableSlugs",
|
|
166
|
+
toGrapherObject: (parsedValue) =>
|
|
167
|
+
omitEmptyStringValues({ tableSlugs: parsedValue }),
|
|
168
|
+
},
|
|
169
|
+
sourceDesc: {
|
|
170
|
+
...StringCellDef,
|
|
171
|
+
keyword: "sourceDesc",
|
|
172
|
+
description: "Short comma-separated list of source names",
|
|
173
|
+
toGrapherObject: (parsedValue) =>
|
|
174
|
+
omitEmptyStringValues({ sourceDesc: parsedValue }),
|
|
175
|
+
},
|
|
176
|
+
hideAnnotationFieldsInTitle: {
|
|
177
|
+
...BooleanCellDef,
|
|
178
|
+
description: "Hide automatic time/entity",
|
|
179
|
+
keyword: "hideAnnotationFieldsInTitle",
|
|
180
|
+
parse: (value: any) => {
|
|
181
|
+
const parsedValue = value === GridBoolean.true
|
|
182
|
+
return {
|
|
183
|
+
entity: parsedValue,
|
|
184
|
+
time: parsedValue,
|
|
185
|
+
changeInPrefix: parsedValue,
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
toGrapherObject: (parsedValue) => ({
|
|
189
|
+
hideAnnotationFieldsInTitle: parsedValue,
|
|
190
|
+
}),
|
|
191
|
+
},
|
|
192
|
+
yScaleToggle: {
|
|
193
|
+
...BooleanCellDef,
|
|
194
|
+
keyword: "yScaleToggle",
|
|
195
|
+
description: "Set to 'true' if the user can change the yAxis",
|
|
196
|
+
toGrapherObject: (parsedValue) => ({
|
|
197
|
+
yAxis: omitEmptyStringValues({ canChangeScaleType: parsedValue }),
|
|
198
|
+
}),
|
|
199
|
+
},
|
|
200
|
+
yAxisMin: {
|
|
201
|
+
...NumericOrAutoCellDef,
|
|
202
|
+
keyword: "yAxisMin",
|
|
203
|
+
description: "Set the minimum parsedValue for the yAxis",
|
|
204
|
+
toGrapherObject: (parsedValue) =>
|
|
205
|
+
omitEmptyObjectValues({
|
|
206
|
+
yAxis: omitEmptyStringValues({ min: parsedValue }),
|
|
207
|
+
}),
|
|
208
|
+
},
|
|
209
|
+
facetYDomain: {
|
|
210
|
+
...EnumCellDef,
|
|
211
|
+
keyword: "facetYDomain",
|
|
212
|
+
description:
|
|
213
|
+
"Whether facets axes default to shared or independent domain",
|
|
214
|
+
terminalOptions: toTerminalOptions(Object.values(FacetAxisDomain)),
|
|
215
|
+
toGrapherObject: (parsedValue) =>
|
|
216
|
+
omitEmptyObjectValues({
|
|
217
|
+
yAxis: omitEmptyStringValues({ facetDomain: parsedValue }),
|
|
218
|
+
}),
|
|
219
|
+
},
|
|
220
|
+
selectedFacetStrategy: {
|
|
221
|
+
...EnumCellDef,
|
|
222
|
+
keyword: "selectedFacetStrategy",
|
|
223
|
+
description: "Whether the chart should be faceted or not",
|
|
224
|
+
terminalOptions: toTerminalOptions(Object.values(FacetStrategy)),
|
|
225
|
+
toGrapherObject: (parsedValue) =>
|
|
226
|
+
omitEmptyStringValues({ selectedFacetStrategy: parsedValue }),
|
|
227
|
+
},
|
|
228
|
+
entityType: {
|
|
229
|
+
...StringCellDef,
|
|
230
|
+
keyword: "entityType",
|
|
231
|
+
description:
|
|
232
|
+
"Default is 'country', but you can specify a different one such as 'state' or 'region'.",
|
|
233
|
+
toGrapherObject: (parsedValue) =>
|
|
234
|
+
omitEmptyStringValues({ entityType: parsedValue }),
|
|
235
|
+
},
|
|
236
|
+
baseColorScheme: {
|
|
237
|
+
...EnumCellDef,
|
|
238
|
+
keyword: "baseColorScheme",
|
|
239
|
+
description:
|
|
240
|
+
"The default color scheme if no color overrides are specified",
|
|
241
|
+
terminalOptions: toTerminalOptions(Object.keys(ColorSchemeName)),
|
|
242
|
+
toGrapherObject: (parsedValue) =>
|
|
243
|
+
omitEmptyStringValues({ baseColorScheme: parsedValue }),
|
|
244
|
+
},
|
|
245
|
+
note: {
|
|
246
|
+
...StringCellDef,
|
|
247
|
+
keyword: "note",
|
|
248
|
+
description: "Chart footnote",
|
|
249
|
+
toGrapherObject: (parsedValue) =>
|
|
250
|
+
omitEmptyStringValues({ note: parsedValue }),
|
|
251
|
+
},
|
|
252
|
+
sortBy: {
|
|
253
|
+
...EnumCellDef,
|
|
254
|
+
keyword: "sortBy",
|
|
255
|
+
description: "Specify what to sort the entities by",
|
|
256
|
+
terminalOptions: toTerminalOptions(Object.values(SortBy)),
|
|
257
|
+
toGrapherObject: (parsedValue) =>
|
|
258
|
+
omitEmptyStringValues({ sortBy: parsedValue }),
|
|
259
|
+
},
|
|
260
|
+
sortOrder: {
|
|
261
|
+
...EnumCellDef,
|
|
262
|
+
keyword: "sortOrder",
|
|
263
|
+
description: "Whether to sort entities ascending or descending",
|
|
264
|
+
terminalOptions: toTerminalOptions(Object.values(SortOrder)),
|
|
265
|
+
toGrapherObject: (parsedValue) =>
|
|
266
|
+
omitEmptyStringValues({ sortOrder: parsedValue }),
|
|
267
|
+
},
|
|
268
|
+
sortColumnSlug: {
|
|
269
|
+
...SlugOrIndicatorIdOrEtlPathCellDef,
|
|
270
|
+
keyword: "sortColumnSlug",
|
|
271
|
+
description:
|
|
272
|
+
"Column slug, variable ID, or catalog path to sort by. This setting is only respected when `sortBy` is set to `column`",
|
|
273
|
+
toGrapherObject: (parsedValue) =>
|
|
274
|
+
omitEmptyStringValues({ sortColumnSlug: parsedValue.toString() }),
|
|
275
|
+
},
|
|
276
|
+
stackMode: {
|
|
277
|
+
...EnumCellDef,
|
|
278
|
+
keyword: "stackMode",
|
|
279
|
+
description:
|
|
280
|
+
"Show chart in absolute (default) or relative mode. Only works for some chart types.",
|
|
281
|
+
terminalOptions: toTerminalOptions(Object.values(StackMode)),
|
|
282
|
+
toGrapherObject: (parsedValue) =>
|
|
283
|
+
omitEmptyStringValues({ stackMode: parsedValue }),
|
|
284
|
+
},
|
|
285
|
+
hideTotalValueLabel: {
|
|
286
|
+
...BooleanCellDef,
|
|
287
|
+
keyword: "hideTotalValueLabel",
|
|
288
|
+
description:
|
|
289
|
+
"Hide the total parsedValue that is normally displayed to the right of the bars in a stacked bar chart.",
|
|
290
|
+
toGrapherObject: (parsedValue) =>
|
|
291
|
+
omitEmptyStringValues({
|
|
292
|
+
hideTotalValueLabel: parsedValue,
|
|
293
|
+
}),
|
|
294
|
+
},
|
|
295
|
+
hideRelativeToggle: {
|
|
296
|
+
...BooleanCellDef,
|
|
297
|
+
keyword: "hideRelativeToggle",
|
|
298
|
+
description: "Whether to hide the relative mode UI toggle",
|
|
299
|
+
toGrapherObject: (parsedValue) =>
|
|
300
|
+
omitEmptyStringValues({ hideRelativeToggle: parsedValue }),
|
|
301
|
+
},
|
|
302
|
+
timelineMinTime: {
|
|
303
|
+
...IntegerCellDef,
|
|
304
|
+
keyword: "timelineMinTime",
|
|
305
|
+
description:
|
|
306
|
+
"Set the minimum time for the timeline. For days, use days since 21 Jan 2020, e.g. 24 Jan 2020 is '3'.",
|
|
307
|
+
toGrapherObject: (parsedValue) =>
|
|
308
|
+
omitEmptyStringValues({ timelineMinTime: parsedValue }),
|
|
309
|
+
},
|
|
310
|
+
timelineMaxTime: {
|
|
311
|
+
...IntegerCellDef,
|
|
312
|
+
keyword: "timelineMaxTime",
|
|
313
|
+
description:
|
|
314
|
+
"Set the maximum time for the timeline. For days, use days since 21 Jan 2020, e.g. 24 Jan 2020 is '3'.",
|
|
315
|
+
toGrapherObject: (parsedValue) =>
|
|
316
|
+
omitEmptyStringValues({ timelineMaxTime: parsedValue }),
|
|
317
|
+
},
|
|
318
|
+
defaultView: {
|
|
319
|
+
...BooleanCellDef,
|
|
320
|
+
keyword: "defaultView",
|
|
321
|
+
description: "Whether this view is used as the default view.",
|
|
322
|
+
toGrapherObject: () => ({}), // explorer-specific, not used in grapher config
|
|
323
|
+
},
|
|
324
|
+
relatedQuestionText: {
|
|
325
|
+
...StringCellDef,
|
|
326
|
+
keyword: "relatedQuestionText",
|
|
327
|
+
description:
|
|
328
|
+
"The text used for the related question (at the very bottom of the chart)",
|
|
329
|
+
toGrapherObject: () => ({}), // handled in code (can be done properly once the relatedQuestion field is refactored)
|
|
330
|
+
},
|
|
331
|
+
relatedQuestionUrl: {
|
|
332
|
+
...UrlCellDef,
|
|
333
|
+
keyword: "relatedQuestionUrl",
|
|
334
|
+
description: "The link of the related question text",
|
|
335
|
+
toGrapherObject: () => ({}), // handled in code (can be done properly once the relatedQuestion field is refactored)
|
|
336
|
+
},
|
|
337
|
+
mapTargetTime: {
|
|
338
|
+
...IntegerCellDef,
|
|
339
|
+
keyword: "mapTargetTime",
|
|
340
|
+
description:
|
|
341
|
+
"Set the 'target time' for the map chart. This is the year that will be shown by default in the map chart.",
|
|
342
|
+
toGrapherObject: (parsedValue) =>
|
|
343
|
+
omitEmptyObjectValues({
|
|
344
|
+
map: omitEmptyStringValues({ time: parsedValue }),
|
|
345
|
+
}),
|
|
346
|
+
},
|
|
347
|
+
missingDataStrategy: {
|
|
348
|
+
...EnumCellDef,
|
|
349
|
+
keyword: "missingDataStrategy",
|
|
350
|
+
description:
|
|
351
|
+
"Hide or show entities for which one or more variables are missing",
|
|
352
|
+
terminalOptions: toTerminalOptions(Object.values(MissingDataStrategy)),
|
|
353
|
+
toGrapherObject: (parsedValue) =>
|
|
354
|
+
omitEmptyStringValues({
|
|
355
|
+
missingDataStrategy: parsedValue,
|
|
356
|
+
}),
|
|
357
|
+
},
|
|
358
|
+
minTime: {
|
|
359
|
+
...IntegerCellDef,
|
|
360
|
+
keyword: "minTime",
|
|
361
|
+
description: "Start point of the initially selected time span",
|
|
362
|
+
toGrapherObject: (parsedValue) =>
|
|
363
|
+
omitEmptyStringValues({ minTime: parsedValue }),
|
|
364
|
+
},
|
|
365
|
+
maxTime: {
|
|
366
|
+
...IntegerCellDef,
|
|
367
|
+
keyword: "maxTime",
|
|
368
|
+
description: "End point of the initially selected time span",
|
|
369
|
+
toGrapherObject: (parsedValue) =>
|
|
370
|
+
omitEmptyStringValues({ maxTime: parsedValue }),
|
|
371
|
+
},
|
|
372
|
+
} as const
|
|
373
|
+
|
|
374
|
+
export function omitEmptyStringValues<T extends Record<string, any>>(
|
|
375
|
+
obj: T
|
|
376
|
+
): Record<string, any> {
|
|
377
|
+
return R.omitBy(obj, (parsedValue) => parsedValue === "")
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export function omitEmptyObjectValues<T extends Record<string, any>>(
|
|
381
|
+
obj: T
|
|
382
|
+
): Record<string, any> {
|
|
383
|
+
return R.omitBy(
|
|
384
|
+
obj,
|
|
385
|
+
(parsedValue) => R.isPlainObject(parsedValue) && R.isEmpty(parsedValue)
|
|
386
|
+
)
|
|
387
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
export const isBlankLine = (line: string[] | undefined) =>
|
|
3
|
+
line === undefined ? true : line.join("") === ""
|
|
4
|
+
|
|
5
|
+
// Todo: figure out Matrix cell type and whether we need the double check
|
|
6
|
+
export const isEmpty = (value: any) => value === "" || value === undefined
|
|
7
|
+
|
|
8
|
+
// Adapted from: https://github.com/dcporter/didyoumean.js/blob/master/didYouMean-1.2.1.js
|
|
9
|
+
export const didYouMean = (
|
|
10
|
+
str = "",
|
|
11
|
+
options: string[] = [],
|
|
12
|
+
caseSensitive = false,
|
|
13
|
+
threshold = 0.4,
|
|
14
|
+
thresholdAbsolute = 20
|
|
15
|
+
) => {
|
|
16
|
+
if (!caseSensitive) str = str.toLowerCase()
|
|
17
|
+
|
|
18
|
+
// Calculate the initial value (the threshold) if present.
|
|
19
|
+
let maximumEditDistanceToBeBestMatch = Math.min(
|
|
20
|
+
threshold * str.length,
|
|
21
|
+
thresholdAbsolute
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
// Get the edit distance to each option. If the closest one is less than 40% (by default) of str's length, then return it.
|
|
25
|
+
let closestMatch
|
|
26
|
+
const len = options.length
|
|
27
|
+
for (let optionIndex = 0; optionIndex < len; optionIndex++) {
|
|
28
|
+
const candidate = options[optionIndex]
|
|
29
|
+
|
|
30
|
+
if (!candidate) continue
|
|
31
|
+
|
|
32
|
+
const editDistance = getEditDistance(
|
|
33
|
+
str,
|
|
34
|
+
caseSensitive ? candidate : candidate.toLowerCase(),
|
|
35
|
+
maximumEditDistanceToBeBestMatch
|
|
36
|
+
)
|
|
37
|
+
if (editDistance < maximumEditDistanceToBeBestMatch) {
|
|
38
|
+
maximumEditDistanceToBeBestMatch = editDistance
|
|
39
|
+
closestMatch = candidate
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return closestMatch
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const MAX_INT = Math.pow(2, 32) - 1
|
|
47
|
+
const getEditDistance = (stringA: string, stringB: string, maxInt: number) => {
|
|
48
|
+
const aLength = stringA.length
|
|
49
|
+
const bLength = stringB.length
|
|
50
|
+
|
|
51
|
+
// Fast path - no A or B.
|
|
52
|
+
if (aLength === 0) return Math.min(maxInt + 1, bLength)
|
|
53
|
+
if (bLength === 0) return Math.min(maxInt + 1, aLength)
|
|
54
|
+
|
|
55
|
+
// Fast path - length diff larger than max.
|
|
56
|
+
if (Math.abs(aLength - bLength) > maxInt) return maxInt + 1
|
|
57
|
+
|
|
58
|
+
// Slow path.
|
|
59
|
+
const matrix = []
|
|
60
|
+
|
|
61
|
+
// Set up the first row ([0, 1, 2, 3, etc]).
|
|
62
|
+
for (let bIndex = 0; bIndex <= bLength; bIndex++) {
|
|
63
|
+
matrix[bIndex] = [bIndex]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Set up the first column (same).
|
|
67
|
+
for (let aIndex = 0; aIndex <= aLength; aIndex++) {
|
|
68
|
+
matrix[0][aIndex] = aIndex
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let colMin
|
|
72
|
+
let minJ
|
|
73
|
+
let maxJ
|
|
74
|
+
|
|
75
|
+
// Loop over the rest of the columns.
|
|
76
|
+
for (let bIndex = 1; bIndex <= bLength; bIndex++) {
|
|
77
|
+
colMin = MAX_INT
|
|
78
|
+
minJ = 1
|
|
79
|
+
if (bIndex > maxInt) minJ = bIndex - maxInt
|
|
80
|
+
maxJ = bLength + 1
|
|
81
|
+
if (maxJ > maxInt + bIndex) maxJ = maxInt + bIndex
|
|
82
|
+
// Loop over the rest of the rows.
|
|
83
|
+
for (let aIndex = 1; aIndex <= aLength; aIndex++) {
|
|
84
|
+
// If j is out of bounds, just put a large value in the slot.
|
|
85
|
+
if (aIndex < minJ || aIndex > maxJ)
|
|
86
|
+
matrix[bIndex][aIndex] = maxInt + 1
|
|
87
|
+
// Otherwise do the normal Levenshtein thing.
|
|
88
|
+
else {
|
|
89
|
+
// If the characters are the same, there's no change in edit distance.
|
|
90
|
+
if (stringB.charAt(bIndex - 1) === stringA.charAt(aIndex - 1))
|
|
91
|
+
matrix[bIndex][aIndex] = matrix[bIndex - 1][aIndex - 1]
|
|
92
|
+
// Otherwise, see if we're substituting, inserting or deleting.
|
|
93
|
+
else
|
|
94
|
+
matrix[bIndex][aIndex] = Math.min(
|
|
95
|
+
matrix[bIndex - 1][aIndex - 1] + 1, // Substitute
|
|
96
|
+
Math.min(
|
|
97
|
+
matrix[bIndex][aIndex - 1] + 1, // Insert
|
|
98
|
+
matrix[bIndex - 1][aIndex] + 1
|
|
99
|
+
)
|
|
100
|
+
) // Delete
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Either way, update colMin.
|
|
104
|
+
if (matrix[bIndex][aIndex] < colMin) colMin = matrix[bIndex][aIndex]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// If this column's minimum is greater than the allowed maximum, there's no point
|
|
108
|
+
// in going on with life.
|
|
109
|
+
if (colMin > maxInt) return maxInt + 1
|
|
110
|
+
}
|
|
111
|
+
// If we made it this far without running into the max, then return the final matrix value.
|
|
112
|
+
return matrix[bLength][aLength]
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const delimitedToMatrix = (
|
|
116
|
+
delimited: string,
|
|
117
|
+
rowDelimiter = "\n",
|
|
118
|
+
columnDelimiter = "\t"
|
|
119
|
+
) => delimited.split(rowDelimiter).map((line) => line.split(columnDelimiter))
|
|
120
|
+
|
|
121
|
+
export const tsvToMatrix = delimitedToMatrix
|