@langchain/macaw-components 1.0.0-beta.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 +21 -0
- package/README.md +27 -0
- package/dist/_chunks/ErrorState-CmPX01HV.js +13361 -0
- package/dist/_chunks/ErrorState-CmPX01HV.js.map +1 -0
- package/dist/_chunks/LoadingIndicator-DgtU9aqD.js +80 -0
- package/dist/_chunks/LoadingIndicator-DgtU9aqD.js.map +1 -0
- package/dist/base.css +305 -0
- package/dist/catalog.json +1675 -0
- package/dist/components/Avatar/Avatar.d.ts +28 -0
- package/dist/components/Avatar/Avatar.js +47 -0
- package/dist/components/Avatar/Avatar.js.map +1 -0
- package/dist/components/Avatar/index.d.ts +2 -0
- package/dist/components/Avatar/index.js +2 -0
- package/dist/components/Badge/Badge.d.ts +25 -0
- package/dist/components/Badge/Badge.js +82 -0
- package/dist/components/Badge/Badge.js.map +1 -0
- package/dist/components/Badge/index.d.ts +2 -0
- package/dist/components/Badge/index.js +2 -0
- package/dist/components/Banner/Banner.d.ts +15 -0
- package/dist/components/Banner/Banner.js +102 -0
- package/dist/components/Banner/Banner.js.map +1 -0
- package/dist/components/Banner/index.d.ts +2 -0
- package/dist/components/Banner/index.js +2 -0
- package/dist/components/BarChart/AnimatedBar.d.ts +20 -0
- package/dist/components/BarChart/AnimatedBar.js +65 -0
- package/dist/components/BarChart/AnimatedBar.js.map +1 -0
- package/dist/components/BarChart/BarChart.d.ts +25 -0
- package/dist/components/BarChart/BarChart.js +248 -0
- package/dist/components/BarChart/BarChart.js.map +1 -0
- package/dist/components/BarChart/BarChart.types.d.ts +239 -0
- package/dist/components/BarChart/BarChart.types.js +0 -0
- package/dist/components/BarChart/BarChart.utils.d.ts +51 -0
- package/dist/components/BarChart/BarChart.utils.js +215 -0
- package/dist/components/BarChart/BarChart.utils.js.map +1 -0
- package/dist/components/BarChart/BarChartAxes.d.ts +22 -0
- package/dist/components/BarChart/BarChartAxes.js +144 -0
- package/dist/components/BarChart/BarChartAxes.js.map +1 -0
- package/dist/components/BarChart/BarChartGuides.d.ts +22 -0
- package/dist/components/BarChart/BarChartGuides.js +83 -0
- package/dist/components/BarChart/BarChartGuides.js.map +1 -0
- package/dist/components/BarChart/BarChartPlot.d.ts +40 -0
- package/dist/components/BarChart/BarChartPlot.js +262 -0
- package/dist/components/BarChart/BarChartPlot.js.map +1 -0
- package/dist/components/BarChart/constants.d.ts +21 -0
- package/dist/components/BarChart/constants.js +26 -0
- package/dist/components/BarChart/constants.js.map +1 -0
- package/dist/components/BarChart/index.d.ts +3 -0
- package/dist/components/BarChart/index.js +3 -0
- package/dist/components/Button/Button.d.ts +36 -0
- package/dist/components/Button/Button.js +99 -0
- package/dist/components/Button/Button.js.map +1 -0
- package/dist/components/Button/constants.d.ts +26 -0
- package/dist/components/Button/constants.js +31 -0
- package/dist/components/Button/constants.js.map +1 -0
- package/dist/components/Button/index.d.ts +2 -0
- package/dist/components/Button/index.js +2 -0
- package/dist/components/ButtonGroup/ButtonGroup.d.ts +30 -0
- package/dist/components/ButtonGroup/ButtonGroup.js +26 -0
- package/dist/components/ButtonGroup/ButtonGroup.js.map +1 -0
- package/dist/components/ButtonGroup/index.d.ts +2 -0
- package/dist/components/ButtonGroup/index.js +2 -0
- package/dist/components/Card/Card.d.ts +10 -0
- package/dist/components/Card/Card.js +23 -0
- package/dist/components/Card/Card.js.map +1 -0
- package/dist/components/Card/index.d.ts +2 -0
- package/dist/components/Card/index.js +2 -0
- package/dist/components/ChartCard/ChartCard.d.ts +53 -0
- package/dist/components/ChartCard/ChartCard.js +172 -0
- package/dist/components/ChartCard/ChartCard.js.map +1 -0
- package/dist/components/ChartCard/ChartCardSkeleton.d.ts +7 -0
- package/dist/components/ChartCard/ChartCardSkeleton.js +61 -0
- package/dist/components/ChartCard/ChartCardSkeleton.js.map +1 -0
- package/dist/components/ChartCard/index.d.ts +4 -0
- package/dist/components/ChartCard/index.js +3 -0
- package/dist/components/ChartLegend/ChartLegend.d.ts +19 -0
- package/dist/components/ChartLegend/ChartLegend.js +195 -0
- package/dist/components/ChartLegend/ChartLegend.js.map +1 -0
- package/dist/components/ChartLegend/ChartLegendItemRenderer.d.ts +14 -0
- package/dist/components/ChartLegend/ChartLegendItemRenderer.js +90 -0
- package/dist/components/ChartLegend/ChartLegendItemRenderer.js.map +1 -0
- package/dist/components/ChartLegend/index.d.ts +3 -0
- package/dist/components/ChartLegend/index.js +3 -0
- package/dist/components/ChartLegend/useChartLegendActiveItem.d.ts +7 -0
- package/dist/components/ChartLegend/useChartLegendActiveItem.js +35 -0
- package/dist/components/ChartLegend/useChartLegendActiveItem.js.map +1 -0
- package/dist/components/ChartLegend/utils.d.ts +20 -0
- package/dist/components/ChartLegend/utils.js +33 -0
- package/dist/components/ChartLegend/utils.js.map +1 -0
- package/dist/components/ChartTooltip/ChartTooltip.d.ts +23 -0
- package/dist/components/ChartTooltip/ChartTooltip.js +83 -0
- package/dist/components/ChartTooltip/ChartTooltip.js.map +1 -0
- package/dist/components/ChartTooltip/index.d.ts +2 -0
- package/dist/components/ChartTooltip/index.js +2 -0
- package/dist/components/Checkbox/Checkbox.d.ts +58 -0
- package/dist/components/Checkbox/Checkbox.js +50 -0
- package/dist/components/Checkbox/Checkbox.js.map +1 -0
- package/dist/components/Checkbox/constants.d.ts +28 -0
- package/dist/components/Checkbox/constants.js +57 -0
- package/dist/components/Checkbox/constants.js.map +1 -0
- package/dist/components/Checkbox/getCheckedState.d.ts +6 -0
- package/dist/components/Checkbox/getCheckedState.js +14 -0
- package/dist/components/Checkbox/getCheckedState.js.map +1 -0
- package/dist/components/Checkbox/index.d.ts +3 -0
- package/dist/components/Checkbox/index.js +3 -0
- package/dist/components/CircularProgress/CircularProgress.d.ts +54 -0
- package/dist/components/CircularProgress/CircularProgress.js +85 -0
- package/dist/components/CircularProgress/CircularProgress.js.map +1 -0
- package/dist/components/CircularProgress/index.d.ts +2 -0
- package/dist/components/CircularProgress/index.js +2 -0
- package/dist/components/Code/Code.utils.d.ts +24 -0
- package/dist/components/Code/Code.utils.js +160 -0
- package/dist/components/Code/Code.utils.js.map +1 -0
- package/dist/components/Code/CodeLite.d.ts +19 -0
- package/dist/components/Code/CodeLite.js +146 -0
- package/dist/components/Code/CodeLite.js.map +1 -0
- package/dist/components/Code/CodeLite.utils.d.ts +24 -0
- package/dist/components/Code/CodeLite.utils.js +273 -0
- package/dist/components/Code/CodeLite.utils.js.map +1 -0
- package/dist/components/Code/ImageReplacerExtension.d.ts +9 -0
- package/dist/components/Code/ImageReplacerExtension.js +227 -0
- package/dist/components/Code/ImageReplacerExtension.js.map +1 -0
- package/dist/components/Code/JsonHighlighterExtension.d.ts +4 -0
- package/dist/components/Code/JsonHighlighterExtension.js +172 -0
- package/dist/components/Code/JsonHighlighterExtension.js.map +1 -0
- package/dist/components/Code/constants.d.ts +6 -0
- package/dist/components/Code/constants.js +11 -0
- package/dist/components/Code/constants.js.map +1 -0
- package/dist/components/Code/index.d.ts +30 -0
- package/dist/components/Code/index.js +140 -0
- package/dist/components/Code/index.js.map +1 -0
- package/dist/components/Code/languages/json.d.ts +1 -0
- package/dist/components/Code/languages/json.js +7 -0
- package/dist/components/Code/languages/json.js.map +1 -0
- package/dist/components/Code/languages/languages.d.ts +7 -0
- package/dist/components/Code/languages/languages.js +12 -0
- package/dist/components/Code/languages/languages.js.map +1 -0
- package/dist/components/Code/languages/python.d.ts +1 -0
- package/dist/components/Code/languages/python.js +7 -0
- package/dist/components/Code/languages/python.js.map +1 -0
- package/dist/components/Code/languages/shell.d.ts +7 -0
- package/dist/components/Code/languages/shell.js +241 -0
- package/dist/components/Code/languages/shell.js.map +1 -0
- package/dist/components/Code/languages/typescript.d.ts +1 -0
- package/dist/components/Code/languages/typescript.js +7 -0
- package/dist/components/Code/languages/typescript.js.map +1 -0
- package/dist/components/Code/languages/yaml.d.ts +2 -0
- package/dist/components/Code/languages/yaml.js +44 -0
- package/dist/components/Code/languages/yaml.js.map +1 -0
- package/dist/components/Code/types.d.ts +8 -0
- package/dist/components/Code/types.js +0 -0
- package/dist/components/Code/utils.d.ts +4 -0
- package/dist/components/Code/utils.js +27 -0
- package/dist/components/Code/utils.js.map +1 -0
- package/dist/components/Command/Command.d.ts +78 -0
- package/dist/components/Command/Command.js +78 -0
- package/dist/components/Command/Command.js.map +1 -0
- package/dist/components/Command/CommandMenu.d.ts +65 -0
- package/dist/components/Command/CommandMenu.js +101 -0
- package/dist/components/Command/CommandMenu.js.map +1 -0
- package/dist/components/Command/index.d.ts +4 -0
- package/dist/components/Command/index.js +3 -0
- package/dist/components/ContextMenu/ContextMenu.d.ts +9 -0
- package/dist/components/ContextMenu/ContextMenu.js +43 -0
- package/dist/components/ContextMenu/ContextMenu.js.map +1 -0
- package/dist/components/ContextMenu/index.d.ts +1 -0
- package/dist/components/ContextMenu/index.js +2 -0
- package/dist/components/CopyButton/CopyButton.d.ts +24 -0
- package/dist/components/CopyButton/CopyButton.js +121 -0
- package/dist/components/CopyButton/CopyButton.js.map +1 -0
- package/dist/components/CopyButton/copyToClipboard.d.ts +1 -0
- package/dist/components/CopyButton/copyToClipboard.js +29 -0
- package/dist/components/CopyButton/copyToClipboard.js.map +1 -0
- package/dist/components/CopyButton/index.d.ts +4 -0
- package/dist/components/CopyButton/index.js +4 -0
- package/dist/components/CopyButton/useCopy.d.ts +10 -0
- package/dist/components/CopyButton/useCopy.js +46 -0
- package/dist/components/CopyButton/useCopy.js.map +1 -0
- package/dist/components/Dialog/index.d.ts +49 -0
- package/dist/components/Dialog/index.js +130 -0
- package/dist/components/Dialog/index.js.map +1 -0
- package/dist/components/Divider/Divider.d.ts +9 -0
- package/dist/components/Divider/Divider.js +27 -0
- package/dist/components/Divider/Divider.js.map +1 -0
- package/dist/components/Divider/index.d.ts +2 -0
- package/dist/components/Divider/index.js +2 -0
- package/dist/components/DonutChart/DonutChart.d.ts +101 -0
- package/dist/components/DonutChart/DonutChart.js +197 -0
- package/dist/components/DonutChart/DonutChart.js.map +1 -0
- package/dist/components/DonutChart/DonutChart.utils.d.ts +38 -0
- package/dist/components/DonutChart/DonutChart.utils.js +93 -0
- package/dist/components/DonutChart/DonutChart.utils.js.map +1 -0
- package/dist/components/DonutChart/constants.d.ts +7 -0
- package/dist/components/DonutChart/constants.js +12 -0
- package/dist/components/DonutChart/constants.js.map +1 -0
- package/dist/components/DonutChart/index.d.ts +4 -0
- package/dist/components/DonutChart/index.js +4 -0
- package/dist/components/DropdownMenu/DropdownMenu.d.ts +24 -0
- package/dist/components/DropdownMenu/DropdownMenu.js +149 -0
- package/dist/components/DropdownMenu/DropdownMenu.js.map +1 -0
- package/dist/components/DropdownMenu/index.d.ts +1 -0
- package/dist/components/DropdownMenu/index.js +2 -0
- package/dist/components/EmptyState/EmptyState.d.ts +26 -0
- package/dist/components/EmptyState/EmptyState.js +85 -0
- package/dist/components/EmptyState/EmptyState.js.map +1 -0
- package/dist/components/EmptyState/index.d.ts +2 -0
- package/dist/components/EmptyState/index.js +2 -0
- package/dist/components/ErrorBoundary.d.ts +35 -0
- package/dist/components/ErrorBoundary.js +41 -0
- package/dist/components/ErrorBoundary.js.map +1 -0
- package/dist/components/ErrorMessage/ErrorMessage.d.ts +17 -0
- package/dist/components/ErrorMessage/ErrorMessage.js +146 -0
- package/dist/components/ErrorMessage/ErrorMessage.js.map +1 -0
- package/dist/components/ErrorMessage/index.d.ts +2 -0
- package/dist/components/ErrorMessage/index.js +2 -0
- package/dist/components/ErrorState/ErrorState.d.ts +23 -0
- package/dist/components/ErrorState/ErrorState.js +2 -0
- package/dist/components/ErrorState/index.d.ts +2 -0
- package/dist/components/ErrorState/index.js +2 -0
- package/dist/components/GroupedTabs/GroupedTabs.d.ts +31 -0
- package/dist/components/GroupedTabs/GroupedTabs.js +92 -0
- package/dist/components/GroupedTabs/GroupedTabs.js.map +1 -0
- package/dist/components/GroupedTabs/index.d.ts +2 -0
- package/dist/components/GroupedTabs/index.js +2 -0
- package/dist/components/HoverCard.d.ts +4 -0
- package/dist/components/HoverCard.js +34 -0
- package/dist/components/HoverCard.js.map +1 -0
- package/dist/components/Icon/Icon.d.ts +25 -0
- package/dist/components/Icon/Icon.js +57 -0
- package/dist/components/Icon/Icon.js.map +1 -0
- package/dist/components/Icon/index.d.ts +2 -0
- package/dist/components/Icon/index.js +2 -0
- package/dist/components/IconButton/IconButton.d.ts +35 -0
- package/dist/components/IconButton/IconButton.js +73 -0
- package/dist/components/IconButton/IconButton.js.map +1 -0
- package/dist/components/IconButton/index.d.ts +2 -0
- package/dist/components/IconButton/index.js +2 -0
- package/dist/components/Input/Input.d.ts +72 -0
- package/dist/components/Input/Input.js +221 -0
- package/dist/components/Input/Input.js.map +1 -0
- package/dist/components/Input/index.d.ts +2 -0
- package/dist/components/Input/index.js +2 -0
- package/dist/components/Input/inputStyles.d.ts +28 -0
- package/dist/components/Input/inputStyles.js +45 -0
- package/dist/components/Input/inputStyles.js.map +1 -0
- package/dist/components/Kbd/Kbd.d.ts +15 -0
- package/dist/components/Kbd/Kbd.js +30 -0
- package/dist/components/Kbd/Kbd.js.map +1 -0
- package/dist/components/Kbd/index.d.ts +2 -0
- package/dist/components/Kbd/index.js +2 -0
- package/dist/components/LineChart/LineChart.d.ts +8 -0
- package/dist/components/LineChart/LineChart.js +194 -0
- package/dist/components/LineChart/LineChart.js.map +1 -0
- package/dist/components/LineChart/LineChart.types.d.ts +138 -0
- package/dist/components/LineChart/LineChart.types.js +0 -0
- package/dist/components/LineChart/LineChart.utils.d.ts +29 -0
- package/dist/components/LineChart/LineChart.utils.js +123 -0
- package/dist/components/LineChart/LineChart.utils.js.map +1 -0
- package/dist/components/LineChart/LineChartPlot.d.ts +43 -0
- package/dist/components/LineChart/LineChartPlot.js +306 -0
- package/dist/components/LineChart/LineChartPlot.js.map +1 -0
- package/dist/components/LineChart/constants.d.ts +3 -0
- package/dist/components/LineChart/constants.js +8 -0
- package/dist/components/LineChart/constants.js.map +1 -0
- package/dist/components/LineChart/index.d.ts +2 -0
- package/dist/components/LineChart/index.js +2 -0
- package/dist/components/LinearProgress/LinearProgress.d.ts +16 -0
- package/dist/components/LinearProgress/LinearProgress.js +42 -0
- package/dist/components/LinearProgress/LinearProgress.js.map +1 -0
- package/dist/components/LinearProgress/index.d.ts +2 -0
- package/dist/components/LinearProgress/index.js +2 -0
- package/dist/components/Link/Link.d.ts +30 -0
- package/dist/components/Link/Link.js +51 -0
- package/dist/components/Link/Link.js.map +1 -0
- package/dist/components/Link/index.d.ts +2 -0
- package/dist/components/Link/index.js +2 -0
- package/dist/components/Logo/index.d.ts +17 -0
- package/dist/components/Logo/index.js +705 -0
- package/dist/components/Logo/index.js.map +1 -0
- package/dist/components/MetricChart/MetricChart.d.ts +9 -0
- package/dist/components/MetricChart/MetricChart.js +42 -0
- package/dist/components/MetricChart/MetricChart.js.map +1 -0
- package/dist/components/MetricChart/formatters.d.ts +18 -0
- package/dist/components/MetricChart/formatters.js +34 -0
- package/dist/components/MetricChart/formatters.js.map +1 -0
- package/dist/components/MetricChart/index.d.ts +4 -0
- package/dist/components/MetricChart/index.js +3 -0
- package/dist/components/Pane/Pane.d.ts +29 -0
- package/dist/components/Pane/Pane.js +171 -0
- package/dist/components/Pane/Pane.js.map +1 -0
- package/dist/components/Pane/Pane.utils.d.ts +10 -0
- package/dist/components/Pane/Pane.utils.js +7 -0
- package/dist/components/Pane/Pane.utils.js.map +1 -0
- package/dist/components/Pane/index.d.ts +3 -0
- package/dist/components/Pane/index.js +3 -0
- package/dist/components/PlainTextEditor/hooks/useResizeTextEditor.d.ts +9 -0
- package/dist/components/PlainTextEditor/hooks/useResizeTextEditor.js +76 -0
- package/dist/components/PlainTextEditor/hooks/useResizeTextEditor.js.map +1 -0
- package/dist/components/PlainTextEditor/index.d.ts +18 -0
- package/dist/components/PlainTextEditor/index.js +71 -0
- package/dist/components/PlainTextEditor/index.js.map +1 -0
- package/dist/components/Popover/Popover.d.ts +13 -0
- package/dist/components/Popover/Popover.js +48 -0
- package/dist/components/Popover/Popover.js.map +1 -0
- package/dist/components/Popover/constants.d.ts +1 -0
- package/dist/components/Popover/constants.js +6 -0
- package/dist/components/Popover/constants.js.map +1 -0
- package/dist/components/Popover/index.d.ts +1 -0
- package/dist/components/Popover/index.js +2 -0
- package/dist/components/PortalSlot.d.ts +11 -0
- package/dist/components/PortalSlot.js +41 -0
- package/dist/components/PortalSlot.js.map +1 -0
- package/dist/components/ProgressBar/ProgressBar.d.ts +38 -0
- package/dist/components/ProgressBar/ProgressBar.js +82 -0
- package/dist/components/ProgressBar/ProgressBar.js.map +1 -0
- package/dist/components/ProgressBar/index.d.ts +2 -0
- package/dist/components/ProgressBar/index.js +2 -0
- package/dist/components/RadioButton/RadioButton.d.ts +62 -0
- package/dist/components/RadioButton/RadioButton.js +38 -0
- package/dist/components/RadioButton/RadioButton.js.map +1 -0
- package/dist/components/RadioButton/constants.d.ts +30 -0
- package/dist/components/RadioButton/constants.js +55 -0
- package/dist/components/RadioButton/constants.js.map +1 -0
- package/dist/components/RadioButton/index.d.ts +2 -0
- package/dist/components/RadioButton/index.js +2 -0
- package/dist/components/RadioCard/RadioCard.d.ts +26 -0
- package/dist/components/RadioCard/RadioCard.js +43 -0
- package/dist/components/RadioCard/RadioCard.js.map +1 -0
- package/dist/components/RadioCard/index.d.ts +2 -0
- package/dist/components/RadioCard/index.js +2 -0
- package/dist/components/RadioGroup/RadioGroup.d.ts +5 -0
- package/dist/components/RadioGroup/RadioGroup.js +17 -0
- package/dist/components/RadioGroup/RadioGroup.js.map +1 -0
- package/dist/components/RadioGroup/RadioGroupItem.d.ts +5 -0
- package/dist/components/RadioGroup/RadioGroupItem.js +22 -0
- package/dist/components/RadioGroup/RadioGroupItem.js.map +1 -0
- package/dist/components/RadioGroup/index.d.ts +4 -0
- package/dist/components/RadioGroup/index.js +3 -0
- package/dist/components/Select/Select.d.ts +84 -0
- package/dist/components/Select/Select.js +120 -0
- package/dist/components/Select/Select.js.map +1 -0
- package/dist/components/Select/SelectPrimitive.d.ts +17 -0
- package/dist/components/Select/SelectPrimitive.js +126 -0
- package/dist/components/Select/SelectPrimitive.js.map +1 -0
- package/dist/components/Select/index.d.ts +4 -0
- package/dist/components/Select/index.js +3 -0
- package/dist/components/Skeleton/Skeleton.d.ts +13 -0
- package/dist/components/Skeleton/Skeleton.js +25 -0
- package/dist/components/Skeleton/Skeleton.js.map +1 -0
- package/dist/components/Skeleton/index.d.ts +1 -0
- package/dist/components/Skeleton/index.js +2 -0
- package/dist/components/Slider/Slider.d.ts +33 -0
- package/dist/components/Slider/Slider.js +64 -0
- package/dist/components/Slider/Slider.js.map +1 -0
- package/dist/components/Slider/index.d.ts +2 -0
- package/dist/components/Slider/index.js +2 -0
- package/dist/components/SparkLineChart/SparkLineChart.d.ts +14 -0
- package/dist/components/SparkLineChart/SparkLineChart.js +112 -0
- package/dist/components/SparkLineChart/SparkLineChart.js.map +1 -0
- package/dist/components/SparkLineChart/index.d.ts +2 -0
- package/dist/components/SparkLineChart/index.js +2 -0
- package/dist/components/Spinner/Spinner.d.ts +12 -0
- package/dist/components/Spinner/Spinner.js +33 -0
- package/dist/components/Spinner/Spinner.js.map +1 -0
- package/dist/components/Spinner/index.d.ts +1 -0
- package/dist/components/Spinner/index.js +2 -0
- package/dist/components/SplitViewPane/SplitViewPane.d.ts +41 -0
- package/dist/components/SplitViewPane/SplitViewPane.js +314 -0
- package/dist/components/SplitViewPane/SplitViewPane.js.map +1 -0
- package/dist/components/SplitViewPane/SplitViewPaneHeader.d.ts +22 -0
- package/dist/components/SplitViewPane/SplitViewPaneHeader.js +105 -0
- package/dist/components/SplitViewPane/SplitViewPaneHeader.js.map +1 -0
- package/dist/components/SplitViewPane/index.d.ts +2 -0
- package/dist/components/SplitViewPane/index.js +3 -0
- package/dist/components/SplitViewPane/openPaneRegistry.d.ts +2 -0
- package/dist/components/SplitViewPane/openPaneRegistry.js +49 -0
- package/dist/components/SplitViewPane/openPaneRegistry.js.map +1 -0
- package/dist/components/Switch/Switch.d.ts +35 -0
- package/dist/components/Switch/Switch.js +65 -0
- package/dist/components/Switch/Switch.js.map +1 -0
- package/dist/components/Switch/index.d.ts +2 -0
- package/dist/components/Switch/index.js +2 -0
- package/dist/components/Tabs/index.d.ts +27 -0
- package/dist/components/Tabs/index.js +45 -0
- package/dist/components/Tabs/index.js.map +1 -0
- package/dist/components/Text/Text.d.ts +13 -0
- package/dist/components/Text/Text.js +58 -0
- package/dist/components/Text/Text.js.map +1 -0
- package/dist/components/Text/index.d.ts +2 -0
- package/dist/components/Text/index.js +2 -0
- package/dist/components/TextVirtualizer.d.ts +8 -0
- package/dist/components/TextVirtualizer.js +53 -0
- package/dist/components/TextVirtualizer.js.map +1 -0
- package/dist/components/TextWithLinks.d.ts +6 -0
- package/dist/components/TextWithLinks.js +61 -0
- package/dist/components/TextWithLinks.js.map +1 -0
- package/dist/components/Textarea/Textarea.d.ts +47 -0
- package/dist/components/Textarea/Textarea.js +150 -0
- package/dist/components/Textarea/Textarea.js.map +1 -0
- package/dist/components/Textarea/index.d.ts +2 -0
- package/dist/components/Textarea/index.js +2 -0
- package/dist/components/ThinkingState/LoadingIndicator.d.ts +19 -0
- package/dist/components/ThinkingState/LoadingIndicator.js +2 -0
- package/dist/components/ThinkingState/NOTICE +25 -0
- package/dist/components/ThinkingState/ThinkingState.d.ts +21 -0
- package/dist/components/ThinkingState/ThinkingState.js +42 -0
- package/dist/components/ThinkingState/ThinkingState.js.map +1 -0
- package/dist/components/ThinkingState/ThinkingStateTimer.d.ts +9 -0
- package/dist/components/ThinkingState/ThinkingStateTimer.js +43 -0
- package/dist/components/ThinkingState/ThinkingStateTimer.js.map +1 -0
- package/dist/components/ThinkingState/index.d.ts +4 -0
- package/dist/components/ThinkingState/index.js +3 -0
- package/dist/components/Toast/ToastContext.d.ts +5 -0
- package/dist/components/Toast/ToastContext.js +9 -0
- package/dist/components/Toast/ToastContext.js.map +1 -0
- package/dist/components/Toast/index.d.ts +13 -0
- package/dist/components/Toast/index.js +166 -0
- package/dist/components/Toast/index.js.map +1 -0
- package/dist/components/Toast/useToast.d.ts +3 -0
- package/dist/components/Toast/useToast.js +11 -0
- package/dist/components/Toast/useToast.js.map +1 -0
- package/dist/components/Tooltip/Tooltip.d.ts +19 -0
- package/dist/components/Tooltip/Tooltip.js +57 -0
- package/dist/components/Tooltip/Tooltip.js.map +1 -0
- package/dist/components/Tooltip/index.d.ts +3 -0
- package/dist/components/Tooltip/index.js +3 -0
- package/dist/components/TopList/TopList.d.ts +3 -0
- package/dist/components/TopList/TopList.js +186 -0
- package/dist/components/TopList/TopList.js.map +1 -0
- package/dist/components/TopList/TopList.types.d.ts +34 -0
- package/dist/components/TopList/TopList.types.js +0 -0
- package/dist/components/TopList/TopList.utils.d.ts +3 -0
- package/dist/components/TopList/TopList.utils.js +16 -0
- package/dist/components/TopList/TopList.utils.js.map +1 -0
- package/dist/components/TopList/index.d.ts +2 -0
- package/dist/components/TopList/index.js +2 -0
- package/dist/components/Typeahead/Typeahead.d.ts +5 -0
- package/dist/components/Typeahead/Typeahead.js +305 -0
- package/dist/components/Typeahead/Typeahead.js.map +1 -0
- package/dist/components/Typeahead/Typeahead.types.d.ts +99 -0
- package/dist/components/Typeahead/Typeahead.types.js +0 -0
- package/dist/components/Typeahead/Typeahead.utils.d.ts +25 -0
- package/dist/components/Typeahead/Typeahead.utils.js +73 -0
- package/dist/components/Typeahead/Typeahead.utils.js.map +1 -0
- package/dist/components/Typeahead/TypeaheadParts.d.ts +25 -0
- package/dist/components/Typeahead/TypeaheadParts.js +109 -0
- package/dist/components/Typeahead/TypeaheadParts.js.map +1 -0
- package/dist/components/Typeahead/TypeaheadView.d.ts +81 -0
- package/dist/components/Typeahead/TypeaheadView.js +228 -0
- package/dist/components/Typeahead/TypeaheadView.js.map +1 -0
- package/dist/components/Typeahead/index.d.ts +2 -0
- package/dist/components/Typeahead/index.js +2 -0
- package/dist/components/Typeahead/useTypeaheadDomSync.d.ts +15 -0
- package/dist/components/Typeahead/useTypeaheadDomSync.js +43 -0
- package/dist/components/Typeahead/useTypeaheadDomSync.js.map +1 -0
- package/dist/components/Typeahead/useTypeaheadUncontrolledInput.d.ts +11 -0
- package/dist/components/Typeahead/useTypeaheadUncontrolledInput.js +32 -0
- package/dist/components/Typeahead/useTypeaheadUncontrolledInput.js.map +1 -0
- package/dist/components/UnsavedChangesDialog.d.ts +14 -0
- package/dist/components/UnsavedChangesDialog.js +67 -0
- package/dist/components/UnsavedChangesDialog.js.map +1 -0
- package/dist/components/index.d.ts +58 -0
- package/dist/components/index.js +35 -0
- package/dist/components.css +102 -0
- package/dist/contexts/ErrorReporterContext.d.ts +6 -0
- package/dist/contexts/ErrorReporterContext.js +7 -0
- package/dist/contexts/ErrorReporterContext.js.map +1 -0
- package/dist/hooks/AppThemeProvider.d.ts +8 -0
- package/dist/hooks/AppThemeProvider.js +52 -0
- package/dist/hooks/AppThemeProvider.js.map +1 -0
- package/dist/hooks/useColorScheme.d.ts +20 -0
- package/dist/hooks/useColorScheme.js +50 -0
- package/dist/hooks/useColorScheme.js.map +1 -0
- package/dist/icons/LongTailPhosphorIcons.d.ts +51 -0
- package/dist/icons/LongTailPhosphorIcons.js +102 -0
- package/dist/icons/LongTailPhosphorIcons.js.map +1 -0
- package/dist/icons/PaddedPhosphorIcons.d.ts +17 -0
- package/dist/icons/PaddedPhosphorIcons.js +55 -0
- package/dist/icons/PaddedPhosphorIcons.js.map +1 -0
- package/dist/icons/WeightedPhosphorIcons.d.ts +45 -0
- package/dist/icons/WeightedPhosphorIcons.js +96 -0
- package/dist/icons/WeightedPhosphorIcons.js.map +1 -0
- package/dist/icons/index.d.ts +2 -0
- package/dist/icons/index.js +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +36 -0
- package/dist/styles.css +10 -0
- package/dist/utilities.css +2 -0
- package/dist/utils/VirtuosoCustomScrollParentContext/index.d.ts +7 -0
- package/dist/utils/VirtuosoCustomScrollParentContext/index.js +15 -0
- package/dist/utils/VirtuosoCustomScrollParentContext/index.js.map +1 -0
- package/dist/utils/VirtuosoCustomScrollParentContext/useScrollParent.d.ts +4 -0
- package/dist/utils/VirtuosoCustomScrollParentContext/useScrollParent.js +10 -0
- package/dist/utils/VirtuosoCustomScrollParentContext/useScrollParent.js.map +1 -0
- package/dist/utils/ZIndexContext.d.ts +5 -0
- package/dist/utils/ZIndexContext.js +13 -0
- package/dist/utils/ZIndexContext.js.map +1 -0
- package/dist/utils/animation.d.ts +37 -0
- package/dist/utils/animation.js +42 -0
- package/dist/utils/animation.js.map +1 -0
- package/dist/utils/chartAxisLayout.d.ts +6 -0
- package/dist/utils/chartAxisLayout.js +8 -0
- package/dist/utils/chartAxisLayout.js.map +1 -0
- package/dist/utils/chartColors.d.ts +38 -0
- package/dist/utils/chartColors.js +78 -0
- package/dist/utils/chartColors.js.map +1 -0
- package/dist/utils/chartConstants.d.ts +10 -0
- package/dist/utils/chartConstants.js +15 -0
- package/dist/utils/chartConstants.js.map +1 -0
- package/dist/utils/chartValues.d.ts +2 -0
- package/dist/utils/chartValues.js +36 -0
- package/dist/utils/chartValues.js.map +1 -0
- package/dist/utils/clamp.d.ts +2 -0
- package/dist/utils/clamp.js +7 -0
- package/dist/utils/clamp.js.map +1 -0
- package/dist/utils/cn.d.ts +2 -0
- package/dist/utils/cn.js +191 -0
- package/dist/utils/cn.js.map +1 -0
- package/dist/utils/componentSizes.d.ts +104 -0
- package/dist/utils/componentSizes.js +104 -0
- package/dist/utils/componentSizes.js.map +1 -0
- package/dist/utils/controlIconSizes.d.ts +10 -0
- package/dist/utils/controlIconSizes.js +32 -0
- package/dist/utils/controlIconSizes.js.map +1 -0
- package/dist/utils/csp-nonce.d.ts +11 -0
- package/dist/utils/csp-nonce.js +17 -0
- package/dist/utils/csp-nonce.js.map +1 -0
- package/dist/utils/get-closest-scroll-parent.d.ts +1 -0
- package/dist/utils/get-closest-scroll-parent.js +16 -0
- package/dist/utils/get-closest-scroll-parent.js.map +1 -0
- package/dist/utils/get-color-by-string.d.ts +1 -0
- package/dist/utils/get-color-by-string.js +10 -0
- package/dist/utils/get-color-by-string.js.map +1 -0
- package/dist/utils/getYAxisLeftMargin.d.ts +10 -0
- package/dist/utils/getYAxisLeftMargin.js +20 -0
- package/dist/utils/getYAxisLeftMargin.js.map +1 -0
- package/dist/utils/icon-types.d.ts +8 -0
- package/dist/utils/icon-types.js +0 -0
- package/dist/utils/lazy-codemirror-loader.d.ts +70 -0
- package/dist/utils/lazy-codemirror-loader.js +79 -0
- package/dist/utils/lazy-codemirror-loader.js.map +1 -0
- package/dist/utils/merge-refs.d.ts +2 -0
- package/dist/utils/merge-refs.js +13 -0
- package/dist/utils/merge-refs.js.map +1 -0
- package/dist/utils/parseTextLinks.d.ts +7 -0
- package/dist/utils/parseTextLinks.js +46 -0
- package/dist/utils/parseTextLinks.js.map +1 -0
- package/dist/utils/prettify-error-payload.d.ts +7 -0
- package/dist/utils/prettify-error-payload.js +188 -0
- package/dist/utils/prettify-error-payload.js.map +1 -0
- package/dist/utils/spacing.d.ts +30 -0
- package/dist/utils/spacing.js +34 -0
- package/dist/utils/spacing.js.map +1 -0
- package/dist/utils/useCodeMirror.d.ts +7 -0
- package/dist/utils/useCodeMirror.js +28 -0
- package/dist/utils/useCodeMirror.js.map +1 -0
- package/dist/utils/useZIndex.d.ts +52 -0
- package/dist/utils/useZIndex.js +62 -0
- package/dist/utils/useZIndex.js.map +1 -0
- package/dist/utils/zIndices.d.ts +42 -0
- package/dist/utils/zIndices.js +46 -0
- package/dist/utils/zIndices.js.map +1 -0
- package/docs/DESIGN.md +134 -0
- package/docs/STYLES.md +568 -0
- package/package.json +619 -0
- package/tailwind.preset.cjs +738 -0
- package/tailwind.preset.d.cts +5 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { clamp } from "../../utils/clamp.js";
|
|
2
|
+
//#region packages/components/src/components/BarChart/BarChart.utils.ts
|
|
3
|
+
var VALUE_FORMATTER = new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 });
|
|
4
|
+
var groupBarChartItemsBy = (items, getKey) => {
|
|
5
|
+
const groups = /* @__PURE__ */ new Map();
|
|
6
|
+
for (const item of items) {
|
|
7
|
+
const key = getKey(item);
|
|
8
|
+
const group = groups.get(key);
|
|
9
|
+
if (group == null) groups.set(key, [item]);
|
|
10
|
+
else group.push(item);
|
|
11
|
+
}
|
|
12
|
+
return groups;
|
|
13
|
+
};
|
|
14
|
+
/** Default value-axis tick text. Consumers localize via `formatValue`. */
|
|
15
|
+
var formatBarChartValue = (value) => VALUE_FORMATTER.format(value);
|
|
16
|
+
var isValidCategory = (category) => typeof category === "string" || Number.isFinite(category);
|
|
17
|
+
/** Categories are compared across types, so the key carries the type too. */
|
|
18
|
+
var getCategoryKey = (category) => `${typeof category}:${category}`;
|
|
19
|
+
var getPointId = (seriesId, point) => point.id ?? `${seriesId}:${getCategoryKey(point.category)}`;
|
|
20
|
+
var expandFlatDomain = (value) => {
|
|
21
|
+
if (value === 0) return [0, 1];
|
|
22
|
+
const padding = Math.abs(value) * .1;
|
|
23
|
+
return [Math.min(0, value - padding), Math.max(0, value + padding)];
|
|
24
|
+
};
|
|
25
|
+
var normalizeBarChartSeries = (series) => series.map((item) => ({
|
|
26
|
+
...item,
|
|
27
|
+
data: item.data.reduce((points, point) => {
|
|
28
|
+
if (!isValidCategory(point.category)) return points;
|
|
29
|
+
points.push({
|
|
30
|
+
...point,
|
|
31
|
+
value: point.value != null && Number.isFinite(point.value) ? point.value : null
|
|
32
|
+
});
|
|
33
|
+
return points;
|
|
34
|
+
}, [])
|
|
35
|
+
}));
|
|
36
|
+
var getBarChartCategories = (series, configuredCategories) => {
|
|
37
|
+
const candidates = configuredCategories ?? series.flatMap((item) => item.data.map((point) => point.category));
|
|
38
|
+
const categories = [];
|
|
39
|
+
const seen = /* @__PURE__ */ new Set();
|
|
40
|
+
for (const category of candidates) {
|
|
41
|
+
if (!isValidCategory(category) || seen.has(category)) continue;
|
|
42
|
+
seen.add(category);
|
|
43
|
+
categories.push(category);
|
|
44
|
+
}
|
|
45
|
+
return categories;
|
|
46
|
+
};
|
|
47
|
+
var getBarChartLayout = (series, categories, mode) => {
|
|
48
|
+
const categorySet = new Set(categories);
|
|
49
|
+
const pointBySeriesAndCategory = /* @__PURE__ */ new Map();
|
|
50
|
+
for (const item of series) {
|
|
51
|
+
const points = /* @__PURE__ */ new Map();
|
|
52
|
+
for (const point of item.data) if (categorySet.has(point.category)) points.set(point.category, point);
|
|
53
|
+
pointBySeriesAndCategory.set(item.id, points);
|
|
54
|
+
}
|
|
55
|
+
const isStacked = mode === "stacked";
|
|
56
|
+
const groupIds = isStacked ? Array.from(new Set(series.map((item) => item.valueAxisId))) : series.map((item) => item.id);
|
|
57
|
+
const groupIndexById = new Map(groupIds.map((groupId, index) => [groupId, index]));
|
|
58
|
+
const groupCount = Math.max(1, groupIds.length);
|
|
59
|
+
const bars = [];
|
|
60
|
+
for (const category of categories) {
|
|
61
|
+
const positiveTotals = /* @__PURE__ */ new Map();
|
|
62
|
+
const negativeTotals = /* @__PURE__ */ new Map();
|
|
63
|
+
for (const item of series) {
|
|
64
|
+
const point = pointBySeriesAndCategory.get(item.id)?.get(category);
|
|
65
|
+
if (point?.value == null) continue;
|
|
66
|
+
const groupId = isStacked ? item.valueAxisId : item.id;
|
|
67
|
+
let startValue = 0;
|
|
68
|
+
let endValue = point.value;
|
|
69
|
+
if (isStacked) {
|
|
70
|
+
const totals = point.value < 0 ? negativeTotals : positiveTotals;
|
|
71
|
+
startValue = totals.get(item.valueAxisId) ?? 0;
|
|
72
|
+
endValue = startValue + point.value;
|
|
73
|
+
totals.set(item.valueAxisId, endValue);
|
|
74
|
+
}
|
|
75
|
+
const bar = {
|
|
76
|
+
id: getPointId(item.id, point),
|
|
77
|
+
category,
|
|
78
|
+
value: point.value,
|
|
79
|
+
startValue,
|
|
80
|
+
endValue,
|
|
81
|
+
seriesId: item.id,
|
|
82
|
+
seriesLabel: item.label,
|
|
83
|
+
legendItemId: point.legendItemId ?? item.id,
|
|
84
|
+
color: point.color ?? item.color,
|
|
85
|
+
valueAxisId: item.valueAxisId,
|
|
86
|
+
opacity: item.opacity,
|
|
87
|
+
groupIndex: groupIndexById.get(groupId) ?? 0,
|
|
88
|
+
groupCount
|
|
89
|
+
};
|
|
90
|
+
bars.push(bar);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return bars;
|
|
94
|
+
};
|
|
95
|
+
var getBarChartValueDomain = (bars, valueAxisId, configuredDomain) => {
|
|
96
|
+
if (configuredDomain != null && Number.isFinite(configuredDomain[0]) && Number.isFinite(configuredDomain[1])) {
|
|
97
|
+
const minimum = Math.min(configuredDomain[0], configuredDomain[1]);
|
|
98
|
+
const maximum = Math.max(configuredDomain[0], configuredDomain[1]);
|
|
99
|
+
return minimum === maximum ? expandFlatDomain(minimum) : [minimum, maximum];
|
|
100
|
+
}
|
|
101
|
+
let minimum = 0;
|
|
102
|
+
let maximum = 0;
|
|
103
|
+
let hasValue = false;
|
|
104
|
+
for (const bar of bars) {
|
|
105
|
+
if (bar.valueAxisId !== valueAxisId) continue;
|
|
106
|
+
for (const value of [bar.startValue, bar.endValue]) {
|
|
107
|
+
if (!Number.isFinite(value)) continue;
|
|
108
|
+
hasValue = true;
|
|
109
|
+
minimum = Math.min(minimum, value);
|
|
110
|
+
maximum = Math.max(maximum, value);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!hasValue) return [0, 1];
|
|
114
|
+
return minimum === maximum ? expandFlatDomain(minimum) : [minimum, maximum];
|
|
115
|
+
};
|
|
116
|
+
/** Builds a square-cornered SVG bar outline. */
|
|
117
|
+
var getBarPath = ({ x, y, width, height }) => `M ${x} ${y} H ${x + width} V ${y + height} H ${x} Z`;
|
|
118
|
+
var toBarChartInteractionBar = (bar) => ({
|
|
119
|
+
id: bar.id,
|
|
120
|
+
category: bar.category,
|
|
121
|
+
value: bar.value,
|
|
122
|
+
startValue: bar.startValue,
|
|
123
|
+
endValue: bar.endValue,
|
|
124
|
+
seriesId: bar.seriesId,
|
|
125
|
+
seriesLabel: bar.seriesLabel,
|
|
126
|
+
color: bar.color,
|
|
127
|
+
valueAxisId: bar.valueAxisId
|
|
128
|
+
});
|
|
129
|
+
/**
|
|
130
|
+
* Resolves each layout bar to SVG geometry.
|
|
131
|
+
*
|
|
132
|
+
* The two ends of a bar are clamped to the plot box independently, so a bar that
|
|
133
|
+
* runs past a configured axis domain is truncated at the edge rather than slid
|
|
134
|
+
* back inside it — sliding would redraw it at a value it does not have, and can
|
|
135
|
+
* even flip a negative bar to the positive side of the baseline. Bars therefore
|
|
136
|
+
* never overflow, which is also why they need no clip path and their focus rings
|
|
137
|
+
* stay visible.
|
|
138
|
+
*/
|
|
139
|
+
var getBarChartRenderedBars = ({ bars, orientation, categoryScale, axisById, groupPadding, minimumBarSize, innerWidth, innerHeight }) => {
|
|
140
|
+
const isVertical = orientation === "vertical";
|
|
141
|
+
const plotSize = isVertical ? innerHeight : innerWidth;
|
|
142
|
+
const categoryBandwidth = categoryScale.bandwidth();
|
|
143
|
+
return bars.flatMap((bar) => {
|
|
144
|
+
const categoryStart = categoryScale(bar.category);
|
|
145
|
+
const axis = axisById.get(bar.valueAxisId);
|
|
146
|
+
if (categoryStart == null || axis == null) return [];
|
|
147
|
+
const groupSlotSize = categoryBandwidth / bar.groupCount;
|
|
148
|
+
const groupSize = Math.max(Math.min(1, groupSlotSize), groupSlotSize * (1 - groupPadding));
|
|
149
|
+
const groupOffset = bar.groupIndex * groupSlotSize + (groupSlotSize - groupSize) / 2;
|
|
150
|
+
const startPosition = axis.scale(bar.startValue);
|
|
151
|
+
const endPosition = axis.scale(bar.endValue);
|
|
152
|
+
const rawValueSize = Math.abs(endPosition - startPosition);
|
|
153
|
+
const valueSize = Math.max(minimumBarSize, rawValueSize);
|
|
154
|
+
const growsFromBaseline = isVertical ? bar.value < 0 : bar.value >= 0;
|
|
155
|
+
const rawStart = rawValueSize >= minimumBarSize ? Math.min(startPosition, endPosition) : growsFromBaseline ? startPosition : startPosition - valueSize;
|
|
156
|
+
const visibleStart = clamp(rawStart, 0, plotSize);
|
|
157
|
+
const visibleSize = clamp(rawStart + valueSize, 0, plotSize) - visibleStart;
|
|
158
|
+
if (visibleSize <= 0) return [];
|
|
159
|
+
const geometry = isVertical ? {
|
|
160
|
+
x: categoryStart + groupOffset,
|
|
161
|
+
y: visibleStart,
|
|
162
|
+
width: groupSize,
|
|
163
|
+
height: visibleSize
|
|
164
|
+
} : {
|
|
165
|
+
x: visibleStart,
|
|
166
|
+
y: categoryStart + groupOffset,
|
|
167
|
+
width: visibleSize,
|
|
168
|
+
height: groupSize
|
|
169
|
+
};
|
|
170
|
+
return [{
|
|
171
|
+
...bar,
|
|
172
|
+
...geometry,
|
|
173
|
+
baselinePosition: clamp(startPosition, 0, plotSize)
|
|
174
|
+
}];
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
var getBarChartIsBarDimmed = ({ bars, activeBuiltInLegendItemId, activeLegendItemId, activeBarId }) => {
|
|
178
|
+
const activeSeriesId = bars.some((bar) => bar.seriesId === activeBuiltInLegendItemId) ? activeBuiltInLegendItemId : null;
|
|
179
|
+
const activeDatumLegendItemId = activeBuiltInLegendItemId == null && bars.some((bar) => bar.legendItemId === activeLegendItemId) ? activeLegendItemId : null;
|
|
180
|
+
return (bar) => activeSeriesId != null ? activeSeriesId !== bar.seriesId : activeDatumLegendItemId != null ? activeDatumLegendItemId !== bar.legendItemId : activeBarId != null && activeBarId !== bar.id;
|
|
181
|
+
};
|
|
182
|
+
var getBarAnimationRanges = (bars, orientation) => {
|
|
183
|
+
const stacks = /* @__PURE__ */ new Map();
|
|
184
|
+
for (const bar of bars) {
|
|
185
|
+
const key = JSON.stringify([
|
|
186
|
+
typeof bar.category,
|
|
187
|
+
bar.category,
|
|
188
|
+
bar.valueAxisId,
|
|
189
|
+
bar.groupIndex,
|
|
190
|
+
bar.value < 0 ? "negative" : "positive"
|
|
191
|
+
]);
|
|
192
|
+
const stack = stacks.get(key);
|
|
193
|
+
if (stack == null) stacks.set(key, [bar]);
|
|
194
|
+
else stack.push(bar);
|
|
195
|
+
}
|
|
196
|
+
const ranges = /* @__PURE__ */ new Map();
|
|
197
|
+
for (const stack of stacks.values()) {
|
|
198
|
+
const isNegative = (stack[0]?.value ?? 0) < 0;
|
|
199
|
+
const starts = stack.map((bar) => orientation === "vertical" ? isNegative ? bar.y : bar.y + bar.height : isNegative ? bar.x + bar.width : bar.x);
|
|
200
|
+
const ends = stack.map((bar) => orientation === "vertical" ? isNegative ? bar.y + bar.height : bar.y : isNegative ? bar.x : bar.x + bar.width);
|
|
201
|
+
const range = orientation === "vertical" ? {
|
|
202
|
+
start: isNegative ? Math.min(...starts) : Math.max(...starts),
|
|
203
|
+
end: isNegative ? Math.max(...ends) : Math.min(...ends)
|
|
204
|
+
} : {
|
|
205
|
+
start: isNegative ? Math.max(...starts) : Math.min(...starts),
|
|
206
|
+
end: isNegative ? Math.min(...ends) : Math.max(...ends)
|
|
207
|
+
};
|
|
208
|
+
for (const bar of stack) ranges.set(bar.id, range);
|
|
209
|
+
}
|
|
210
|
+
return ranges;
|
|
211
|
+
};
|
|
212
|
+
//#endregion
|
|
213
|
+
export { formatBarChartValue, getBarAnimationRanges, getBarChartCategories, getBarChartIsBarDimmed, getBarChartLayout, getBarChartRenderedBars, getBarChartValueDomain, getBarPath, getCategoryKey, groupBarChartItemsBy, normalizeBarChartSeries, toBarChartInteractionBar };
|
|
214
|
+
|
|
215
|
+
//# sourceMappingURL=BarChart.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BarChart.utils.js","names":[],"sources":["../../../src/components/BarChart/BarChart.utils.ts"],"sourcesContent":["import type { scaleBand } from '@visx/scale';\n\nimport { clamp } from '../../utils/clamp';\nimport type {\n BarChartCategory,\n BarChartDataPoint,\n BarChartDisplayAxis,\n BarChartDisplaySeries,\n BarChartInteractionBar,\n BarChartLayoutBar,\n BarChartMode,\n BarChartOrientation,\n BarChartRenderedBar,\n BarChartSeries,\n} from './BarChart.types';\n\nconst VALUE_FORMATTER = new Intl.NumberFormat('en-US', {\n maximumFractionDigits: 2,\n});\n\nexport const groupBarChartItemsBy = <Item>(\n items: readonly Item[],\n getKey: (item: Item) => string\n): ReadonlyMap<string, Item[]> => {\n const groups = new Map<string, Item[]>();\n for (const item of items) {\n const key = getKey(item);\n const group = groups.get(key);\n if (group == null) groups.set(key, [item]);\n else group.push(item);\n }\n return groups;\n};\n\n/** Default value-axis tick text. Consumers localize via `formatValue`. */\nexport const formatBarChartValue = (value: number): string =>\n VALUE_FORMATTER.format(value);\n\nconst isValidCategory = (category: BarChartCategory): boolean =>\n typeof category === 'string' || Number.isFinite(category);\n\n/** Categories are compared across types, so the key carries the type too. */\nexport const getCategoryKey = (category: BarChartCategory): string =>\n `${typeof category}:${category}`;\n\nconst getPointId = (seriesId: string, point: BarChartDataPoint): string =>\n point.id ?? `${seriesId}:${getCategoryKey(point.category)}`;\n\nconst expandFlatDomain = (value: number): [number, number] => {\n if (value === 0) return [0, 1];\n const padding = Math.abs(value) * 0.1;\n return [Math.min(0, value - padding), Math.max(0, value + padding)];\n};\n\nexport const normalizeBarChartSeries = (\n series: readonly BarChartSeries[]\n): readonly BarChartSeries[] =>\n series.map((item) => ({\n ...item,\n data: item.data.reduce<BarChartDataPoint[]>((points, point) => {\n if (!isValidCategory(point.category)) return points;\n points.push({\n ...point,\n value:\n point.value != null && Number.isFinite(point.value)\n ? point.value\n : null,\n });\n return points;\n }, []),\n }));\n\nexport const getBarChartCategories = (\n series: readonly BarChartSeries[],\n configuredCategories?: readonly BarChartCategory[]\n): readonly BarChartCategory[] => {\n const candidates =\n configuredCategories ??\n series.flatMap((item) => item.data.map((point) => point.category));\n const categories: BarChartCategory[] = [];\n const seen = new Set<BarChartCategory>();\n\n for (const category of candidates) {\n if (!isValidCategory(category) || seen.has(category)) continue;\n seen.add(category);\n categories.push(category);\n }\n return categories;\n};\n\nexport const getBarChartLayout = (\n series: readonly BarChartDisplaySeries[],\n categories: readonly BarChartCategory[],\n mode: BarChartMode\n): readonly BarChartLayoutBar[] => {\n const categorySet = new Set(categories);\n const pointBySeriesAndCategory = new Map<\n string,\n Map<BarChartCategory, BarChartDataPoint>\n >();\n for (const item of series) {\n const points = new Map<BarChartCategory, BarChartDataPoint>();\n for (const point of item.data) {\n if (categorySet.has(point.category)) points.set(point.category, point);\n }\n pointBySeriesAndCategory.set(item.id, points);\n }\n\n const isStacked = mode === 'stacked';\n const groupIds = isStacked\n ? Array.from(new Set(series.map((item) => item.valueAxisId)))\n : series.map((item) => item.id);\n const groupIndexById = new Map(\n groupIds.map((groupId, index) => [groupId, index])\n );\n const groupCount = Math.max(1, groupIds.length);\n const bars: BarChartLayoutBar[] = [];\n\n for (const category of categories) {\n const positiveTotals = new Map<string, number>();\n const negativeTotals = new Map<string, number>();\n\n for (const item of series) {\n const point = pointBySeriesAndCategory.get(item.id)?.get(category);\n if (point?.value == null) continue;\n\n const groupId = isStacked ? item.valueAxisId : item.id;\n let startValue = 0;\n let endValue = point.value;\n\n if (isStacked) {\n const totals = point.value < 0 ? negativeTotals : positiveTotals;\n startValue = totals.get(item.valueAxisId) ?? 0;\n endValue = startValue + point.value;\n totals.set(item.valueAxisId, endValue);\n }\n\n const bar: BarChartLayoutBar = {\n id: getPointId(item.id, point),\n category,\n value: point.value,\n startValue,\n endValue,\n seriesId: item.id,\n seriesLabel: item.label,\n legendItemId: point.legendItemId ?? item.id,\n color: point.color ?? item.color,\n valueAxisId: item.valueAxisId,\n opacity: item.opacity,\n groupIndex: groupIndexById.get(groupId) ?? 0,\n groupCount,\n };\n bars.push(bar);\n }\n }\n\n return bars;\n};\n\nexport const getBarChartValueDomain = (\n bars: readonly BarChartLayoutBar[],\n valueAxisId: string,\n configuredDomain?: readonly [number, number]\n): [number, number] => {\n if (\n configuredDomain != null &&\n Number.isFinite(configuredDomain[0]) &&\n Number.isFinite(configuredDomain[1])\n ) {\n const minimum = Math.min(configuredDomain[0], configuredDomain[1]);\n const maximum = Math.max(configuredDomain[0], configuredDomain[1]);\n return minimum === maximum ? expandFlatDomain(minimum) : [minimum, maximum];\n }\n\n // A bar is read against the baseline, so the domain always spans zero.\n let minimum = 0;\n let maximum = 0;\n let hasValue = false;\n for (const bar of bars) {\n if (bar.valueAxisId !== valueAxisId) continue;\n for (const value of [bar.startValue, bar.endValue]) {\n if (!Number.isFinite(value)) continue;\n hasValue = true;\n minimum = Math.min(minimum, value);\n maximum = Math.max(maximum, value);\n }\n }\n if (!hasValue) return [0, 1];\n return minimum === maximum ? expandFlatDomain(minimum) : [minimum, maximum];\n};\n\n/** Builds a square-cornered SVG bar outline. */\nexport const getBarPath = ({\n x,\n y,\n width,\n height,\n}: {\n x: number;\n y: number;\n width: number;\n height: number;\n}) => `M ${x} ${y} H ${x + width} V ${y + height} H ${x} Z`;\n\nexport const toBarChartInteractionBar = (\n bar: BarChartLayoutBar\n): BarChartInteractionBar => ({\n id: bar.id,\n category: bar.category,\n value: bar.value,\n startValue: bar.startValue,\n endValue: bar.endValue,\n seriesId: bar.seriesId,\n seriesLabel: bar.seriesLabel,\n color: bar.color,\n valueAxisId: bar.valueAxisId,\n});\n\n/**\n * Resolves each layout bar to SVG geometry.\n *\n * The two ends of a bar are clamped to the plot box independently, so a bar that\n * runs past a configured axis domain is truncated at the edge rather than slid\n * back inside it — sliding would redraw it at a value it does not have, and can\n * even flip a negative bar to the positive side of the baseline. Bars therefore\n * never overflow, which is also why they need no clip path and their focus rings\n * stay visible.\n */\nexport const getBarChartRenderedBars = ({\n bars,\n orientation,\n categoryScale,\n axisById,\n groupPadding,\n minimumBarSize,\n innerWidth,\n innerHeight,\n}: {\n bars: readonly BarChartLayoutBar[];\n orientation: BarChartOrientation;\n categoryScale: ReturnType<typeof scaleBand<BarChartCategory>>;\n axisById: ReadonlyMap<string, BarChartDisplayAxis>;\n groupPadding: number;\n minimumBarSize: number;\n innerWidth: number;\n innerHeight: number;\n}): readonly BarChartRenderedBar[] => {\n const isVertical = orientation === 'vertical';\n const plotSize = isVertical ? innerHeight : innerWidth;\n const categoryBandwidth = categoryScale.bandwidth();\n\n return bars.flatMap((bar) => {\n const categoryStart = categoryScale(bar.category);\n const axis = axisById.get(bar.valueAxisId);\n if (categoryStart == null || axis == null) return [];\n\n const groupSlotSize = categoryBandwidth / bar.groupCount;\n // Dense charts drive the slot below a pixel; a hairline still reads as data.\n const groupSize = Math.max(\n Math.min(1, groupSlotSize),\n groupSlotSize * (1 - groupPadding)\n );\n const groupOffset =\n bar.groupIndex * groupSlotSize + (groupSlotSize - groupSize) / 2;\n const startPosition = axis.scale(bar.startValue);\n const endPosition = axis.scale(bar.endValue);\n const rawValueSize = Math.abs(endPosition - startPosition);\n const valueSize = Math.max(minimumBarSize, rawValueSize);\n // A bar padded up to the minimum size keeps growing away from the baseline,\n // which is the top of the SVG axis for positive vertical bars.\n const growsFromBaseline = isVertical ? bar.value < 0 : bar.value >= 0;\n const rawStart =\n rawValueSize >= minimumBarSize\n ? Math.min(startPosition, endPosition)\n : growsFromBaseline\n ? startPosition\n : startPosition - valueSize;\n const visibleStart = clamp(rawStart, 0, plotSize);\n const visibleSize = clamp(rawStart + valueSize, 0, plotSize) - visibleStart;\n if (visibleSize <= 0) return [];\n\n const geometry = isVertical\n ? {\n x: categoryStart + groupOffset,\n y: visibleStart,\n width: groupSize,\n height: visibleSize,\n }\n : {\n x: visibleStart,\n y: categoryStart + groupOffset,\n width: visibleSize,\n height: groupSize,\n };\n return [\n {\n ...bar,\n ...geometry,\n baselinePosition: clamp(startPosition, 0, plotSize),\n },\n ];\n });\n};\n\nexport const getBarChartIsBarDimmed = ({\n bars,\n activeBuiltInLegendItemId,\n activeLegendItemId,\n activeBarId,\n}: {\n bars: readonly BarChartRenderedBar[];\n activeBuiltInLegendItemId?: string | null;\n activeLegendItemId?: string | null;\n activeBarId?: string | null;\n}) => {\n const activeSeriesId = bars.some(\n (bar) => bar.seriesId === activeBuiltInLegendItemId\n )\n ? activeBuiltInLegendItemId\n : null;\n const activeDatumLegendItemId =\n activeBuiltInLegendItemId == null &&\n bars.some((bar) => bar.legendItemId === activeLegendItemId)\n ? activeLegendItemId\n : null;\n\n return (bar: BarChartRenderedBar): boolean =>\n activeSeriesId != null\n ? activeSeriesId !== bar.seriesId\n : activeDatumLegendItemId != null\n ? activeDatumLegendItemId !== bar.legendItemId\n : activeBarId != null && activeBarId !== bar.id;\n};\n\ntype BarAnimationRange = { start: number; end: number };\n\nexport const getBarAnimationRanges = (\n bars: readonly BarChartRenderedBar[],\n orientation: BarChartOrientation\n): ReadonlyMap<string, BarAnimationRange> => {\n // Each signed half of a stack gets one reveal edge. Grouped bars naturally\n // form one-item stacks and retain their baseline-to-value animation.\n const stacks = new Map<string, BarChartRenderedBar[]>();\n for (const bar of bars) {\n const key = JSON.stringify([\n typeof bar.category,\n bar.category,\n bar.valueAxisId,\n bar.groupIndex,\n bar.value < 0 ? 'negative' : 'positive',\n ]);\n const stack = stacks.get(key);\n if (stack == null) stacks.set(key, [bar]);\n else stack.push(bar);\n }\n\n const ranges = new Map<string, BarAnimationRange>();\n for (const stack of stacks.values()) {\n const isNegative = (stack[0]?.value ?? 0) < 0;\n const starts = stack.map((bar) =>\n orientation === 'vertical'\n ? isNegative\n ? bar.y\n : bar.y + bar.height\n : isNegative\n ? bar.x + bar.width\n : bar.x\n );\n const ends = stack.map((bar) =>\n orientation === 'vertical'\n ? isNegative\n ? bar.y + bar.height\n : bar.y\n : isNegative\n ? bar.x\n : bar.x + bar.width\n );\n const range =\n orientation === 'vertical'\n ? {\n start: isNegative ? Math.min(...starts) : Math.max(...starts),\n end: isNegative ? Math.max(...ends) : Math.min(...ends),\n }\n : {\n start: isNegative ? Math.max(...starts) : Math.min(...starts),\n end: isNegative ? Math.min(...ends) : Math.max(...ends),\n };\n for (const bar of stack) ranges.set(bar.id, range);\n }\n\n return ranges;\n};\n"],"mappings":";;AAgBA,IAAM,kBAAkB,IAAI,KAAK,aAAa,SAAS,EACrD,uBAAuB,EACzB,CAAC;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A,MAAM,QACJ,gBAAgB,aACZ;GACE,OAAO,aAAa,KAAK,IAAI,GAAG,MAAM,IAAI,KAAK,IAAI,GAAG,MAAM;GAC5D,KAAK,aAAa,KAAK,IAAI,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,IAAI;EACxD,IACA;GACE,OAAO,aAAa,KAAK,IAAI,GAAG,MAAM,IAAI,KAAK,IAAI,GAAG,MAAM;GAC5D,KAAK,aAAa,KAAK,IAAI,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,IAAI;EACxD;EACN,KAAK,MAAM,OAAO,OAAO,OAAO,IAAI,IAAI,IAAI,KAAK;CACnD;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { scaleBand } from '@visx/scale';
|
|
2
|
+
import type { BarChartCategory, BarChartCategoryAxis, BarChartDisplayAxis, BarChartOrientation, BarChartSlots } from './BarChart.types.js';
|
|
3
|
+
type BarChartAxesProps = {
|
|
4
|
+
orientation: BarChartOrientation;
|
|
5
|
+
categories: readonly BarChartCategory[];
|
|
6
|
+
categoryAxis?: BarChartCategoryAxis;
|
|
7
|
+
categoryAxisThickness: number;
|
|
8
|
+
categoryScale: ReturnType<typeof scaleBand<BarChartCategory>>;
|
|
9
|
+
categoryTickValues: readonly BarChartCategory[];
|
|
10
|
+
axes: readonly BarChartDisplayAxis[];
|
|
11
|
+
slots?: BarChartSlots;
|
|
12
|
+
innerWidth: number;
|
|
13
|
+
innerHeight: number;
|
|
14
|
+
getCategoryPosition: (category: BarChartCategory) => number | undefined;
|
|
15
|
+
formatCategory: (category: BarChartCategory) => string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Secondary value axes stack outward from the plot edge, each offset by the
|
|
19
|
+
* thickness the chart margin already reserved for the ones before it.
|
|
20
|
+
*/
|
|
21
|
+
export declare const BarChartAxes: ({ orientation, categories, categoryAxis, categoryAxisThickness, categoryScale, categoryTickValues, axes, slots, innerWidth, innerHeight, getCategoryPosition, formatCategory, }: BarChartAxesProps) => import("react").JSX.Element;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Tooltip } from "../Tooltip/Tooltip.js";
|
|
2
|
+
import "../../utils/chartConstants.js";
|
|
3
|
+
import { formatBarChartValue } from "./BarChart.utils.js";
|
|
4
|
+
import { getChartAxisLabelOffset, getSecondaryChartAxisOffset } from "../../utils/chartAxisLayout.js";
|
|
5
|
+
import "./constants.js";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { AxisBottom, AxisLeft, AxisRight, AxisTop } from "@visx/axis";
|
|
8
|
+
//#region packages/components/src/components/BarChart/BarChartAxes.tsx
|
|
9
|
+
var tickLabelStyle = {
|
|
10
|
+
fill: "var(--text-tertiary)",
|
|
11
|
+
fontSize: 12
|
|
12
|
+
};
|
|
13
|
+
var axisLabelProps = {
|
|
14
|
+
fill: "var(--text-secondary)",
|
|
15
|
+
fontSize: 12,
|
|
16
|
+
textAnchor: "middle"
|
|
17
|
+
};
|
|
18
|
+
var AxisLabel = ({ label, x, y, rotation }) => /* @__PURE__ */ jsx(Tooltip, {
|
|
19
|
+
title: label,
|
|
20
|
+
children: /* @__PURE__ */ jsx("text", {
|
|
21
|
+
...axisLabelProps,
|
|
22
|
+
x,
|
|
23
|
+
y,
|
|
24
|
+
transform: rotation == null ? void 0 : `rotate(${rotation}, ${x}, ${y})`,
|
|
25
|
+
children: label
|
|
26
|
+
})
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Secondary value axes stack outward from the plot edge, each offset by the
|
|
30
|
+
* thickness the chart margin already reserved for the ones before it.
|
|
31
|
+
*/
|
|
32
|
+
var BarChartAxes = ({ orientation, categories, categoryAxis, categoryAxisThickness, categoryScale, categoryTickValues, axes, slots, innerWidth, innerHeight, getCategoryPosition, formatCategory }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
33
|
+
slots?.categoryAxis != null ? slots.categoryAxis({
|
|
34
|
+
orientation,
|
|
35
|
+
categories,
|
|
36
|
+
innerWidth,
|
|
37
|
+
innerHeight,
|
|
38
|
+
bandwidth: categoryScale.bandwidth(),
|
|
39
|
+
getCategoryPosition,
|
|
40
|
+
formatValue: formatCategory
|
|
41
|
+
}) : orientation === "vertical" ? /* @__PURE__ */ jsx(AxisBottom, {
|
|
42
|
+
top: innerHeight,
|
|
43
|
+
scale: categoryScale,
|
|
44
|
+
tickValues: Array.from(categoryTickValues),
|
|
45
|
+
tickFormat: formatCategory,
|
|
46
|
+
hideAxisLine: true,
|
|
47
|
+
hideTicks: true,
|
|
48
|
+
tickLabelProps: () => ({
|
|
49
|
+
...tickLabelStyle,
|
|
50
|
+
textAnchor: "middle"
|
|
51
|
+
})
|
|
52
|
+
}) : /* @__PURE__ */ jsx(AxisLeft, {
|
|
53
|
+
scale: categoryScale,
|
|
54
|
+
tickValues: Array.from(categoryTickValues),
|
|
55
|
+
tickFormat: formatCategory,
|
|
56
|
+
hideAxisLine: true,
|
|
57
|
+
hideTicks: true,
|
|
58
|
+
tickLabelProps: () => ({
|
|
59
|
+
...tickLabelStyle,
|
|
60
|
+
textAnchor: "end",
|
|
61
|
+
dx: "-0.25em",
|
|
62
|
+
dy: "0.25em"
|
|
63
|
+
})
|
|
64
|
+
}),
|
|
65
|
+
axes.map((axis, index) => {
|
|
66
|
+
if (slots?.valueAxis != null) return /* @__PURE__ */ jsx("g", { children: slots.valueAxis({
|
|
67
|
+
orientation,
|
|
68
|
+
axis,
|
|
69
|
+
index,
|
|
70
|
+
innerWidth,
|
|
71
|
+
innerHeight,
|
|
72
|
+
getValuePosition: axis.scale
|
|
73
|
+
}) }, axis.id);
|
|
74
|
+
const commonProps = {
|
|
75
|
+
scale: axis.scale,
|
|
76
|
+
numTicks: axis.tickCount ?? 4,
|
|
77
|
+
tickValues: axis.tickValues == null ? void 0 : Array.from(axis.tickValues),
|
|
78
|
+
tickFormat: (value) => (axis.formatValue ?? formatBarChartValue)(value.valueOf()),
|
|
79
|
+
tickLength: 8,
|
|
80
|
+
hideAxisLine: true,
|
|
81
|
+
hideTicks: true
|
|
82
|
+
};
|
|
83
|
+
if (orientation === "vertical") {
|
|
84
|
+
const sideTickLabelProps = () => ({
|
|
85
|
+
...tickLabelStyle,
|
|
86
|
+
textAnchor: index === 0 ? "end" : "start",
|
|
87
|
+
dx: index === 0 ? "-0.25em" : "0.25em",
|
|
88
|
+
dy: "0.25em"
|
|
89
|
+
});
|
|
90
|
+
return index === 0 ? /* @__PURE__ */ jsx(AxisLeft, {
|
|
91
|
+
...commonProps,
|
|
92
|
+
tickLabelProps: sideTickLabelProps
|
|
93
|
+
}, axis.id) : /* @__PURE__ */ jsx(AxisRight, {
|
|
94
|
+
...commonProps,
|
|
95
|
+
left: innerWidth + getSecondaryChartAxisOffset(axes, index),
|
|
96
|
+
tickLabelProps: sideTickLabelProps
|
|
97
|
+
}, axis.id);
|
|
98
|
+
}
|
|
99
|
+
const edgeTickLabelProps = () => ({
|
|
100
|
+
...tickLabelStyle,
|
|
101
|
+
textAnchor: "middle"
|
|
102
|
+
});
|
|
103
|
+
return index === 0 ? /* @__PURE__ */ jsx(AxisBottom, {
|
|
104
|
+
...commonProps,
|
|
105
|
+
top: innerHeight,
|
|
106
|
+
tickLabelProps: edgeTickLabelProps
|
|
107
|
+
}, axis.id) : /* @__PURE__ */ jsx(AxisTop, {
|
|
108
|
+
...commonProps,
|
|
109
|
+
top: -getSecondaryChartAxisOffset(axes, index),
|
|
110
|
+
tickLabelProps: edgeTickLabelProps
|
|
111
|
+
}, axis.id);
|
|
112
|
+
}),
|
|
113
|
+
slots?.categoryAxis == null && categoryAxis?.label != null && (orientation === "vertical" ? /* @__PURE__ */ jsx(AxisLabel, {
|
|
114
|
+
label: categoryAxis.label,
|
|
115
|
+
x: innerWidth / 2,
|
|
116
|
+
y: innerHeight + getChartAxisLabelOffset(categoryAxisThickness)
|
|
117
|
+
}) : /* @__PURE__ */ jsx(AxisLabel, {
|
|
118
|
+
label: categoryAxis.label,
|
|
119
|
+
x: -getChartAxisLabelOffset(categoryAxisThickness),
|
|
120
|
+
y: innerHeight / 2,
|
|
121
|
+
rotation: -90
|
|
122
|
+
})),
|
|
123
|
+
slots?.valueAxis == null && axes.map((axis, index) => {
|
|
124
|
+
if (axis.label == null) return null;
|
|
125
|
+
if (orientation === "vertical") {
|
|
126
|
+
const x = index === 0 ? -getChartAxisLabelOffset(axis.thickness) : innerWidth + getSecondaryChartAxisOffset(axes, index) + getChartAxisLabelOffset(axis.thickness);
|
|
127
|
+
return /* @__PURE__ */ jsx(AxisLabel, {
|
|
128
|
+
label: axis.label,
|
|
129
|
+
x,
|
|
130
|
+
y: innerHeight / 2,
|
|
131
|
+
rotation: index === 0 ? -90 : 90
|
|
132
|
+
}, axis.id);
|
|
133
|
+
}
|
|
134
|
+
return /* @__PURE__ */ jsx(AxisLabel, {
|
|
135
|
+
label: axis.label,
|
|
136
|
+
x: innerWidth / 2,
|
|
137
|
+
y: index === 0 ? innerHeight + getChartAxisLabelOffset(axis.thickness) : -getSecondaryChartAxisOffset(axes, index) - getChartAxisLabelOffset(axis.thickness)
|
|
138
|
+
}, axis.id);
|
|
139
|
+
})
|
|
140
|
+
] });
|
|
141
|
+
//#endregion
|
|
142
|
+
export { BarChartAxes };
|
|
143
|
+
|
|
144
|
+
//# sourceMappingURL=BarChartAxes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BarChartAxes.js","names":[],"sources":["../../../src/components/BarChart/BarChartAxes.tsx"],"sourcesContent":["import { AxisBottom, AxisLeft, AxisRight, AxisTop } from '@visx/axis';\nimport type { scaleBand } from '@visx/scale';\n\nimport {\n getChartAxisLabelOffset,\n getSecondaryChartAxisOffset,\n} from '../../utils/chartAxisLayout';\nimport {\n CHART_TICK_FONT_SIZE,\n CHART_VALUE_AXIS_TICK_LENGTH,\n} from '../../utils/chartConstants';\nimport { Tooltip } from '../Tooltip';\nimport type {\n BarChartCategory,\n BarChartCategoryAxis,\n BarChartDisplayAxis,\n BarChartOrientation,\n BarChartSlots,\n} from './BarChart.types';\nimport { formatBarChartValue } from './BarChart.utils';\nimport { BAR_CHART_DEFAULT_TICK_COUNT } from './constants';\n\nconst tickLabelStyle = {\n fill: 'var(--text-tertiary)',\n fontSize: CHART_TICK_FONT_SIZE,\n};\nconst axisLabelProps = {\n fill: 'var(--text-secondary)',\n fontSize: CHART_TICK_FONT_SIZE,\n textAnchor: 'middle',\n} as const;\n\nconst AxisLabel = ({\n label,\n x,\n y,\n rotation,\n}: {\n label: string;\n x: number;\n y: number;\n rotation?: number;\n}) => (\n <Tooltip title={label}>\n <text\n {...axisLabelProps}\n x={x}\n y={y}\n transform={\n rotation == null ? undefined : `rotate(${rotation}, ${x}, ${y})`\n }\n >\n {label}\n </text>\n </Tooltip>\n);\n\ntype BarChartAxesProps = {\n orientation: BarChartOrientation;\n categories: readonly BarChartCategory[];\n categoryAxis?: BarChartCategoryAxis;\n categoryAxisThickness: number;\n categoryScale: ReturnType<typeof scaleBand<BarChartCategory>>;\n categoryTickValues: readonly BarChartCategory[];\n axes: readonly BarChartDisplayAxis[];\n slots?: BarChartSlots;\n innerWidth: number;\n innerHeight: number;\n getCategoryPosition: (category: BarChartCategory) => number | undefined;\n formatCategory: (category: BarChartCategory) => string;\n};\n\n/**\n * Secondary value axes stack outward from the plot edge, each offset by the\n * thickness the chart margin already reserved for the ones before it.\n */\nexport const BarChartAxes = ({\n orientation,\n categories,\n categoryAxis,\n categoryAxisThickness,\n categoryScale,\n categoryTickValues,\n axes,\n slots,\n innerWidth,\n innerHeight,\n getCategoryPosition,\n formatCategory,\n}: BarChartAxesProps) => (\n <>\n {slots?.categoryAxis != null ? (\n slots.categoryAxis({\n orientation,\n categories,\n innerWidth,\n innerHeight,\n bandwidth: categoryScale.bandwidth(),\n getCategoryPosition,\n formatValue: formatCategory,\n })\n ) : orientation === 'vertical' ? (\n <AxisBottom\n top={innerHeight}\n scale={categoryScale}\n tickValues={Array.from(categoryTickValues)}\n tickFormat={formatCategory}\n hideAxisLine\n hideTicks\n tickLabelProps={() => ({ ...tickLabelStyle, textAnchor: 'middle' })}\n />\n ) : (\n <AxisLeft\n scale={categoryScale}\n tickValues={Array.from(categoryTickValues)}\n tickFormat={formatCategory}\n hideAxisLine\n hideTicks\n tickLabelProps={() => ({\n ...tickLabelStyle,\n textAnchor: 'end',\n dx: '-0.25em',\n dy: '0.25em',\n })}\n />\n )}\n {axes.map((axis, index) => {\n if (slots?.valueAxis != null) {\n return (\n <g key={axis.id}>\n {slots.valueAxis({\n orientation,\n axis,\n index,\n innerWidth,\n innerHeight,\n getValuePosition: axis.scale,\n })}\n </g>\n );\n }\n const commonProps = {\n scale: axis.scale,\n numTicks: axis.tickCount ?? BAR_CHART_DEFAULT_TICK_COUNT,\n tickValues:\n axis.tickValues == null ? undefined : Array.from(axis.tickValues),\n tickFormat: (value: { valueOf(): number }) =>\n (axis.formatValue ?? formatBarChartValue)(value.valueOf()),\n tickLength: CHART_VALUE_AXIS_TICK_LENGTH,\n hideAxisLine: true,\n hideTicks: true,\n };\n\n if (orientation === 'vertical') {\n const sideTickLabelProps = () => ({\n ...tickLabelStyle,\n textAnchor: index === 0 ? ('end' as const) : ('start' as const),\n dx: index === 0 ? '-0.25em' : '0.25em',\n dy: '0.25em',\n });\n return index === 0 ? (\n <AxisLeft\n key={axis.id}\n {...commonProps}\n tickLabelProps={sideTickLabelProps}\n />\n ) : (\n <AxisRight\n key={axis.id}\n {...commonProps}\n left={innerWidth + getSecondaryChartAxisOffset(axes, index)}\n tickLabelProps={sideTickLabelProps}\n />\n );\n }\n\n const edgeTickLabelProps = () => ({\n ...tickLabelStyle,\n textAnchor: 'middle' as const,\n });\n return index === 0 ? (\n <AxisBottom\n key={axis.id}\n {...commonProps}\n top={innerHeight}\n tickLabelProps={edgeTickLabelProps}\n />\n ) : (\n <AxisTop\n key={axis.id}\n {...commonProps}\n top={-getSecondaryChartAxisOffset(axes, index)}\n tickLabelProps={edgeTickLabelProps}\n />\n );\n })}\n {slots?.categoryAxis == null &&\n categoryAxis?.label != null &&\n (orientation === 'vertical' ? (\n <AxisLabel\n label={categoryAxis.label}\n x={innerWidth / 2}\n y={innerHeight + getChartAxisLabelOffset(categoryAxisThickness)}\n />\n ) : (\n <AxisLabel\n label={categoryAxis.label}\n x={-getChartAxisLabelOffset(categoryAxisThickness)}\n y={innerHeight / 2}\n rotation={-90}\n />\n ))}\n {slots?.valueAxis == null &&\n axes.map((axis, index) => {\n if (axis.label == null) return null;\n if (orientation === 'vertical') {\n const x =\n index === 0\n ? -getChartAxisLabelOffset(axis.thickness)\n : innerWidth +\n getSecondaryChartAxisOffset(axes, index) +\n getChartAxisLabelOffset(axis.thickness);\n return (\n <AxisLabel\n key={axis.id}\n label={axis.label}\n x={x}\n y={innerHeight / 2}\n rotation={index === 0 ? -90 : 90}\n />\n );\n }\n return (\n <AxisLabel\n key={axis.id}\n label={axis.label}\n x={innerWidth / 2}\n y={\n index === 0\n ? innerHeight + getChartAxisLabelOffset(axis.thickness)\n : -getSecondaryChartAxisOffset(axes, index) -\n getChartAxisLabelOffset(axis.thickness)\n }\n />\n );\n })}\n </>\n);\n"],"mappings":";;;;;;;;AAsBA,IAAM,iBAAiB;CACrB,MAAM;CACN,UAAA;AACF;AACA,IAAM,iBAAiB;CACrB,MAAM;CACN,UAAA;CACA,YAAY;AACd;AAEA,IAAM,aAAa,EACjB,OACA,GACA,GACA,eAOA,oBAAC,SAAD;CAAS,OAAO;CACd,UAAA,oBAAC,QAAD;EACE,GAAI;EACD;EACA;EACH,WACE,YAAY,OAAO,KAAA,IAAY,UAAU,SAAS,IAAI,EAAE,IAAI,EAAE;EAG/D,UAAA;CACG,CAAA;AACC,CAAA;;;;;AAsBX,IAAa,gBAAgB,EAC3B,aACA,YACA,cACA,uBACA,eACA,oBACA,MACA,OACA,YACA,aACA,qBACA,qBAEA,qBAAA,UAAA,EAAA,UAAA;CACG,OAAO,gBAAgB,OACt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O,UAAU,IACf,oBAAC,YAAD;GAEE,GAAI;GACJ,KAAK;GACL,gBAAgB;EACjB,GAJM,KAAK,EAIX,IAED,oBAAC,SAAD;GAEE,GAAI;GACJ,KAAK,CAAC,4BAA4B,MAAM,KAAK;GAC7C,gBAAgB;EACjB,GAJM,KAAK,EAIX;CAEL,CAAC;CACA,OAAO,gBAAgB,QACtB,cAAc,SAAS,SACtB,gBAAgB,aACf,oBAAC,WAAD;EACE,OAAO,aAAa;EACpB,GAAG,aAAa;EAChB,GAAG,cAAc,wBAAwB,qBAAqB;CAC/D,CAAA,IAED,oBAAC,WAAD;EACE,OAAO,aAAa;EACpB,GAAG,CAAC,wBAAwB,qBAAqB;EACjD,GAAG,cAAc;EACjB,UAAU;CACX,CAAA;CAEJ,OAAO,aAAa,QACnB,KAAK,KAAK,MAAM,UAAU;EACxB,IAAI,KAAK,SAAS,MAAM,OAAO;EAC/B,IAAI,gBAAgB,YAAY;GAC9B,MAAM,IACJ,UAAU,IACN,CAAC,wBAAwB,KAAK,SAAS,IACvC,aACA,4BAA4B,MAAM,KAAK,IACvC,wBAAwB,KAAK,SAAS;GAC5C,OACE,oBAAC,WAAD;IAEE,OAAO,KAAK;IACT;IACH,GAAG,cAAc;IACjB,UAAU,UAAU,IAAI,MAAM;GAC/B,GALM,KAAK,EAKX;EAEL;EACA,OACE,oBAAC,WAAD;GAEE,OAAO,KAAK;GACZ,GAAG,aAAa;GAChB,GACE,UAAU,IACN,cAAc,wBAAwB,KAAK,SAAS,IACpD,CAAC,4BAA4B,MAAM,KAAK,IACxC,wBAAwB,KAAK,SAAS;EAE7C,GATM,KAAK,EASX;CAEL,CAAC;AACH,EAAA,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { scaleBand } from '@visx/scale';
|
|
2
|
+
import type { BarChartCategory, BarChartDisplayAxis, BarChartGrid, BarChartOrientation, BarChartSelectionRange, BarChartValueBand } from './BarChart.types.js';
|
|
3
|
+
type BarChartGuidesProps = {
|
|
4
|
+
orientation: BarChartOrientation;
|
|
5
|
+
primaryAxis: BarChartDisplayAxis;
|
|
6
|
+
axisById: ReadonlyMap<string, BarChartDisplayAxis>;
|
|
7
|
+
categoryScale: ReturnType<typeof scaleBand<BarChartCategory>>;
|
|
8
|
+
categoryTickValues: readonly BarChartCategory[];
|
|
9
|
+
grid?: BarChartGrid;
|
|
10
|
+
valueBands: readonly BarChartValueBand[];
|
|
11
|
+
selectionRange?: BarChartSelectionRange;
|
|
12
|
+
activeCategory?: BarChartCategory | null;
|
|
13
|
+
innerWidth: number;
|
|
14
|
+
innerHeight: number;
|
|
15
|
+
formatCategory: (category: BarChartCategory) => string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Everything drawn beneath the bars: threshold bands, the selected range, and
|
|
19
|
+
* the value and category grids.
|
|
20
|
+
*/
|
|
21
|
+
export declare const BarChartGuides: ({ orientation, primaryAxis, axisById, categoryScale, categoryTickValues, grid, valueBands, selectionRange, activeCategory, innerWidth, innerHeight, formatCategory, }: BarChartGuidesProps) => import("react").JSX.Element;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import "../../utils/chartConstants.js";
|
|
2
|
+
import { clamp } from "../../utils/clamp.js";
|
|
3
|
+
import "./constants.js";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { GridColumns, GridRows } from "@visx/grid";
|
|
6
|
+
//#region packages/components/src/components/BarChart/BarChartGuides.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Everything drawn beneath the bars: threshold bands, the selected range, and
|
|
9
|
+
* the value and category grids.
|
|
10
|
+
*/
|
|
11
|
+
var BarChartGuides = ({ orientation, primaryAxis, axisById, categoryScale, categoryTickValues, grid, valueBands, selectionRange, activeCategory, innerWidth, innerHeight, formatCategory }) => {
|
|
12
|
+
const isVertical = orientation === "vertical";
|
|
13
|
+
const selectionStart = selectionRange == null ? void 0 : categoryScale(selectionRange.from);
|
|
14
|
+
const selectionEnd = selectionRange == null ? void 0 : categoryScale(selectionRange.to);
|
|
15
|
+
const activeCategoryStart = activeCategory == null ? void 0 : categoryScale(activeCategory);
|
|
16
|
+
const selectionBounds = selectionRange == null || selectionStart == null || selectionEnd == null ? null : {
|
|
17
|
+
start: Math.min(selectionStart, selectionEnd),
|
|
18
|
+
size: Math.abs(selectionEnd - selectionStart) + categoryScale.bandwidth()
|
|
19
|
+
};
|
|
20
|
+
const gridProps = {
|
|
21
|
+
width: innerWidth,
|
|
22
|
+
height: innerHeight,
|
|
23
|
+
stroke: "var(--border-subtle)",
|
|
24
|
+
strokeDasharray: "4 2",
|
|
25
|
+
pointerEvents: "none"
|
|
26
|
+
};
|
|
27
|
+
const valueTickValues = grid?.tickValues ?? primaryAxis.tickValues;
|
|
28
|
+
const valueGridProps = {
|
|
29
|
+
...gridProps,
|
|
30
|
+
scale: primaryAxis.scale,
|
|
31
|
+
numTicks: grid?.tickCount ?? primaryAxis.tickCount ?? 4,
|
|
32
|
+
tickValues: valueTickValues == null ? void 0 : Array.from(valueTickValues)
|
|
33
|
+
};
|
|
34
|
+
const categoryGridProps = {
|
|
35
|
+
...gridProps,
|
|
36
|
+
scale: categoryScale,
|
|
37
|
+
tickValues: Array.from(categoryTickValues)
|
|
38
|
+
};
|
|
39
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
40
|
+
valueBands.map((band) => {
|
|
41
|
+
const axis = band.valueAxisId == null ? primaryAxis : axisById.get(band.valueAxisId);
|
|
42
|
+
if (axis == null) return null;
|
|
43
|
+
const [domainMinimum, domainMaximum] = axis.scale.domain();
|
|
44
|
+
const fromPosition = axis.scale(band.from ?? domainMinimum);
|
|
45
|
+
const toPosition = axis.scale(band.to ?? domainMaximum);
|
|
46
|
+
const start = Math.min(fromPosition, toPosition);
|
|
47
|
+
const size = Math.abs(toPosition - fromPosition);
|
|
48
|
+
return /* @__PURE__ */ jsx("rect", {
|
|
49
|
+
x: isVertical ? 0 : start,
|
|
50
|
+
y: isVertical ? start : 0,
|
|
51
|
+
width: isVertical ? innerWidth : size,
|
|
52
|
+
height: isVertical ? size : innerHeight,
|
|
53
|
+
fill: band.color,
|
|
54
|
+
opacity: clamp(band.opacity ?? .5, 0, 1),
|
|
55
|
+
role: band.ariaLabel == null ? void 0 : "img",
|
|
56
|
+
"aria-label": band.ariaLabel
|
|
57
|
+
}, band.id);
|
|
58
|
+
}),
|
|
59
|
+
selectionBounds != null && selectionRange != null && /* @__PURE__ */ jsx("rect", {
|
|
60
|
+
x: isVertical ? selectionBounds.start : 0,
|
|
61
|
+
y: isVertical ? 0 : selectionBounds.start,
|
|
62
|
+
width: isVertical ? selectionBounds.size : innerWidth,
|
|
63
|
+
height: isVertical ? innerHeight : selectionBounds.size,
|
|
64
|
+
fill: "var(--bg-brand-subtle)",
|
|
65
|
+
role: "img",
|
|
66
|
+
"aria-label": `Selected range from ${formatCategory(selectionRange.from)} to ${formatCategory(selectionRange.to)}`
|
|
67
|
+
}),
|
|
68
|
+
activeCategoryStart != null && /* @__PURE__ */ jsx("rect", {
|
|
69
|
+
x: isVertical ? activeCategoryStart : 0,
|
|
70
|
+
y: isVertical ? 0 : activeCategoryStart,
|
|
71
|
+
width: isVertical ? categoryScale.bandwidth() : innerWidth,
|
|
72
|
+
height: isVertical ? innerHeight : categoryScale.bandwidth(),
|
|
73
|
+
fill: "var(--bg-surface-level-2-hover)",
|
|
74
|
+
pointerEvents: "none"
|
|
75
|
+
}),
|
|
76
|
+
(grid?.value ?? true) && (isVertical ? /* @__PURE__ */ jsx(GridRows, { ...valueGridProps }) : /* @__PURE__ */ jsx(GridColumns, { ...valueGridProps })),
|
|
77
|
+
(grid?.category ?? false) && (isVertical ? /* @__PURE__ */ jsx(GridColumns, { ...categoryGridProps }) : /* @__PURE__ */ jsx(GridRows, { ...categoryGridProps }))
|
|
78
|
+
] });
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
export { BarChartGuides };
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=BarChartGuides.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BarChartGuides.js","names":[],"sources":["../../../src/components/BarChart/BarChartGuides.tsx"],"sourcesContent":["import { GridColumns, GridRows } from '@visx/grid';\nimport type { scaleBand } from '@visx/scale';\n\nimport { CHART_DASHED_STROKE_DASHARRAY } from '../../utils/chartConstants';\nimport { clamp } from '../../utils/clamp';\nimport type {\n BarChartCategory,\n BarChartDisplayAxis,\n BarChartGrid,\n BarChartOrientation,\n BarChartSelectionRange,\n BarChartValueBand,\n} from './BarChart.types';\nimport {\n BAR_CHART_DEFAULT_TICK_COUNT,\n BAR_CHART_DEFAULT_VALUE_BAND_OPACITY,\n} from './constants';\n\ntype BarChartGuidesProps = {\n orientation: BarChartOrientation;\n primaryAxis: BarChartDisplayAxis;\n axisById: ReadonlyMap<string, BarChartDisplayAxis>;\n categoryScale: ReturnType<typeof scaleBand<BarChartCategory>>;\n categoryTickValues: readonly BarChartCategory[];\n grid?: BarChartGrid;\n valueBands: readonly BarChartValueBand[];\n selectionRange?: BarChartSelectionRange;\n activeCategory?: BarChartCategory | null;\n innerWidth: number;\n innerHeight: number;\n formatCategory: (category: BarChartCategory) => string;\n};\n\n/**\n * Everything drawn beneath the bars: threshold bands, the selected range, and\n * the value and category grids.\n */\nexport const BarChartGuides = ({\n orientation,\n primaryAxis,\n axisById,\n categoryScale,\n categoryTickValues,\n grid,\n valueBands,\n selectionRange,\n activeCategory,\n innerWidth,\n innerHeight,\n formatCategory,\n}: BarChartGuidesProps) => {\n const isVertical = orientation === 'vertical';\n const selectionStart =\n selectionRange == null ? undefined : categoryScale(selectionRange.from);\n const selectionEnd =\n selectionRange == null ? undefined : categoryScale(selectionRange.to);\n const activeCategoryStart =\n activeCategory == null ? undefined : categoryScale(activeCategory);\n const selectionBounds =\n selectionRange == null || selectionStart == null || selectionEnd == null\n ? null\n : {\n start: Math.min(selectionStart, selectionEnd),\n size:\n Math.abs(selectionEnd - selectionStart) + categoryScale.bandwidth(),\n };\n const gridProps = {\n width: innerWidth,\n height: innerHeight,\n stroke: 'var(--border-subtle)',\n strokeDasharray: CHART_DASHED_STROKE_DASHARRAY,\n pointerEvents: 'none' as const,\n };\n // An empty tickValues array would draw no guides at all; visx needs\n // undefined to fall back to numTicks.\n const valueTickValues = grid?.tickValues ?? primaryAxis.tickValues;\n const valueGridProps = {\n ...gridProps,\n scale: primaryAxis.scale,\n numTicks:\n grid?.tickCount ?? primaryAxis.tickCount ?? BAR_CHART_DEFAULT_TICK_COUNT,\n tickValues:\n valueTickValues == null ? undefined : Array.from(valueTickValues),\n };\n const categoryGridProps = {\n ...gridProps,\n scale: categoryScale,\n tickValues: Array.from(categoryTickValues),\n };\n\n return (\n <>\n {valueBands.map((band) => {\n const axis =\n band.valueAxisId == null\n ? primaryAxis\n : axisById.get(band.valueAxisId);\n if (axis == null) return null;\n const [domainMinimum, domainMaximum] = axis.scale.domain();\n const fromPosition = axis.scale(band.from ?? domainMinimum);\n const toPosition = axis.scale(band.to ?? domainMaximum);\n const start = Math.min(fromPosition, toPosition);\n const size = Math.abs(toPosition - fromPosition);\n return (\n <rect\n key={band.id}\n x={isVertical ? 0 : start}\n y={isVertical ? start : 0}\n width={isVertical ? innerWidth : size}\n height={isVertical ? size : innerHeight}\n fill={band.color}\n opacity={clamp(\n band.opacity ?? BAR_CHART_DEFAULT_VALUE_BAND_OPACITY,\n 0,\n 1\n )}\n role={band.ariaLabel == null ? undefined : 'img'}\n aria-label={band.ariaLabel}\n />\n );\n })}\n {selectionBounds != null && selectionRange != null && (\n <rect\n x={isVertical ? selectionBounds.start : 0}\n y={isVertical ? 0 : selectionBounds.start}\n width={isVertical ? selectionBounds.size : innerWidth}\n height={isVertical ? innerHeight : selectionBounds.size}\n // Bars paint over this layer, so the full-strength subtle brand\n // surface hides no data and stays readable in dark mode.\n fill=\"var(--bg-brand-subtle)\"\n role=\"img\"\n aria-label={`Selected range from ${formatCategory(\n selectionRange.from\n )} to ${formatCategory(selectionRange.to)}`}\n />\n )}\n {activeCategoryStart != null && (\n <rect\n x={isVertical ? activeCategoryStart : 0}\n y={isVertical ? 0 : activeCategoryStart}\n width={isVertical ? categoryScale.bandwidth() : innerWidth}\n height={isVertical ? innerHeight : categoryScale.bandwidth()}\n fill=\"var(--bg-surface-level-2-hover)\"\n pointerEvents=\"none\"\n />\n )}\n {(grid?.value ?? true) &&\n (isVertical ? (\n <GridRows {...valueGridProps} />\n ) : (\n <GridColumns {...valueGridProps} />\n ))}\n {(grid?.category ?? false) &&\n (isVertical ? (\n <GridColumns {...categoryGridProps} />\n ) : (\n <GridRows {...categoryGridProps} />\n ))}\n </>\n );\n};\n"],"mappings":";;;;;;;;;;AAqCA,IAAa,kBAAkB,EAC7B,aACA,aACA,UACA,eACA,oBACA,MACA,YACA,gBACA,gBACA,YACA,aACA,qBACyB;CACzB,MAAM,aAAa,gBAAgB;CACnC,MAAM,iBACJ,kBAAkB,OAAO,KAAA,IAAY,cAAc,eAAe,IAAI;CACxE,MAAM,eACJ,kBAAkB,OAAO,KAAA,IAAY,cAAc,eAAe,EAAE;CACtE,MAAM,sBACJ,kBAAkB,OAAO,KAAA,IAAY,cAAc,cAAc;CACnE,MAAM,kBACJ,kBAAkB,QAAQ,kBAAkB,QAAQ,gBAAgB,OAChE,OACA;EACE,OAAO,KAAK,IAAI,gBAAgB,YAAY;EAC5C,MACE,KAAK,IAAI,eAAe,cAAc,IAAI,cAAc,UAAU;CACtE;CACN,MAAM,YAAY;EAChB,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,iBAAA;EACA,eAAe;CACjB;CAGA,MAAM,kBAAkB,MAAM,cAAc,YAAY;CACxD,MAAM,iBAAiB;EACrB,GAAG;EACH,OAAO,YAAY;EACnB,UACE,MAAM,aAAa,YAAY,aAAA;EACjC,YACE,mBAAmB,OAAO,KAAA,IAAY,MAAM,KAAK,eAAe;CACpE;CACA,MAAM,oBAAoB;EACxB,GAAG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,UAAD,EAAU,GAAI,eAAiB,CAAA,IAE/B,oBAAC,aAAD,EAAa,GAAI,eAAiB,CAAA;GAEpC,MAAM,YAAY,WACjB,aACC,oBAAC,aAAD,EAAa,GAAI,kBAAoB,CAAA,IAErC,oBAAC,UAAD,EAAU,GAAI,kBAAoB,CAAA;CAEtC,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { BarChartCategory, BarChartCategoryAxis, BarChartDisplayAxis, BarChartDisplaySeries, BarChartGrid, BarChartInteractionProps, BarChartLayoutBar, BarChartOrientation, BarChartSelectionRange, BarChartSlots, BarChartValueBand } from './BarChart.types.js';
|
|
2
|
+
export type BarChartPlotProps = BarChartInteractionProps & {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
innerWidth: number;
|
|
6
|
+
innerHeight: number;
|
|
7
|
+
chartMargin: {
|
|
8
|
+
top: number;
|
|
9
|
+
right: number;
|
|
10
|
+
bottom: number;
|
|
11
|
+
left: number;
|
|
12
|
+
};
|
|
13
|
+
categories: readonly BarChartCategory[];
|
|
14
|
+
series: readonly BarChartDisplaySeries[];
|
|
15
|
+
bars: readonly BarChartLayoutBar[];
|
|
16
|
+
axes: readonly BarChartDisplayAxis[];
|
|
17
|
+
orientation: BarChartOrientation;
|
|
18
|
+
categoryAxis?: BarChartCategoryAxis;
|
|
19
|
+
categoryAxisThickness: number;
|
|
20
|
+
categoryPadding: {
|
|
21
|
+
inner: number;
|
|
22
|
+
outer: number;
|
|
23
|
+
};
|
|
24
|
+
groupPadding: number;
|
|
25
|
+
minimumBarSize: number;
|
|
26
|
+
shouldAnimate: boolean;
|
|
27
|
+
grid?: BarChartGrid;
|
|
28
|
+
valueBands: readonly BarChartValueBand[];
|
|
29
|
+
activeCategory?: BarChartCategory | null;
|
|
30
|
+
activeGuideBarId?: string | null;
|
|
31
|
+
activeBarId?: string | null;
|
|
32
|
+
activeBuiltInLegendItemId?: string | null;
|
|
33
|
+
activeLegendItemId?: string | null;
|
|
34
|
+
selectionRange?: BarChartSelectionRange;
|
|
35
|
+
slots?: BarChartSlots;
|
|
36
|
+
isRendering: boolean;
|
|
37
|
+
'aria-describedby'?: string;
|
|
38
|
+
'aria-label': string;
|
|
39
|
+
};
|
|
40
|
+
export declare const BarChartPlot: ({ width, height, innerWidth, innerHeight, chartMargin, categories, series, bars, axes, orientation, categoryAxis, categoryAxisThickness, categoryPadding, groupPadding, minimumBarSize, shouldAnimate, grid, valueBands, activeCategory, activeGuideBarId, activeBarId, activeBuiltInLegendItemId, activeLegendItemId, selectionRange, slots, isRendering, "aria-describedby": ariaDescribedBy, "aria-label": ariaLabel, getBarAriaLabel, getCategoryAriaLabel, onDatumPointerDown, onDatumPointerMove, onDatumPointerOut, onDatumPointerUp, onDatumActivate, onDatumFocus, onDatumBlur, onBarPointerMove, onBarPointerOut, onBarActivate, onBarFocus, onBarBlur, }: BarChartPlotProps) => import("react").JSX.Element;
|