@eylulg/ui 1.1.0 → 2.0.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/README.md +172 -223
- package/dist/components/{Avatar → atoms/Avatar}/Avatar.d.ts +3 -1
- package/dist/components/{Avatar → atoms/Avatar}/Avatar.js +4 -4
- package/dist/components/atoms/Avatar/Avatar.js.map +1 -0
- package/dist/components/{Avatar → atoms/Avatar}/index.d.ts +1 -1
- package/dist/components/atoms/Avatar/index.js +2 -0
- package/dist/components/{Badge → atoms/Badge}/Badge.d.ts +10 -6
- package/dist/components/{Badge → atoms/Badge}/Badge.js +12 -16
- package/dist/components/atoms/Badge/Badge.js.map +1 -0
- package/dist/components/atoms/Badge/index.d.ts +2 -0
- package/dist/components/atoms/BrandLoader/BrandLoader.d.ts +14 -0
- package/dist/components/atoms/BrandLoader/BrandLoader.js +57 -0
- package/dist/components/atoms/BrandLoader/BrandLoader.js.map +1 -0
- package/dist/components/atoms/BrandLoader/index.d.ts +2 -0
- package/dist/components/atoms/BrandLoader/index.js +2 -0
- package/dist/{chrome → components/atoms/BrandLogo}/BrandLogo.d.ts +1 -1
- package/dist/{chrome → components/atoms/BrandLogo}/BrandLogo.js +3 -4
- package/dist/components/atoms/BrandLogo/BrandLogo.js.map +1 -0
- package/dist/components/atoms/BrandLogo/index.d.ts +2 -0
- package/dist/components/atoms/BrandLogo/index.js +1 -0
- package/dist/components/{Button → atoms/Button}/Button.d.ts +13 -9
- package/dist/components/atoms/Button/Button.js +88 -0
- package/dist/components/atoms/Button/Button.js.map +1 -0
- package/dist/components/{Button → atoms/Button}/buttonStyles.d.ts +4 -6
- package/dist/components/atoms/Button/buttonStyles.js +25 -0
- package/dist/components/atoms/Button/buttonStyles.js.map +1 -0
- package/dist/components/atoms/Button/index.d.ts +2 -0
- package/dist/components/atoms/Button/index.js +4 -0
- package/dist/components/{Checkbox → atoms/Checkbox}/Checkbox.js +10 -14
- package/dist/components/atoms/Checkbox/Checkbox.js.map +1 -0
- package/dist/components/atoms/IconButton/IconButton.d.ts +21 -0
- package/dist/components/atoms/IconButton/IconButton.js +43 -0
- package/dist/components/atoms/IconButton/IconButton.js.map +1 -0
- package/dist/components/{Kbd → atoms/Kbd}/Kbd.d.ts +2 -2
- package/dist/components/{Kbd → atoms/Kbd}/Kbd.js +9 -8
- package/dist/components/atoms/Kbd/Kbd.js.map +1 -0
- package/dist/components/atoms/NavItem/NavItem.d.ts +24 -0
- package/dist/components/atoms/NavItem/NavItem.js +42 -0
- package/dist/components/atoms/NavItem/NavItem.js.map +1 -0
- package/dist/components/atoms/NavItem/index.d.ts +2 -0
- package/dist/components/atoms/NavItem/index.js +1 -0
- package/dist/components/{ProgressBar → atoms/ProgressBar}/ProgressBar.d.ts +2 -2
- package/dist/components/{ProgressBar → atoms/ProgressBar}/ProgressBar.js +6 -5
- package/dist/components/atoms/ProgressBar/ProgressBar.js.map +1 -0
- package/dist/components/atoms/ProgressBar/index.d.ts +2 -0
- package/dist/components/{Skeleton → atoms/Skeleton}/Skeleton.js +3 -5
- package/dist/components/atoms/Skeleton/Skeleton.js.map +1 -0
- package/dist/components/{Spinner → atoms/Spinner}/Spinner.js +2 -2
- package/dist/components/atoms/Spinner/Spinner.js.map +1 -0
- package/dist/components/{Switch → atoms/Switch}/Switch.d.ts +3 -3
- package/dist/components/atoms/Switch/Switch.js +35 -0
- package/dist/components/atoms/Switch/Switch.js.map +1 -0
- package/dist/components/atoms/TextLink/TextLink.d.ts +18 -0
- package/dist/components/atoms/TextLink/TextLink.js +21 -0
- package/dist/components/atoms/TextLink/TextLink.js.map +1 -0
- package/dist/components/atoms/TextLink/index.d.ts +2 -0
- package/dist/components/atoms/TextLink/index.js +1 -0
- package/dist/components/{Tooltip → atoms/Tooltip}/Tooltip.js +4 -4
- package/dist/components/atoms/Tooltip/Tooltip.js.map +1 -0
- package/dist/components/{Tooltip → atoms/Tooltip}/TooltipOverlay.js +2 -2
- package/dist/components/atoms/Tooltip/TooltipOverlay.js.map +1 -0
- package/dist/components/{Breadcrumbs → molecules/Breadcrumbs}/Breadcrumbs.js +5 -4
- package/dist/components/molecules/Breadcrumbs/Breadcrumbs.js.map +1 -0
- package/dist/components/{Card → molecules/Card}/Card.d.ts +3 -1
- package/dist/components/{Card → molecules/Card}/Card.js +21 -13
- package/dist/components/molecules/Card/Card.js.map +1 -0
- package/dist/components/molecules/Card/index.d.ts +2 -0
- package/dist/components/{CodeBlock → molecules/CodeBlock}/CodeBlock.d.ts +7 -5
- package/dist/components/{CodeBlock → molecules/CodeBlock}/CodeBlock.js +20 -12
- package/dist/components/molecules/CodeBlock/CodeBlock.js.map +1 -0
- package/dist/components/{Combobox → molecules/Combobox}/Combobox.d.ts +4 -1
- package/dist/components/molecules/Combobox/Combobox.js +91 -0
- package/dist/components/molecules/Combobox/Combobox.js.map +1 -0
- package/dist/components/{DatePicker → molecules/DatePicker}/DatePicker.d.ts +7 -4
- package/dist/components/molecules/DatePicker/DatePicker.js +138 -0
- package/dist/components/molecules/DatePicker/DatePicker.js.map +1 -0
- package/dist/components/molecules/Dialog/Dialog.d.ts +20 -0
- package/dist/components/{Dialog → molecules/Dialog}/Dialog.js +7 -7
- package/dist/components/molecules/Dialog/Dialog.js.map +1 -0
- package/dist/components/molecules/Dialog/DialogOverlay.d.ts +3 -0
- package/dist/components/molecules/Dialog/DialogOverlay.js +60 -0
- package/dist/components/molecules/Dialog/DialogOverlay.js.map +1 -0
- package/dist/components/molecules/Drawer/Drawer.d.ts +21 -0
- package/dist/components/{Drawer → molecules/Drawer}/Drawer.js +7 -7
- package/dist/components/molecules/Drawer/Drawer.js.map +1 -0
- package/dist/components/{Drawer → molecules/Drawer}/DrawerOverlay.d.ts +1 -1
- package/dist/components/molecules/Drawer/DrawerOverlay.js +66 -0
- package/dist/components/molecules/Drawer/DrawerOverlay.js.map +1 -0
- package/dist/components/{DropdownMenu → molecules/DropdownMenu}/DropdownMenu.d.ts +8 -9
- package/dist/components/{DropdownMenu → molecules/DropdownMenu}/DropdownMenu.js +8 -20
- package/dist/components/molecules/DropdownMenu/DropdownMenu.js.map +1 -0
- package/dist/components/{DropdownMenu → molecules/DropdownMenu}/DropdownMenuParts.d.ts +1 -1
- package/dist/components/{DropdownMenu → molecules/DropdownMenu}/DropdownMenuParts.js +17 -28
- package/dist/components/molecules/DropdownMenu/DropdownMenuParts.js.map +1 -0
- package/dist/components/{EmptyState → molecules/EmptyState}/EmptyState.d.ts +3 -4
- package/dist/components/{EmptyState → molecules/EmptyState}/EmptyState.js +6 -5
- package/dist/components/molecules/EmptyState/EmptyState.js.map +1 -0
- package/dist/components/{FileDropZone → molecules/FileDropZone}/FileDropZone.d.ts +1 -1
- package/dist/components/{FileDropZone → molecules/FileDropZone}/FileDropZone.js +6 -5
- package/dist/components/molecules/FileDropZone/FileDropZone.js.map +1 -0
- package/dist/components/{Input → molecules/Input}/Input.d.ts +8 -6
- package/dist/components/molecules/Input/Input.js +45 -0
- package/dist/components/molecules/Input/Input.js.map +1 -0
- package/dist/components/molecules/Input/index.d.ts +2 -0
- package/dist/components/{Pagination → molecules/Pagination}/Pagination.d.ts +6 -2
- package/dist/components/{Pagination → molecules/Pagination}/Pagination.js +44 -34
- package/dist/components/molecules/Pagination/Pagination.js.map +1 -0
- package/dist/components/molecules/Pagination/index.d.ts +2 -0
- package/dist/components/molecules/Pagination/index.js +2 -0
- package/dist/components/{Popover → molecules/Popover}/Popover.d.ts +1 -1
- package/dist/components/{Popover → molecules/Popover}/Popover.js +7 -7
- package/dist/components/molecules/Popover/Popover.js.map +1 -0
- package/dist/components/{Popover → molecules/Popover}/PopoverOverlay.js +5 -4
- package/dist/components/molecules/Popover/PopoverOverlay.js.map +1 -0
- package/dist/components/molecules/RadioGroup/RadioGroup.js +43 -0
- package/dist/components/molecules/RadioGroup/RadioGroup.js.map +1 -0
- package/dist/components/{SegmentedControl → molecules/SegmentedControl}/SegmentedControl.d.ts +6 -7
- package/dist/components/molecules/SegmentedControl/SegmentedControl.js +71 -0
- package/dist/components/molecules/SegmentedControl/SegmentedControl.js.map +1 -0
- package/dist/components/molecules/SegmentedControl/index.d.ts +2 -0
- package/dist/components/{Select → molecules/Select}/Select.d.ts +4 -1
- package/dist/components/molecules/Select/Select.js +58 -0
- package/dist/components/molecules/Select/Select.js.map +1 -0
- package/dist/components/molecules/Stat/Stat.d.ts +36 -0
- package/dist/components/molecules/Stat/Stat.js +85 -0
- package/dist/components/molecules/Stat/Stat.js.map +1 -0
- package/dist/components/molecules/Stat/index.d.ts +2 -0
- package/dist/components/molecules/Stat/index.js +2 -0
- package/dist/components/{Tabs → molecules/Tabs}/Tabs.js +5 -5
- package/dist/components/molecules/Tabs/Tabs.js.map +1 -0
- package/dist/components/molecules/Tag/Tag.js +49 -0
- package/dist/components/molecules/Tag/Tag.js.map +1 -0
- package/dist/components/{Textarea → molecules/Textarea}/Textarea.d.ts +3 -11
- package/dist/components/molecules/Textarea/Textarea.js +29 -0
- package/dist/components/molecules/Textarea/Textarea.js.map +1 -0
- package/dist/components/molecules/Textarea/index.d.ts +2 -0
- package/dist/components/{Toast → molecules/Toast}/Toast.d.ts +12 -8
- package/dist/components/{Toast → molecules/Toast}/Toast.js +13 -18
- package/dist/components/molecules/Toast/Toast.js.map +1 -0
- package/dist/components/molecules/Toast/ToastItem.d.ts +6 -0
- package/dist/components/{Toast → molecules/Toast}/ToastItem.js +25 -27
- package/dist/components/molecules/Toast/ToastItem.js.map +1 -0
- package/dist/components/{Toast → molecules/Toast}/index.d.ts +1 -1
- package/dist/components/{Chart → organisms/Chart}/BarChart.d.ts +1 -1
- package/dist/components/organisms/Chart/BarChart.js +304 -0
- package/dist/components/organisms/Chart/BarChart.js.map +1 -0
- package/dist/components/{Chart → organisms/Chart}/ChartFrame.d.ts +2 -2
- package/dist/components/{Chart → organisms/Chart}/ChartFrame.js +14 -18
- package/dist/components/organisms/Chart/ChartFrame.js.map +1 -0
- package/dist/components/{Chart → organisms/Chart}/ChartLegend.d.ts +3 -2
- package/dist/components/{Chart → organisms/Chart}/ChartLegend.js +2 -2
- package/dist/components/organisms/Chart/ChartLegend.js.map +1 -0
- package/dist/components/{Chart → organisms/Chart}/ChartTable.js +8 -12
- package/dist/components/organisms/Chart/ChartTable.js.map +1 -0
- package/dist/components/{Chart → organisms/Chart}/ChartTooltip.d.ts +3 -2
- package/dist/components/{Chart → organisms/Chart}/ChartTooltip.js +3 -3
- package/dist/components/organisms/Chart/ChartTooltip.js.map +1 -0
- package/dist/components/{Chart → organisms/Chart}/HeatGrid.d.ts +6 -3
- package/dist/components/organisms/Chart/HeatGrid.js +235 -0
- package/dist/components/organisms/Chart/HeatGrid.js.map +1 -0
- package/dist/components/{Chart → organisms/Chart}/LineChart.d.ts +1 -1
- package/dist/components/organisms/Chart/LineChart.js +227 -0
- package/dist/components/organisms/Chart/LineChart.js.map +1 -0
- package/dist/components/organisms/Chart/Sparkline.d.ts +14 -0
- package/dist/components/organisms/Chart/Sparkline.js +39 -0
- package/dist/components/organisms/Chart/Sparkline.js.map +1 -0
- package/dist/components/{Chart → organisms/Chart}/format.d.ts +2 -0
- package/dist/components/{Chart → organisms/Chart}/format.js +6 -4
- package/dist/components/organisms/Chart/format.js.map +1 -0
- package/dist/components/{Chart → organisms/Chart}/geometry.js +1 -1
- package/dist/components/organisms/Chart/geometry.js.map +1 -0
- package/dist/components/{Chart → organisms/Chart}/index.d.ts +2 -2
- package/dist/components/{Chart → organisms/Chart}/index.js +2 -2
- package/dist/components/{Chart → organisms/Chart}/interaction.d.ts +10 -6
- package/dist/components/{Chart → organisms/Chart}/interaction.js +13 -10
- package/dist/components/organisms/Chart/interaction.js.map +1 -0
- package/dist/components/{Chart → organisms/Chart}/labels.js +1 -1
- package/dist/components/organisms/Chart/labels.js.map +1 -0
- package/dist/components/{Chart → organisms/Chart}/scale.js +1 -1
- package/dist/components/organisms/Chart/scale.js.map +1 -0
- package/dist/components/organisms/Chart/series.d.ts +30 -0
- package/dist/components/organisms/Chart/series.js +108 -0
- package/dist/components/organisms/Chart/series.js.map +1 -0
- package/dist/components/{Chart → organisms/Chart}/summary.js +2 -5
- package/dist/components/organisms/Chart/summary.js.map +1 -0
- package/dist/components/{Chart → organisms/Chart}/types.d.ts +2 -2
- package/dist/components/{Chart → organisms/Chart}/useElementWidth.js +1 -1
- package/dist/components/organisms/Chart/useElementWidth.js.map +1 -0
- package/dist/components/{CommandPalette → organisms/CommandPalette}/CommandPalette.d.ts +7 -8
- package/dist/components/{CommandPalette → organisms/CommandPalette}/CommandPalette.js +4 -10
- package/dist/components/organisms/CommandPalette/CommandPalette.js.map +1 -0
- package/dist/components/organisms/CommandPalette/CommandPaletteOverlay.d.ts +4 -0
- package/dist/components/organisms/CommandPalette/CommandPaletteOverlay.js +150 -0
- package/dist/components/organisms/CommandPalette/CommandPaletteOverlay.js.map +1 -0
- package/dist/components/{CommandPalette → organisms/CommandPalette}/index.d.ts +1 -1
- package/dist/components/{PageHeader → organisms/PageHeader}/PageHeader.js +5 -5
- package/dist/components/organisms/PageHeader/PageHeader.js.map +1 -0
- package/dist/{chrome → components/organisms/SidebarNav}/SidebarNav.d.ts +1 -1
- package/dist/{chrome → components/organisms/SidebarNav}/SidebarNav.js +18 -26
- package/dist/components/organisms/SidebarNav/SidebarNav.js.map +1 -0
- package/dist/components/organisms/SidebarNav/index.d.ts +2 -0
- package/dist/components/organisms/SidebarNav/index.js +2 -0
- package/dist/components/organisms/SiteFooter/SiteFooter.d.ts +33 -0
- package/dist/components/organisms/SiteFooter/SiteFooter.js +87 -0
- package/dist/components/organisms/SiteFooter/SiteFooter.js.map +1 -0
- package/dist/components/organisms/SiteFooter/index.d.ts +2 -0
- package/dist/components/organisms/SiteFooter/index.js +1 -0
- package/dist/components/{Table → organisms/Table}/Table.d.ts +9 -6
- package/dist/components/{Table → organisms/Table}/Table.js +36 -23
- package/dist/components/organisms/Table/Table.js.map +1 -0
- package/dist/components/organisms/ThemeToggle/ThemeToggle.d.ts +36 -0
- package/dist/components/organisms/ThemeToggle/ThemeToggle.js +88 -0
- package/dist/components/organisms/ThemeToggle/ThemeToggle.js.map +1 -0
- package/dist/components/organisms/ThemeToggle/ThemeToggleMenu.d.ts +14 -0
- package/dist/components/organisms/ThemeToggle/ThemeToggleMenu.js +50 -0
- package/dist/components/organisms/ThemeToggle/ThemeToggleMenu.js.map +1 -0
- package/dist/components/organisms/ThemeToggle/index.d.ts +2 -0
- package/dist/components/organisms/ThemeToggle/index.js +2 -0
- package/dist/components/organisms/ThemeToggle/themeChoices.d.ts +7 -0
- package/dist/components/organisms/ThemeToggle/themeChoices.js +17 -0
- package/dist/components/organisms/ThemeToggle/themeChoices.js.map +1 -0
- package/dist/components/organisms/TopNav/TopNav.d.ts +51 -0
- package/dist/components/organisms/TopNav/TopNav.js +148 -0
- package/dist/components/organisms/TopNav/TopNav.js.map +1 -0
- package/dist/components/organisms/TopNav/index.d.ts +2 -0
- package/dist/components/organisms/TopNav/index.js +2 -0
- package/dist/{chrome → components/templates/AppShell}/AppShell.d.ts +10 -6
- package/dist/{chrome → components/templates/AppShell}/AppShell.js +12 -17
- package/dist/components/templates/AppShell/AppShell.js.map +1 -0
- package/dist/components/templates/AppShell/index.d.ts +2 -0
- package/dist/components/templates/AppShell/index.js +1 -0
- package/dist/{chrome → data}/projects.d.ts +13 -8
- package/dist/{chrome → data}/projects.js +48 -25
- package/dist/data/projects.js.map +1 -0
- package/dist/fonts.css +27 -2
- package/dist/index.d.ts +56 -38
- package/dist/index.js +55 -42
- package/dist/internal/Field.d.ts +16 -11
- package/dist/internal/Field.js +29 -23
- package/dist/internal/Field.js.map +1 -1
- package/dist/internal/OverlayParts.d.ts +43 -0
- package/dist/internal/OverlayParts.js +43 -0
- package/dist/internal/OverlayParts.js.map +1 -0
- package/dist/internal/PreloadOnIntent.d.ts +2 -3
- package/dist/internal/PreloadOnIntent.js +3 -3
- package/dist/internal/PreloadOnIntent.js.map +1 -1
- package/dist/{chrome → internal}/brandLogoPath.js +1 -2
- package/dist/internal/brandLogoPath.js.map +1 -0
- package/dist/internal/button.d.ts +7 -0
- package/dist/internal/button.js +19 -0
- package/dist/internal/button.js.map +1 -0
- package/dist/internal/control.d.ts +32 -0
- package/dist/internal/control.js +59 -0
- package/dist/internal/control.js.map +1 -0
- package/dist/internal/focusRing.d.ts +7 -1
- package/dist/internal/focusRing.js +8 -3
- package/dist/internal/focusRing.js.map +1 -1
- package/dist/internal/layout.d.ts +9 -0
- package/dist/internal/layout.js +13 -0
- package/dist/internal/layout.js.map +1 -0
- package/dist/internal/lazyModule.d.ts +8 -2
- package/dist/internal/lazyModule.js +20 -6
- package/dist/internal/lazyModule.js.map +1 -1
- package/dist/internal/link.d.ts +3 -0
- package/dist/internal/link.js +10 -0
- package/dist/internal/link.js.map +1 -0
- package/dist/internal/listParts.d.ts +12 -0
- package/dist/internal/listParts.js +32 -0
- package/dist/internal/listParts.js.map +1 -0
- package/dist/internal/surfaces.d.ts +11 -5
- package/dist/internal/surfaces.js +13 -7
- package/dist/internal/surfaces.js.map +1 -1
- package/dist/internal/toggle.d.ts +8 -0
- package/dist/internal/toggle.js +22 -0
- package/dist/internal/toggle.js.map +1 -0
- package/dist/internal/types.d.ts +2 -5
- package/dist/{chrome → router}/Anchor.js +1 -2
- package/dist/{chrome → router}/Anchor.js.map +1 -1
- package/dist/{chrome → router}/LinkRouter.js +1 -1
- package/dist/{chrome → router}/LinkRouter.js.map +1 -1
- package/dist/{chrome → router}/types.d.ts +3 -3
- package/dist/styles/themes/variants.d.ts +0 -12
- package/dist/styles/themes/variants.js +3 -43
- package/dist/styles/themes/variants.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{chrome → theme}/themeScript.d.ts +2 -5
- package/dist/{chrome → theme}/themeScript.js +4 -7
- package/dist/theme/themeScript.js.map +1 -0
- package/dist/{chrome → theme}/useTheme.js +1 -1
- package/dist/theme/useTheme.js.map +1 -0
- package/dist/theme.css +87 -56
- package/dist/tokens.css +42 -48
- package/dist/utils/cx.d.ts +0 -12
- package/dist/utils/cx.js +18 -10
- package/dist/utils/cx.js.map +1 -1
- package/package.json +147 -107
- package/dist/chrome/AppShell.js.map +0 -1
- package/dist/chrome/BrandLogo.js.map +0 -1
- package/dist/chrome/BrandMark.d.ts +0 -12
- package/dist/chrome/BrandMark.js +0 -40
- package/dist/chrome/BrandMark.js.map +0 -1
- package/dist/chrome/MobileMenu.d.ts +0 -19
- package/dist/chrome/MobileMenu.js +0 -52
- package/dist/chrome/MobileMenu.js.map +0 -1
- package/dist/chrome/ProjectSwitcher.d.ts +0 -30
- package/dist/chrome/ProjectSwitcher.js +0 -64
- package/dist/chrome/ProjectSwitcher.js.map +0 -1
- package/dist/chrome/ProjectSwitcherMenu.d.ts +0 -13
- package/dist/chrome/ProjectSwitcherMenu.js +0 -50
- package/dist/chrome/ProjectSwitcherMenu.js.map +0 -1
- package/dist/chrome/SidebarNav.js.map +0 -1
- package/dist/chrome/SiteFooter.d.ts +0 -37
- package/dist/chrome/SiteFooter.js +0 -105
- package/dist/chrome/SiteFooter.js.map +0 -1
- package/dist/chrome/TextSizeToggle.d.ts +0 -11
- package/dist/chrome/TextSizeToggle.js +0 -38
- package/dist/chrome/TextSizeToggle.js.map +0 -1
- package/dist/chrome/ThemeToggle.d.ts +0 -26
- package/dist/chrome/ThemeToggle.js +0 -100
- package/dist/chrome/ThemeToggle.js.map +0 -1
- package/dist/chrome/ThemeToggleMenu.d.ts +0 -16
- package/dist/chrome/ThemeToggleMenu.js +0 -42
- package/dist/chrome/ThemeToggleMenu.js.map +0 -1
- package/dist/chrome/TopNav.d.ts +0 -42
- package/dist/chrome/TopNav.js +0 -117
- package/dist/chrome/TopNav.js.map +0 -1
- package/dist/chrome/brandLogoPath.js.map +0 -1
- package/dist/chrome/index.d.ts +0 -28
- package/dist/chrome/index.js +0 -15
- package/dist/chrome/projects.js.map +0 -1
- package/dist/chrome/themeChoices.d.ts +0 -6
- package/dist/chrome/themeChoices.js +0 -18
- package/dist/chrome/themeChoices.js.map +0 -1
- package/dist/chrome/themeScript.js.map +0 -1
- package/dist/chrome/useTextSize.d.ts +0 -16
- package/dist/chrome/useTextSize.js +0 -64
- package/dist/chrome/useTextSize.js.map +0 -1
- package/dist/chrome/useTheme.js.map +0 -1
- package/dist/components/Avatar/Avatar.js.map +0 -1
- package/dist/components/Avatar/index.js +0 -2
- package/dist/components/Badge/Badge.js.map +0 -1
- package/dist/components/Badge/index.d.ts +0 -2
- package/dist/components/Breadcrumbs/Breadcrumbs.js.map +0 -1
- package/dist/components/Button/Button.js +0 -73
- package/dist/components/Button/Button.js.map +0 -1
- package/dist/components/Button/buttonStyles.js +0 -32
- package/dist/components/Button/buttonStyles.js.map +0 -1
- package/dist/components/Button/index.d.ts +0 -2
- package/dist/components/Button/index.js +0 -4
- package/dist/components/Card/Card.js.map +0 -1
- package/dist/components/Card/index.d.ts +0 -2
- package/dist/components/Chart/BarChart.js +0 -327
- package/dist/components/Chart/BarChart.js.map +0 -1
- package/dist/components/Chart/ChartFrame.js.map +0 -1
- package/dist/components/Chart/ChartLegend.js.map +0 -1
- package/dist/components/Chart/ChartTable.js.map +0 -1
- package/dist/components/Chart/ChartTooltip.js.map +0 -1
- package/dist/components/Chart/HeatGrid.js +0 -256
- package/dist/components/Chart/HeatGrid.js.map +0 -1
- package/dist/components/Chart/LineChart.js +0 -248
- package/dist/components/Chart/LineChart.js.map +0 -1
- package/dist/components/Chart/format.js.map +0 -1
- package/dist/components/Chart/geometry.js.map +0 -1
- package/dist/components/Chart/interaction.js.map +0 -1
- package/dist/components/Chart/labels.js.map +0 -1
- package/dist/components/Chart/scale.js.map +0 -1
- package/dist/components/Chart/series.d.ts +0 -14
- package/dist/components/Chart/series.js +0 -72
- package/dist/components/Chart/series.js.map +0 -1
- package/dist/components/Chart/summary.js.map +0 -1
- package/dist/components/Chart/useElementWidth.js.map +0 -1
- package/dist/components/Checkbox/Checkbox.js.map +0 -1
- package/dist/components/CodeBlock/CodeBlock.js.map +0 -1
- package/dist/components/Combobox/Combobox.js +0 -106
- package/dist/components/Combobox/Combobox.js.map +0 -1
- package/dist/components/CommandPalette/CommandPalette.js.map +0 -1
- package/dist/components/CommandPalette/CommandPaletteOverlay.d.ts +0 -11
- package/dist/components/CommandPalette/CommandPaletteOverlay.js +0 -180
- package/dist/components/CommandPalette/CommandPaletteOverlay.js.map +0 -1
- package/dist/components/DatePicker/DatePicker.js +0 -142
- package/dist/components/DatePicker/DatePicker.js.map +0 -1
- package/dist/components/Dialog/Dialog.d.ts +0 -37
- package/dist/components/Dialog/Dialog.js.map +0 -1
- package/dist/components/Dialog/DialogOverlay.d.ts +0 -3
- package/dist/components/Dialog/DialogOverlay.js +0 -72
- package/dist/components/Dialog/DialogOverlay.js.map +0 -1
- package/dist/components/Drawer/Drawer.d.ts +0 -36
- package/dist/components/Drawer/Drawer.js.map +0 -1
- package/dist/components/Drawer/DrawerOverlay.js +0 -71
- package/dist/components/Drawer/DrawerOverlay.js.map +0 -1
- package/dist/components/DropdownMenu/DropdownMenu.js.map +0 -1
- package/dist/components/DropdownMenu/DropdownMenuParts.js.map +0 -1
- package/dist/components/EmptyState/EmptyState.js.map +0 -1
- package/dist/components/FileDropZone/FileDropZone.js.map +0 -1
- package/dist/components/IconButton/IconButton.d.ts +0 -17
- package/dist/components/IconButton/IconButton.js +0 -37
- package/dist/components/IconButton/IconButton.js.map +0 -1
- package/dist/components/Input/Input.js +0 -43
- package/dist/components/Input/Input.js.map +0 -1
- package/dist/components/Input/index.d.ts +0 -2
- package/dist/components/Kbd/Kbd.js.map +0 -1
- package/dist/components/PageHeader/PageHeader.js.map +0 -1
- package/dist/components/Pagination/Pagination.js.map +0 -1
- package/dist/components/Pagination/index.d.ts +0 -2
- package/dist/components/Pagination/index.js +0 -2
- package/dist/components/Popover/Popover.js.map +0 -1
- package/dist/components/Popover/PopoverOverlay.js.map +0 -1
- package/dist/components/ProgressBar/ProgressBar.js.map +0 -1
- package/dist/components/ProgressBar/index.d.ts +0 -2
- package/dist/components/RadioGroup/RadioGroup.js +0 -46
- package/dist/components/RadioGroup/RadioGroup.js.map +0 -1
- package/dist/components/SegmentedControl/SegmentedControl.js +0 -55
- package/dist/components/SegmentedControl/SegmentedControl.js.map +0 -1
- package/dist/components/SegmentedControl/index.d.ts +0 -2
- package/dist/components/Select/Select.js +0 -64
- package/dist/components/Select/Select.js.map +0 -1
- package/dist/components/Skeleton/Skeleton.js.map +0 -1
- package/dist/components/Spinner/Spinner.js.map +0 -1
- package/dist/components/Stat/Stat.d.ts +0 -49
- package/dist/components/Stat/Stat.js +0 -125
- package/dist/components/Stat/Stat.js.map +0 -1
- package/dist/components/Stat/index.d.ts +0 -2
- package/dist/components/Stat/index.js +0 -2
- package/dist/components/Switch/Switch.js +0 -39
- package/dist/components/Switch/Switch.js.map +0 -1
- package/dist/components/Table/Table.js.map +0 -1
- package/dist/components/Tabs/Tabs.js.map +0 -1
- package/dist/components/Tag/Tag.js +0 -48
- package/dist/components/Tag/Tag.js.map +0 -1
- package/dist/components/Textarea/Textarea.js +0 -30
- package/dist/components/Textarea/Textarea.js.map +0 -1
- package/dist/components/Textarea/index.d.ts +0 -2
- package/dist/components/Toast/Toast.js.map +0 -1
- package/dist/components/Toast/ToastItem.d.ts +0 -6
- package/dist/components/Toast/ToastItem.js.map +0 -1
- package/dist/components/Tooltip/Tooltip.js.map +0 -1
- package/dist/components/Tooltip/TooltipOverlay.js.map +0 -1
- package/dist/internal/LazyDialogTrigger.d.ts +0 -8
- package/dist/internal/LazyDialogTrigger.js +0 -15
- package/dist/internal/LazyDialogTrigger.js.map +0 -1
- package/dist/internal/Spinner.d.ts +0 -3
- package/dist/internal/Spinner.js +0 -14
- package/dist/internal/Spinner.js.map +0 -1
- package/dist/internal/useLazyMenuTrigger.d.ts +0 -23
- package/dist/internal/useLazyMenuTrigger.js +0 -47
- package/dist/internal/useLazyMenuTrigger.js.map +0 -1
- package/dist/utils/cxLite.d.ts +0 -12
- package/dist/utils/cxLite.js +0 -23
- package/dist/utils/cxLite.js.map +0 -1
- /package/dist/components/{Badge → atoms/Badge}/index.js +0 -0
- /package/dist/components/{Checkbox → atoms/Checkbox}/Checkbox.d.ts +0 -0
- /package/dist/components/{Checkbox → atoms/Checkbox}/index.d.ts +0 -0
- /package/dist/components/{Checkbox → atoms/Checkbox}/index.js +0 -0
- /package/dist/components/{IconButton → atoms/IconButton}/index.d.ts +0 -0
- /package/dist/components/{IconButton → atoms/IconButton}/index.js +0 -0
- /package/dist/components/{Kbd → atoms/Kbd}/index.d.ts +0 -0
- /package/dist/components/{Kbd → atoms/Kbd}/index.js +0 -0
- /package/dist/components/{ProgressBar → atoms/ProgressBar}/index.js +0 -0
- /package/dist/components/{Skeleton → atoms/Skeleton}/Skeleton.d.ts +0 -0
- /package/dist/components/{Skeleton → atoms/Skeleton}/index.d.ts +0 -0
- /package/dist/components/{Skeleton → atoms/Skeleton}/index.js +0 -0
- /package/dist/components/{Spinner → atoms/Spinner}/Spinner.d.ts +0 -0
- /package/dist/components/{Spinner → atoms/Spinner}/index.d.ts +0 -0
- /package/dist/components/{Spinner → atoms/Spinner}/index.js +0 -0
- /package/dist/components/{Switch → atoms/Switch}/index.d.ts +0 -0
- /package/dist/components/{Switch → atoms/Switch}/index.js +0 -0
- /package/dist/components/{Tooltip → atoms/Tooltip}/Tooltip.d.ts +0 -0
- /package/dist/components/{Tooltip → atoms/Tooltip}/TooltipOverlay.d.ts +0 -0
- /package/dist/components/{Tooltip → atoms/Tooltip}/index.d.ts +0 -0
- /package/dist/components/{Tooltip → atoms/Tooltip}/index.js +0 -0
- /package/dist/components/{Breadcrumbs → molecules/Breadcrumbs}/Breadcrumbs.d.ts +0 -0
- /package/dist/components/{Breadcrumbs → molecules/Breadcrumbs}/index.d.ts +0 -0
- /package/dist/components/{Breadcrumbs → molecules/Breadcrumbs}/index.js +0 -0
- /package/dist/components/{Card → molecules/Card}/index.js +0 -0
- /package/dist/components/{CodeBlock → molecules/CodeBlock}/index.d.ts +0 -0
- /package/dist/components/{CodeBlock → molecules/CodeBlock}/index.js +0 -0
- /package/dist/components/{Combobox → molecules/Combobox}/index.d.ts +0 -0
- /package/dist/components/{Combobox → molecules/Combobox}/index.js +0 -0
- /package/dist/components/{DatePicker → molecules/DatePicker}/index.d.ts +0 -0
- /package/dist/components/{DatePicker → molecules/DatePicker}/index.js +0 -0
- /package/dist/components/{Dialog → molecules/Dialog}/index.d.ts +0 -0
- /package/dist/components/{Dialog → molecules/Dialog}/index.js +0 -0
- /package/dist/components/{Drawer → molecules/Drawer}/index.d.ts +0 -0
- /package/dist/components/{Drawer → molecules/Drawer}/index.js +0 -0
- /package/dist/components/{DropdownMenu → molecules/DropdownMenu}/index.d.ts +0 -0
- /package/dist/components/{DropdownMenu → molecules/DropdownMenu}/index.js +0 -0
- /package/dist/components/{EmptyState → molecules/EmptyState}/index.d.ts +0 -0
- /package/dist/components/{EmptyState → molecules/EmptyState}/index.js +0 -0
- /package/dist/components/{FileDropZone → molecules/FileDropZone}/index.d.ts +0 -0
- /package/dist/components/{FileDropZone → molecules/FileDropZone}/index.js +0 -0
- /package/dist/components/{Input → molecules/Input}/index.js +0 -0
- /package/dist/components/{Popover → molecules/Popover}/PopoverOverlay.d.ts +0 -0
- /package/dist/components/{Popover → molecules/Popover}/index.d.ts +0 -0
- /package/dist/components/{Popover → molecules/Popover}/index.js +0 -0
- /package/dist/components/{RadioGroup → molecules/RadioGroup}/RadioGroup.d.ts +0 -0
- /package/dist/components/{RadioGroup → molecules/RadioGroup}/index.d.ts +0 -0
- /package/dist/components/{RadioGroup → molecules/RadioGroup}/index.js +0 -0
- /package/dist/components/{SegmentedControl → molecules/SegmentedControl}/index.js +0 -0
- /package/dist/components/{Select → molecules/Select}/index.d.ts +0 -0
- /package/dist/components/{Select → molecules/Select}/index.js +0 -0
- /package/dist/components/{Tabs → molecules/Tabs}/Tabs.d.ts +0 -0
- /package/dist/components/{Tabs → molecules/Tabs}/index.d.ts +0 -0
- /package/dist/components/{Tabs → molecules/Tabs}/index.js +0 -0
- /package/dist/components/{Tag → molecules/Tag}/Tag.d.ts +0 -0
- /package/dist/components/{Tag → molecules/Tag}/index.d.ts +0 -0
- /package/dist/components/{Tag → molecules/Tag}/index.js +0 -0
- /package/dist/components/{Textarea → molecules/Textarea}/index.js +0 -0
- /package/dist/components/{Toast → molecules/Toast}/index.js +0 -0
- /package/dist/components/{Chart → organisms/Chart}/ChartTable.d.ts +0 -0
- /package/dist/components/{Chart → organisms/Chart}/geometry.d.ts +0 -0
- /package/dist/components/{Chart → organisms/Chart}/labels.d.ts +0 -0
- /package/dist/components/{Chart → organisms/Chart}/scale.d.ts +0 -0
- /package/dist/components/{Chart → organisms/Chart}/summary.d.ts +0 -0
- /package/dist/components/{Chart → organisms/Chart}/useElementWidth.d.ts +0 -0
- /package/dist/components/{CommandPalette → organisms/CommandPalette}/index.js +0 -0
- /package/dist/components/{PageHeader → organisms/PageHeader}/PageHeader.d.ts +0 -0
- /package/dist/components/{PageHeader → organisms/PageHeader}/index.d.ts +0 -0
- /package/dist/components/{PageHeader → organisms/PageHeader}/index.js +0 -0
- /package/dist/components/{Table → organisms/Table}/index.d.ts +0 -0
- /package/dist/components/{Table → organisms/Table}/index.js +0 -0
- /package/dist/{chrome → internal}/brandLogoPath.d.ts +0 -0
- /package/dist/{chrome → router}/Anchor.d.ts +0 -0
- /package/dist/{chrome → router}/LinkRouter.d.ts +0 -0
- /package/dist/{chrome → theme}/useTheme.d.ts +0 -0
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { ChartBaseProps } from './types';
|
|
2
|
-
export type HeatGridTone = 'success' | 'error' | 'warning' | 'neutral';
|
|
2
|
+
export type HeatGridTone = 'success' | 'error' | 'warning' | 'neutral' | 'quiet';
|
|
3
3
|
export interface HeatGridState {
|
|
4
4
|
/** Shown in the legend, the tooltip, the table and to screen readers. */
|
|
5
5
|
label: string;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Picks the fill and the icon. Every tone has its own icon, so colour is never the only signal.
|
|
8
|
+
* `quiet` is a muted check for the expected outcome, so that only the exceptions stand out.
|
|
9
|
+
*/
|
|
7
10
|
tone: HeatGridTone;
|
|
8
11
|
}
|
|
9
12
|
export interface HeatGridLine {
|
|
@@ -47,4 +50,4 @@ export interface HeatGridProps extends Omit<ChartBaseProps, 'height'> {
|
|
|
47
50
|
* a fill and an icon; in value mode each cell is shaded by its number. Arrow keys move between
|
|
48
51
|
* cells, and hover or focus shows the row, the column and the detail.
|
|
49
52
|
*/
|
|
50
|
-
export declare function HeatGrid({ rows, columns, cells, states, rowLabel, valueFormat, hasValueLabels, title, hideTitle, summary, locale, labels,
|
|
53
|
+
export declare function HeatGrid({ rows, columns, cells, states, rowLabel, valueFormat, hasValueLabels, title, hideTitle, summary, locale, labels, className, }: HeatGridProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx } from "../../../utils/cx.js";
|
|
3
|
+
import { ChartFrame } from "./ChartFrame.js";
|
|
4
|
+
import { ChartLegend } from "./ChartLegend.js";
|
|
5
|
+
import { ChartTooltip } from "./ChartTooltip.js";
|
|
6
|
+
import { createValueFormat } from "./format.js";
|
|
7
|
+
import { ChartMark, useChartInteraction } from "./interaction.js";
|
|
8
|
+
import { chartLabels } from "./labels.js";
|
|
9
|
+
import { plural } from "./summary.js";
|
|
10
|
+
import { useRef, useState } from "react";
|
|
11
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
import { Check, Minus, TriangleAlert, X } from "lucide-react";
|
|
13
|
+
// src/components/organisms/Chart/HeatGrid.tsx
|
|
14
|
+
var tones = {
|
|
15
|
+
success: {
|
|
16
|
+
cell: "bg-success-subtle text-success",
|
|
17
|
+
ink: "text-success",
|
|
18
|
+
icon: Check
|
|
19
|
+
},
|
|
20
|
+
error: {
|
|
21
|
+
cell: "bg-error-subtle text-error",
|
|
22
|
+
ink: "text-error",
|
|
23
|
+
icon: X
|
|
24
|
+
},
|
|
25
|
+
warning: {
|
|
26
|
+
cell: "bg-warning-subtle text-warning",
|
|
27
|
+
ink: "text-warning",
|
|
28
|
+
icon: TriangleAlert
|
|
29
|
+
},
|
|
30
|
+
neutral: {
|
|
31
|
+
cell: "bg-tertiary text-tertiary",
|
|
32
|
+
ink: "text-tertiary",
|
|
33
|
+
icon: Minus
|
|
34
|
+
},
|
|
35
|
+
quiet: {
|
|
36
|
+
cell: "bg-tertiary text-tertiary",
|
|
37
|
+
ink: "text-tertiary",
|
|
38
|
+
icon: Check
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var lightInk = "text-chart-seq-ink-dark dark:text-chart-seq-ink-light";
|
|
42
|
+
var darkInk = "text-chart-seq-ink-light dark:text-chart-seq-ink-dark";
|
|
43
|
+
var steps = [
|
|
44
|
+
cx("bg-chart-seq-1", lightInk),
|
|
45
|
+
cx("bg-chart-seq-2", lightInk),
|
|
46
|
+
cx("bg-chart-seq-3", lightInk),
|
|
47
|
+
cx("bg-chart-seq-4", darkInk),
|
|
48
|
+
cx("bg-chart-seq-5", darkInk)
|
|
49
|
+
];
|
|
50
|
+
var cell = "flex h-9 min-w-0 items-center justify-center rounded-xs text-xs font-medium tabular-nums";
|
|
51
|
+
var stateCell = "border border-current/30";
|
|
52
|
+
function stepOf(value, min, max) {
|
|
53
|
+
if (max === min) return 2;
|
|
54
|
+
return Math.min(steps.length - 1, Math.floor((value - min) / (max - min) * steps.length));
|
|
55
|
+
}
|
|
56
|
+
function ToneIcon({ tone, className }) {
|
|
57
|
+
const Icon = tones[tone].icon;
|
|
58
|
+
return /* @__PURE__ */ jsx(Icon, {
|
|
59
|
+
"aria-hidden": "true",
|
|
60
|
+
className: className ?? "size-4",
|
|
61
|
+
strokeWidth: 2.5
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A matrix of rows by columns. In state mode each cell is a state such as pass or fail, shown with
|
|
66
|
+
* a fill and an icon; in value mode each cell is shaded by its number. Arrow keys move between
|
|
67
|
+
* cells, and hover or focus shows the row, the column and the detail.
|
|
68
|
+
*/
|
|
69
|
+
function HeatGrid({ rows, columns, cells, states, rowLabel, valueFormat, hasValueLabels = true, title, hideTitle, summary, locale, labels, className }) {
|
|
70
|
+
const text = chartLabels(labels);
|
|
71
|
+
const rowHeader = rowLabel ?? text.row;
|
|
72
|
+
const byPosition = new Map(cells.map((c) => [`${c.row}\u0000${c.column}`, c]));
|
|
73
|
+
const at = (row, column) => byPosition.get(`${row}\u0000${column}`);
|
|
74
|
+
const numbers = cells.flatMap((c) => c.value === void 0 ? [] : [c.value]);
|
|
75
|
+
const [min, max] = [Math.min(...numbers), Math.max(...numbers)];
|
|
76
|
+
const vf = createValueFormat(Math.max(Math.abs(min), Math.abs(max)), locale, valueFormat);
|
|
77
|
+
const describe = (c) => {
|
|
78
|
+
if (!c) return "";
|
|
79
|
+
const base = states ? states[c.state ?? ""]?.label ?? "" : c.value === void 0 ? "" : vf.full(c.value);
|
|
80
|
+
return c.detail ? `${base}: ${c.detail}` : base;
|
|
81
|
+
};
|
|
82
|
+
const counts = states ? Object.entries(states).map(([key, state]) => `${cells.filter((c) => c.state === key).length} ${state.label}`).join(", ") : numbers.length > 0 ? `values from ${vf.full(min)} to ${vf.full(max)}` : "";
|
|
83
|
+
const headline = `Grid of ${plural(rows.length, "row", "rows")} by ${plural(columns.length, "column", "columns")}: ${counts}.`;
|
|
84
|
+
const wrapper = useRef(null);
|
|
85
|
+
const [anchor, setAnchor] = useState({
|
|
86
|
+
x: 0,
|
|
87
|
+
y: 0,
|
|
88
|
+
below: false
|
|
89
|
+
});
|
|
90
|
+
const interaction = useChartInteraction(rows.length * columns.length, columns.length, (element) => {
|
|
91
|
+
const box = wrapper.current?.getBoundingClientRect();
|
|
92
|
+
const target = element?.getBoundingClientRect();
|
|
93
|
+
if (!box || !target) return;
|
|
94
|
+
const top = target.top - box.top;
|
|
95
|
+
const below = top < 96;
|
|
96
|
+
setAnchor({
|
|
97
|
+
x: target.left - box.left + target.width / 2,
|
|
98
|
+
y: below ? top + target.height : top,
|
|
99
|
+
below
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
function renderPlot(width) {
|
|
103
|
+
const template = `${width < 420 ? 88 : 144}px repeat(${columns.length}, minmax(2.25rem, 1fr))`;
|
|
104
|
+
const isVertical = columns.length > 6 || width < 420;
|
|
105
|
+
const activeRow = interaction.active === null ? null : rows[Math.floor(interaction.active / columns.length)];
|
|
106
|
+
const activeColumn = interaction.active === null ? null : columns[interaction.active % columns.length];
|
|
107
|
+
const activeCell = activeRow && activeColumn ? at(activeRow.id, activeColumn.id) : void 0;
|
|
108
|
+
const activeState = states?.[activeCell?.state ?? ""];
|
|
109
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
110
|
+
ref: wrapper,
|
|
111
|
+
className: "relative",
|
|
112
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
113
|
+
className: "relative max-w-full overflow-x-auto py-1 pr-1",
|
|
114
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
115
|
+
role: "grid",
|
|
116
|
+
"aria-label": title,
|
|
117
|
+
className: "flex w-max min-w-full flex-col gap-0.5",
|
|
118
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
119
|
+
role: "row",
|
|
120
|
+
className: "grid gap-0.5",
|
|
121
|
+
style: { gridTemplateColumns: template },
|
|
122
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
123
|
+
role: "columnheader",
|
|
124
|
+
className: "sticky left-0 z-10 bg-[var(--chart-surface,var(--ui-bg-primary))] pr-2 text-xs text-tertiary",
|
|
125
|
+
children: rowHeader
|
|
126
|
+
}), columns.map((column) => /* @__PURE__ */ jsx("div", {
|
|
127
|
+
role: "columnheader",
|
|
128
|
+
className: cx("flex min-w-0 justify-center pb-1 text-xs font-medium text-secondary", isVertical ? "items-end" : "text-center"),
|
|
129
|
+
children: isVertical ? /* @__PURE__ */ jsx("span", {
|
|
130
|
+
className: "max-h-28 rotate-180 overflow-hidden text-ellipsis whitespace-nowrap [writing-mode:vertical-rl]",
|
|
131
|
+
children: column.label
|
|
132
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
133
|
+
className: "min-w-0 truncate",
|
|
134
|
+
children: column.label
|
|
135
|
+
})
|
|
136
|
+
}, column.id))]
|
|
137
|
+
}), rows.map((row, rowIndex) => /* @__PURE__ */ jsxs("div", {
|
|
138
|
+
role: "row",
|
|
139
|
+
className: "grid gap-0.5",
|
|
140
|
+
style: { gridTemplateColumns: template },
|
|
141
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
142
|
+
role: "rowheader",
|
|
143
|
+
className: "sticky left-0 z-10 flex items-center bg-[var(--chart-surface,var(--ui-bg-primary))] pr-2 text-sm text-primary",
|
|
144
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
145
|
+
className: "min-w-0 truncate",
|
|
146
|
+
children: row.label
|
|
147
|
+
})
|
|
148
|
+
}), columns.map((column, columnIndex) => {
|
|
149
|
+
const data = at(row.id, column.id);
|
|
150
|
+
const index = rowIndex * columns.length + columnIndex;
|
|
151
|
+
const state = states?.[data?.state ?? ""];
|
|
152
|
+
return /* @__PURE__ */ jsxs(ChartMark, {
|
|
153
|
+
role: "gridcell",
|
|
154
|
+
index,
|
|
155
|
+
interaction,
|
|
156
|
+
className: cx(cell, state ? [stateCell, tones[state.tone].cell] : data?.value !== void 0 ? steps[stepOf(data.value, min, max)] : "bg-secondary"),
|
|
157
|
+
children: [state ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(ToneIcon, { tone: state.tone }), /* @__PURE__ */ jsx("span", {
|
|
158
|
+
className: "sr-only",
|
|
159
|
+
children: state.label
|
|
160
|
+
})] }) : data?.value !== void 0 ? /* @__PURE__ */ jsx("span", {
|
|
161
|
+
className: hasValueLabels ? void 0 : "sr-only",
|
|
162
|
+
children: vf.full(data.value)
|
|
163
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
164
|
+
className: "sr-only",
|
|
165
|
+
children: text.noData
|
|
166
|
+
}), data?.detail && /* @__PURE__ */ jsx("span", {
|
|
167
|
+
className: "sr-only",
|
|
168
|
+
children: `: ${data.detail}`
|
|
169
|
+
})]
|
|
170
|
+
}, column.id);
|
|
171
|
+
})]
|
|
172
|
+
}, row.id))]
|
|
173
|
+
})
|
|
174
|
+
}), activeRow && activeColumn && /* @__PURE__ */ jsx(ChartTooltip, {
|
|
175
|
+
x: anchor.x,
|
|
176
|
+
y: anchor.y,
|
|
177
|
+
containerWidth: width,
|
|
178
|
+
title: `${activeRow.label}, ${activeColumn.label}`,
|
|
179
|
+
variant: "bar",
|
|
180
|
+
placement: anchor.below ? "below" : "above",
|
|
181
|
+
rows: [{
|
|
182
|
+
id: "cell",
|
|
183
|
+
value: activeState ? activeState.label : activeCell?.value === void 0 ? text.noData : vf.full(activeCell.value),
|
|
184
|
+
label: activeCell?.detail ?? "",
|
|
185
|
+
marker: activeState ? /* @__PURE__ */ jsx("span", {
|
|
186
|
+
className: cx("shrink-0", tones[activeState.tone].ink),
|
|
187
|
+
children: /* @__PURE__ */ jsx(ToneIcon, {
|
|
188
|
+
tone: activeState.tone,
|
|
189
|
+
className: "size-3.5"
|
|
190
|
+
})
|
|
191
|
+
}) : void 0
|
|
192
|
+
}]
|
|
193
|
+
})]
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return /* @__PURE__ */ jsx(ChartFrame, {
|
|
197
|
+
title,
|
|
198
|
+
hideTitle,
|
|
199
|
+
labels,
|
|
200
|
+
className,
|
|
201
|
+
isEmpty: rows.length === 0 || columns.length === 0,
|
|
202
|
+
summary: summary ?? headline,
|
|
203
|
+
legend: states ? /* @__PURE__ */ jsx(ChartLegend, { items: Object.entries(states).map(([key, state]) => ({
|
|
204
|
+
id: key,
|
|
205
|
+
label: state.label,
|
|
206
|
+
marker: /* @__PURE__ */ jsx("span", {
|
|
207
|
+
"aria-hidden": "true",
|
|
208
|
+
className: cx("flex size-5 shrink-0 items-center justify-center rounded-xs", stateCell, tones[state.tone].cell),
|
|
209
|
+
children: /* @__PURE__ */ jsx(ToneIcon, {
|
|
210
|
+
tone: state.tone,
|
|
211
|
+
className: "size-3.5"
|
|
212
|
+
})
|
|
213
|
+
})
|
|
214
|
+
})) }) : numbers.length > 0 && /* @__PURE__ */ jsxs("div", {
|
|
215
|
+
className: "flex items-center gap-2 text-sm text-secondary",
|
|
216
|
+
children: [
|
|
217
|
+
/* @__PURE__ */ jsx("span", { children: vf.full(min) }),
|
|
218
|
+
/* @__PURE__ */ jsx("span", {
|
|
219
|
+
"aria-hidden": "true",
|
|
220
|
+
className: "flex gap-0.5",
|
|
221
|
+
children: steps.map((step) => /* @__PURE__ */ jsx("span", { className: cx("h-3 w-6 first:rounded-l-xs last:rounded-r-xs", step) }, step))
|
|
222
|
+
}),
|
|
223
|
+
/* @__PURE__ */ jsx("span", { children: vf.full(max) })
|
|
224
|
+
]
|
|
225
|
+
}),
|
|
226
|
+
table: {
|
|
227
|
+
head: [rowHeader, ...columns.map((c) => c.label)],
|
|
228
|
+
rows: rows.map((row) => [row.label, ...columns.map((column) => describe(at(row.id, column.id)))])
|
|
229
|
+
},
|
|
230
|
+
children: renderPlot
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
export { HeatGrid };
|
|
234
|
+
|
|
235
|
+
//# sourceMappingURL=HeatGrid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HeatGrid.js","names":["_Fragment"],"sources":["../../../../src/components/organisms/Chart/HeatGrid.tsx"],"sourcesContent":["import { Check, Minus, TriangleAlert, X } from 'lucide-react';\nimport { useRef, useState } from 'react';\nimport { cx } from '../../../utils/cx';\nimport { ChartFrame } from './ChartFrame';\nimport { ChartLegend } from './ChartLegend';\nimport { ChartTooltip } from './ChartTooltip';\nimport { createValueFormat } from './format';\nimport { ChartMark, useChartInteraction } from './interaction';\nimport { chartLabels } from './labels';\nimport { plural } from './summary';\nimport type { ChartBaseProps } from './types';\n\nexport type HeatGridTone = 'success' | 'error' | 'warning' | 'neutral' | 'quiet';\n\nexport interface HeatGridState {\n /** Shown in the legend, the tooltip, the table and to screen readers. */\n label: string;\n /**\n * Picks the fill and the icon. Every tone has its own icon, so colour is never the only signal.\n * `quiet` is a muted check for the expected outcome, so that only the exceptions stand out.\n */\n tone: HeatGridTone;\n}\n\nexport interface HeatGridLine {\n id: string;\n label: string;\n}\n\nexport interface HeatGridCell {\n /** The `id` of a row. */\n row: string;\n /** The `id` of a column. */\n column: string;\n /** In value mode, the number shown. */\n value?: number;\n /** In state mode, a key of `states`. */\n state?: string;\n /**\n * Extra text, such as why a check failed. It shows in the tooltip, is read after the state by\n * screen readers and is listed in the table.\n */\n detail?: string;\n}\n\nexport interface HeatGridProps extends Omit<ChartBaseProps, 'height'> {\n rows: HeatGridLine[];\n columns: HeatGridLine[];\n /** Cells that are missing show as empty. */\n cells: HeatGridCell[];\n /**\n * Turns on state mode: each cell is one of these states, drawn with a fill and an icon. Without\n * it the grid is in value mode and shades each cell by its number in five steps.\n */\n states?: Record<string, HeatGridState>;\n /** Header of the first table column. Defaults to `labels.row`. */\n rowLabel?: string;\n /** Intl options for values in value mode. */\n valueFormat?: Intl.NumberFormatOptions;\n /** Prints the number in each cell in value mode. Defaults to true. */\n hasValueLabels?: boolean;\n}\n\nconst tones: Record<HeatGridTone, { cell: string; ink: string; icon: typeof Check }> = {\n success: { cell: 'bg-success-subtle text-success', ink: 'text-success', icon: Check },\n error: { cell: 'bg-error-subtle text-error', ink: 'text-error', icon: X },\n warning: { cell: 'bg-warning-subtle text-warning', ink: 'text-warning', icon: TriangleAlert },\n neutral: { cell: 'bg-tertiary text-tertiary', ink: 'text-tertiary', icon: Minus },\n quiet: { cell: 'bg-tertiary text-tertiary', ink: 'text-tertiary', icon: Check },\n};\n\nconst lightInk = 'text-chart-seq-ink-dark dark:text-chart-seq-ink-light';\nconst darkInk = 'text-chart-seq-ink-light dark:text-chart-seq-ink-dark';\nconst steps = [\n cx('bg-chart-seq-1', lightInk),\n cx('bg-chart-seq-2', lightInk),\n cx('bg-chart-seq-3', lightInk),\n cx('bg-chart-seq-4', darkInk),\n cx('bg-chart-seq-5', darkInk),\n];\n\nconst cell =\n 'flex h-9 min-w-0 items-center justify-center rounded-xs text-xs font-medium tabular-nums';\nconst stateCell = 'border border-current/30';\n\nfunction stepOf(value: number, min: number, max: number): number {\n if (max === min) return 2;\n return Math.min(steps.length - 1, Math.floor(((value - min) / (max - min)) * steps.length));\n}\n\nfunction ToneIcon({ tone, className }: { tone: HeatGridTone; className?: string }) {\n const Icon = tones[tone].icon;\n return <Icon aria-hidden='true' className={className ?? 'size-4'} strokeWidth={2.5} />;\n}\n\n/**\n * A matrix of rows by columns. In state mode each cell is a state such as pass or fail, shown with\n * a fill and an icon; in value mode each cell is shaded by its number. Arrow keys move between\n * cells, and hover or focus shows the row, the column and the detail.\n */\nexport function HeatGrid({\n rows,\n columns,\n cells,\n states,\n rowLabel,\n valueFormat,\n hasValueLabels = true,\n title,\n hideTitle,\n summary,\n locale,\n labels,\n className,\n}: HeatGridProps) {\n const text = chartLabels(labels);\n const rowHeader = rowLabel ?? text.row;\n const byPosition = new Map(cells.map((c) => [`${c.row}\\u0000${c.column}`, c]));\n const at = (row: string, column: string) => byPosition.get(`${row}\\u0000${column}`);\n const numbers = cells.flatMap((c) => (c.value === undefined ? [] : [c.value]));\n const [min, max] = [Math.min(...numbers), Math.max(...numbers)];\n const vf = createValueFormat(Math.max(Math.abs(min), Math.abs(max)), locale, valueFormat);\n\n const describe = (c: HeatGridCell | undefined): string => {\n if (!c) return '';\n const base = states\n ? (states[c.state ?? '']?.label ?? '')\n : c.value === undefined\n ? ''\n : vf.full(c.value);\n return c.detail ? `${base}: ${c.detail}` : base;\n };\n\n const counts = states\n ? Object.entries(states)\n .map(([key, state]) => `${cells.filter((c) => c.state === key).length} ${state.label}`)\n .join(', ')\n : numbers.length > 0\n ? `values from ${vf.full(min)} to ${vf.full(max)}`\n : '';\n const headline = `Grid of ${plural(rows.length, 'row', 'rows')} by ${plural(columns.length, 'column', 'columns')}: ${counts}.`;\n\n const wrapper = useRef<HTMLDivElement>(null);\n const [anchor, setAnchor] = useState({ x: 0, y: 0, below: false });\n const interaction = useChartInteraction(\n rows.length * columns.length,\n columns.length,\n (element) => {\n const box = wrapper.current?.getBoundingClientRect();\n const target = element?.getBoundingClientRect();\n if (!box || !target) return;\n const top = target.top - box.top;\n const below = top < 96;\n setAnchor({\n x: target.left - box.left + target.width / 2,\n y: below ? top + target.height : top,\n below,\n });\n },\n );\n\n function renderPlot(width: number) {\n const headerWidth = width < 420 ? 88 : 144;\n const template = `${headerWidth}px repeat(${columns.length}, minmax(2.25rem, 1fr))`;\n const isVertical = columns.length > 6 || width < 420;\n const activeRow =\n interaction.active === null ? null : rows[Math.floor(interaction.active / columns.length)];\n const activeColumn =\n interaction.active === null ? null : columns[interaction.active % columns.length];\n const activeCell = activeRow && activeColumn ? at(activeRow.id, activeColumn.id) : undefined;\n const activeState = states?.[activeCell?.state ?? ''];\n\n return (\n <div ref={wrapper} className='relative'>\n <div className='relative max-w-full overflow-x-auto py-1 pr-1'>\n <div role='grid' aria-label={title} className='flex w-max min-w-full flex-col gap-0.5'>\n <div role='row' className='grid gap-0.5' style={{ gridTemplateColumns: template }}>\n <div\n role='columnheader'\n className='sticky left-0 z-10 bg-[var(--chart-surface,var(--ui-bg-primary))] pr-2 text-xs text-tertiary'\n >\n {rowHeader}\n </div>\n {columns.map((column) => (\n <div\n key={column.id}\n role='columnheader'\n className={cx(\n 'flex min-w-0 justify-center pb-1 text-xs font-medium text-secondary',\n isVertical ? 'items-end' : 'text-center',\n )}\n >\n {isVertical ? (\n <span className='max-h-28 rotate-180 overflow-hidden text-ellipsis whitespace-nowrap [writing-mode:vertical-rl]'>\n {column.label}\n </span>\n ) : (\n <span className='min-w-0 truncate'>{column.label}</span>\n )}\n </div>\n ))}\n </div>\n {rows.map((row, rowIndex) => (\n <div\n key={row.id}\n role='row'\n className='grid gap-0.5'\n style={{ gridTemplateColumns: template }}\n >\n <div\n role='rowheader'\n className='sticky left-0 z-10 flex items-center bg-[var(--chart-surface,var(--ui-bg-primary))] pr-2 text-sm text-primary'\n >\n <span className='min-w-0 truncate'>{row.label}</span>\n </div>\n {columns.map((column, columnIndex) => {\n const data = at(row.id, column.id);\n const index = rowIndex * columns.length + columnIndex;\n const state = states?.[data?.state ?? ''];\n return (\n <ChartMark\n role='gridcell'\n key={column.id}\n index={index}\n interaction={interaction}\n className={cx(\n cell,\n state\n ? [stateCell, tones[state.tone].cell]\n : data?.value !== undefined\n ? steps[stepOf(data.value, min, max)]\n : 'bg-secondary',\n )}\n >\n {state ? (\n <>\n <ToneIcon tone={state.tone} />\n <span className='sr-only'>{state.label}</span>\n </>\n ) : data?.value !== undefined ? (\n <span className={hasValueLabels ? undefined : 'sr-only'}>\n {vf.full(data.value)}\n </span>\n ) : (\n <span className='sr-only'>{text.noData}</span>\n )}\n {data?.detail && <span className='sr-only'>{`: ${data.detail}`}</span>}\n </ChartMark>\n );\n })}\n </div>\n ))}\n </div>\n </div>\n {activeRow && activeColumn && (\n <ChartTooltip\n x={anchor.x}\n y={anchor.y}\n containerWidth={width}\n title={`${activeRow.label}, ${activeColumn.label}`}\n variant='bar'\n placement={anchor.below ? 'below' : 'above'}\n rows={[\n {\n id: 'cell',\n value: activeState\n ? activeState.label\n : activeCell?.value === undefined\n ? text.noData\n : vf.full(activeCell.value),\n label: activeCell?.detail ?? '',\n marker: activeState ? (\n <span className={cx('shrink-0', tones[activeState.tone].ink)}>\n <ToneIcon tone={activeState.tone} className='size-3.5' />\n </span>\n ) : undefined,\n },\n ]}\n />\n )}\n </div>\n );\n }\n\n return (\n <ChartFrame\n title={title}\n hideTitle={hideTitle}\n labels={labels}\n className={className}\n isEmpty={rows.length === 0 || columns.length === 0}\n summary={summary ?? headline}\n legend={\n states ? (\n <ChartLegend\n items={Object.entries(states).map(([key, state]) => ({\n id: key,\n label: state.label,\n marker: (\n <span\n aria-hidden='true'\n className={cx(\n 'flex size-5 shrink-0 items-center justify-center rounded-xs',\n stateCell,\n tones[state.tone].cell,\n )}\n >\n <ToneIcon tone={state.tone} className='size-3.5' />\n </span>\n ),\n }))}\n />\n ) : (\n numbers.length > 0 && (\n <div className='flex items-center gap-2 text-sm text-secondary'>\n <span>{vf.full(min)}</span>\n <span aria-hidden='true' className='flex gap-0.5'>\n {steps.map((step) => (\n <span\n key={step}\n className={cx('h-3 w-6 first:rounded-l-xs last:rounded-r-xs', step)}\n />\n ))}\n </span>\n <span>{vf.full(max)}</span>\n </div>\n )\n )\n }\n table={{\n head: [rowHeader, ...columns.map((c) => c.label)],\n rows: rows.map((row) => [\n row.label,\n ...columns.map((column) => describe(at(row.id, column.id))),\n ]),\n }}\n >\n {renderPlot}\n </ChartFrame>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AA+DA,IAAM,QAAiF;CACrF,SAAS;EAAE,MAAM;EAAkC,KAAK;EAAgB,MAAM;CAAM;CACpF,OAAO;EAAE,MAAM;EAA8B,KAAK;EAAc,MAAM;CAAE;CACxE,SAAS;EAAE,MAAM;EAAkC,KAAK;EAAgB,MAAM;CAAc;CAC5F,SAAS;EAAE,MAAM;EAA6B,KAAK;EAAiB,MAAM;CAAM;CAChF,OAAO;EAAE,MAAM;EAA6B,KAAK;EAAiB,MAAM;CAAM;AAChF;AAEA,IAAM,WAAW;AACjB,IAAM,UAAU;AAChB,IAAM,QAAQ;CACZ,GAAG,kBAAkB,QAAQ;CAC7B,GAAG,kBAAkB,QAAQ;CAC7B,GAAG,kBAAkB,QAAQ;CAC7B,GAAG,kBAAkB,OAAO;CAC5B,GAAG,kBAAkB,OAAO;AAC9B;AAEA,IAAM,OACJ;AACF,IAAM,YAAY;AAElB,SAAS,OAAO,OAAe,KAAa,KAAqB;CAC/D,IAAI,QAAQ,KAAK,OAAO;CACxB,OAAO,KAAK,IAAI,MAAM,SAAS,GAAG,KAAK,OAAQ,QAAQ,QAAQ,MAAM,OAAQ,MA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WAAU;IAAY,CAAA;GAC9C,CAAA;EAEV,EAAE,EACH,CAAA,IAED,QAAQ,SAAS,KACf,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA;IACE,oBAAC,QAAD,EAAA,UAAO,GAAG,KAAK,GAAG,EAAQ,CAAA;IAC1B,oBAAC,QAAD;KAAM,eAAY;KAAO,WAAU;KAChC,UAAA,MAAM,KAAK,SACV,oBAAC,QAAD,EAEE,WAAW,GAAG,gDAAgD,IAAI,EACnE,GAFM,IAEN,CACF;IACG,CAAA;IACN,oBAAC,QAAD,EAAA,UAAO,GAAG,KAAK,GAAG,EAAQ,CAAA;GACvB;;EAIX,OAAO;GACL,MAAM,CAAC,WAAW,GAAG,QAAQ,KAAK,MAAM,EAAE,KAAK,CAAC;GAChD,MAAM,KAAK,KAAK,QAAQ,CACtB,IAAI,OACJ,GAAG,QAAQ,KAAK,WAAW,SAAS,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC,CAAC,CAC5D,CAAC;EACH;EAEC,UAAA;CACS,CAAA;AAEhB"}
|
|
@@ -20,4 +20,4 @@ export interface LineChartProps extends ChartBaseProps {
|
|
|
20
20
|
* Tab enters the plot and the arrow keys move along it. Each series has its own colour and marker
|
|
21
21
|
* shape, a legend entry and, where there is room, a label at the line end.
|
|
22
22
|
*/
|
|
23
|
-
export declare function LineChart({ x, series, xLabel, valueFormat, xFormat, yDomain, hasDirectLabels, title, hideTitle, summary, locale, labels, height,
|
|
23
|
+
export declare function LineChart({ x, series, xLabel, valueFormat, xFormat, yDomain, hasDirectLabels, title, hideTitle, summary, locale, labels, height, className, }: LineChartProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { ChartFrame } from "./ChartFrame.js";
|
|
3
|
+
import { ChartLegend } from "./ChartLegend.js";
|
|
4
|
+
import { ChartTooltip } from "./ChartTooltip.js";
|
|
5
|
+
import { createValueFormat, createXFormat, textWidth, truncate, xKind, xNumbers } from "./format.js";
|
|
6
|
+
import { markerPath } from "./geometry.js";
|
|
7
|
+
import { ChartMark, markHitArea, useChartInteraction } from "./interaction.js";
|
|
8
|
+
import { chartLabels } from "./labels.js";
|
|
9
|
+
import { linearScale, niceTicks, sampleIndexes } from "./scale.js";
|
|
10
|
+
import { isNumber, knownValues, legendItems, seriesCells, seriesColors, seriesStyle } from "./series.js";
|
|
11
|
+
import { describeAll, plural } from "./summary.js";
|
|
12
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
// src/components/organisms/Chart/LineChart.tsx
|
|
14
|
+
var margin = {
|
|
15
|
+
top: 12,
|
|
16
|
+
bottom: 28
|
|
17
|
+
};
|
|
18
|
+
var edge = 6;
|
|
19
|
+
var labelGap = 14;
|
|
20
|
+
function tickAnchor(position, tickWidth, plotWidth) {
|
|
21
|
+
if (position < tickWidth / 2) return "start";
|
|
22
|
+
return position > plotWidth - tickWidth / 2 ? "end" : "middle";
|
|
23
|
+
}
|
|
24
|
+
var xLabelKey = {
|
|
25
|
+
time: "date",
|
|
26
|
+
number: "value",
|
|
27
|
+
category: "category"
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* One or more series over a time or ordered x axis. Hover or focus shows every series at that x;
|
|
31
|
+
* Tab enters the plot and the arrow keys move along it. Each series has its own colour and marker
|
|
32
|
+
* shape, a legend entry and, where there is room, a label at the line end.
|
|
33
|
+
*/
|
|
34
|
+
function LineChart({ x, series, xLabel, valueFormat, xFormat, yDomain, hasDirectLabels = true, title, hideTitle, summary, locale, labels, height = 240, className }) {
|
|
35
|
+
const text = chartLabels(labels);
|
|
36
|
+
const values = knownValues(series);
|
|
37
|
+
const fx = createXFormat(x, locale, xFormat);
|
|
38
|
+
const vf = createValueFormat(Math.max(0, ...values.map(Math.abs)), locale, valueFormat);
|
|
39
|
+
const positions = x.map((_, index) => fx.full(index));
|
|
40
|
+
const headline = `Line chart with ${plural(series.length, "series", "series")} and ${plural(x.length, "point", "points")}, from ${positions[0]} to ${positions[positions.length - 1]}.`;
|
|
41
|
+
const colors = seriesColors(series);
|
|
42
|
+
const interaction = useChartInteraction(x.length);
|
|
43
|
+
function renderPlot(width) {
|
|
44
|
+
const known = series.flatMap((s) => s.values.filter(isNumber));
|
|
45
|
+
const [low, high] = yDomain ?? [Math.min(0, ...known), Math.max(0, ...known)];
|
|
46
|
+
const plotHeight = height - margin.top - margin.bottom;
|
|
47
|
+
const ticks = niceTicks(low, high, Math.max(2, Math.floor(plotHeight / 48) + 1), known.every(Number.isInteger));
|
|
48
|
+
const domain = yDomain ?? [ticks.min, ticks.max];
|
|
49
|
+
const yTicks = yDomain ? ticks.ticks.filter((t) => t >= low && t <= high) : ticks.ticks;
|
|
50
|
+
const y = linearScale(domain, [plotHeight, 0]);
|
|
51
|
+
const ends = series.flatMap((s, index) => {
|
|
52
|
+
const at = s.values.findLastIndex(isNumber);
|
|
53
|
+
const value = s.values[at];
|
|
54
|
+
return isNumber(value) ? [{
|
|
55
|
+
index,
|
|
56
|
+
at,
|
|
57
|
+
y: y(value),
|
|
58
|
+
label: truncate(s.label, 16)
|
|
59
|
+
}] : [];
|
|
60
|
+
});
|
|
61
|
+
const sorted = ends.map((end) => end.y).sort((a, b) => a - b);
|
|
62
|
+
const hasRoom = sorted.every((value, index) => index === 0 || value - (sorted[index - 1] ?? 0) >= labelGap);
|
|
63
|
+
const showLabels = hasDirectLabels && series.length <= 4 && width >= 480 && hasRoom;
|
|
64
|
+
const left = Math.max(...yTicks.map((tick) => textWidth(vf.axis(tick)))) + 12;
|
|
65
|
+
const right = showLabels ? Math.max(...ends.map((end) => textWidth(end.label))) + 18 : 14;
|
|
66
|
+
const plotWidth = Math.max(40, width - left - right);
|
|
67
|
+
const numbers = xNumbers(x);
|
|
68
|
+
const xScale = linearScale([Math.min(...numbers), Math.max(...numbers)], [edge, plotWidth - edge]);
|
|
69
|
+
const at = (index) => xScale(numbers[index] ?? 0);
|
|
70
|
+
const tickWidth = Math.max(...x.map((_, index) => textWidth(fx.tick(index)))) + 16;
|
|
71
|
+
const xTicks = sampleIndexes(x.length, Math.floor(plotWidth / tickWidth)).map((index) => {
|
|
72
|
+
const position = at(index);
|
|
73
|
+
const anchor = tickAnchor(position, tickWidth, plotWidth);
|
|
74
|
+
const size = textWidth(fx.tick(index));
|
|
75
|
+
const from = position - {
|
|
76
|
+
start: 0,
|
|
77
|
+
middle: size / 2,
|
|
78
|
+
end: size
|
|
79
|
+
}[anchor];
|
|
80
|
+
return {
|
|
81
|
+
index,
|
|
82
|
+
position,
|
|
83
|
+
anchor,
|
|
84
|
+
from,
|
|
85
|
+
to: from + size
|
|
86
|
+
};
|
|
87
|
+
}).reduceRight((kept, tick) => {
|
|
88
|
+
const next = kept[0];
|
|
89
|
+
return next && tick.to + 8 > next.from ? kept : [tick, ...kept];
|
|
90
|
+
}, []);
|
|
91
|
+
const showAllMarkers = x.length <= 12 && plotWidth / x.length >= 24;
|
|
92
|
+
const active = interaction.active;
|
|
93
|
+
const rows = (index) => series.flatMap((s, position) => {
|
|
94
|
+
const value = s.values[index];
|
|
95
|
+
return isNumber(value) ? [{
|
|
96
|
+
id: s.id,
|
|
97
|
+
label: s.label,
|
|
98
|
+
value: vf.full(value),
|
|
99
|
+
index: colors[position] ?? position
|
|
100
|
+
}] : [];
|
|
101
|
+
});
|
|
102
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
103
|
+
/* @__PURE__ */ jsx("svg", {
|
|
104
|
+
width,
|
|
105
|
+
height,
|
|
106
|
+
"aria-hidden": "true",
|
|
107
|
+
className: "block",
|
|
108
|
+
children: /* @__PURE__ */ jsxs("g", {
|
|
109
|
+
transform: `translate(${left} ${margin.top})`,
|
|
110
|
+
children: [
|
|
111
|
+
yTicks.map((tick) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
|
|
112
|
+
x1: 0,
|
|
113
|
+
x2: plotWidth,
|
|
114
|
+
y1: y(tick),
|
|
115
|
+
y2: y(tick),
|
|
116
|
+
className: tick === 0 ? "stroke-(--ui-border-default)" : "stroke-(--ui-border-subtle)"
|
|
117
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
118
|
+
x: -8,
|
|
119
|
+
y: y(tick),
|
|
120
|
+
dy: "0.32em",
|
|
121
|
+
textAnchor: "end",
|
|
122
|
+
className: "fill-(--ui-text-tertiary) text-xs",
|
|
123
|
+
children: vf.axis(tick)
|
|
124
|
+
})] }, tick)),
|
|
125
|
+
xTicks.map(({ index, position, anchor }) => /* @__PURE__ */ jsx("text", {
|
|
126
|
+
x: position,
|
|
127
|
+
y: plotHeight + 18,
|
|
128
|
+
textAnchor: anchor,
|
|
129
|
+
className: "fill-(--ui-text-tertiary) text-xs",
|
|
130
|
+
children: fx.tick(index)
|
|
131
|
+
}, index)),
|
|
132
|
+
active !== null && /* @__PURE__ */ jsx("line", {
|
|
133
|
+
x1: at(active),
|
|
134
|
+
x2: at(active),
|
|
135
|
+
y1: 0,
|
|
136
|
+
y2: plotHeight,
|
|
137
|
+
className: "stroke-(--ui-border-strong)"
|
|
138
|
+
}),
|
|
139
|
+
series.map((s, position) => {
|
|
140
|
+
const style = seriesStyle(colors[position] ?? position);
|
|
141
|
+
const points = s.values.map((value, index) => isNumber(value) ? {
|
|
142
|
+
index,
|
|
143
|
+
x: at(index),
|
|
144
|
+
y: y(value)
|
|
145
|
+
} : null);
|
|
146
|
+
const path = points.map((point, index) => point ? `${points[index - 1] ? "L" : "M"}${point.x.toFixed(2)} ${point.y.toFixed(2)}` : "").join("");
|
|
147
|
+
const lastAt = s.values.findLastIndex(isNumber);
|
|
148
|
+
return /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("path", {
|
|
149
|
+
d: path,
|
|
150
|
+
fill: "none",
|
|
151
|
+
strokeWidth: 2,
|
|
152
|
+
strokeLinecap: "round",
|
|
153
|
+
strokeLinejoin: "round",
|
|
154
|
+
strokeDasharray: style.dash,
|
|
155
|
+
className: style.stroke
|
|
156
|
+
}), points.map((point, index) => {
|
|
157
|
+
if (!point) return null;
|
|
158
|
+
const isAlone = !points[index - 1] && !points[index + 1];
|
|
159
|
+
const isActive = index === active;
|
|
160
|
+
if (!(showAllMarkers || isAlone || isActive || index === lastAt)) return null;
|
|
161
|
+
const r = isActive ? 5 : 4;
|
|
162
|
+
return /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("path", {
|
|
163
|
+
d: markerPath(style.shape, point.x, point.y, r + 2),
|
|
164
|
+
className: "fill-[var(--chart-surface,var(--ui-bg-primary))]"
|
|
165
|
+
}), /* @__PURE__ */ jsx("path", {
|
|
166
|
+
d: markerPath(style.shape, point.x, point.y, r),
|
|
167
|
+
className: style.fill
|
|
168
|
+
})] }, index);
|
|
169
|
+
})] }, s.id);
|
|
170
|
+
}),
|
|
171
|
+
showLabels && ends.map((end) => /* @__PURE__ */ jsx("text", {
|
|
172
|
+
x: at(end.at) + 12,
|
|
173
|
+
y: end.y,
|
|
174
|
+
dy: "0.32em",
|
|
175
|
+
className: "fill-(--ui-text-secondary) text-xs",
|
|
176
|
+
children: end.label
|
|
177
|
+
}, end.index))
|
|
178
|
+
]
|
|
179
|
+
})
|
|
180
|
+
}),
|
|
181
|
+
x.map((_, index) => {
|
|
182
|
+
const from = index === 0 ? 0 : (at(index - 1) + at(index)) / 2;
|
|
183
|
+
const to = index === x.length - 1 ? plotWidth : (at(index) + at(index + 1)) / 2;
|
|
184
|
+
return /* @__PURE__ */ jsx(ChartMark, {
|
|
185
|
+
index,
|
|
186
|
+
interaction,
|
|
187
|
+
className: markHitArea,
|
|
188
|
+
label: `${fx.full(index)}: ${rows(index).map((row) => `${row.label} ${row.value}`).join(", ") || text.noData}`,
|
|
189
|
+
style: {
|
|
190
|
+
left: left + from,
|
|
191
|
+
top: margin.top,
|
|
192
|
+
width: Math.max(2, to - from),
|
|
193
|
+
height: plotHeight
|
|
194
|
+
}
|
|
195
|
+
}, index);
|
|
196
|
+
}),
|
|
197
|
+
active !== null && /* @__PURE__ */ jsx(ChartTooltip, {
|
|
198
|
+
x: left + at(active),
|
|
199
|
+
y: margin.top + plotHeight / 2,
|
|
200
|
+
containerWidth: width,
|
|
201
|
+
title: fx.full(active),
|
|
202
|
+
rows: rows(active),
|
|
203
|
+
variant: "line"
|
|
204
|
+
})
|
|
205
|
+
] });
|
|
206
|
+
}
|
|
207
|
+
return /* @__PURE__ */ jsx(ChartFrame, {
|
|
208
|
+
title,
|
|
209
|
+
hideTitle,
|
|
210
|
+
labels,
|
|
211
|
+
className,
|
|
212
|
+
isEmpty: x.length === 0 || values.length === 0,
|
|
213
|
+
summary: summary ?? describeAll(headline, series, positions, vf.full),
|
|
214
|
+
legend: series.length > 1 && /* @__PURE__ */ jsx(ChartLegend, {
|
|
215
|
+
variant: "line",
|
|
216
|
+
items: legendItems(series)
|
|
217
|
+
}),
|
|
218
|
+
table: {
|
|
219
|
+
head: [xLabel ?? text[xLabelKey[xKind(x)]], ...series.map((s) => s.label)],
|
|
220
|
+
rows: x.map((_, index) => [positions[index] ?? "", ...seriesCells(series, index, vf.full)])
|
|
221
|
+
},
|
|
222
|
+
children: renderPlot
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
export { LineChart };
|
|
226
|
+
|
|
227
|
+
//# sourceMappingURL=LineChart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LineChart.js","names":["_Fragment"],"sources":["../../../../src/components/organisms/Chart/LineChart.tsx"],"sourcesContent":["import { ChartFrame } from './ChartFrame';\nimport { ChartLegend } from './ChartLegend';\nimport { ChartTooltip, type TooltipRow } from './ChartTooltip';\nimport { createValueFormat, createXFormat, textWidth, truncate, xKind, xNumbers } from './format';\nimport { markerPath } from './geometry';\nimport { ChartMark, markHitArea, useChartInteraction } from './interaction';\nimport { chartLabels } from './labels';\nimport { linearScale, niceTicks, sampleIndexes } from './scale';\nimport {\n isNumber,\n knownValues,\n legendItems,\n seriesCells,\n seriesColors,\n seriesStyle,\n} from './series';\nimport { describeAll, plural } from './summary';\nimport type { ChartBaseProps, ChartSeries, XValue } from './types';\n\nexport interface LineChartProps extends ChartBaseProps {\n /** The x position of every point: dates, numbers or names. Shared by all series. */\n x: XValue[];\n /** Up to six series get a colour each; more are drawn in a muted colour and told apart by shape. */\n series: ChartSeries[];\n /** Header of the first table column. Defaults to the date, value or category label by the kind of x. */\n xLabel?: string;\n /** Intl options for values in the axis, tooltip and table, for example `{ style: 'percent' }`. */\n valueFormat?: Intl.NumberFormatOptions;\n /** Intl options for date ticks. Include `timeZone` to read dates in a fixed zone. */\n xFormat?: Intl.DateTimeFormatOptions;\n /** The y range. Defaults to the data widened to include zero, rounded to a tick. */\n yDomain?: [number, number];\n /** Names each line at its right end when there are four or fewer and the chart is wide enough. */\n hasDirectLabels?: boolean;\n}\n\nconst margin = { top: 12, bottom: 28 };\nconst edge = 6;\nconst labelGap = 14;\n\ninterface XTick {\n index: number;\n position: number;\n anchor: 'start' | 'middle' | 'end';\n from: number;\n to: number;\n}\n\nfunction tickAnchor(position: number, tickWidth: number, plotWidth: number): XTick['anchor'] {\n if (position < tickWidth / 2) return 'start';\n return position > plotWidth - tickWidth / 2 ? 'end' : 'middle';\n}\n\nconst xLabelKey = { time: 'date', number: 'value', category: 'category' } as const;\n\n/**\n * One or more series over a time or ordered x axis. Hover or focus shows every series at that x;\n * Tab enters the plot and the arrow keys move along it. Each series has its own colour and marker\n * shape, a legend entry and, where there is room, a label at the line end.\n */\nexport function LineChart({\n x,\n series,\n xLabel,\n valueFormat,\n xFormat,\n yDomain,\n hasDirectLabels = true,\n title,\n hideTitle,\n summary,\n locale,\n labels,\n height = 240,\n className,\n}: LineChartProps) {\n const text = chartLabels(labels);\n const values = knownValues(series);\n const fx = createXFormat(x, locale, xFormat);\n const vf = createValueFormat(Math.max(0, ...values.map(Math.abs)), locale, valueFormat);\n const positions = x.map((_, index) => fx.full(index));\n const headline = `Line chart with ${plural(series.length, 'series', 'series')} and ${plural(x.length, 'point', 'points')}, from ${positions[0]} to ${positions[positions.length - 1]}.`;\n const colors = seriesColors(series);\n\n const interaction = useChartInteraction(x.length);\n\n function renderPlot(width: number) {\n const known = series.flatMap((s) => s.values.filter(isNumber));\n const [low, high] = yDomain ?? [Math.min(0, ...known), Math.max(0, ...known)];\n const plotHeight = height - margin.top - margin.bottom;\n const ticks = niceTicks(\n low,\n high,\n Math.max(2, Math.floor(plotHeight / 48) + 1),\n known.every(Number.isInteger),\n );\n const domain: [number, number] = yDomain ?? [ticks.min, ticks.max];\n const yTicks = yDomain ? ticks.ticks.filter((t) => t >= low && t <= high) : ticks.ticks;\n const y = linearScale(domain, [plotHeight, 0]);\n\n const ends = series.flatMap((s, index) => {\n const at = s.values.findLastIndex(isNumber);\n const value = s.values[at];\n return isNumber(value) ? [{ index, at, y: y(value), label: truncate(s.label, 16) }] : [];\n });\n const sorted = ends.map((end) => end.y).sort((a, b) => a - b);\n const hasRoom = sorted.every(\n (value, index) => index === 0 || value - (sorted[index - 1] ?? 0) >= labelGap,\n );\n const showLabels = hasDirectLabels && series.length <= 4 && width >= 480 && hasRoom;\n\n const left = Math.max(...yTicks.map((tick) => textWidth(vf.axis(tick)))) + 12;\n const right = showLabels ? Math.max(...ends.map((end) => textWidth(end.label))) + 18 : 14;\n const plotWidth = Math.max(40, width - left - right);\n\n const numbers = xNumbers(x);\n const xScale = linearScale(\n [Math.min(...numbers), Math.max(...numbers)],\n [edge, plotWidth - edge],\n );\n const at = (index: number) => xScale(numbers[index] ?? 0);\n\n const tickWidth = Math.max(...x.map((_, index) => textWidth(fx.tick(index)))) + 16;\n const xTicks = sampleIndexes(x.length, Math.floor(plotWidth / tickWidth))\n .map((index): XTick => {\n const position = at(index);\n const anchor = tickAnchor(position, tickWidth, plotWidth);\n const size = textWidth(fx.tick(index));\n const from = position - { start: 0, middle: size / 2, end: size }[anchor];\n return { index, position, anchor, from, to: from + size };\n })\n .reduceRight<XTick[]>((kept, tick) => {\n const next = kept[0];\n return next && tick.to + 8 > next.from ? kept : [tick, ...kept];\n }, []);\n const showAllMarkers = x.length <= 12 && plotWidth / x.length >= 24;\n const active = interaction.active;\n\n const rows = (index: number): TooltipRow[] =>\n series.flatMap((s, position) => {\n const value = s.values[index];\n return isNumber(value)\n ? [\n {\n id: s.id,\n label: s.label,\n value: vf.full(value),\n index: colors[position] ?? position,\n },\n ]\n : [];\n });\n\n return (\n <>\n <svg width={width} height={height} aria-hidden='true' className='block'>\n <g transform={`translate(${left} ${margin.top})`}>\n {yTicks.map((tick) => (\n <g key={tick}>\n <line\n x1={0}\n x2={plotWidth}\n y1={y(tick)}\n y2={y(tick)}\n className={\n tick === 0 ? 'stroke-(--ui-border-default)' : 'stroke-(--ui-border-subtle)'\n }\n />\n <text\n x={-8}\n y={y(tick)}\n dy='0.32em'\n textAnchor='end'\n className='fill-(--ui-text-tertiary) text-xs'\n >\n {vf.axis(tick)}\n </text>\n </g>\n ))}\n {xTicks.map(({ index, position, anchor }) => (\n <text\n key={index}\n x={position}\n y={plotHeight + 18}\n textAnchor={anchor}\n className='fill-(--ui-text-tertiary) text-xs'\n >\n {fx.tick(index)}\n </text>\n ))}\n {active !== null && (\n <line\n x1={at(active)}\n x2={at(active)}\n y1={0}\n y2={plotHeight}\n className='stroke-(--ui-border-strong)'\n />\n )}\n {series.map((s, position) => {\n const style = seriesStyle(colors[position] ?? position);\n const points = s.values.map((value, index) =>\n isNumber(value) ? { index, x: at(index), y: y(value) } : null,\n );\n const path = points\n .map((point, index) =>\n point\n ? `${points[index - 1] ? 'L' : 'M'}${point.x.toFixed(2)} ${point.y.toFixed(2)}`\n : '',\n )\n .join('');\n const lastAt = s.values.findLastIndex(isNumber);\n return (\n <g key={s.id}>\n <path\n d={path}\n fill='none'\n strokeWidth={2}\n strokeLinecap='round'\n strokeLinejoin='round'\n strokeDasharray={style.dash}\n className={style.stroke}\n />\n {points.map((point, index) => {\n if (!point) return null;\n const isAlone = !points[index - 1] && !points[index + 1];\n const isActive = index === active;\n if (!(showAllMarkers || isAlone || isActive || index === lastAt)) return null;\n const r = isActive ? 5 : 4;\n return (\n <g key={index}>\n <path\n d={markerPath(style.shape, point.x, point.y, r + 2)}\n className='fill-[var(--chart-surface,var(--ui-bg-primary))]'\n />\n <path\n d={markerPath(style.shape, point.x, point.y, r)}\n className={style.fill}\n />\n </g>\n );\n })}\n </g>\n );\n })}\n {showLabels &&\n ends.map((end) => (\n <text\n key={end.index}\n x={at(end.at) + 12}\n y={end.y}\n dy='0.32em'\n className='fill-(--ui-text-secondary) text-xs'\n >\n {end.label}\n </text>\n ))}\n </g>\n </svg>\n {x.map((_, index) => {\n const from = index === 0 ? 0 : (at(index - 1) + at(index)) / 2;\n const to = index === x.length - 1 ? plotWidth : (at(index) + at(index + 1)) / 2;\n return (\n <ChartMark\n key={index}\n index={index}\n interaction={interaction}\n className={markHitArea}\n label={`${fx.full(index)}: ${\n rows(index)\n .map((row) => `${row.label} ${row.value}`)\n .join(', ') || text.noData\n }`}\n style={{\n left: left + from,\n top: margin.top,\n width: Math.max(2, to - from),\n height: plotHeight,\n }}\n />\n );\n })}\n {active !== null && (\n <ChartTooltip\n x={left + at(active)}\n y={margin.top + plotHeight / 2}\n containerWidth={width}\n title={fx.full(active)}\n rows={rows(active)}\n variant='line'\n />\n )}\n </>\n );\n }\n\n return (\n <ChartFrame\n title={title}\n hideTitle={hideTitle}\n labels={labels}\n className={className}\n isEmpty={x.length === 0 || values.length === 0}\n summary={summary ?? describeAll(headline, series, positions, vf.full)}\n legend={series.length > 1 && <ChartLegend variant='line' items={legendItems(series)} />}\n table={{\n head: [xLabel ?? text[xLabelKey[xKind(x)]], ...series.map((s) => s.label)],\n rows: x.map((_, index) => [positions[index] ?? '', ...seriesCells(series, index, vf.full)]),\n }}\n >\n {renderPlot}\n </ChartFrame>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAoCA,IAAM,SAAS;CAAE,KAAK;CAAI,QAAQ;AAAG;AACrC,IAAM,OAAO;AACb,IAAM,WAAW;AAUjB,SAAS,W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A,OACE,oBAAC,YAAD;EACS;EACI;EACH;EACG;EACX,SAAS,EAAE,WAAW,KAAK,OAAO,WAAW;EAC7C,SAAS,WAAW,YAAY,UAAU,QAAQ,WAAW,GAAG,IAAI;EACpE,QAAQ,OAAO,SAAS,KAAK,oBAAC,aAAD;GAAa,SAAQ;GAAO,OAAO,YAAY,MAAM;EAAI,CAAA;EACtF,OAAO;GACL,MAAM,CAAC,UAAU,KAAK,UAAU,MAAM,CAAC,KAAK,GAAG,OAAO,KAAK,MAAM,EAAE,KAAK,CAAC;GACzE,MAAM,EAAE,KAAK,GAAG,UAAU,CAAC,UAAU,UAAU,IAAI,GAAG,YAAY,QAAQ,OAAO,GAAG,IAAI,CAAC,CAAC;EAC5F;EAEC,UAAA;CACS,CAAA;AAEhB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface SparklineProps {
|
|
2
|
+
values: number[];
|
|
3
|
+
width?: number;
|
|
4
|
+
height?: number;
|
|
5
|
+
/** `brand` draws the line in the project colour instead of the text colour. */
|
|
6
|
+
tone?: 'brand';
|
|
7
|
+
/** Gives the chart role="img" with this name. Without it the chart is decorative. */
|
|
8
|
+
'aria-label'?: string;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Builds the SVG points for a line through `values`, scaled to the box with a 1px inset. */
|
|
12
|
+
export declare function sparklinePoints(values: number[], width: number, height: number): string;
|
|
13
|
+
/** A tiny line chart in the current text colour, or the project colour with `tone='brand'`. */
|
|
14
|
+
export declare function Sparkline({ values, width, height, tone, 'aria-label': ariaLabel, className, }: SparklineProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx } from "../../../utils/cx.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/organisms/Chart/Sparkline.tsx
|
|
5
|
+
/** Builds the SVG points for a line through `values`, scaled to the box with a 1px inset. */
|
|
6
|
+
function sparklinePoints(values, width, height) {
|
|
7
|
+
if (values.length === 0) return "";
|
|
8
|
+
const min = Math.min(...values);
|
|
9
|
+
const span = Math.max(...values) - min;
|
|
10
|
+
const step = values.length > 1 ? (width - 2) / (values.length - 1) : 0;
|
|
11
|
+
return values.map((value, index) => {
|
|
12
|
+
const x = 1 + index * step;
|
|
13
|
+
const y = span === 0 ? height / 2 : 1 + (1 - (value - min) / span) * (height - 2);
|
|
14
|
+
return `${Number(x.toFixed(2))},${Number(y.toFixed(2))}`;
|
|
15
|
+
}).join(" ");
|
|
16
|
+
}
|
|
17
|
+
/** A tiny line chart in the current text colour, or the project colour with `tone='brand'`. */
|
|
18
|
+
function Sparkline({ values, width = 96, height = 32, tone, "aria-label": ariaLabel, className }) {
|
|
19
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
20
|
+
width,
|
|
21
|
+
height,
|
|
22
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
23
|
+
role: ariaLabel ? "img" : void 0,
|
|
24
|
+
"aria-label": ariaLabel,
|
|
25
|
+
"aria-hidden": ariaLabel ? void 0 : true,
|
|
26
|
+
className: cx(tone === "brand" && "text-(--ui-bg-brand-solid)", className),
|
|
27
|
+
children: /* @__PURE__ */ jsx("polyline", {
|
|
28
|
+
points: sparklinePoints(values, width, height),
|
|
29
|
+
fill: "none",
|
|
30
|
+
stroke: "currentColor",
|
|
31
|
+
strokeWidth: 2,
|
|
32
|
+
strokeLinecap: "round",
|
|
33
|
+
strokeLinejoin: "round"
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export { Sparkline, sparklinePoints };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=Sparkline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sparkline.js","names":[],"sources":["../../../../src/components/organisms/Chart/Sparkline.tsx"],"sourcesContent":["import { cx } from '../../../utils/cx';\n\nexport interface SparklineProps {\n values: number[];\n width?: number;\n height?: number;\n /** `brand` draws the line in the project colour instead of the text colour. */\n tone?: 'brand';\n /** Gives the chart role=\"img\" with this name. Without it the chart is decorative. */\n 'aria-label'?: string;\n className?: string;\n}\n\n/** Builds the SVG points for a line through `values`, scaled to the box with a 1px inset. */\nexport function sparklinePoints(values: number[], width: number, height: number): string {\n if (values.length === 0) return '';\n const min = Math.min(...values);\n const max = Math.max(...values);\n const span = max - min;\n const step = values.length > 1 ? (width - 2) / (values.length - 1) : 0;\n return values\n .map((value, index) => {\n const x = 1 + index * step;\n const y = span === 0 ? height / 2 : 1 + (1 - (value - min) / span) * (height - 2);\n return `${Number(x.toFixed(2))},${Number(y.toFixed(2))}`;\n })\n .join(' ');\n}\n\n/** A tiny line chart in the current text colour, or the project colour with `tone='brand'`. */\nexport function Sparkline({\n values,\n width = 96,\n height = 32,\n tone,\n 'aria-label': ariaLabel,\n className,\n}: SparklineProps) {\n return (\n <svg\n width={width}\n height={height}\n viewBox={`0 0 ${width} ${height}`}\n role={ariaLabel ? 'img' : undefined}\n aria-label={ariaLabel}\n aria-hidden={ariaLabel ? undefined : true}\n className={cx(tone === 'brand' && 'text-(--ui-bg-brand-solid)', className)}\n >\n <polyline\n points={sparklinePoints(values, width, height)}\n fill='none'\n stroke='currentColor'\n strokeWidth={2}\n strokeLinecap='round'\n strokeLinejoin='round'\n />\n </svg>\n );\n}\n"],"mappings":";;;;;AAcA,SAAgB,gBAAgB,QAAkB,OAAe,QAAwB;CACvF,IAAI,OAAO,WAAW,GAAG,OAAO;CAChC,MAAM,MAAM,KAAK,IAAI,GAAG,MAAM;CAE9B,MAAM,OADM,KAAK,IAAI,GAAG,MACX,IAAM;CACnB,MAAM,OAAO,OAAO,SAAS,KAAK,QAAQ,MAAM,OAAO,SAAS,KAAK;CACrE,OAAO,OACJ,KAAK,OAAO,UAAU;EACrB,MAAM,IAAI,IAAI,QAAQ;EACtB,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,KAAK,KAAK,QAAQ,OAAO,SAAS,SAAS;EAC/E,OAAO,GAAG,OAAO,EAAE,QAAQ,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,QAAQ,CAAC,CAAC;CACvD,CAAC,CAAC,CACD,KAAK,GAAG;AACb;;AAGA,SAAgB,UAAU,EACxB,QACA,QAAQ,IACR,SAAS,IACT,MACA,cAAc,WACd,aACiB;CACjB,OACE,oBAAC,OAAD;EACS;EACC;EACR,SAAS,OAAO,MAAM,GAAG;EACzB,MAAM,YAAY,QAAQ,KAAA;EAC1B,cAAY;EACZ,eAAa,YAAY,KAAA,IAAY;EACrC,WAAW,GAAG,SAAS,WAAW,8BAA8B,SAAS;EAEzE,UAAA,oBAAC,YAAD;GACE,QAAQ,gBAAgB,QAAQ,OAAO,MAAM;GAC7C,MAAK;GACL,QAAO;GACP,aAAa;GACb,eAAc;GACd,gBAAe;EAChB,CAAA;CACE,CAAA;AAET"}
|
|
@@ -16,6 +16,8 @@ export interface ValueFormat {
|
|
|
16
16
|
axis: (value: number) => string;
|
|
17
17
|
}
|
|
18
18
|
export declare function createValueFormat(max: number, locale?: string, options?: Intl.NumberFormatOptions): ValueFormat;
|
|
19
|
+
/** Average width of one character at the chart's 12px text, in pixels. */
|
|
20
|
+
export declare const charWidth = 6.6;
|
|
19
21
|
/** Rough width of `text` at 12px in the UI font, for margins and tick density. */
|
|
20
22
|
export declare function textWidth(text: string): number;
|
|
21
23
|
/** `text` as it is when it fits in `width` pixels, otherwise shortened with an ellipsis. */
|