@knk1313/plain-ui 0.0.0-stage → 0.2.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 +86 -2
- package/dist/components/accordion/Accordion.d.ts +27 -0
- package/dist/components/accordion/Accordion.js +18 -0
- package/dist/components/accordion/index.d.ts +1 -0
- package/dist/components/accordion/index.js +1 -0
- package/dist/components/agent-form/AgentForm.d.ts +40 -0
- package/dist/components/agent-form/AgentForm.js +100 -0
- package/dist/components/agent-form/index.d.ts +1 -0
- package/dist/components/agent-form/index.js +1 -0
- package/dist/components/agent-steps/AgentSteps.d.ts +21 -0
- package/dist/components/agent-steps/AgentSteps.js +42 -0
- package/dist/components/agent-steps/index.d.ts +1 -0
- package/dist/components/agent-steps/index.js +1 -0
- package/dist/components/agent-thinking/AgentThinking.d.ts +12 -0
- package/dist/components/agent-thinking/AgentThinking.js +18 -0
- package/dist/components/agent-thinking/index.d.ts +1 -0
- package/dist/components/agent-thinking/index.js +1 -0
- package/dist/components/area-chart/AreaChart.d.ts +10 -0
- package/dist/components/area-chart/AreaChart.js +83 -0
- package/dist/components/area-chart/index.d.ts +1 -0
- package/dist/components/area-chart/index.js +1 -0
- package/dist/components/auth-card/AuthCard.d.ts +14 -0
- package/dist/components/auth-card/AuthCard.js +9 -0
- package/dist/components/auth-card/PasswordInput.d.ts +13 -0
- package/dist/components/auth-card/PasswordInput.js +26 -0
- package/dist/components/auth-card/index.d.ts +2 -0
- package/dist/components/auth-card/index.js +2 -0
- package/dist/components/avatar/Avatar.d.ts +14 -0
- package/dist/components/avatar/Avatar.js +42 -0
- package/dist/components/avatar/index.d.ts +1 -0
- package/dist/components/avatar/index.js +1 -0
- package/dist/components/badge/Badge.d.ts +9 -0
- package/dist/components/badge/Badge.js +15 -0
- package/dist/components/badge/index.d.ts +1 -0
- package/dist/components/badge/index.js +1 -0
- package/dist/components/banner/Banner.d.ts +9 -0
- package/dist/components/banner/Banner.js +36 -0
- package/dist/components/banner/index.d.ts +1 -0
- package/dist/components/banner/index.js +1 -0
- package/dist/components/bar-chart/BarChart.d.ts +3 -0
- package/dist/components/bar-chart/BarChart.js +47 -0
- package/dist/components/bar-chart/index.d.ts +1 -0
- package/dist/components/bar-chart/index.js +1 -0
- package/dist/components/bar-list/BarList.d.ts +26 -0
- package/dist/components/bar-list/BarList.js +24 -0
- package/dist/components/bar-list/index.d.ts +1 -0
- package/dist/components/bar-list/index.js +1 -0
- package/dist/components/breadcrumb/Breadcrumb.d.ts +12 -0
- package/dist/components/breadcrumb/Breadcrumb.js +9 -0
- package/dist/components/breadcrumb/index.d.ts +1 -0
- package/dist/components/breadcrumb/index.js +1 -0
- package/dist/components/button/Button.d.ts +24 -0
- package/dist/components/button/Button.js +31 -0
- package/dist/components/button/buttonStyle.d.ts +9 -0
- package/dist/components/button/buttonStyle.js +41 -0
- package/dist/components/button/index.d.ts +1 -0
- package/dist/components/button/index.js +1 -0
- package/dist/components/button-group/ButtonGroup.d.ts +18 -0
- package/dist/components/button-group/ButtonGroup.js +26 -0
- package/dist/components/button-group/index.d.ts +1 -0
- package/dist/components/button-group/index.js +1 -0
- package/dist/components/calendar/Calendar.d.ts +20 -0
- package/dist/components/calendar/Calendar.js +98 -0
- package/dist/components/calendar/index.d.ts +1 -0
- package/dist/components/calendar/index.js +1 -0
- package/dist/components/calendar-view/CalendarView.d.ts +34 -0
- package/dist/components/calendar-view/CalendarView.js +111 -0
- package/dist/components/calendar-view/index.d.ts +1 -0
- package/dist/components/calendar-view/index.js +1 -0
- package/dist/components/card/Card.d.ts +6 -0
- package/dist/components/card/Card.js +6 -0
- package/dist/components/card/index.d.ts +1 -0
- package/dist/components/card/index.js +1 -0
- package/dist/components/carousel/Carousel.d.ts +18 -0
- package/dist/components/carousel/Carousel.js +58 -0
- package/dist/components/carousel/index.d.ts +1 -0
- package/dist/components/carousel/index.js +1 -0
- package/dist/components/chart/Axis.d.ts +51 -0
- package/dist/components/chart/Axis.js +127 -0
- package/dist/components/chart/ChartFrame.d.ts +79 -0
- package/dist/components/chart/ChartFrame.js +80 -0
- package/dist/components/chart/ChartTooltip.d.ts +12 -0
- package/dist/components/chart/ChartTooltip.js +57 -0
- package/dist/components/chart/Legend.d.ts +11 -0
- package/dist/components/chart/Legend.js +6 -0
- package/dist/components/chart/Sparkline.d.ts +5 -0
- package/dist/components/chart/Sparkline.js +20 -0
- package/dist/components/chart/format.d.ts +2 -0
- package/dist/components/chart/format.js +17 -0
- package/dist/components/chart/heatmap.d.ts +18 -0
- package/dist/components/chart/heatmap.js +47 -0
- package/dist/components/chart/index.d.ts +1 -0
- package/dist/components/chart/index.js +1 -0
- package/dist/components/chart/line.d.ts +1 -0
- package/dist/components/chart/line.js +15 -0
- package/dist/components/chart/scale.d.ts +15 -0
- package/dist/components/chart/scale.js +100 -0
- package/dist/components/chart/series.d.ts +44 -0
- package/dist/components/chart/series.js +86 -0
- package/dist/components/chart/spacing.d.ts +29 -0
- package/dist/components/chart/spacing.js +34 -0
- package/dist/components/chart/types.d.ts +29 -0
- package/dist/components/chart/types.js +2 -0
- package/dist/components/chart/useChartHover.d.ts +34 -0
- package/dist/components/chart/useChartHover.js +97 -0
- package/dist/components/checkbox/Checkbox.d.ts +10 -0
- package/dist/components/checkbox/Checkbox.js +38 -0
- package/dist/components/checkbox/index.d.ts +1 -0
- package/dist/components/checkbox/index.js +1 -0
- package/dist/components/chip/Chip.d.ts +21 -0
- package/dist/components/chip/Chip.js +10 -0
- package/dist/components/chip/index.d.ts +1 -0
- package/dist/components/chip/index.js +1 -0
- package/dist/components/close-button/CloseButton.d.ts +14 -0
- package/dist/components/close-button/CloseButton.js +9 -0
- package/dist/components/close-button/index.d.ts +1 -0
- package/dist/components/close-button/index.js +1 -0
- package/dist/components/color-picker/ColorPicker.d.ts +21 -0
- package/dist/components/color-picker/ColorPicker.js +20 -0
- package/dist/components/color-picker/index.d.ts +1 -0
- package/dist/components/color-picker/index.js +1 -0
- package/dist/components/combo-chart/ComboChart.d.ts +12 -0
- package/dist/components/combo-chart/ComboChart.js +84 -0
- package/dist/components/combo-chart/index.d.ts +1 -0
- package/dist/components/combo-chart/index.js +1 -0
- package/dist/components/combobox/Combobox.d.ts +33 -0
- package/dist/components/combobox/Combobox.js +246 -0
- package/dist/components/combobox/index.d.ts +1 -0
- package/dist/components/combobox/index.js +1 -0
- package/dist/components/command-palette/CommandPalette.d.ts +36 -0
- package/dist/components/command-palette/CommandPalette.js +156 -0
- package/dist/components/command-palette/index.d.ts +1 -0
- package/dist/components/command-palette/index.js +1 -0
- package/dist/components/composer/Composer.d.ts +32 -0
- package/dist/components/composer/Composer.js +101 -0
- package/dist/components/composer/index.d.ts +1 -0
- package/dist/components/composer/index.js +1 -0
- package/dist/components/composer-attachments/ComposerAttachments.d.ts +25 -0
- package/dist/components/composer-attachments/ComposerAttachments.js +52 -0
- package/dist/components/composer-attachments/index.d.ts +1 -0
- package/dist/components/composer-attachments/index.js +1 -0
- package/dist/components/composer-panel/ComposerPanel.d.ts +26 -0
- package/dist/components/composer-panel/ComposerPanel.js +154 -0
- package/dist/components/composer-panel/index.d.ts +1 -0
- package/dist/components/composer-panel/index.js +1 -0
- package/dist/components/contribution-chart/ContributionChart.d.ts +25 -0
- package/dist/components/contribution-chart/ContributionChart.js +127 -0
- package/dist/components/contribution-chart/index.d.ts +1 -0
- package/dist/components/contribution-chart/index.js +1 -0
- package/dist/components/data-grid/DataGrid.d.ts +40 -0
- package/dist/components/data-grid/DataGrid.js +157 -0
- package/dist/components/data-grid/index.d.ts +1 -0
- package/dist/components/data-grid/index.js +1 -0
- package/dist/components/data-table/DataTable.d.ts +87 -0
- package/dist/components/data-table/DataTable.js +150 -0
- package/dist/components/data-table/index.d.ts +2 -0
- package/dist/components/data-table/index.js +2 -0
- package/dist/components/data-table/query.d.ts +54 -0
- package/dist/components/data-table/query.js +70 -0
- package/dist/components/date-picker/DatePicker.d.ts +25 -0
- package/dist/components/date-picker/DatePicker.js +154 -0
- package/dist/components/date-picker/index.d.ts +1 -0
- package/dist/components/date-picker/index.js +1 -0
- package/dist/components/dialog/ConfirmDialog.d.ts +25 -0
- package/dist/components/dialog/ConfirmDialog.js +69 -0
- package/dist/components/dialog/Dialog.d.ts +25 -0
- package/dist/components/dialog/Dialog.js +11 -0
- package/dist/components/dialog/DialogFrame.d.ts +22 -0
- package/dist/components/dialog/DialogFrame.js +21 -0
- package/dist/components/dialog/DiscardChangesDialog.d.ts +10 -0
- package/dist/components/dialog/DiscardChangesDialog.js +10 -0
- package/dist/components/dialog/index.d.ts +2 -0
- package/dist/components/dialog/index.js +2 -0
- package/dist/components/dialog/useDiscardOnClose.d.ts +20 -0
- package/dist/components/dialog/useDiscardOnClose.js +26 -0
- package/dist/components/dialog/useModalDialog.d.ts +20 -0
- package/dist/components/dialog/useModalDialog.js +85 -0
- package/dist/components/drawer/Drawer.d.ts +14 -0
- package/dist/components/drawer/Drawer.js +22 -0
- package/dist/components/drawer/index.d.ts +1 -0
- package/dist/components/drawer/index.js +1 -0
- package/dist/components/empty-state/EmptyState.d.ts +11 -0
- package/dist/components/empty-state/EmptyState.js +7 -0
- package/dist/components/empty-state/index.d.ts +1 -0
- package/dist/components/empty-state/index.js +1 -0
- package/dist/components/error-state/ErrorState.d.ts +8 -0
- package/dist/components/error-state/ErrorState.js +7 -0
- package/dist/components/error-state/index.d.ts +1 -0
- package/dist/components/error-state/index.js +1 -0
- package/dist/components/error-summary/ErrorSummary.d.ts +21 -0
- package/dist/components/error-summary/ErrorSummary.js +16 -0
- package/dist/components/error-summary/index.d.ts +1 -0
- package/dist/components/error-summary/index.js +1 -0
- package/dist/components/field/Field.d.ts +23 -0
- package/dist/components/field/Field.js +20 -0
- package/dist/components/field/index.d.ts +1 -0
- package/dist/components/field/index.js +1 -0
- package/dist/components/field-error/FieldError.d.ts +10 -0
- package/dist/components/field-error/FieldError.js +52 -0
- package/dist/components/field-error/index.d.ts +1 -0
- package/dist/components/field-error/index.js +1 -0
- package/dist/components/file-upload/FileUpload.d.ts +50 -0
- package/dist/components/file-upload/FileUpload.js +169 -0
- package/dist/components/file-upload/fileSize.d.ts +1 -0
- package/dist/components/file-upload/fileSize.js +13 -0
- package/dist/components/file-upload/index.d.ts +1 -0
- package/dist/components/file-upload/index.js +1 -0
- package/dist/components/form-section/FormSection.d.ts +16 -0
- package/dist/components/form-section/FormSection.js +14 -0
- package/dist/components/form-section/index.d.ts +1 -0
- package/dist/components/form-section/index.js +1 -0
- package/dist/components/form-steps/FormSteps.d.ts +18 -0
- package/dist/components/form-steps/FormSteps.js +26 -0
- package/dist/components/form-steps/index.d.ts +1 -0
- package/dist/components/form-steps/index.js +1 -0
- package/dist/components/funnel-chart/FunnelChart.d.ts +12 -0
- package/dist/components/funnel-chart/FunnelChart.js +69 -0
- package/dist/components/funnel-chart/index.d.ts +1 -0
- package/dist/components/funnel-chart/index.js +1 -0
- package/dist/components/header/Header.d.ts +14 -0
- package/dist/components/header/Header.js +31 -0
- package/dist/components/header/index.d.ts +1 -0
- package/dist/components/header/index.js +1 -0
- package/dist/components/heatmap-chart/HeatmapChart.d.ts +10 -0
- package/dist/components/heatmap-chart/HeatmapChart.js +76 -0
- package/dist/components/heatmap-chart/index.d.ts +1 -0
- package/dist/components/heatmap-chart/index.js +1 -0
- package/dist/components/image-error/ImageError.d.ts +11 -0
- package/dist/components/image-error/ImageError.js +16 -0
- package/dist/components/image-error/index.d.ts +1 -0
- package/dist/components/image-error/index.js +1 -0
- package/dist/components/image-loader/ImageLoader.d.ts +9 -0
- package/dist/components/image-loader/ImageLoader.js +10 -0
- package/dist/components/image-loader/index.d.ts +1 -0
- package/dist/components/image-loader/index.js +1 -0
- package/dist/components/index.d.ts +98 -0
- package/dist/components/index.js +97 -0
- package/dist/components/input/Input.d.ts +6 -0
- package/dist/components/input/Input.js +8 -0
- package/dist/components/input/index.d.ts +1 -0
- package/dist/components/input/index.js +1 -0
- package/dist/components/input/inputStyle.d.ts +14 -0
- package/dist/components/input/inputStyle.js +35 -0
- package/dist/components/item-range/ItemRange.d.ts +11 -0
- package/dist/components/item-range/ItemRange.js +13 -0
- package/dist/components/item-range/index.d.ts +1 -0
- package/dist/components/item-range/index.js +1 -0
- package/dist/components/label/Label.d.ts +8 -0
- package/dist/components/label/Label.js +5 -0
- package/dist/components/label/index.d.ts +1 -0
- package/dist/components/label/index.js +1 -0
- package/dist/components/line-chart/LineChart.d.ts +10 -0
- package/dist/components/line-chart/LineChart.js +29 -0
- package/dist/components/line-chart/index.d.ts +1 -0
- package/dist/components/line-chart/index.js +1 -0
- package/dist/components/link-button/LinkButton.d.ts +29 -0
- package/dist/components/link-button/LinkButton.js +15 -0
- package/dist/components/link-button/index.d.ts +1 -0
- package/dist/components/link-button/index.js +1 -0
- package/dist/components/menu/Menu.d.ts +33 -0
- package/dist/components/menu/Menu.js +113 -0
- package/dist/components/menu/index.d.ts +1 -0
- package/dist/components/menu/index.js +1 -0
- package/dist/components/meter/Meter.d.ts +24 -0
- package/dist/components/meter/Meter.js +65 -0
- package/dist/components/meter/index.d.ts +1 -0
- package/dist/components/meter/index.js +1 -0
- package/dist/components/nav-group/NavGroup.d.ts +24 -0
- package/dist/components/nav-group/NavGroup.js +23 -0
- package/dist/components/nav-group/index.d.ts +1 -0
- package/dist/components/nav-group/index.js +1 -0
- package/dist/components/notification/Notification.d.ts +25 -0
- package/dist/components/notification/Notification.js +13 -0
- package/dist/components/notification/index.d.ts +1 -0
- package/dist/components/notification/index.js +1 -0
- package/dist/components/notification-center/NotificationCenter.d.ts +33 -0
- package/dist/components/notification-center/NotificationCenter.js +29 -0
- package/dist/components/notification-center/index.d.ts +1 -0
- package/dist/components/notification-center/index.js +1 -0
- package/dist/components/number-field/NumberField.d.ts +28 -0
- package/dist/components/number-field/NumberField.js +155 -0
- package/dist/components/number-field/index.d.ts +1 -0
- package/dist/components/number-field/index.js +1 -0
- package/dist/components/otp-input/OtpInput.d.ts +14 -0
- package/dist/components/otp-input/OtpInput.js +70 -0
- package/dist/components/otp-input/index.d.ts +1 -0
- package/dist/components/otp-input/index.js +1 -0
- package/dist/components/pagination/Pagination.d.ts +21 -0
- package/dist/components/pagination/Pagination.js +51 -0
- package/dist/components/pagination/index.d.ts +1 -0
- package/dist/components/pagination/index.js +1 -0
- package/dist/components/popover/Popover.d.ts +23 -0
- package/dist/components/popover/Popover.js +83 -0
- package/dist/components/popover/index.d.ts +1 -0
- package/dist/components/popover/index.js +1 -0
- package/dist/components/progress/Progress.d.ts +12 -0
- package/dist/components/progress/Progress.js +30 -0
- package/dist/components/progress/index.d.ts +1 -0
- package/dist/components/progress/index.js +1 -0
- package/dist/components/question-form/QuestionForm.d.ts +59 -0
- package/dist/components/question-form/QuestionForm.js +128 -0
- package/dist/components/question-form/index.d.ts +1 -0
- package/dist/components/question-form/index.js +1 -0
- package/dist/components/radar-chart/RadarChart.d.ts +3 -0
- package/dist/components/radar-chart/RadarChart.js +72 -0
- package/dist/components/radar-chart/geometry.d.ts +16 -0
- package/dist/components/radar-chart/geometry.js +56 -0
- package/dist/components/radar-chart/index.d.ts +1 -0
- package/dist/components/radar-chart/index.js +1 -0
- package/dist/components/radial-chart/RadialChart.d.ts +39 -0
- package/dist/components/radial-chart/RadialChart.js +135 -0
- package/dist/components/radial-chart/index.d.ts +1 -0
- package/dist/components/radial-chart/index.js +1 -0
- package/dist/components/radio/Radio.d.ts +31 -0
- package/dist/components/radio/Radio.js +24 -0
- package/dist/components/radio/index.d.ts +1 -0
- package/dist/components/radio/index.js +1 -0
- package/dist/components/reply-loader/ReplyLoader.d.ts +10 -0
- package/dist/components/reply-loader/ReplyLoader.js +9 -0
- package/dist/components/reply-loader/index.d.ts +1 -0
- package/dist/components/reply-loader/index.js +1 -0
- package/dist/components/sankey-chart/SankeyChart.d.ts +35 -0
- package/dist/components/sankey-chart/SankeyChart.js +218 -0
- package/dist/components/sankey-chart/index.d.ts +1 -0
- package/dist/components/sankey-chart/index.js +1 -0
- package/dist/components/scatter-chart/ScatterChart.d.ts +38 -0
- package/dist/components/scatter-chart/ScatterChart.js +69 -0
- package/dist/components/scatter-chart/index.d.ts +1 -0
- package/dist/components/scatter-chart/index.js +1 -0
- package/dist/components/search-field/SearchField.d.ts +17 -0
- package/dist/components/search-field/SearchField.js +92 -0
- package/dist/components/search-field/index.d.ts +1 -0
- package/dist/components/search-field/index.js +1 -0
- package/dist/components/segmented-control/SegmentedControl.d.ts +26 -0
- package/dist/components/segmented-control/SegmentedControl.js +38 -0
- package/dist/components/segmented-control/index.d.ts +1 -0
- package/dist/components/segmented-control/index.js +1 -0
- package/dist/components/select/Select.d.ts +11 -0
- package/dist/components/select/Select.js +30 -0
- package/dist/components/select/index.d.ts +1 -0
- package/dist/components/select/index.js +1 -0
- package/dist/components/separator/Separator.d.ts +14 -0
- package/dist/components/separator/Separator.js +12 -0
- package/dist/components/separator/index.d.ts +1 -0
- package/dist/components/separator/index.js +1 -0
- package/dist/components/settings-modal/SettingsModal.d.ts +35 -0
- package/dist/components/settings-modal/SettingsModal.js +120 -0
- package/dist/components/settings-modal/index.d.ts +1 -0
- package/dist/components/settings-modal/index.js +1 -0
- package/dist/components/sidebar/Sidebar.d.ts +30 -0
- package/dist/components/sidebar/Sidebar.js +30 -0
- package/dist/components/sidebar/index.d.ts +1 -0
- package/dist/components/sidebar/index.js +1 -0
- package/dist/components/skeleton/Skeleton.d.ts +6 -0
- package/dist/components/skeleton/Skeleton.js +6 -0
- package/dist/components/skeleton/index.d.ts +1 -0
- package/dist/components/skeleton/index.js +1 -0
- package/dist/components/skip-link/SkipLink.d.ts +8 -0
- package/dist/components/skip-link/SkipLink.js +10 -0
- package/dist/components/skip-link/index.d.ts +1 -0
- package/dist/components/skip-link/index.js +1 -0
- package/dist/components/slider/Slider.d.ts +19 -0
- package/dist/components/slider/Slider.js +49 -0
- package/dist/components/slider/index.d.ts +1 -0
- package/dist/components/slider/index.js +1 -0
- package/dist/components/spinner/Spinner.d.ts +5 -0
- package/dist/components/spinner/Spinner.js +7 -0
- package/dist/components/spinner/index.d.ts +1 -0
- package/dist/components/spinner/index.js +1 -0
- package/dist/components/stacked-bar/StackedBar.d.ts +29 -0
- package/dist/components/stacked-bar/StackedBar.js +77 -0
- package/dist/components/stacked-bar/index.d.ts +1 -0
- package/dist/components/stacked-bar/index.js +1 -0
- package/dist/components/stat-card/StatCard.d.ts +19 -0
- package/dist/components/stat-card/StatCard.js +32 -0
- package/dist/components/stat-card/index.d.ts +1 -0
- package/dist/components/stat-card/index.js +1 -0
- package/dist/components/switch/Switch.d.ts +10 -0
- package/dist/components/switch/Switch.js +22 -0
- package/dist/components/switch/index.d.ts +1 -0
- package/dist/components/switch/index.js +1 -0
- package/dist/components/table/SortableHeader.d.ts +12 -0
- package/dist/components/table/SortableHeader.js +11 -0
- package/dist/components/table/Table.d.ts +15 -0
- package/dist/components/table/Table.js +26 -0
- package/dist/components/table/align.d.ts +1 -0
- package/dist/components/table/align.js +5 -0
- package/dist/components/table/index.d.ts +4 -0
- package/dist/components/table/index.js +2 -0
- package/dist/components/tabs/Tabs.d.ts +38 -0
- package/dist/components/tabs/Tabs.js +137 -0
- package/dist/components/tabs/fitTabs.d.ts +18 -0
- package/dist/components/tabs/fitTabs.js +46 -0
- package/dist/components/tabs/index.d.ts +1 -0
- package/dist/components/tabs/index.js +1 -0
- package/dist/components/tag-group/TagGroup.d.ts +29 -0
- package/dist/components/tag-group/TagGroup.js +82 -0
- package/dist/components/tag-group/index.d.ts +1 -0
- package/dist/components/tag-group/index.js +1 -0
- package/dist/components/task-list/TaskList.d.ts +46 -0
- package/dist/components/task-list/TaskList.js +30 -0
- package/dist/components/task-list/index.d.ts +1 -0
- package/dist/components/task-list/index.js +1 -0
- package/dist/components/text-link/TextLink.d.ts +27 -0
- package/dist/components/text-link/TextLink.js +22 -0
- package/dist/components/text-link/index.d.ts +1 -0
- package/dist/components/text-link/index.js +1 -0
- package/dist/components/textarea/Textarea.d.ts +6 -0
- package/dist/components/textarea/Textarea.js +9 -0
- package/dist/components/textarea/index.d.ts +1 -0
- package/dist/components/textarea/index.js +1 -0
- package/dist/components/time-field/TimeField.d.ts +6 -0
- package/dist/components/time-field/TimeField.js +9 -0
- package/dist/components/time-field/index.d.ts +1 -0
- package/dist/components/time-field/index.js +1 -0
- package/dist/components/toast/Toast.d.ts +19 -0
- package/dist/components/toast/Toast.js +190 -0
- package/dist/components/toast/index.d.ts +1 -0
- package/dist/components/toast/index.js +1 -0
- package/dist/components/token-input/TokenInput.d.ts +27 -0
- package/dist/components/token-input/TokenInput.js +153 -0
- package/dist/components/token-input/index.d.ts +1 -0
- package/dist/components/token-input/index.js +1 -0
- package/dist/components/tooltip/Tooltip.d.ts +17 -0
- package/dist/components/tooltip/Tooltip.js +144 -0
- package/dist/components/tooltip/index.d.ts +1 -0
- package/dist/components/tooltip/index.js +1 -0
- package/dist/components/tree-view/TreeView.d.ts +29 -0
- package/dist/components/tree-view/TreeView.js +140 -0
- package/dist/components/tree-view/index.d.ts +1 -0
- package/dist/components/tree-view/index.js +1 -0
- package/dist/components/unsaved-changes/index.d.ts +1 -0
- package/dist/components/unsaved-changes/index.js +1 -0
- package/dist/components/unsaved-changes/useUnsavedChanges.d.ts +12 -0
- package/dist/components/unsaved-changes/useUnsavedChanges.js +45 -0
- package/dist/components/usage-limit/UsageLimit.d.ts +15 -0
- package/dist/components/usage-limit/UsageLimit.js +21 -0
- package/dist/components/usage-limit/index.d.ts +1 -0
- package/dist/components/usage-limit/index.js +1 -0
- package/dist/components/web-search-results/WebSearchResults.d.ts +21 -0
- package/dist/components/web-search-results/WebSearchResults.js +17 -0
- package/dist/components/web-search-results/index.d.ts +1 -0
- package/dist/components/web-search-results/index.js +1 -0
- package/dist/lib/anchor.d.ts +21 -0
- package/dist/lib/anchor.js +50 -0
- package/dist/lib/cn.d.ts +1 -0
- package/dist/lib/cn.js +5 -0
- package/dist/lib/date.d.ts +77 -0
- package/dist/lib/date.js +165 -0
- package/dist/lib/icon-message.d.ts +16 -0
- package/dist/lib/icon-message.js +7 -0
- package/dist/lib/number.d.ts +1 -0
- package/dist/lib/number.js +5 -0
- package/dist/lib/slot.d.ts +8 -0
- package/dist/lib/slot.js +53 -0
- package/dist/lib/variant.d.ts +1 -0
- package/dist/lib/variant.js +1 -0
- package/docs/a11y.md +320 -0
- package/docs/chart/axis.md +82 -0
- package/docs/chart/color.md +120 -0
- package/docs/chart/drawing.md +283 -0
- package/docs/chart/reading.md +79 -0
- package/docs/chart/size-and-spacing.md +85 -0
- package/docs/chart.md +47 -0
- package/docs/color/contrast.md +80 -0
- package/docs/color/data-viz.md +66 -0
- package/docs/color/foundation.md +91 -0
- package/docs/color/neutral.md +88 -0
- package/docs/color/state.md +111 -0
- package/docs/color.md +22 -0
- package/docs/components/accordion.md +51 -0
- package/docs/components/agent-form.md +56 -0
- package/docs/components/agent-steps.md +75 -0
- package/docs/components/agent-thinking.md +70 -0
- package/docs/components/area-chart.md +55 -0
- package/docs/components/auth-card.md +126 -0
- package/docs/components/avatar.md +38 -0
- package/docs/components/badge.md +28 -0
- package/docs/components/banner.md +19 -0
- package/docs/components/bar-list.md +77 -0
- package/docs/components/button-group.md +74 -0
- package/docs/components/button.md +49 -0
- package/docs/components/calendar-view.md +106 -0
- package/docs/components/calendar.md +44 -0
- package/docs/components/carousel.md +81 -0
- package/docs/components/chart.md +45 -0
- package/docs/components/chat-message.md +199 -0
- package/docs/components/checkbox.md +27 -0
- package/docs/components/chip.md +34 -0
- package/docs/components/choosing.md +26 -0
- package/docs/components/close-button.md +17 -0
- package/docs/components/color-picker.md +52 -0
- package/docs/components/combo-chart.md +74 -0
- package/docs/components/combobox.md +60 -0
- package/docs/components/command-palette.md +151 -0
- package/docs/components/composer-attachments.md +116 -0
- package/docs/components/composer-panel.md +106 -0
- package/docs/components/composer.md +163 -0
- package/docs/components/contribution-chart.md +70 -0
- package/docs/components/data-grid.md +132 -0
- package/docs/components/data-table.md +165 -0
- package/docs/components/date-picker.md +120 -0
- package/docs/components/dialog.md +211 -0
- package/docs/components/drawer.md +38 -0
- package/docs/components/empty-state.md +17 -0
- package/docs/components/error-state.md +13 -0
- package/docs/components/error-summary.md +49 -0
- package/docs/components/field.md +84 -0
- package/docs/components/file-upload.md +161 -0
- package/docs/components/focus.md +25 -0
- package/docs/components/form-section.md +49 -0
- package/docs/components/form-steps.md +63 -0
- package/docs/components/funnel-chart.md +49 -0
- package/docs/components/heatmap-chart.md +64 -0
- package/docs/components/image-error.md +73 -0
- package/docs/components/image-loader.md +53 -0
- package/docs/components/input.md +21 -0
- package/docs/components/item-range.md +10 -0
- package/docs/components/link-button.md +16 -0
- package/docs/components/menu.md +115 -0
- package/docs/components/meter.md +83 -0
- package/docs/components/nav-group.md +33 -0
- package/docs/components/notification-center.md +100 -0
- package/docs/components/notification.md +127 -0
- package/docs/components/number-field.md +128 -0
- package/docs/components/otp-input.md +86 -0
- package/docs/components/pagination.md +29 -0
- package/docs/components/popover.md +43 -0
- package/docs/components/progress.md +25 -0
- package/docs/components/prohibitions.md +58 -0
- package/docs/components/props.md +20 -0
- package/docs/components/question-form.md +125 -0
- package/docs/components/radar-chart.md +61 -0
- package/docs/components/radial-chart.md +74 -0
- package/docs/components/radio.md +24 -0
- package/docs/components/reply-loader.md +80 -0
- package/docs/components/sankey-chart.md +71 -0
- package/docs/components/scatter-chart.md +61 -0
- package/docs/components/search-field.md +44 -0
- package/docs/components/segmented-control.md +35 -0
- package/docs/components/select.md +28 -0
- package/docs/components/separator.md +23 -0
- package/docs/components/settings-modal.md +128 -0
- package/docs/components/sidebar.md +145 -0
- package/docs/components/skeleton.md +27 -0
- package/docs/components/skip-link.md +17 -0
- package/docs/components/slider.md +82 -0
- package/docs/components/spinner.md +8 -0
- package/docs/components/stacked-bar.md +66 -0
- package/docs/components/stat-card.md +78 -0
- package/docs/components/switch.md +61 -0
- package/docs/components/table.md +43 -0
- package/docs/components/tabs.md +104 -0
- package/docs/components/tag-group.md +115 -0
- package/docs/components/task-list.md +99 -0
- package/docs/components/text-link.md +17 -0
- package/docs/components/textarea.md +27 -0
- package/docs/components/time-field.md +97 -0
- package/docs/components/toast.md +73 -0
- package/docs/components/token-input.md +135 -0
- package/docs/components/tooltip.md +41 -0
- package/docs/components/tree-view.md +71 -0
- package/docs/components/usage-limit.md +47 -0
- package/docs/components/web-search-results.md +60 -0
- package/docs/components.md +234 -0
- package/docs/design.md +31 -0
- package/docs/form/clearing-errors.md +28 -0
- package/docs/form/error-announcement.md +69 -0
- package/docs/form/long-forms.md +103 -0
- package/docs/form/placeholder.md +40 -0
- package/docs/form/submit-errors.md +102 -0
- package/docs/form/submitting.md +72 -0
- package/docs/form/unsaved-changes.md +146 -0
- package/docs/form/validation-timing.md +44 -0
- package/docs/form.md +39 -0
- package/docs/glossary.md +169 -0
- package/docs/icon.md +245 -0
- package/docs/interaction/before.md +64 -0
- package/docs/interaction/motion.md +38 -0
- package/docs/interaction/pending.md +38 -0
- package/docs/interaction/permissions.md +133 -0
- package/docs/interaction/result.md +38 -0
- package/docs/interaction/states.md +159 -0
- package/docs/interaction.md +31 -0
- package/docs/layout/alignment.md +145 -0
- package/docs/layout/hit-area.md +58 -0
- package/docs/layout/mobile.md +200 -0
- package/docs/layout/responsive.md +73 -0
- package/docs/layout/scroll.md +51 -0
- package/docs/layout/surface.md +110 -0
- package/docs/layout.md +31 -0
- package/docs/list/board.md +85 -0
- package/docs/list/paging.md +146 -0
- package/docs/list/search.md +98 -0
- package/docs/list/toolbar.md +91 -0
- package/docs/list.md +39 -0
- package/docs/log.md +94 -0
- package/docs/manual.md +183 -0
- package/docs/navigation/header-and-transition.md +82 -0
- package/docs/navigation/location.md +68 -0
- package/docs/navigation/menu-items.md +152 -0
- package/docs/navigation/menu-structure.md +68 -0
- package/docs/navigation.md +23 -0
- package/docs/publish.md +26 -0
- package/docs/rules.md +246 -0
- package/docs/scenario.md +218 -0
- package/docs/spacing/placement.md +219 -0
- package/docs/spacing/radius.md +45 -0
- package/docs/spacing/scale.md +91 -0
- package/docs/spacing.md +17 -0
- package/docs/typography.md +233 -0
- package/docs/writing/date-and-number.md +25 -0
- package/docs/writing/error-and-empty.md +58 -0
- package/docs/writing/label-and-button.md +124 -0
- package/docs/writing/tone.md +156 -0
- package/docs/writing.md +27 -0
- package/icons/index.d.ts +1 -0
- package/icons/index.js +3 -0
- package/package.json +117 -4
- package/scripts/lint/colors.mjs +103 -0
- package/scripts/lint/deps.mjs +33 -0
- package/scripts/lint/icons.mjs +177 -0
- package/scripts/lint/interaction.mjs +163 -0
- package/scripts/lint/layout.mjs +103 -0
- package/scripts/lint/markup.mjs +271 -0
- package/scripts/lint/shared.mjs +340 -0
- package/scripts/lint/spacing.mjs +70 -0
- package/scripts/lint/typography.mjs +141 -0
- package/scripts/lint/writing.mjs +107 -0
- package/scripts/lint.mjs +166 -0
- package/scripts/plain-ui-lint.mjs +33 -0
- package/tokens/tokens.css +482 -0
- package/tokens/tokens.values.json +234 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ChartSeries } from "../chart/types.js";
|
|
2
|
+
export declare const LABEL_MAX = 96;
|
|
3
|
+
/** 中心と半径。svg の中の座標 */
|
|
4
|
+
export interface RadarArea {
|
|
5
|
+
cx: number;
|
|
6
|
+
cy: number;
|
|
7
|
+
radius: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function axisAngle(index: number, count: number): number;
|
|
10
|
+
export declare const TOP_LABEL_OFFSET: number;
|
|
11
|
+
export declare function layoutRadar(labels: readonly string[], width: number, height: number): RadarArea;
|
|
12
|
+
export declare function nearestAxis(x: number, y: number, area: RadarArea, count: number): number | null;
|
|
13
|
+
export declare function radarPath(values: ChartSeries["values"], point: (i: number, value: number) => {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
}): string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// レーダーチャートの形の計算(中心と半径、軸の向き、マウスに近い軸、多角形の線)。部品の中だけで使い、書き出さない
|
|
2
|
+
import { AXIS_FONT_SIZE, textWidth } from "../chart/scale.js";
|
|
3
|
+
import { LABEL_GAP, SPACE_XS } from "../chart/spacing.js";
|
|
4
|
+
// 項目の名前に使う幅の上限。項目の軸(CategoryAxis)と同じ96pxにする
|
|
5
|
+
export const LABEL_MAX = 96;
|
|
6
|
+
// 軸の向き(ラジアン)。1つ目の軸を真上に置き、時計回りに等しい角度で並べる
|
|
7
|
+
export function axisAngle(index, count) {
|
|
8
|
+
return -Math.PI / 2 + (2 * Math.PI * index) / Math.max(count, 1);
|
|
9
|
+
}
|
|
10
|
+
// 真上の軸の先から、名前の文字の下端までの高さ。真上の軸の先のすぐ上(SPACE_XS)には、いちばん外の目盛りの値を書くので、
|
|
11
|
+
// 名前はその上に、SPACE_XS だけ離して置く
|
|
12
|
+
export const TOP_LABEL_OFFSET = SPACE_XS + AXIS_FONT_SIZE + SPACE_XS;
|
|
13
|
+
// svg の大きさと項目の名前から、中心と半径を決める。
|
|
14
|
+
// 左右には、項目の名前(96pxまで)と LABEL_GAP を置ける分をあける。上には、いちばん外の目盛りの値と真上の軸の名前を、
|
|
15
|
+
// 下には、LABEL_GAP と名前の文字の高さをあける。
|
|
16
|
+
// 狭い幅でも図が小さくなりすぎないように、半径は幅の1/4より小さくしない。そのときは、左右の名前を切り詰める
|
|
17
|
+
export function layoutRadar(labels, width, height) {
|
|
18
|
+
const longest = Math.min(LABEL_MAX, Math.max(0, ...labels.map(label => textWidth(label))));
|
|
19
|
+
const top = TOP_LABEL_OFFSET + AXIS_FONT_SIZE;
|
|
20
|
+
const bottom = LABEL_GAP + AXIS_FONT_SIZE;
|
|
21
|
+
const byWidth = width / 2 - LABEL_GAP - longest;
|
|
22
|
+
const byHeight = (height - top - bottom) / 2;
|
|
23
|
+
const radius = Math.max(1, Math.min(byHeight, Math.max(byWidth, width / 4)));
|
|
24
|
+
return { cx: width / 2, cy: top + Math.max(byHeight, 1), radius };
|
|
25
|
+
}
|
|
26
|
+
// マウスの位置から、中心から見た向きがいちばん近い軸を選ぶ
|
|
27
|
+
export function nearestAxis(x, y, area, count) {
|
|
28
|
+
if (count === 0)
|
|
29
|
+
return null;
|
|
30
|
+
const angle = Math.atan2(y - area.cy, x - area.cx) + Math.PI / 2;
|
|
31
|
+
const step = (2 * Math.PI) / count;
|
|
32
|
+
return ((Math.round(angle / step) % count) + count) % count;
|
|
33
|
+
}
|
|
34
|
+
// 系列の多角形の d。値のない項目で線を切る。最後の頂点から最初の頂点へは、どちらにも値があるときだけ閉じる
|
|
35
|
+
export function radarPath(values, point) {
|
|
36
|
+
const count = values.length;
|
|
37
|
+
const present = (i) => typeof values[i] === "number" && Number.isFinite(values[i]);
|
|
38
|
+
if (count > 0 && values.every((_, i) => present(i))) {
|
|
39
|
+
return values.map((v, i) => `${i === 0 ? "M" : "L"}${point(i, v).x} ${point(i, v).y}`).join("") + "Z";
|
|
40
|
+
}
|
|
41
|
+
// 値のない項目の次から描き始め、ひと回りする。こうすると、最後の頂点から最初の頂点への線も、切らずにつなげる
|
|
42
|
+
const start = values.findIndex((_, i) => !present(i)) + 1;
|
|
43
|
+
let d = "";
|
|
44
|
+
let drawing = false;
|
|
45
|
+
for (let k = 0; k < count; k++) {
|
|
46
|
+
const i = (start + k) % count;
|
|
47
|
+
if (!present(i)) {
|
|
48
|
+
drawing = false;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const p = point(i, values[i]);
|
|
52
|
+
d += `${drawing ? "L" : "M"}${p.x} ${p.y}`;
|
|
53
|
+
drawing = true;
|
|
54
|
+
}
|
|
55
|
+
return d;
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./RadarChart.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./RadarChart.js";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** 円形の進みの1つのリング */
|
|
2
|
+
export interface RadialChartItem {
|
|
3
|
+
/** リングの名前。凡例、ツールチップ、値の表の1列目に出す */
|
|
4
|
+
name: string;
|
|
5
|
+
/** 今の値。0以上にする。値のないリングは null にする */
|
|
6
|
+
value: number | null;
|
|
7
|
+
/** 目標(満点)の値。弧は value / max の割合まで塗る。省いたときは100 */
|
|
8
|
+
max?: number;
|
|
9
|
+
/** このリングの値の単位。リングごとに単位が違うとき(「kcal」「分」)だけ渡す。省いたときは、部品の unit */
|
|
10
|
+
unit?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface RadialChartProps {
|
|
13
|
+
/** グラフの名前。図の上に出し、図と値の表の名前にもする */
|
|
14
|
+
label: string;
|
|
15
|
+
/** グラフが伝える要点を、1〜2文で書く。「今月の目標の8割まで進みました。」のようにする */
|
|
16
|
+
description: string;
|
|
17
|
+
/** リング。外側から順に描く。3つまで */
|
|
18
|
+
items: readonly RadialChartItem[];
|
|
19
|
+
/**
|
|
20
|
+
* 形。full は円(円形の進み)、half は半円(ゲージ)。省いたときは full。
|
|
21
|
+
* どちらも、弧を今の値の割合まで塗る。ゲージにも針は描かない(docs/chart/drawing.md の CHART-025)
|
|
22
|
+
*/
|
|
23
|
+
shape?: "full" | "half";
|
|
24
|
+
/** 値の単位(「%」「点」「件」)。値の書き方は docs/writing/date-and-number.md の「日付、数値、単位」に従う */
|
|
25
|
+
unit?: string;
|
|
26
|
+
/** 値の名前。値の表の列の見出しと、ツールチップに出す。省いたときは「値」 */
|
|
27
|
+
valueLabel?: string;
|
|
28
|
+
/** 目標(max)の名前(「目標」「満点」)。リングが1つのときに数値の下に出し、値の表の列の見出しにもする。省いたときは「目標」 */
|
|
29
|
+
maxLabel?: string;
|
|
30
|
+
/** リングの名前の列の見出し。値の表の1列目の見出しにする。省いたときは「項目」 */
|
|
31
|
+
categoryLabel?: string;
|
|
32
|
+
/** 値が1つもないときの文。省いたときは「まだデータがありません。」 */
|
|
33
|
+
emptyMessage?: string;
|
|
34
|
+
/** 図の高さ(px)。省いたときは、full が240、half が160。幅は、置いた場所の幅に合わせる */
|
|
35
|
+
height?: number;
|
|
36
|
+
/** 外側の配置(余白と幅)だけに使う */
|
|
37
|
+
className?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare function RadialChart({ items, shape, unit, valueLabel, maxLabel, categoryLabel, height, ...props }: RadialChartProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow } from "../table/Table.js";
|
|
5
|
+
import { ChartLayout } from "../chart/ChartFrame.js";
|
|
6
|
+
import { ChartTooltip } from "../chart/ChartTooltip.js";
|
|
7
|
+
import { formatValue } from "../chart/format.js";
|
|
8
|
+
import { Legend } from "../chart/Legend.js";
|
|
9
|
+
import { AXIS_FONT_SIZE, textWidth } from "../chart/scale.js";
|
|
10
|
+
import { SERIES_STROKE, seriesIndex } from "../chart/series.js";
|
|
11
|
+
import { RING_GAP, SPACE_XS } from "../chart/spacing.js";
|
|
12
|
+
import { ChartTooltipContent, usePointerPick } from "../chart/useChartHover.js";
|
|
13
|
+
// リングの数の上限(docs/chart/drawing.md の CHART-024)。内側のリングほど短くなり、4つ目からは弧の長さを見比べられない
|
|
14
|
+
const MAX_RINGS = 3;
|
|
15
|
+
// リングの太さ(px)。間隔ではなく形の値(docs/chart/size-and-spacing.md の「間隔」の表の外)
|
|
16
|
+
const RING_WIDTH = 16;
|
|
17
|
+
const isValue = (v) => typeof v === "number" && Number.isFinite(v);
|
|
18
|
+
const maxOf = (item) => item.max ?? 100;
|
|
19
|
+
// 目標に対する割合(%)。小数第1位までにする。値がないか、目標が0以下のときは null
|
|
20
|
+
function ratioOf(item) {
|
|
21
|
+
const max = maxOf(item);
|
|
22
|
+
if (!isValue(item.value) || !(max > 0))
|
|
23
|
+
return null;
|
|
24
|
+
return Math.round((item.value / max) * 1000) / 10;
|
|
25
|
+
}
|
|
26
|
+
// 弧を塗る割合(0〜1)。目標を超えたときは1周(半円では端まで)で止め、2周目は描かない。超えた量は文字の値で読む
|
|
27
|
+
function fillOf(item) {
|
|
28
|
+
const ratio = ratioOf(item);
|
|
29
|
+
return ratio === null ? 0 : Math.min(1, Math.max(0, ratio / 100));
|
|
30
|
+
}
|
|
31
|
+
// 開発時の知らせ。リングが多すぎるとき(CHART-024)と、負の値や0以下の目標を渡したとき
|
|
32
|
+
function useRadialWarning(items) {
|
|
33
|
+
const tooMany = items.length > MAX_RINGS;
|
|
34
|
+
const invalid = items.some(item => (isValue(item.value) && item.value < 0) || !(maxOf(item) > 0));
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (tooMany)
|
|
37
|
+
console.warn(`RadialChart: リングは${MAX_RINGS}つまでにする。4つ以上は BarList か表で示す(docs/chart/drawing.md の CHART-024)`);
|
|
38
|
+
}, [tooMany]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (invalid)
|
|
41
|
+
console.warn("RadialChart: value は0以上、max は0より大きくする。上限や目標のない量は、円形の進みで描かない(docs/chart/drawing.md の CHART-026)");
|
|
42
|
+
}, [invalid]);
|
|
43
|
+
}
|
|
44
|
+
// 点数や目標に対する割合を、円の弧で示す。shape="half" で、半円のゲージにする。
|
|
45
|
+
// 弧は、真上(半円では左の端)から時計回りに、目標に対する割合まで塗る。リングは3つまで外側から重ね、系列の色(chart-1〜chart-3)で塗る。
|
|
46
|
+
// 色だけで見分けさせず、凡例とツールチップの見本で、何番目のリングかを形で示す(docs/chart/color.md の CHART-002)。
|
|
47
|
+
// リングが1つのときは、真ん中に数値と目標を書く。2つ以上のときは、凡例に名前と数値を並べる
|
|
48
|
+
export function RadialChart({ items, shape = "full", unit, valueLabel = "値", maxLabel = "目標", categoryLabel = "項目", height, ...props }) {
|
|
49
|
+
useRadialWarning(items);
|
|
50
|
+
const rings = items.slice(0, MAX_RINGS);
|
|
51
|
+
const ratioLabel = `${maxLabel}に対する割合`;
|
|
52
|
+
const unitOf = (item) => item.unit ?? unit;
|
|
53
|
+
const legend = rings.length > 1 ? (_jsx(Legend, { items: rings.map((item, i) => ({
|
|
54
|
+
name: item.name,
|
|
55
|
+
value: formatValue(item.value, unitOf(item)),
|
|
56
|
+
swatch: _jsx(RingSwatch, { index: i, count: rings.length, shape: shape }),
|
|
57
|
+
})) })) : undefined;
|
|
58
|
+
return (_jsx(ChartLayout, { ...props, component: "RadialChart", seriesNames: rings.map(item => item.name), empty: !items.some(item => isValue(item.value)), height: height ?? (shape === "half" ? 160 : 240), swatch: i => _jsx(RingSwatch, { index: i, count: rings.length, shape: shape }), legend: legend, maxSeries: Infinity, table: _jsxs(Table, { children: [_jsx("caption", { className: "sr-only", children: props.label }), _jsx(TableHead, { children: _jsxs(TableRow, { children: [_jsx(TableHeaderCell, { children: categoryLabel }), _jsx(TableHeaderCell, { className: "text-right", children: valueLabel }), _jsx(TableHeaderCell, { className: "text-right", children: maxLabel }), _jsx(TableHeaderCell, { className: "text-right", children: ratioLabel })] }) }), _jsx(TableBody, { children: items.map((item, i) => (_jsxs(TableRow, { children: [_jsx(TableHeaderCell, { scope: "row", children: item.name }), _jsx(TableCell, { className: "whitespace-nowrap text-right tabular-nums", children: formatValue(item.value, unitOf(item)) }), _jsx(TableCell, { className: "whitespace-nowrap text-right tabular-nums", children: formatValue(maxOf(item), unitOf(item)) }), _jsx(TableCell, { className: "whitespace-nowrap text-right tabular-nums", children: formatValue(ratioOf(item), "%") })] }, i))) })] }), children: size => (_jsx(RadialPlot, { rings: rings, shape: shape, unitOf: unitOf, valueLabel: valueLabel, maxLabel: maxLabel, ratioLabel: ratioLabel, ...size })) }));
|
|
59
|
+
}
|
|
60
|
+
// 中心(cx, cy)から半径 r の円の上の、角度 angle(ラジアン。0 が右、時計回り)の点
|
|
61
|
+
function at(cx, cy, r, angle) {
|
|
62
|
+
return { x: cx + r * Math.cos(angle), y: cy + r * Math.sin(angle) };
|
|
63
|
+
}
|
|
64
|
+
// 角度 start から、時計回りに span(ラジアン)だけ進む弧の線。1周のときは、半周の弧を2つつないで円にする
|
|
65
|
+
function arcPath(cx, cy, r, start, span) {
|
|
66
|
+
if (span >= Math.PI * 2 - 1e-6) {
|
|
67
|
+
const a = at(cx, cy, r, start);
|
|
68
|
+
const b = at(cx, cy, r, start + Math.PI);
|
|
69
|
+
return `M${a.x} ${a.y}A${r} ${r} 0 1 1 ${b.x} ${b.y}A${r} ${r} 0 1 1 ${a.x} ${a.y}`;
|
|
70
|
+
}
|
|
71
|
+
const a = at(cx, cy, r, start);
|
|
72
|
+
const b = at(cx, cy, r, start + span);
|
|
73
|
+
return `M${a.x} ${a.y}A${r} ${r} 0 ${span > Math.PI ? 1 : 0} 1 ${b.x} ${b.y}`;
|
|
74
|
+
}
|
|
75
|
+
// 形ごとの、弧の始まりの角度と、目標まで塗ったときの角度の幅。円は真上から1周、半円は左の端から真上を通って右の端まで
|
|
76
|
+
function sweep(shape) {
|
|
77
|
+
return shape === "full" ? { start: -Math.PI / 2, total: Math.PI * 2 } : { start: Math.PI, total: Math.PI };
|
|
78
|
+
}
|
|
79
|
+
// 凡例とツールチップの見本。リングの数だけ同心の弧を細い線で描き、そのリングの位置の弧だけを系列の色で太く描く。
|
|
80
|
+
// 色を見分けられなくても、外から何番目のリングかが形で分かる
|
|
81
|
+
function RingSwatch({ index, count, shape }) {
|
|
82
|
+
const { start, total } = sweep(shape);
|
|
83
|
+
const cy = shape === "full" ? 8 : 12;
|
|
84
|
+
return (_jsx("svg", { "aria-hidden": "true", viewBox: "0 0 16 16", className: "size-4 shrink-0", children: Array.from({ length: count }, (_, i) => {
|
|
85
|
+
const r = 7 - i * 2.5;
|
|
86
|
+
return i === index ? (_jsx("path", { d: arcPath(8, cy, r, start, total), fill: "none", strokeWidth: "2", className: SERIES_STROKE[seriesIndex(i)] }, i)) : (_jsx("path", { d: arcPath(8, cy, r, start, total), fill: "none", strokeWidth: "1", className: "stroke-muted-foreground" }, i));
|
|
87
|
+
}) }));
|
|
88
|
+
}
|
|
89
|
+
// 真ん中の数値の文字の大きさ(text-2xl)と、その下の目標の文字の大きさ(text-xs)
|
|
90
|
+
const VALUE_FONT_SIZE = 24;
|
|
91
|
+
function RadialPlot({ rings, shape, unitOf, valueLabel, maxLabel, ratioLabel, width, height }) {
|
|
92
|
+
const { start, total } = sweep(shape);
|
|
93
|
+
// 円は、幅と高さの小さいほうを直径にして真ん中に置く。半円は、幅の半分と高さの小さいほうを半径にし、平らな辺を下にそろえる
|
|
94
|
+
const outer = shape === "full" ? Math.min(width, height) / 2 : Math.min(width / 2, height);
|
|
95
|
+
const cx = width / 2;
|
|
96
|
+
const cy = shape === "full" ? height / 2 : (height + outer) / 2;
|
|
97
|
+
// リングの太さの中央の半径。外側から順に、リングどうしの間(XS)をあけて内側へ並べる
|
|
98
|
+
const radius = (i) => outer - RING_WIDTH / 2 - i * (RING_WIDTH + RING_GAP);
|
|
99
|
+
const inner = outer - rings.length * RING_WIDTH - (rings.length - 1) * RING_GAP;
|
|
100
|
+
// マウスの位置から、乗せているリングを決める。リングの太さに、隣との間の半分ずつを足した帯で判定する。半円では、平らな辺より下では出さない
|
|
101
|
+
const hover = usePointerPick((x, y) => {
|
|
102
|
+
if (shape === "half" && y > cy)
|
|
103
|
+
return null;
|
|
104
|
+
const d = Math.hypot(x - cx, y - cy);
|
|
105
|
+
const i = Math.floor((outer + RING_GAP / 2 - d) / (RING_WIDTH + RING_GAP));
|
|
106
|
+
return i >= 0 && i < rings.length ? i : null;
|
|
107
|
+
});
|
|
108
|
+
const active = hover.index;
|
|
109
|
+
const activeItem = active !== null ? rings[active] : undefined;
|
|
110
|
+
// リングが1つのときは、真ん中に数値と目標を書く。内側の円に収まらないときは書かない(値は値の表とツールチップで読める)
|
|
111
|
+
const single = rings.length === 1 ? rings[0] : undefined;
|
|
112
|
+
const valueText = single ? formatValue(single.value, unitOf(single)) : "";
|
|
113
|
+
const maxText = single ? `${maxLabel} ${formatValue(maxOf(single), unitOf(single))}` : "";
|
|
114
|
+
const room = shape === "full" ? inner * 2 * 0.8 : inner * 2 * 0.9;
|
|
115
|
+
const showCenter = single !== undefined &&
|
|
116
|
+
textWidth(valueText, VALUE_FONT_SIZE) <= room &&
|
|
117
|
+
textWidth(maxText) <= room &&
|
|
118
|
+
VALUE_FONT_SIZE + SPACE_XS + AXIS_FONT_SIZE <= (shape === "full" ? inner * 2 * 0.8 : inner * 0.9);
|
|
119
|
+
// 円では、数値と目標の2行の組を中心にそろえる。半円では、目標の行の下端を平らな辺にそろえる
|
|
120
|
+
const maxBaseline = shape === "full" ? cy + (VALUE_FONT_SIZE + SPACE_XS + AXIS_FONT_SIZE) / 2 : cy;
|
|
121
|
+
const valueBaseline = maxBaseline - AXIS_FONT_SIZE - SPACE_XS;
|
|
122
|
+
return (_jsxs(_Fragment, { children: [_jsxs("svg", { "aria-hidden": "true", width: width, height: height, className: "block overflow-visible", children: [rings.map((item, i) => {
|
|
123
|
+
const r = radius(i);
|
|
124
|
+
const fill = fillOf(item);
|
|
125
|
+
return (_jsxs("g", { children: [_jsx("path", { d: arcPath(cx, cy, r, start, total), fill: "none", strokeWidth: RING_WIDTH, className: "stroke-muted" }), fill > 0 && (_jsx("path", { d: arcPath(cx, cy, r, start, total * fill), fill: "none", strokeWidth: RING_WIDTH, className: SERIES_STROKE[seriesIndex(i)] }))] }, i));
|
|
126
|
+
}), active !== null && (_jsxs("g", { fill: "none", strokeWidth: "2", className: "stroke-foreground", children: [_jsx("path", { d: arcPath(cx, cy, radius(active) + RING_WIDTH / 2 + 1, start, total) }), _jsx("path", { d: arcPath(cx, cy, radius(active) - RING_WIDTH / 2 - 1, start, total) })] })), showCenter && (_jsxs(_Fragment, { children: [_jsx("text", { x: cx, y: valueBaseline, textAnchor: "middle", className: "fill-foreground text-2xl font-semibold tabular-nums", children: valueText }), _jsx("text", { x: cx, y: maxBaseline, textAnchor: "middle", className: "fill-muted-foreground text-xs tabular-nums", children: maxText })] })), _jsx("rect", { x: cx - outer - RING_GAP, y: cy - outer - RING_GAP, width: (outer + RING_GAP) * 2, height: shape === "full" ? (outer + RING_GAP) * 2 : outer + RING_GAP, fill: "transparent", ...hover.handlers })] }), _jsx(ChartTooltip, { position: hover.position, onDismiss: hover.dismiss, children: active !== null && activeItem && (_jsx(ChartTooltipContent, { label: activeItem.name, rows: [
|
|
127
|
+
{
|
|
128
|
+
name: valueLabel,
|
|
129
|
+
swatch: rings.length > 1 ? _jsx(RingSwatch, { index: active, count: rings.length, shape: shape }) : undefined,
|
|
130
|
+
value: formatValue(activeItem.value, unitOf(activeItem)),
|
|
131
|
+
},
|
|
132
|
+
{ name: maxLabel, value: formatValue(maxOf(activeItem), unitOf(activeItem)) },
|
|
133
|
+
{ name: ratioLabel, value: formatValue(ratioOf(activeItem), "%") },
|
|
134
|
+
] })) })] }));
|
|
135
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./RadialChart.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./RadialChart.js";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type FieldsetHTMLAttributes, type InputHTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
export interface RadioGroupProps extends Omit<FieldsetHTMLAttributes<HTMLFieldSetElement>, "onChange" | "defaultValue"> {
|
|
3
|
+
/** グループの名前。`<legend>` に書き、読み上げで何の選択かを伝える */
|
|
4
|
+
legend: string;
|
|
5
|
+
/** 送信するときの名前。子の Radio に配る */
|
|
6
|
+
name: string;
|
|
7
|
+
/** 選択中の Radio の value。渡すと、選択を使う側で持つ */
|
|
8
|
+
value?: string;
|
|
9
|
+
/** 選択を使う側で持たないときの、初めの選択 */
|
|
10
|
+
defaultValue?: string;
|
|
11
|
+
/** Radio を選んだときに、その value で呼ぶ */
|
|
12
|
+
onChange?: (value: string) => void;
|
|
13
|
+
/** 必須の項目。`<legend>` の後ろに「必須」と書き、Radio に required を付ける */
|
|
14
|
+
required?: boolean;
|
|
15
|
+
/** どう直せばよいかを書いたエラー。ないときは省く */
|
|
16
|
+
error?: string;
|
|
17
|
+
/** Radio を並べる */
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
/** 外側の配置(余白と幅)だけに使う */
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function RadioGroup({ legend, name, value, defaultValue, onChange, required, error, children, className, "aria-describedby": describedBy, ...props }: RadioGroupProps): import("react").JSX.Element;
|
|
23
|
+
export interface RadioProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "name" | "value" | "children"> {
|
|
24
|
+
/** 送信する値。グループの中で重ならない文字列にする */
|
|
25
|
+
value: string;
|
|
26
|
+
/** 選択肢の文言 */
|
|
27
|
+
children: ReactNode;
|
|
28
|
+
/** 外側の配置(余白と幅)だけに使う */
|
|
29
|
+
className?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare function Radio({ value, children, className, onChange, ...props }: RadioProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useId } from "react";
|
|
3
|
+
import { FieldError } from "../field-error/FieldError.js";
|
|
4
|
+
import { cn } from "../../lib/cn.js";
|
|
5
|
+
import { inputFocus, inputInvalid, inputSurface } from "../input/inputStyle.js";
|
|
6
|
+
const RadioGroupContext = createContext(null);
|
|
7
|
+
// fieldset と legend でグループに名前を付け、name と選択を子の Radio に配る。
|
|
8
|
+
// 矢印キーでの移動はネイティブの振る舞いに任せる
|
|
9
|
+
export function RadioGroup({ legend, name, value, defaultValue, onChange, required, error, children, className, "aria-describedby": describedBy, ...props }) {
|
|
10
|
+
const errorId = useId();
|
|
11
|
+
return (_jsxs("fieldset", { className: cn("min-w-0", className), "aria-describedby": cn(describedBy, error && errorId) || undefined, ...props, children: [_jsxs("legend", { className: "mb-2 text-sm font-medium leading-tight text-foreground", children: [legend, required && _jsx("span", { className: "font-normal text-muted-foreground", children: "\uFF08\u5FC5\u9808\uFF09" })] }), _jsx(RadioGroupContext.Provider, { value: { name, value, defaultValue, onChange, required, invalid: Boolean(error) }, children: _jsx("div", { children: children }) }), _jsx(FieldError, { id: errorId, className: "*:mt-2", children: error })] }));
|
|
12
|
+
}
|
|
13
|
+
// ネイティブの <input type="radio"> の見た目だけを描き直す。
|
|
14
|
+
// label で丸と文言を包み、行の全体を押せる範囲にして、高さを44px以上にする
|
|
15
|
+
export function Radio({ value, children, className, onChange, ...props }) {
|
|
16
|
+
const group = useContext(RadioGroupContext);
|
|
17
|
+
const controlled = group?.value !== undefined;
|
|
18
|
+
return (_jsx("label", { className: cn("flex min-h-11 w-fit min-w-11 cursor-pointer items-center text-sm leading-tight text-foreground has-disabled:cursor-not-allowed has-disabled:opacity-50", className), children: _jsxs("span", { className: "flex items-start gap-2", children: [_jsx("span", { className: "flex h-lh shrink-0 items-center", children: _jsxs("span", { className: "relative flex size-5 shrink-0", children: [_jsx("input", { type: "radio", name: group?.name, value: value, required: group?.required, "aria-invalid": group?.invalid || undefined, checked: controlled ? group?.value === value : undefined, defaultChecked: !controlled && group?.defaultValue !== undefined ? group.defaultValue === value : undefined, onChange: e => {
|
|
19
|
+
group?.onChange?.(value);
|
|
20
|
+
onChange?.(e);
|
|
21
|
+
},
|
|
22
|
+
// 枠線、フォーカス、エラーは入力欄と同じ(inputStyle.ts)。無効のときは label の側で薄くするので、ここではカーソルだけを変える
|
|
23
|
+
className: cn("peer size-5 cursor-pointer appearance-none rounded-full checked:border-primary checked:bg-primary disabled:cursor-not-allowed", inputSurface, inputFocus, inputInvalid), ...props }), _jsx("span", { "aria-hidden": "true", className: "pointer-events-none absolute inset-0 m-auto size-2 rounded-full bg-primary-icon opacity-0 peer-checked:opacity-100" })] }) }), _jsx("span", { children: children })] }) }));
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Radio.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Radio.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HTMLAttributes } from "react";
|
|
2
|
+
export interface ReplyLoaderProps extends Omit<HTMLAttributes<HTMLDivElement>, "children" | "role" | "aria-live" | "aria-atomic"> {
|
|
3
|
+
/** 返答を待っている間(文がまだ出ていない間)は true にする。文が出始めたら、生成が終わったら、止めたら、失敗したら false にする */
|
|
4
|
+
pending: boolean;
|
|
5
|
+
/** 進行中の文言。見た目にも読み上げにも、この文言だけを出す。省いたときは「返答を生成しています」 */
|
|
6
|
+
label?: string;
|
|
7
|
+
/** 外側の配置(余白と幅)だけに使う */
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function ReplyLoader({ pending, label, className, ...props }: ReplyLoaderProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Spinner } from "../spinner/Spinner.js";
|
|
3
|
+
// 返答を待っている間に、メッセージの並びの末尾(返答が出る場所)で、スピナーと文言で進行中を示す。入力欄のそばには置かない(COMPONENTS-083)。
|
|
4
|
+
// 外側は、進行中でないときも置いておく role="status"(aria-live="polite")の領域にする。領域が後から DOM に入ると、
|
|
5
|
+
// 読み上げられないことがあるためである。進行中になったら文言を入れ、読み上げでは文言だけを1回伝える。
|
|
6
|
+
// 少しずつ増える返答の途中の文と、生成が終わった後の全文は、この部品では読ませない(全文は使う側のメッセージの領域で読む)
|
|
7
|
+
export function ReplyLoader({ pending, label = "返答を生成しています", className, ...props }) {
|
|
8
|
+
return (_jsx("div", { ...props, role: "status", "aria-live": "polite", "aria-atomic": "true", className: className, children: pending && (_jsxs("p", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: [_jsx(Spinner, {}), _jsx("span", { className: "text-trim", children: label })] })) }));
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ReplyLoader.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ReplyLoader.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** サンキー図の1つの流れ */
|
|
2
|
+
export interface SankeyLink {
|
|
3
|
+
/** 流れの元の項目の名前 */
|
|
4
|
+
source: string;
|
|
5
|
+
/** 流れの先の項目の名前 */
|
|
6
|
+
target: string;
|
|
7
|
+
/** 流れの量。0以上にする */
|
|
8
|
+
value: number;
|
|
9
|
+
}
|
|
10
|
+
export interface SankeyChartProps {
|
|
11
|
+
/** グラフの名前。図の上に出し、図と値の表の名前にもする */
|
|
12
|
+
label: string;
|
|
13
|
+
/** グラフが伝える要点を、1〜2文で書く。「申し込みの半分は、検索から来ています。」のようにする */
|
|
14
|
+
description: string;
|
|
15
|
+
/**
|
|
16
|
+
* 流れ。項目は、名前で結びつける。項目の段(列)は、最初の元から数えた流れの数で決まり、同じ段の項目は、流れに初めて出た順に上から並べる。
|
|
17
|
+
* 1つの段の項目は5つまでにする(docs/chart/color.md の CHART-029)。流れを元の項目へ戻さない(docs/chart/drawing.md の CHART-028)
|
|
18
|
+
*/
|
|
19
|
+
links: readonly SankeyLink[];
|
|
20
|
+
/** 量の単位(「件」「万円」)。値の書き方は docs/writing/date-and-number.md の「日付、数値、単位」に従う */
|
|
21
|
+
unit?: string;
|
|
22
|
+
/** 量の名前(「申し込みの数」)。値の表の列の見出しと、ツールチップに出す。省いたときは「量」 */
|
|
23
|
+
valueLabel?: string;
|
|
24
|
+
/** 値の表の、流れの元の列の見出し。省いたときは「元」 */
|
|
25
|
+
sourceLabel?: string;
|
|
26
|
+
/** 値の表の、流れの先の列の見出し。省いたときは「先」 */
|
|
27
|
+
targetLabel?: string;
|
|
28
|
+
/** 値が1つもないときの文。省いたときは「まだデータがありません。」 */
|
|
29
|
+
emptyMessage?: string;
|
|
30
|
+
/** 図の高さ(px)。省いたときは240。幅は、置いた場所の幅に合わせる */
|
|
31
|
+
height?: number;
|
|
32
|
+
/** 外側の配置(余白と幅)だけに使う */
|
|
33
|
+
className?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare function SankeyChart({ links, unit, valueLabel, sourceLabel, targetLabel, ...props }: SankeyChartProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow } from "../table/Table.js";
|
|
5
|
+
import { ChartLayout } from "../chart/ChartFrame.js";
|
|
6
|
+
import { ChartTooltip } from "../chart/ChartTooltip.js";
|
|
7
|
+
import { formatValue } from "../chart/format.js";
|
|
8
|
+
import { AXIS_FONT_SIZE, LABEL_MAX, textWidth, truncate } from "../chart/scale.js";
|
|
9
|
+
import { AREA_OPACITY, MAX_SERIES, SERIES_FILL, SERIES_STROKE, seriesIndex } from "../chart/series.js";
|
|
10
|
+
import { LABEL_GAP, NODE_GAP } from "../chart/spacing.js";
|
|
11
|
+
import { ChartTooltipContent, usePointerPick } from "../chart/useChartHover.js";
|
|
12
|
+
// 項目の棒の太さ(px)。間隔ではなく形の値(docs/chart/size-and-spacing.md の「間隔」の表の外)
|
|
13
|
+
const NODE_WIDTH = 12;
|
|
14
|
+
const RATIO_LABEL = "元に対する割合";
|
|
15
|
+
const isPositive = (v) => Number.isFinite(v) && v > 0;
|
|
16
|
+
// 流れから、項目、段、量を決める。段は、最初の元(入る流れのない項目)から数えた、いちばん長い流れの数にする。
|
|
17
|
+
// 元へ戻る流れ(循環)は、段を決められないので描かない。描かないのは戻る流れだけにし、その先の流れは描く
|
|
18
|
+
function buildGraph(links) {
|
|
19
|
+
const names = [];
|
|
20
|
+
const indexOf = new Map();
|
|
21
|
+
const nodeOf = (name) => {
|
|
22
|
+
if (!indexOf.has(name)) {
|
|
23
|
+
indexOf.set(name, names.length);
|
|
24
|
+
names.push(name);
|
|
25
|
+
}
|
|
26
|
+
return indexOf.get(name);
|
|
27
|
+
};
|
|
28
|
+
const edges = links
|
|
29
|
+
.map((link, index) => ({ source: nodeOf(link.source), target: nodeOf(link.target), value: link.value, index }))
|
|
30
|
+
.filter(edge => isPositive(edge.value));
|
|
31
|
+
// 戻る流れを見つける。入る流れのない項目から順に、流れを渡した順に深さ優先でたどり、たどっている途中の項目へ戻る流れ(後退辺)を戻る流れとする。
|
|
32
|
+
// 同じ項目への流れも、たどっている途中の項目へ戻るので、ここで見つかる。入る流れのない項目からたどれない循環は、名前が先に出た項目からたどる
|
|
33
|
+
const state = names.map(() => 0); // 0:まだ、1:たどっている途中、2:たどり終えた
|
|
34
|
+
const back = new Set();
|
|
35
|
+
const visit = (node) => {
|
|
36
|
+
state[node] = 1;
|
|
37
|
+
for (const edge of edges) {
|
|
38
|
+
if (edge.source !== node)
|
|
39
|
+
continue;
|
|
40
|
+
if (state[edge.target] === 1)
|
|
41
|
+
back.add(edge.index);
|
|
42
|
+
else if (state[edge.target] === 0)
|
|
43
|
+
visit(edge.target);
|
|
44
|
+
}
|
|
45
|
+
state[node] = 2;
|
|
46
|
+
};
|
|
47
|
+
const roots = names.map((_, i) => i).filter(i => !edges.some(edge => edge.target === i));
|
|
48
|
+
for (const node of [...roots, ...names.map((_, i) => i)])
|
|
49
|
+
if (state[node] === 0)
|
|
50
|
+
visit(node);
|
|
51
|
+
const drawn = edges.filter(edge => !back.has(edge.index));
|
|
52
|
+
// 残りの流れには循環がないので、入る流れのない項目から順に、段を決める(Kahn の方法)
|
|
53
|
+
const depth = names.map(() => 0);
|
|
54
|
+
const incoming = names.map((_, i) => drawn.filter(edge => edge.target === i).length);
|
|
55
|
+
const queue = names.map((_, i) => i).filter(i => incoming[i] === 0);
|
|
56
|
+
while (queue.length > 0) {
|
|
57
|
+
const node = queue.shift();
|
|
58
|
+
for (const edge of drawn) {
|
|
59
|
+
if (edge.source !== node)
|
|
60
|
+
continue;
|
|
61
|
+
depth[edge.target] = Math.max(depth[edge.target] ?? 0, (depth[node] ?? 0) + 1);
|
|
62
|
+
incoming[edge.target] = (incoming[edge.target] ?? 0) - 1;
|
|
63
|
+
if (incoming[edge.target] === 0)
|
|
64
|
+
queue.push(edge.target);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const used = new Set(drawn.flatMap(edge => [edge.source, edge.target]));
|
|
68
|
+
const columns = Math.max(0, ...[...used].map(i => (depth[i] ?? 0) + 1));
|
|
69
|
+
const counts = Array.from({ length: columns }, () => 0);
|
|
70
|
+
const nodes = names.map((name, i) => {
|
|
71
|
+
const sum = (key) => drawn.filter(edge => edge[key] === i).reduce((total, edge) => total + edge.value, 0);
|
|
72
|
+
const column = depth[i] ?? 0;
|
|
73
|
+
const order = used.has(i) ? (counts[column] = (counts[column] ?? 0) + 1) - 1 : -1;
|
|
74
|
+
return { name, column, order, value: Math.max(sum("source"), sum("target")) };
|
|
75
|
+
});
|
|
76
|
+
return { nodes, links: drawn, columns, cyclic: [...back].sort((a, b) => a - b) };
|
|
77
|
+
}
|
|
78
|
+
// 開発時の知らせ。1つの段に6つ以上の項目があるとき(CHART-029)、元へ戻る流れがあるとき(CHART-028)、負の量を渡したとき
|
|
79
|
+
function useSankeyWarning(graph, links) {
|
|
80
|
+
const crowded = Array.from({ length: graph.columns }, (_, c) => graph.nodes.filter(n => n.column === c && n.order >= 0).length).some(n => n > MAX_SERIES);
|
|
81
|
+
const negative = links.some(link => link.value < 0);
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (crowded)
|
|
84
|
+
console.warn(`SankeyChart: 1つの段の項目は${MAX_SERIES}つまでにする。小さい項目は「その他」にまとめる(docs/chart/color.md の CHART-029)`);
|
|
85
|
+
}, [crowded]);
|
|
86
|
+
const cyclic = graph.cyclic.length > 0;
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (cyclic)
|
|
89
|
+
console.warn("SankeyChart: 元の項目へ戻る流れ(同じ項目への流れを含む)は描けない。戻る流れは、別の項目の名前にするか、表で示す(docs/chart/drawing.md の CHART-028)");
|
|
90
|
+
}, [cyclic]);
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (negative)
|
|
93
|
+
console.warn("SankeyChart: 流れの量は0以上にする。負の量の流れは描かない");
|
|
94
|
+
}, [negative]);
|
|
95
|
+
}
|
|
96
|
+
// 元の量に対する、その流れの量の割合(%)。小数第1位まで
|
|
97
|
+
function ratioOf(graph, link) {
|
|
98
|
+
const source = graph.nodes.find(node => node.name === link.source);
|
|
99
|
+
if (!source || !(source.value > 0) || !Number.isFinite(link.value))
|
|
100
|
+
return null;
|
|
101
|
+
return Math.round((link.value / source.value) * 1000) / 10;
|
|
102
|
+
}
|
|
103
|
+
// 量の流れと分かれ方を、帯の太さで示す。項目は段ごとに縦の棒で並べ、名前と量を棒の横に書く。
|
|
104
|
+
// 項目の棒は、段の中の順に系列の色(chart-1〜chart-5)で塗り、流れの帯は、元の項目の色で薄く塗って、縁を元の色の線で描く。
|
|
105
|
+
// 項目は名前で、流れは両端の項目とのつながりで見分けるので、色だけで区別させない(docs/chart/color.md の CHART-002)
|
|
106
|
+
export function SankeyChart({ links, unit, valueLabel = "量", sourceLabel = "元", targetLabel = "先", ...props }) {
|
|
107
|
+
const graph = buildGraph(links);
|
|
108
|
+
useSankeyWarning(graph, links);
|
|
109
|
+
return (_jsx(ChartLayout, { ...props, component: "SankeyChart", seriesNames: [], empty: graph.links.length === 0, swatch: () => null, table: _jsxs(_Fragment, { children: [_jsxs(Table, { children: [_jsx("caption", { className: "sr-only", children: props.label }), _jsx(TableHead, { children: _jsxs(TableRow, { children: [_jsx(TableHeaderCell, { children: sourceLabel }), _jsx(TableHeaderCell, { children: targetLabel }), _jsx(TableHeaderCell, { className: "text-right", children: valueLabel }), _jsx(TableHeaderCell, { className: "text-right", children: RATIO_LABEL })] }) }), _jsx(TableBody, { children: links.map((link, i) => (_jsxs(TableRow, { children: [_jsx(TableHeaderCell, { scope: "row", children: link.source }), _jsx(TableCell, { children: link.target }), _jsx(TableCell, { className: "whitespace-nowrap text-right tabular-nums", children: formatValue(link.value, unit) }), _jsx(TableCell, { className: "whitespace-nowrap text-right tabular-nums", children: formatValue(ratioOf(graph, link), "%") })] }, i))) })] }), graph.cyclic.length > 0 && (_jsxs("p", { className: "mt-2 text-xs text-muted-foreground", children: ["\u5143\u306E\u9805\u76EE\u3078\u623B\u308B\u6D41\u308C\uFF08", graph.cyclic.map(i => `${links[i]?.source}から${links[i]?.target}`).join("、"), "\uFF09\u306F\u3001\u56F3\u306B\u63CF\u3044\u3066\u3044\u307E\u305B\u3093\u3002"] }))] }), children: size => _jsx(SankeyPlot, { graph: graph, links: links, unit: unit, valueLabel: valueLabel, ...size }) }));
|
|
110
|
+
}
|
|
111
|
+
// 3次のベジェ曲線の、t(0〜1)の位置の値
|
|
112
|
+
const bezier = (a, b, c, d, t) => (1 - t) ** 3 * a + 3 * (1 - t) ** 2 * t * b + 3 * (1 - t) * t ** 2 * c + t ** 3 * d;
|
|
113
|
+
function SankeyPlot({ graph, links, unit, valueLabel, width, height }) {
|
|
114
|
+
const { nodes, columns } = graph;
|
|
115
|
+
const visible = nodes.filter(node => node.order >= 0);
|
|
116
|
+
// 項目の名前と量の文字。名前のあとに S をあけて量を書く
|
|
117
|
+
const valueText = (node) => formatValue(node.value, unit);
|
|
118
|
+
const labelWidth = (node) => Math.min(LABEL_MAX, textWidth(node.name)) + LABEL_GAP + textWidth(valueText(node));
|
|
119
|
+
// 最初の段の名前は棒の左に、最後の段の名前は棒の右に書くので、その幅を左右にあける。あける幅は、図の幅の1/4までにする
|
|
120
|
+
const gutter = (column) => Math.min(width / 4, Math.max(0, ...visible.filter(node => node.column === column).map(labelWidth)) + LABEL_GAP);
|
|
121
|
+
const leftGutter = gutter(0);
|
|
122
|
+
const rightGutter = columns > 1 ? gutter(columns - 1) : 0;
|
|
123
|
+
const span = Math.max(1, width - leftGutter - rightGutter - NODE_WIDTH);
|
|
124
|
+
const nodeX = (column) => leftGutter + (columns > 1 ? (span * column) / (columns - 1) : 0);
|
|
125
|
+
// 量の縦の倍率。どの段も、項目の棒と、項目どうしの間(M)が、高さに収まるようにする
|
|
126
|
+
const scale = Math.min(...Array.from({ length: columns }, (_, c) => {
|
|
127
|
+
const inColumn = visible.filter(node => node.column === c);
|
|
128
|
+
const total = inColumn.reduce((sum, node) => sum + node.value, 0);
|
|
129
|
+
return total > 0 ? Math.max(0, height - NODE_GAP * (inColumn.length - 1)) / total : Infinity;
|
|
130
|
+
}));
|
|
131
|
+
const k = Number.isFinite(scale) ? scale : 0;
|
|
132
|
+
// 項目の棒の上端。段の中で、上から順に積む
|
|
133
|
+
const nodeY = nodes.map(() => 0);
|
|
134
|
+
for (let c = 0; c < columns; c++) {
|
|
135
|
+
let y = 0;
|
|
136
|
+
for (const node of visible.filter(n => n.column === c).sort((a, b) => a.order - b.order)) {
|
|
137
|
+
nodeY[nodes.indexOf(node)] = y;
|
|
138
|
+
y += node.value * k + NODE_GAP;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// 流れの帯の、元と先での上端。元では先の項目の上下の順に、先では元の項目の上下の順に積み、帯どうしを交差させにくくする
|
|
142
|
+
const offsetOut = nodes.map(() => 0);
|
|
143
|
+
const offsetIn = nodes.map(() => 0);
|
|
144
|
+
const bands = graph.links.map(link => ({ link, sy: 0, ty: 0, thickness: link.value * k }));
|
|
145
|
+
const byTarget = [...bands].sort((a, b) => (nodeY[a.link.target] ?? 0) - (nodeY[b.link.target] ?? 0));
|
|
146
|
+
for (const band of byTarget) {
|
|
147
|
+
band.sy = (nodeY[band.link.source] ?? 0) + (offsetOut[band.link.source] ?? 0);
|
|
148
|
+
offsetOut[band.link.source] = (offsetOut[band.link.source] ?? 0) + band.thickness;
|
|
149
|
+
}
|
|
150
|
+
const bySource = [...bands].sort((a, b) => (nodeY[a.link.source] ?? 0) - (nodeY[b.link.source] ?? 0));
|
|
151
|
+
for (const band of bySource) {
|
|
152
|
+
band.ty = (nodeY[band.link.target] ?? 0) + (offsetIn[band.link.target] ?? 0);
|
|
153
|
+
offsetIn[band.link.target] = (offsetIn[band.link.target] ?? 0) + band.thickness;
|
|
154
|
+
}
|
|
155
|
+
const geometry = bands.map(band => {
|
|
156
|
+
const x0 = nodeX(nodes[band.link.source]?.column ?? 0) + NODE_WIDTH;
|
|
157
|
+
const x1 = nodeX(nodes[band.link.target]?.column ?? 0);
|
|
158
|
+
const xm = (x0 + x1) / 2;
|
|
159
|
+
const t = band.thickness;
|
|
160
|
+
const d = `M${x0} ${band.sy}C${xm} ${band.sy} ${xm} ${band.ty} ${x1} ${band.ty}L${x1} ${band.ty + t}C${xm} ${band.ty + t} ${xm} ${band.sy + t} ${x0} ${band.sy + t}Z`;
|
|
161
|
+
return { ...band, x0, x1, xm, d };
|
|
162
|
+
});
|
|
163
|
+
// マウスの位置から、乗せている項目か流れを決める。番号は、流れを 0〜、項目を流れの数〜にする。項目の棒を先に判定する
|
|
164
|
+
const hover = usePointerPick((x, y) => {
|
|
165
|
+
for (const node of visible) {
|
|
166
|
+
const i = nodes.indexOf(node);
|
|
167
|
+
const left = nodeX(node.column);
|
|
168
|
+
const top = nodeY[i] ?? 0;
|
|
169
|
+
if (x >= left - 2 && x <= left + NODE_WIDTH + 2 && y >= top - 2 && y <= top + node.value * k + 2)
|
|
170
|
+
return geometry.length + i;
|
|
171
|
+
}
|
|
172
|
+
for (let i = geometry.length - 1; i >= 0; i--) {
|
|
173
|
+
const g = geometry[i];
|
|
174
|
+
if (!g || x < g.x0 || x > g.x1)
|
|
175
|
+
continue;
|
|
176
|
+
// 横の位置 x になる t を、二分法で探す(x は t について単調に増える)
|
|
177
|
+
let lo = 0;
|
|
178
|
+
let hi = 1;
|
|
179
|
+
for (let step = 0; step < 20; step++) {
|
|
180
|
+
const mid = (lo + hi) / 2;
|
|
181
|
+
if (bezier(g.x0, g.xm, g.xm, g.x1, mid) < x)
|
|
182
|
+
lo = mid;
|
|
183
|
+
else
|
|
184
|
+
hi = mid;
|
|
185
|
+
}
|
|
186
|
+
const center = bezier(g.sy, g.sy, g.ty, g.ty, lo) + g.thickness / 2;
|
|
187
|
+
if (Math.abs(y - center) <= Math.max(g.thickness / 2, 2))
|
|
188
|
+
return i;
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
});
|
|
192
|
+
const active = hover.index;
|
|
193
|
+
const activeLink = active !== null && active < geometry.length ? geometry[active] : undefined;
|
|
194
|
+
const activeNode = active !== null && active >= geometry.length ? nodes[active - geometry.length] : undefined;
|
|
195
|
+
const nameOf = (i) => nodes[i]?.name ?? "";
|
|
196
|
+
const original = activeLink ? links[activeLink.link.index] : undefined;
|
|
197
|
+
return (_jsxs(_Fragment, { children: [_jsxs("svg", { "aria-hidden": "true", width: width, height: height, className: "block overflow-visible", children: [geometry.map((g, i) => {
|
|
198
|
+
const color = seriesIndex(nodes[g.link.source]?.order ?? 0);
|
|
199
|
+
return _jsx("path", { d: g.d, fillOpacity: AREA_OPACITY, strokeWidth: "1", className: `${SERIES_FILL[color]} ${SERIES_STROKE[color]}` }, i);
|
|
200
|
+
}), activeLink && _jsx("path", { d: activeLink.d, fill: "none", strokeWidth: "2", className: "stroke-foreground" }), visible.map(node => {
|
|
201
|
+
const i = nodes.indexOf(node);
|
|
202
|
+
const x = nodeX(node.column);
|
|
203
|
+
const y = nodeY[i] ?? 0;
|
|
204
|
+
const h = Math.max(1, node.value * k);
|
|
205
|
+
// 最初の段(段が1つでないとき)は棒の左に右そろえで、ほかの段は棒の右に書く
|
|
206
|
+
const onLeft = node.column === 0 && columns > 1;
|
|
207
|
+
const room = onLeft ? leftGutter - LABEL_GAP : node.column === columns - 1 ? rightGutter - LABEL_GAP : span / Math.max(columns - 1, 1) - NODE_WIDTH - LABEL_GAP * 2;
|
|
208
|
+
// 名前と量が収まらないときは、量を省いて名前を優先する(量はツールチップと値の表で読める)。それでも長い名前は「…」で切り詰める
|
|
209
|
+
const fullValue = valueText(node);
|
|
210
|
+
const both = Math.min(LABEL_MAX, textWidth(node.name)) + LABEL_GAP + textWidth(fullValue) <= room;
|
|
211
|
+
const value = both ? fullValue : "";
|
|
212
|
+
const name = truncate(node.name, Math.max(0, both ? room - LABEL_GAP - textWidth(fullValue) : room));
|
|
213
|
+
return (_jsxs("g", { children: [_jsx("rect", { x: x, y: y, width: NODE_WIDTH, height: h, className: SERIES_FILL[seriesIndex(node.order)] }), node === activeNode && _jsx("rect", { x: x - 1, y: y - 1, width: NODE_WIDTH + 2, height: h + 2, fill: "none", strokeWidth: "2", className: "stroke-foreground" }), _jsxs("text", { x: onLeft ? x - LABEL_GAP : x + NODE_WIDTH + LABEL_GAP, y: Math.min(Math.max(y + h / 2, AXIS_FONT_SIZE / 2), height - AXIS_FONT_SIZE / 2), textAnchor: onLeft ? "end" : "start", dominantBaseline: "central", className: "text-xs", children: [_jsx("tspan", { className: "fill-foreground", children: name }), value && (_jsx("tspan", { dx: LABEL_GAP, className: "fill-muted-foreground tabular-nums", children: value }))] })] }, i));
|
|
214
|
+
}), _jsx("rect", { x: 0, y: 0, width: width, height: height, fill: "transparent", ...hover.handlers })] }), _jsxs(ChartTooltip, { position: hover.position, onDismiss: hover.dismiss, children: [activeLink && original && (_jsx(ChartTooltipContent, { label: `${nameOf(activeLink.link.source)}から${nameOf(activeLink.link.target)}`, rows: [
|
|
215
|
+
{ name: valueLabel, value: formatValue(original.value, unit) },
|
|
216
|
+
{ name: RATIO_LABEL, value: formatValue(ratioOf(graph, original), "%") },
|
|
217
|
+
] })), activeNode && _jsx(ChartTooltipContent, { label: activeNode.name, rows: [{ name: valueLabel, value: valueText(activeNode) }] })] })] }));
|
|
218
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./SankeyChart.js";
|