@shohojdhara/atomix 0.1.30 → 0.2.1
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/CHANGELOG.md +0 -0
- package/LICENSE +0 -0
- package/README.md +151 -39
- package/dist/atomix.css +13529 -0
- package/dist/atomix.min.css +15 -0
- package/dist/index.d.ts +6112 -1757
- package/dist/index.esm.js +16852 -8364
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +16892 -8369
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/themes/boomdevs.css +13241 -0
- package/dist/themes/boomdevs.min.css +353 -0
- package/dist/themes/esrar.css +15374 -0
- package/dist/themes/esrar.min.css +189 -0
- package/dist/themes/mashroom.css +28079 -0
- package/dist/themes/mashroom.min.css +403 -0
- package/dist/themes/shaj-default.css +14203 -0
- package/dist/themes/shaj-default.min.css +500 -0
- package/dist/themes/yabai.css +13711 -0
- package/dist/themes/yabai.min.css +189 -0
- package/package.json +126 -99
- package/src/components/Accordion/Accordion.stories.tsx +271 -0
- package/src/components/Accordion/Accordion.tsx +131 -0
- package/src/components/Accordion/index.ts +3 -0
- package/src/components/AtomixLogo/AtomixLogo.tsx +36 -0
- package/src/components/AtomixLogo/index.ts +3 -0
- package/src/components/AtomixLogo.tsx +40 -0
- package/src/components/Avatar/Avatar.stories.tsx +257 -0
- package/src/components/Avatar/Avatar.tsx +68 -0
- package/src/components/Avatar/AvatarGroup.tsx +73 -0
- package/src/components/Avatar/index.ts +3 -0
- package/src/components/Badge/Badge.stories.tsx +371 -0
- package/src/components/Badge/Badge.tsx +39 -0
- package/src/components/Badge/index.ts +3 -0
- package/src/components/Block/Block.stories.tsx +408 -0
- package/src/components/Block/Block.tsx +137 -0
- package/src/components/Block/index.ts +1 -0
- package/src/components/Breadcrumb/Breadcrumb.stories.tsx +106 -0
- package/src/components/Breadcrumb/Breadcrumb.tsx +112 -0
- package/src/components/Breadcrumb/index.ts +3 -0
- package/src/components/Button/Button.stories.tsx +312 -0
- package/src/components/Button/Button.tsx +69 -0
- package/src/components/Button/index.ts +3 -0
- package/src/components/Callout/Callout.stories.tsx +588 -0
- package/src/components/Callout/Callout.tsx +78 -0
- package/src/components/Callout/index.ts +1 -0
- package/src/components/Card/Card.stories.tsx +105 -0
- package/src/components/Card/Card.tsx +69 -0
- package/src/components/Card/ElevationCard.tsx +47 -0
- package/src/components/Card/index.ts +15 -0
- package/src/components/Chart/AdvancedChart.tsx +624 -0
- package/src/components/Chart/AnimatedChart.tsx +206 -0
- package/src/components/Chart/AreaChart.tsx +27 -0
- package/src/components/Chart/BarChart.tsx +148 -0
- package/src/components/Chart/BubbleChart.tsx +411 -0
- package/src/components/Chart/CandlestickChart.tsx +765 -0
- package/src/components/Chart/Chart.stories.tsx +527 -0
- package/src/components/Chart/Chart.tsx +218 -0
- package/src/components/Chart/ChartRenderer.tsx +322 -0
- package/src/components/Chart/ChartToolbar.tsx +436 -0
- package/src/components/Chart/ChartTooltip.tsx +101 -0
- package/src/components/Chart/DonutChart.tsx +370 -0
- package/src/components/Chart/FunnelChart.tsx +393 -0
- package/src/components/Chart/GaugeChart.tsx +550 -0
- package/src/components/Chart/HeatmapChart.tsx +614 -0
- package/src/components/Chart/LineChart.tsx +172 -0
- package/src/components/Chart/LineChartNew.tsx +167 -0
- package/src/components/Chart/MultiAxisChart.tsx +498 -0
- package/src/components/Chart/PieChart.tsx +103 -0
- package/src/components/Chart/RadarChart.tsx +332 -0
- package/src/components/Chart/RealTimeChart.tsx +436 -0
- package/src/components/Chart/ScatterChart.tsx +152 -0
- package/src/components/Chart/TreemapChart.tsx +574 -0
- package/src/components/Chart/WaterfallChart.tsx +450 -0
- package/src/components/Chart/index.ts +119 -0
- package/src/components/Chart/types.ts +338 -0
- package/src/components/ColorModeToggle/ColorModeToggle.stories.tsx +44 -0
- package/src/components/ColorModeToggle/ColorModeToggle.tsx +85 -0
- package/src/components/ColorModeToggle/index.ts +2 -0
- package/src/components/Countdown/Countdown.stories.tsx +46 -0
- package/src/components/Countdown/Countdown.tsx +90 -0
- package/src/components/Countdown/index.ts +2 -0
- package/src/components/DataTable/DataTable.stories.tsx +248 -0
- package/src/components/DataTable/DataTable.tsx +213 -0
- package/src/components/DataTable/index.ts +3 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +364 -0
- package/src/components/DatePicker/DatePicker.tsx +504 -0
- package/src/components/DatePicker/index.ts +4 -0
- package/src/components/DatePicker/readme.md +106 -0
- package/src/components/DatePicker/types.ts +167 -0
- package/src/components/DatePicker/utils.ts +185 -0
- package/src/components/Dropdown/Dropdown.stories.tsx +358 -0
- package/src/components/Dropdown/Dropdown.tsx +352 -0
- package/src/components/Dropdown/index.ts +14 -0
- package/src/components/Dropdown/readme.md +151 -0
- package/src/components/EdgePanel/EdgePanel.stories.tsx +266 -0
- package/src/components/EdgePanel/EdgePanel.tsx +73 -0
- package/src/components/EdgePanel/index.ts +1 -0
- package/src/components/Form/Checkbox.stories.tsx +76 -0
- package/src/components/Form/Checkbox.tsx +69 -0
- package/src/components/Form/Form.stories.tsx +497 -0
- package/src/components/Form/Form.tsx +46 -0
- package/src/components/Form/FormGroup.stories.tsx +162 -0
- package/src/components/Form/FormGroup.tsx +53 -0
- package/src/components/Form/Input.stories.tsx +106 -0
- package/src/components/Form/Input.tsx +87 -0
- package/src/components/Form/Radio.stories.tsx +94 -0
- package/src/components/Form/Radio.tsx +65 -0
- package/src/components/Form/Select.stories.tsx +151 -0
- package/src/components/Form/Select.tsx +191 -0
- package/src/components/Form/Textarea.stories.tsx +123 -0
- package/src/components/Form/Textarea.tsx +78 -0
- package/src/components/Form/index.ts +7 -0
- package/src/components/Hero/Hero.stories.tsx +295 -0
- package/src/components/Hero/Hero.tsx +175 -0
- package/src/components/Hero/index.ts +6 -0
- package/src/components/Icon/Icon.tsx +87 -0
- package/src/components/Icon/index.ts +2 -0
- package/src/components/List/List.stories.tsx +122 -0
- package/src/components/List/List.tsx +35 -0
- package/src/components/List/ListGroup.tsx +35 -0
- package/src/components/List/index.ts +2 -0
- package/src/components/Messages/Messages.stories.tsx +160 -0
- package/src/components/Messages/Messages.tsx +172 -0
- package/src/components/Messages/index.ts +3 -0
- package/src/components/Modal/Modal.stories.tsx +284 -0
- package/src/components/Modal/Modal.tsx +198 -0
- package/src/components/Modal/README.md +169 -0
- package/src/components/Modal/index.ts +1 -0
- package/src/components/Navigation/Menu/MegaMenu.tsx +109 -0
- package/src/components/Navigation/Menu/Menu.stories.tsx +339 -0
- package/src/components/Navigation/Menu/Menu.tsx +111 -0
- package/src/components/Navigation/Nav/Nav.stories.tsx +456 -0
- package/src/components/Navigation/Nav/Nav.tsx +51 -0
- package/src/components/Navigation/Nav/NavDropdown.tsx +105 -0
- package/src/components/Navigation/Nav/NavItem.tsx +168 -0
- package/src/components/Navigation/Navbar/Navbar.stories.tsx +569 -0
- package/src/components/Navigation/Navbar/Navbar.tsx +150 -0
- package/src/components/Navigation/README.md +314 -0
- package/src/components/Navigation/SideMenu/SideMenu.README.md +494 -0
- package/src/components/Navigation/SideMenu/SideMenu.stories.tsx +609 -0
- package/src/components/Navigation/SideMenu/SideMenu.tsx +101 -0
- package/src/components/Navigation/SideMenu/SideMenuItem.tsx +103 -0
- package/src/components/Navigation/SideMenu/SideMenuList.tsx +41 -0
- package/src/components/Navigation/index.ts +23 -0
- package/src/components/Pagination/Pagination.stories.tsx +188 -0
- package/src/components/Pagination/Pagination.tsx +162 -0
- package/src/components/Pagination/index.ts +1 -0
- package/src/components/PhotoViewer/PhotoViewer.stories.tsx +397 -0
- package/src/components/PhotoViewer/PhotoViewer.tsx +246 -0
- package/src/components/PhotoViewer/PhotoViewerHeader.tsx +184 -0
- package/src/components/PhotoViewer/PhotoViewerImage.tsx +173 -0
- package/src/components/PhotoViewer/PhotoViewerInfo.tsx +91 -0
- package/src/components/PhotoViewer/PhotoViewerNavigation.tsx +85 -0
- package/src/components/PhotoViewer/PhotoViewerThumbnails.tsx +63 -0
- package/src/components/PhotoViewer/README.md +358 -0
- package/src/components/PhotoViewer/examples/ImageGallery.tsx +187 -0
- package/src/components/PhotoViewer/examples/SimpleGallery.tsx +73 -0
- package/src/components/PhotoViewer/examples/index.ts +2 -0
- package/src/components/PhotoViewer/index.ts +14 -0
- package/src/components/Popover/Popover.stories.tsx +143 -0
- package/src/components/Popover/Popover.tsx +137 -0
- package/src/components/Popover/index.ts +5 -0
- package/src/components/Popover/readme.md +120 -0
- package/src/components/ProductReview/ProductReview.stories.tsx +88 -0
- package/src/components/ProductReview/ProductReview.tsx +169 -0
- package/src/components/ProductReview/index.ts +3 -0
- package/src/components/Progress/Progress.stories.tsx +75 -0
- package/src/components/Progress/Progress.tsx +45 -0
- package/src/components/Progress/index.ts +1 -0
- package/src/components/Rating/Rating.stories.tsx +109 -0
- package/src/components/Rating/Rating.tsx +286 -0
- package/src/components/Rating/index.ts +6 -0
- package/src/components/River/River.stories.tsx +230 -0
- package/src/components/River/River.tsx +134 -0
- package/src/components/River/index.ts +2 -0
- package/src/components/SectionIntro/SectionIntro.stories.tsx +143 -0
- package/src/components/SectionIntro/SectionIntro.tsx +184 -0
- package/src/components/SectionIntro/index.ts +3 -0
- package/src/components/Slider/Slider.stories.tsx +241 -0
- package/src/components/Slider/Slider.tsx +225 -0
- package/src/components/Slider/index.ts +24 -0
- package/src/components/Spinner/Spinner.stories.tsx +65 -0
- package/src/components/Spinner/Spinner.tsx +36 -0
- package/src/components/Spinner/index.ts +2 -0
- package/src/components/Steps/Steps.stories.tsx +158 -0
- package/src/components/Steps/Steps.tsx +115 -0
- package/src/components/Steps/index.ts +3 -0
- package/src/components/Tab/Tab.stories.tsx +129 -0
- package/src/components/Tab/Tab.tsx +111 -0
- package/src/components/Tab/index.ts +2 -0
- package/src/components/Testimonial/Testimonial.stories.tsx +180 -0
- package/src/components/Testimonial/Testimonial.tsx +138 -0
- package/src/components/Testimonial/index.ts +3 -0
- package/src/components/Todo/Todo.stories.tsx +103 -0
- package/src/components/Todo/Todo.tsx +158 -0
- package/src/components/Todo/index.ts +1 -0
- package/src/components/Toggle/Toggle.stories.tsx +49 -0
- package/src/components/Toggle/Toggle.tsx +84 -0
- package/src/components/Toggle/index.ts +2 -0
- package/src/components/Tooltip/Tooltip.stories.tsx +115 -0
- package/src/components/Tooltip/Tooltip.tsx +150 -0
- package/src/components/Tooltip/index.ts +3 -0
- package/src/components/Upload/Upload.stories.tsx +220 -0
- package/src/components/Upload/Upload.tsx +354 -0
- package/src/components/Upload/index.ts +3 -0
- package/src/components/VideoPlayer/VideoPlayer.stories.tsx +484 -0
- package/src/components/VideoPlayer/VideoPlayer.tsx +574 -0
- package/src/components/VideoPlayer/index.ts +7 -0
- package/src/components/index.ts +111 -0
- package/src/layouts/Grid/Container.tsx +58 -0
- package/src/layouts/Grid/Grid.stories.tsx +861 -0
- package/src/layouts/Grid/Grid.tsx +68 -0
- package/src/layouts/Grid/GridCol.tsx +161 -0
- package/src/layouts/Grid/README.md +108 -0
- package/src/layouts/Grid/Row.tsx +70 -0
- package/src/layouts/Grid/index.ts +8 -0
- package/src/layouts/MasonryGrid/MasonryGrid.stories.tsx +387 -0
- package/src/layouts/MasonryGrid/MasonryGrid.tsx +408 -0
- package/src/layouts/MasonryGrid/MasonryGridItem.tsx +44 -0
- package/src/layouts/MasonryGrid/README.md +117 -0
- package/src/layouts/MasonryGrid/index.ts +4 -0
- package/src/layouts/index.ts +7 -0
- package/src/lib/README.md +89 -0
- package/src/lib/composables/index.ts +63 -0
- package/src/lib/composables/useAccordion.ts +129 -0
- package/src/lib/composables/useAmbientMode.ts +90 -0
- package/src/lib/composables/useBadge.ts +42 -0
- package/src/lib/composables/useBarChart.ts +365 -0
- package/src/lib/composables/useBlock.ts +56 -0
- package/src/lib/composables/useBreadcrumb.ts +81 -0
- package/src/lib/composables/useButton.ts +59 -0
- package/src/lib/composables/useCallout.ts +55 -0
- package/src/lib/composables/useCard.ts +155 -0
- package/src/lib/composables/useChart.ts +1082 -0
- package/src/lib/composables/useChartAnalytics.ts +505 -0
- package/src/lib/composables/useChartData.ts +38 -0
- package/src/lib/composables/useChartExport.ts +392 -0
- package/src/lib/composables/useChartInteraction.ts +34 -0
- package/src/lib/composables/useChartInteractions.ts +123 -0
- package/src/lib/composables/useChartPerformance.ts +323 -0
- package/src/lib/composables/useChartScale.ts +48 -0
- package/src/lib/composables/useChartToolbar.ts +532 -0
- package/src/lib/composables/useCheckbox.ts +70 -0
- package/src/lib/composables/useDataTable.ts +208 -0
- package/src/lib/composables/useDatePicker.ts +564 -0
- package/src/lib/composables/useDropdown.ts +272 -0
- package/src/lib/composables/useEdgePanel.ts +261 -0
- package/src/lib/composables/useForm.ts +62 -0
- package/src/lib/composables/useFormGroup.ts +51 -0
- package/src/lib/composables/useHero.ts +250 -0
- package/src/lib/composables/useInput.ts +58 -0
- package/src/lib/composables/useLineChart.ts +319 -0
- package/src/lib/composables/useMessages.ts +77 -0
- package/src/lib/composables/useModal.ts +110 -0
- package/src/lib/composables/useNavbar.ts +288 -0
- package/src/lib/composables/usePagination.ts +101 -0
- package/src/lib/composables/usePhotoViewer.ts +937 -0
- package/src/lib/composables/usePieChart.ts +362 -0
- package/src/lib/composables/usePopover.ts +354 -0
- package/src/lib/composables/useProgress.ts +74 -0
- package/src/lib/composables/useRadio.ts +47 -0
- package/src/lib/composables/useRating.ts +174 -0
- package/src/lib/composables/useRiver.ts +205 -0
- package/src/lib/composables/useSelect.ts +52 -0
- package/src/lib/composables/useSideMenu.ts +197 -0
- package/src/lib/composables/useSlider.ts +339 -0
- package/src/lib/composables/useSpinner.ts +42 -0
- package/src/lib/composables/useTextarea.ts +55 -0
- package/src/lib/composables/useTodo.ts +141 -0
- package/src/lib/composables/useVideoPlayer.ts +398 -0
- package/src/lib/constants/components.ts +1433 -0
- package/src/lib/constants/index.ts +4 -0
- package/src/lib/index.ts +11 -0
- package/src/lib/types/components.ts +4750 -0
- package/src/lib/types/index.ts +2 -0
- package/src/lib/utils/dom.ts +41 -0
- package/src/lib/utils/icons.ts +74 -0
- package/src/lib/utils/index.ts +55 -0
- package/src/lib/utils/useForkRef.test.tsx +64 -0
- package/src/lib/utils/useForkRef.ts +36 -0
- package/src/lib/utils.test.ts +14 -0
- package/src/styles/01-settings/_index.scss +2 -0
- package/src/styles/01-settings/_settings.accordion.scss +7 -5
- package/src/styles/01-settings/_settings.animations.scss +0 -0
- package/src/styles/01-settings/_settings.avatar-group.scss +6 -3
- package/src/styles/01-settings/_settings.avatar.scss +2 -2
- package/src/styles/01-settings/_settings.badge.scss +15 -9
- package/src/styles/01-settings/_settings.block.scss +11 -0
- package/src/styles/01-settings/_settings.border-radius.scss +12 -9
- package/src/styles/01-settings/_settings.border.scss +4 -1
- package/src/styles/01-settings/_settings.box-shadow.scss +1 -1
- package/src/styles/01-settings/_settings.breadcrumb.scss +9 -8
- package/src/styles/01-settings/_settings.breakpoints.scss +0 -0
- package/src/styles/01-settings/_settings.btn-group.scss +4 -1
- package/src/styles/01-settings/_settings.button.scss +19 -21
- package/src/styles/01-settings/_settings.callout.scss +42 -24
- package/src/styles/01-settings/_settings.card.scss +12 -10
- package/src/styles/01-settings/_settings.chart.scss +199 -0
- package/src/styles/01-settings/_settings.checkbox-group.scss +0 -0
- package/src/styles/01-settings/_settings.checkbox.scss +0 -0
- package/src/styles/01-settings/_settings.color-mode.scss +0 -0
- package/src/styles/01-settings/_settings.colors.scss +20 -0
- package/src/styles/01-settings/_settings.config.scss +1 -1
- package/src/styles/01-settings/_settings.countdown.scss +0 -0
- package/src/styles/01-settings/_settings.data-table.scss +0 -0
- package/src/styles/01-settings/_settings.datepicker.scss +0 -0
- package/src/styles/01-settings/_settings.dropdown.scss +0 -0
- package/src/styles/01-settings/_settings.edge-panel.scss +0 -0
- package/src/styles/01-settings/_settings.fonts.scss +1 -1
- package/src/styles/01-settings/_settings.form-group.scss +0 -0
- package/src/styles/01-settings/_settings.form.scss +0 -0
- package/src/styles/01-settings/_settings.grid.scss +3 -3
- package/src/styles/01-settings/_settings.hero.scss +1 -1
- package/src/styles/01-settings/_settings.input.scss +1 -1
- package/src/styles/01-settings/_settings.link.scss +0 -0
- package/src/styles/01-settings/_settings.list-group.scss +0 -0
- package/src/styles/01-settings/_settings.list.scss +0 -0
- package/src/styles/01-settings/_settings.maps.scss +43 -8
- package/src/styles/01-settings/_settings.masonry-grid.scss +0 -0
- package/src/styles/01-settings/_settings.menu.scss +0 -0
- package/src/styles/01-settings/_settings.messages.scss +0 -0
- package/src/styles/01-settings/_settings.modal.scss +1 -1
- package/src/styles/01-settings/_settings.nav.scss +0 -0
- package/src/styles/01-settings/_settings.navbar.scss +0 -0
- package/src/styles/01-settings/_settings.pagination.scss +0 -0
- package/src/styles/01-settings/_settings.photoviewer.scss +89 -23
- package/src/styles/01-settings/_settings.popover.scss +0 -0
- package/src/styles/01-settings/_settings.position.scss +0 -0
- package/src/styles/01-settings/_settings.progress.scss +0 -0
- package/src/styles/01-settings/_settings.rating.scss +0 -0
- package/src/styles/01-settings/_settings.river.scss +0 -0
- package/src/styles/01-settings/_settings.sectionintro.scss +0 -0
- package/src/styles/01-settings/_settings.select.scss +0 -0
- package/src/styles/01-settings/_settings.side-menu.scss +0 -0
- package/src/styles/01-settings/_settings.skeleton.scss +0 -0
- package/src/styles/01-settings/_settings.slider.scss +59 -0
- package/src/styles/01-settings/_settings.spacing.scss +11 -3
- package/src/styles/01-settings/_settings.spinner.scss +0 -0
- package/src/styles/01-settings/_settings.steps.scss +1 -1
- package/src/styles/01-settings/_settings.tabs.scss +4 -4
- package/src/styles/01-settings/_settings.testimonials.scss +0 -0
- package/src/styles/01-settings/_settings.todo.scss +0 -0
- package/src/styles/01-settings/_settings.toggle.scss +1 -1
- package/src/styles/01-settings/_settings.tooltip.scss +0 -0
- package/src/styles/01-settings/_settings.typography.scss +2 -0
- package/src/styles/01-settings/_settings.upload.scss +0 -0
- package/src/styles/01-settings/_settings.video-player.scss +64 -0
- package/src/styles/01-settings/_settings.z-layers.scss +0 -0
- package/src/styles/02-tools/_index.scss +1 -0
- package/src/styles/02-tools/_tools.animations.scss +82 -0
- package/src/styles/02-tools/_tools.border-radius.scss +0 -0
- package/src/styles/02-tools/_tools.breakpoints.scss +0 -0
- package/src/styles/02-tools/_tools.button.scss +5 -0
- package/src/styles/02-tools/_tools.clearfix.scss +0 -0
- package/src/styles/02-tools/_tools.color-functions.scss +0 -0
- package/src/styles/02-tools/_tools.color-mode.scss +1 -1
- package/src/styles/02-tools/_tools.component.scss +479 -0
- package/src/styles/02-tools/_tools.event.scss +0 -0
- package/src/styles/02-tools/_tools.grid.scss +0 -0
- package/src/styles/02-tools/_tools.hidden-visually.scss +0 -0
- package/src/styles/02-tools/_tools.hidden.scss +0 -0
- package/src/styles/02-tools/_tools.map-loop.scss +0 -0
- package/src/styles/02-tools/_tools.media-queries.scss +0 -0
- package/src/styles/02-tools/_tools.object-fit.scss +0 -0
- package/src/styles/02-tools/_tools.placeholder.scss +0 -0
- package/src/styles/02-tools/_tools.rem.scss +5 -1
- package/src/styles/02-tools/_tools.size.scss +0 -0
- package/src/styles/02-tools/_tools.spacing.scss +0 -0
- package/src/styles/02-tools/_tools.to-rgb.scss +0 -0
- package/src/styles/02-tools/_tools.transition.scss +0 -0
- package/src/styles/02-tools/_tools.utilities.scss +0 -0
- package/src/styles/02-tools/_tools.utility-api.scss +23 -2
- package/src/styles/03-generic/_generic.fonts.scss +0 -0
- package/src/styles/03-generic/_generic.reset.scss +0 -0
- package/src/styles/03-generic/_generic.root.scss +5 -1
- package/src/styles/03-generic/_generic.selection.scss +0 -0
- package/src/styles/03-generic/_index.scss +0 -0
- package/src/styles/04-elements/_elements.all.scss +0 -0
- package/src/styles/04-elements/_elements.body.scss +0 -0
- package/src/styles/04-elements/_elements.heading.scss +0 -0
- package/src/styles/04-elements/_elements.html.scss +0 -0
- package/src/styles/04-elements/_elements.links.scss +0 -0
- package/src/styles/04-elements/_index.scss +0 -0
- package/src/styles/05-objects/_index.scss +1 -0
- package/src/styles/05-objects/_objects.block.scss +122 -0
- package/src/styles/05-objects/_objects.container.scss +14 -10
- package/src/styles/05-objects/_objects.grid.scss +0 -0
- package/src/styles/05-objects/_objects.masonry-grid.scss +0 -0
- package/src/styles/06-components/_components.accordion.scss +3 -1
- package/src/styles/06-components/_components.avatar-group.scss +0 -0
- package/src/styles/06-components/_components.avatar.scss +0 -0
- package/src/styles/06-components/_components.badge.scss +9 -9
- package/src/styles/06-components/_components.breadcrumb.scss +0 -0
- package/src/styles/06-components/_components.btn-group.scss +0 -0
- package/src/styles/06-components/_components.button.scss +0 -0
- package/src/styles/06-components/_components.callout.scss +2 -1
- package/src/styles/06-components/_components.card.scss +0 -1
- package/src/styles/06-components/_components.chart.scss +2102 -0
- package/src/styles/06-components/_components.checkbox-group.scss +0 -0
- package/src/styles/06-components/_components.checkbox.scss +0 -0
- package/src/styles/06-components/_components.color-mode-toggle.scss +0 -0
- package/src/styles/06-components/_components.countdown.scss +0 -0
- package/src/styles/06-components/_components.data-table.scss +0 -0
- package/src/styles/06-components/_components.datepicker.scss +0 -0
- package/src/styles/06-components/_components.dropdown.scss +0 -0
- package/src/styles/06-components/_components.edge-panel.scss +0 -0
- package/src/styles/06-components/_components.form-group.scss +0 -0
- package/src/styles/06-components/_components.form.scss +0 -0
- package/src/styles/06-components/_components.hero.scss +1 -0
- package/src/styles/06-components/_components.icon.scss +2 -2
- package/src/styles/06-components/_components.image-gallery.scss +0 -0
- package/src/styles/06-components/_components.input.scss +0 -0
- package/src/styles/06-components/_components.list-group.scss +0 -0
- package/src/styles/06-components/_components.list.scss +0 -0
- package/src/styles/06-components/_components.menu.scss +0 -0
- package/src/styles/06-components/_components.messages.scss +0 -0
- package/src/styles/06-components/_components.modal.scss +3 -0
- package/src/styles/06-components/_components.nav.scss +0 -0
- package/src/styles/06-components/_components.navbar.scss +0 -0
- package/src/styles/06-components/_components.pagination.scss +0 -0
- package/src/styles/06-components/_components.photoviewer.scss +603 -545
- package/src/styles/06-components/_components.popover.scss +0 -0
- package/src/styles/06-components/_components.product-review.scss +0 -0
- package/src/styles/06-components/_components.progress.scss +0 -0
- package/src/styles/06-components/_components.rating.scss +0 -0
- package/src/styles/06-components/_components.river.scss +0 -0
- package/src/styles/06-components/_components.sectionintro.scss +0 -0
- package/src/styles/06-components/_components.select.scss +0 -0
- package/src/styles/06-components/_components.side-menu.scss +0 -0
- package/src/styles/06-components/_components.skeleton.scss +0 -0
- package/src/styles/06-components/_components.slider.scss +273 -0
- package/src/styles/06-components/_components.spinner.scss +0 -0
- package/src/styles/06-components/_components.steps.scss +1 -0
- package/src/styles/06-components/_components.tabs.scss +0 -0
- package/src/styles/06-components/_components.testimonials.scss +0 -0
- package/src/styles/06-components/_components.todo.scss +0 -0
- package/src/styles/06-components/_components.toggle.scss +0 -0
- package/src/styles/06-components/_components.tooltip.scss +4 -9
- package/src/styles/06-components/_components.upload.scss +0 -0
- package/src/styles/06-components/_components.video-player.scss +623 -0
- package/src/styles/06-components/_index.scss +3 -0
- package/src/styles/06-components/old.chart.styles.scss +2819 -0
- package/src/styles/99-utilities/_index.scss +0 -0
- package/src/styles/99-utilities/_utilities.background.scss +0 -0
- package/src/styles/99-utilities/_utilities.border.scss +0 -0
- package/src/styles/99-utilities/_utilities.clearfix.scss +0 -0
- package/src/styles/99-utilities/_utilities.display.scss +0 -0
- package/src/styles/99-utilities/_utilities.flex.scss +0 -0
- package/src/styles/99-utilities/_utilities.link.scss +0 -0
- package/src/styles/99-utilities/_utilities.object-fit.scss +0 -0
- package/src/styles/99-utilities/_utilities.opacity.scss +0 -0
- package/src/styles/99-utilities/_utilities.overflow.scss +0 -0
- package/src/styles/99-utilities/_utilities.position.scss +0 -0
- package/src/styles/99-utilities/_utilities.scss +2 -1
- package/src/styles/99-utilities/_utilities.shadow.scss +0 -0
- package/src/styles/99-utilities/_utilities.sizes.scss +0 -0
- package/src/styles/99-utilities/_utilities.spacing.scss +0 -0
- package/src/styles/99-utilities/_utilities.text.scss +5 -0
- package/src/styles/99-utilities/_utilities.visibility.scss +0 -0
- package/src/styles/99-utilities/_utilities.visually-hidden.scss +0 -0
- package/src/styles/99-utilities/_utilities.z-index.scss +0 -0
- package/src/styles/css-modules.d.ts +0 -0
- package/src/styles/index.scss +0 -0
- package/dist/index.css +0 -15
- package/dist/index.esm.css +0 -15
- package/dist/index.min.css +0 -15
|
@@ -0,0 +1,1082 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { CHART } from '../constants/components';
|
|
3
|
+
import { ChartDataset, ChartProps } from '../types/components';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Chart interaction state interface
|
|
7
|
+
*/
|
|
8
|
+
export interface ChartInteractionState {
|
|
9
|
+
hoveredPoint: {
|
|
10
|
+
datasetIndex: number;
|
|
11
|
+
pointIndex: number;
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
clientX: number;
|
|
15
|
+
clientY: number;
|
|
16
|
+
} | null;
|
|
17
|
+
selectedPoints: Array<{ datasetIndex: number; pointIndex: number }>;
|
|
18
|
+
zoomLevel: number;
|
|
19
|
+
panOffset: { x: number; y: number };
|
|
20
|
+
isAnimating: boolean;
|
|
21
|
+
isDragging: boolean;
|
|
22
|
+
dragStart: { x: number; y: number } | null;
|
|
23
|
+
crosshair: { x: number; y: number } | null;
|
|
24
|
+
brushSelection: { start: number; end: number } | null;
|
|
25
|
+
focusedPointIndex: number;
|
|
26
|
+
// Touch and pen support
|
|
27
|
+
touchState: {
|
|
28
|
+
touches: Array<{ id: number; x: number; y: number }>;
|
|
29
|
+
lastDistance: number;
|
|
30
|
+
isPinching: boolean;
|
|
31
|
+
isTouch: boolean;
|
|
32
|
+
lastTouchTime: number;
|
|
33
|
+
};
|
|
34
|
+
penState: {
|
|
35
|
+
isPen: boolean;
|
|
36
|
+
pressure: number;
|
|
37
|
+
tiltX: number;
|
|
38
|
+
tiltY: number;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Chart scales interface
|
|
44
|
+
*/
|
|
45
|
+
export interface ChartScales {
|
|
46
|
+
xScale: (index: number, dataLength?: number) => number;
|
|
47
|
+
yScale: (value: number) => number;
|
|
48
|
+
minValue: number;
|
|
49
|
+
maxValue: number;
|
|
50
|
+
valueRange: number;
|
|
51
|
+
innerWidth: number;
|
|
52
|
+
innerHeight: number;
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
padding: { top: number; right: number; bottom: number; left: number };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Comprehensive chart hook with shared functionality
|
|
60
|
+
* @param initialProps - Initial chart properties
|
|
61
|
+
* @returns Chart state and methods
|
|
62
|
+
*/
|
|
63
|
+
export function useChart(initialProps?: Partial<ChartProps>) {
|
|
64
|
+
const [interactionState, setInteractionState] = useState<ChartInteractionState>({
|
|
65
|
+
hoveredPoint: null,
|
|
66
|
+
selectedPoints: [],
|
|
67
|
+
zoomLevel: 1,
|
|
68
|
+
panOffset: { x: 0, y: 0 },
|
|
69
|
+
isAnimating: false,
|
|
70
|
+
isDragging: false,
|
|
71
|
+
dragStart: null,
|
|
72
|
+
crosshair: null,
|
|
73
|
+
brushSelection: null,
|
|
74
|
+
focusedPointIndex: 0,
|
|
75
|
+
touchState: {
|
|
76
|
+
touches: [],
|
|
77
|
+
lastDistance: 0,
|
|
78
|
+
isPinching: false,
|
|
79
|
+
isTouch: false,
|
|
80
|
+
lastTouchTime: 0,
|
|
81
|
+
},
|
|
82
|
+
penState: {
|
|
83
|
+
isPen: false,
|
|
84
|
+
pressure: 0,
|
|
85
|
+
tiltX: 0,
|
|
86
|
+
tiltY: 0,
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Default chart properties
|
|
91
|
+
const defaultProps: Partial<ChartProps> = {
|
|
92
|
+
type: 'line',
|
|
93
|
+
size: 'md',
|
|
94
|
+
variant: 'primary',
|
|
95
|
+
loading: false,
|
|
96
|
+
interactive: true,
|
|
97
|
+
...initialProps,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// Animation frame ref for smooth updates
|
|
101
|
+
const animationFrameRef = useRef<number | null>(null);
|
|
102
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
103
|
+
const svgRef = useRef<SVGSVGElement>(null);
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Generate chart class based on properties
|
|
107
|
+
*/
|
|
108
|
+
const generateChartClass = useCallback(
|
|
109
|
+
(props: Partial<ChartProps>): string => {
|
|
110
|
+
const {
|
|
111
|
+
type = defaultProps.type,
|
|
112
|
+
size = defaultProps.size,
|
|
113
|
+
variant = defaultProps.variant,
|
|
114
|
+
loading = defaultProps.loading,
|
|
115
|
+
error,
|
|
116
|
+
className = '',
|
|
117
|
+
} = props;
|
|
118
|
+
|
|
119
|
+
const typeClass = type ? `${CHART.TYPE_PREFIX}${type}` : '';
|
|
120
|
+
const sizeClass = size === 'md' ? '' : `${CHART.SIZE_PREFIX}${size}`;
|
|
121
|
+
const variantClass = variant ? `${CHART.VARIANT_PREFIX}${variant}` : '';
|
|
122
|
+
const loadingClass = loading ? CHART.LOADING_STATE_CLASS : '';
|
|
123
|
+
const errorClass = error ? CHART.ERROR_STATE_CLASS : '';
|
|
124
|
+
|
|
125
|
+
return `${CHART.BASE_CLASS} ${typeClass} ${variantClass} ${sizeClass} ${loadingClass} ${errorClass} ${className}`.trim();
|
|
126
|
+
},
|
|
127
|
+
[defaultProps]
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Generate chart attributes for accessibility
|
|
132
|
+
*/
|
|
133
|
+
const generateChartAttributes = useCallback((props: Partial<ChartProps>) => {
|
|
134
|
+
const { loading, error, type } = props;
|
|
135
|
+
|
|
136
|
+
const attributes: Record<string, string> = {
|
|
137
|
+
role: 'img',
|
|
138
|
+
'aria-live': 'polite',
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
if (loading) {
|
|
142
|
+
attributes['aria-busy'] = 'true';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (error) {
|
|
146
|
+
attributes['aria-invalid'] = 'true';
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (type) {
|
|
150
|
+
attributes['data-chart-type'] = type;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return attributes;
|
|
154
|
+
}, []);
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Calculate chart dimensions and scales with zoom and pan support
|
|
158
|
+
*/
|
|
159
|
+
const calculateScales = useCallback(
|
|
160
|
+
(
|
|
161
|
+
datasets: ChartDataset[],
|
|
162
|
+
width: number = CHART.DEFAULT_WIDTH,
|
|
163
|
+
height: number = CHART.DEFAULT_HEIGHT,
|
|
164
|
+
padding = { top: 20, right: 30, bottom: 40, left: 50 },
|
|
165
|
+
config?: any
|
|
166
|
+
): ChartScales | null => {
|
|
167
|
+
if (!datasets.length) return null;
|
|
168
|
+
|
|
169
|
+
const innerWidth = width - padding.left - padding.right;
|
|
170
|
+
const innerHeight = height - padding.top - padding.bottom;
|
|
171
|
+
|
|
172
|
+
// Calculate value bounds
|
|
173
|
+
const allValues = datasets.flatMap(
|
|
174
|
+
dataset => dataset.data?.map(d => (typeof d.value === 'number' ? d.value : 0)) || []
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
if (allValues.length === 0) return null;
|
|
178
|
+
|
|
179
|
+
const minValue = config?.yAxis?.min ?? Math.min(0, ...allValues);
|
|
180
|
+
const maxValue = config?.yAxis?.max ?? Math.max(...allValues, 1);
|
|
181
|
+
const valueRange = maxValue - minValue;
|
|
182
|
+
|
|
183
|
+
// Scale functions with zoom and pan support
|
|
184
|
+
const xScale = (index: number, dataLength?: number) => {
|
|
185
|
+
const totalLength = dataLength || datasets[0]?.data?.length || 1;
|
|
186
|
+
if (totalLength <= 1) return padding.left + innerWidth / 2;
|
|
187
|
+
|
|
188
|
+
const baseX = padding.left + (index / (totalLength - 1)) * innerWidth;
|
|
189
|
+
return baseX * interactionState.zoomLevel + interactionState.panOffset.x;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const yScale = (value: number) => {
|
|
193
|
+
if (valueRange === 0) return padding.top + innerHeight / 2;
|
|
194
|
+
|
|
195
|
+
const baseY = padding.top + innerHeight - ((value - minValue) / valueRange) * innerHeight;
|
|
196
|
+
return baseY * interactionState.zoomLevel + interactionState.panOffset.y;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
xScale,
|
|
201
|
+
yScale,
|
|
202
|
+
minValue,
|
|
203
|
+
maxValue,
|
|
204
|
+
valueRange,
|
|
205
|
+
innerWidth,
|
|
206
|
+
innerHeight,
|
|
207
|
+
width,
|
|
208
|
+
height,
|
|
209
|
+
padding,
|
|
210
|
+
};
|
|
211
|
+
},
|
|
212
|
+
[interactionState.zoomLevel, interactionState.panOffset]
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Generate color palette using CSS custom properties
|
|
217
|
+
*/
|
|
218
|
+
const getChartColors = useCallback((count: number) => {
|
|
219
|
+
const colors = [
|
|
220
|
+
'var(--atomix-primary)',
|
|
221
|
+
'var(--atomix-secondary)',
|
|
222
|
+
'var(--atomix-success)',
|
|
223
|
+
'var(--atomix-info)',
|
|
224
|
+
'var(--atomix-warning)',
|
|
225
|
+
'var(--atomix-error)',
|
|
226
|
+
'var(--atomix-primary-5)',
|
|
227
|
+
'var(--atomix-primary-7)',
|
|
228
|
+
'var(--atomix-primary-3)',
|
|
229
|
+
'var(--atomix-gray-6)',
|
|
230
|
+
'var(--atomix-gray-8)',
|
|
231
|
+
'var(--atomix-gray-4)',
|
|
232
|
+
];
|
|
233
|
+
|
|
234
|
+
return Array.from({ length: count }, (_, i) => colors[i % colors.length]);
|
|
235
|
+
}, []);
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Enhanced point interaction handlers
|
|
239
|
+
*/
|
|
240
|
+
const handlePointHover = useCallback(
|
|
241
|
+
(
|
|
242
|
+
datasetIndex: number,
|
|
243
|
+
pointIndex: number,
|
|
244
|
+
x: number,
|
|
245
|
+
y: number,
|
|
246
|
+
clientX: number,
|
|
247
|
+
clientY: number
|
|
248
|
+
) => {
|
|
249
|
+
setInteractionState(prev => ({
|
|
250
|
+
...prev,
|
|
251
|
+
hoveredPoint: { datasetIndex, pointIndex, x, y, clientX, clientY },
|
|
252
|
+
focusedPointIndex: pointIndex,
|
|
253
|
+
}));
|
|
254
|
+
},
|
|
255
|
+
[]
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
const handlePointLeave = useCallback(() => {
|
|
259
|
+
setInteractionState(prev => ({
|
|
260
|
+
...prev,
|
|
261
|
+
hoveredPoint: null,
|
|
262
|
+
}));
|
|
263
|
+
}, []);
|
|
264
|
+
|
|
265
|
+
const handlePointClick = useCallback(
|
|
266
|
+
(datasetIndex: number, pointIndex: number, multiSelect: boolean = false) => {
|
|
267
|
+
setInteractionState(prev => {
|
|
268
|
+
const pointKey = { datasetIndex, pointIndex };
|
|
269
|
+
const existingIndex = prev.selectedPoints.findIndex(
|
|
270
|
+
p => p.datasetIndex === datasetIndex && p.pointIndex === pointIndex
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
let newSelectedPoints;
|
|
274
|
+
if (existingIndex >= 0) {
|
|
275
|
+
// Remove if already selected
|
|
276
|
+
newSelectedPoints = prev.selectedPoints.filter((_, i) => i !== existingIndex);
|
|
277
|
+
} else {
|
|
278
|
+
// Add to selection
|
|
279
|
+
newSelectedPoints = multiSelect ? [...prev.selectedPoints, pointKey] : [pointKey];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return {
|
|
283
|
+
...prev,
|
|
284
|
+
selectedPoints: newSelectedPoints,
|
|
285
|
+
};
|
|
286
|
+
});
|
|
287
|
+
},
|
|
288
|
+
[]
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Enhanced zoom and pan handlers
|
|
293
|
+
*/
|
|
294
|
+
const handleZoom = useCallback((delta: number, centerX: number, centerY?: number) => {
|
|
295
|
+
setInteractionState(prev => {
|
|
296
|
+
const zoomFactor = 1 - delta * 0.001;
|
|
297
|
+
const newZoomLevel = Math.max(0.1, Math.min(10, prev.zoomLevel * zoomFactor));
|
|
298
|
+
|
|
299
|
+
// Adjust pan offset to zoom towards the center point
|
|
300
|
+
const zoomRatio = newZoomLevel / prev.zoomLevel;
|
|
301
|
+
const newPanOffset = {
|
|
302
|
+
x: centerX - (centerX - prev.panOffset.x) * zoomRatio,
|
|
303
|
+
y: centerY ? centerY - (centerY - prev.panOffset.y) * zoomRatio : prev.panOffset.y,
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
return {
|
|
307
|
+
...prev,
|
|
308
|
+
zoomLevel: newZoomLevel,
|
|
309
|
+
panOffset: newPanOffset,
|
|
310
|
+
};
|
|
311
|
+
});
|
|
312
|
+
}, []);
|
|
313
|
+
|
|
314
|
+
const handlePan = useCallback((deltaX: number, deltaY: number) => {
|
|
315
|
+
setInteractionState(prev => ({
|
|
316
|
+
...prev,
|
|
317
|
+
panOffset: {
|
|
318
|
+
x: prev.panOffset.x + deltaX,
|
|
319
|
+
y: prev.panOffset.y + deltaY,
|
|
320
|
+
},
|
|
321
|
+
}));
|
|
322
|
+
}, []);
|
|
323
|
+
|
|
324
|
+
const handleDragStart = useCallback((x: number, y: number) => {
|
|
325
|
+
setInteractionState(prev => ({
|
|
326
|
+
...prev,
|
|
327
|
+
isDragging: true,
|
|
328
|
+
dragStart: { x, y },
|
|
329
|
+
}));
|
|
330
|
+
}, []);
|
|
331
|
+
|
|
332
|
+
const handleDragEnd = useCallback(() => {
|
|
333
|
+
setInteractionState(prev => ({
|
|
334
|
+
...prev,
|
|
335
|
+
isDragging: false,
|
|
336
|
+
dragStart: null,
|
|
337
|
+
}));
|
|
338
|
+
}, []);
|
|
339
|
+
|
|
340
|
+
const handleCrosshair = useCallback((x: number, y: number) => {
|
|
341
|
+
setInteractionState(prev => ({
|
|
342
|
+
...prev,
|
|
343
|
+
crosshair: { x, y },
|
|
344
|
+
}));
|
|
345
|
+
}, []);
|
|
346
|
+
|
|
347
|
+
const clearCrosshair = useCallback(() => {
|
|
348
|
+
setInteractionState(prev => ({
|
|
349
|
+
...prev,
|
|
350
|
+
crosshair: null,
|
|
351
|
+
}));
|
|
352
|
+
}, []);
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Touch and pen interaction handlers
|
|
356
|
+
*/
|
|
357
|
+
const handleTouchStart = useCallback((event: TouchEvent | React.TouchEvent) => {
|
|
358
|
+
const touches = Array.from(event.touches).map(touch => ({
|
|
359
|
+
id: touch.identifier,
|
|
360
|
+
x: touch.clientX,
|
|
361
|
+
y: touch.clientY,
|
|
362
|
+
}));
|
|
363
|
+
|
|
364
|
+
setInteractionState(prev => {
|
|
365
|
+
const newState = {
|
|
366
|
+
...prev,
|
|
367
|
+
touchState: {
|
|
368
|
+
...prev.touchState,
|
|
369
|
+
touches,
|
|
370
|
+
isTouch: true,
|
|
371
|
+
lastTouchTime: Date.now(),
|
|
372
|
+
},
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
// Single touch - start dragging
|
|
376
|
+
if (touches.length === 1 && touches[0]) {
|
|
377
|
+
const rect = (event.target as Element).getBoundingClientRect();
|
|
378
|
+
const x = touches[0].x - rect.left;
|
|
379
|
+
const y = touches[0].y - rect.top;
|
|
380
|
+
|
|
381
|
+
return {
|
|
382
|
+
...newState,
|
|
383
|
+
isDragging: true,
|
|
384
|
+
dragStart: { x, y },
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// Multi-touch - prepare for pinch
|
|
389
|
+
if (touches.length === 2 && touches[0] && touches[1]) {
|
|
390
|
+
const distance = Math.sqrt(
|
|
391
|
+
Math.pow(touches[1].x - touches[0].x, 2) + Math.pow(touches[1].y - touches[0].y, 2)
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
return {
|
|
395
|
+
...newState,
|
|
396
|
+
touchState: {
|
|
397
|
+
...newState.touchState,
|
|
398
|
+
lastDistance: distance,
|
|
399
|
+
isPinching: true,
|
|
400
|
+
},
|
|
401
|
+
isDragging: false,
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return newState;
|
|
406
|
+
});
|
|
407
|
+
}, []);
|
|
408
|
+
|
|
409
|
+
const handleTouchMove = useCallback((event: TouchEvent | React.TouchEvent) => {
|
|
410
|
+
event.preventDefault(); // Prevent scrolling
|
|
411
|
+
|
|
412
|
+
const touches = Array.from(event.touches).map(touch => ({
|
|
413
|
+
id: touch.identifier,
|
|
414
|
+
x: touch.clientX,
|
|
415
|
+
y: touch.clientY,
|
|
416
|
+
}));
|
|
417
|
+
|
|
418
|
+
setInteractionState(prev => {
|
|
419
|
+
const rect = (event.target as Element).getBoundingClientRect();
|
|
420
|
+
|
|
421
|
+
// Single touch - pan
|
|
422
|
+
if (touches.length === 1 && touches[0] && prev.isDragging && prev.dragStart) {
|
|
423
|
+
const x = touches[0].x - rect.left;
|
|
424
|
+
const y = touches[0].y - rect.top;
|
|
425
|
+
const deltaX = x - prev.dragStart.x;
|
|
426
|
+
const deltaY = y - prev.dragStart.y;
|
|
427
|
+
|
|
428
|
+
return {
|
|
429
|
+
...prev,
|
|
430
|
+
panOffset: {
|
|
431
|
+
x: prev.panOffset.x + deltaX,
|
|
432
|
+
y: prev.panOffset.y + deltaY,
|
|
433
|
+
},
|
|
434
|
+
dragStart: { x, y },
|
|
435
|
+
touchState: {
|
|
436
|
+
...prev.touchState,
|
|
437
|
+
touches,
|
|
438
|
+
},
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// Two touches - pinch zoom
|
|
443
|
+
if (touches.length === 2 && touches[0] && touches[1] && prev.touchState.isPinching) {
|
|
444
|
+
const distance = Math.sqrt(
|
|
445
|
+
Math.pow(touches[1].x - touches[0].x, 2) + Math.pow(touches[1].y - touches[0].y, 2)
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
if (prev.touchState.lastDistance > 0) {
|
|
449
|
+
const scale = distance / prev.touchState.lastDistance;
|
|
450
|
+
const newZoomLevel = Math.max(0.1, Math.min(10, prev.zoomLevel * scale));
|
|
451
|
+
|
|
452
|
+
// Calculate center point for zoom
|
|
453
|
+
const centerX = (touches[0]!.x + touches[1]!.x) / 2 - rect.left;
|
|
454
|
+
const centerY = (touches[0]!.y + touches[1]!.y) / 2 - rect.top;
|
|
455
|
+
|
|
456
|
+
// Adjust pan offset to zoom towards center
|
|
457
|
+
const zoomRatio = newZoomLevel / prev.zoomLevel;
|
|
458
|
+
const newPanOffset = {
|
|
459
|
+
x: centerX - (centerX - prev.panOffset.x) * zoomRatio,
|
|
460
|
+
y: centerY - (centerY - prev.panOffset.y) * zoomRatio,
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
return {
|
|
464
|
+
...prev,
|
|
465
|
+
zoomLevel: newZoomLevel,
|
|
466
|
+
panOffset: newPanOffset,
|
|
467
|
+
touchState: {
|
|
468
|
+
...prev.touchState,
|
|
469
|
+
touches,
|
|
470
|
+
lastDistance: distance,
|
|
471
|
+
},
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
return {
|
|
476
|
+
...prev,
|
|
477
|
+
touchState: {
|
|
478
|
+
...prev.touchState,
|
|
479
|
+
touches,
|
|
480
|
+
lastDistance: distance,
|
|
481
|
+
},
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
return {
|
|
486
|
+
...prev,
|
|
487
|
+
touchState: {
|
|
488
|
+
...prev.touchState,
|
|
489
|
+
touches,
|
|
490
|
+
},
|
|
491
|
+
};
|
|
492
|
+
});
|
|
493
|
+
}, []);
|
|
494
|
+
|
|
495
|
+
const handleTouchEnd = useCallback((event: TouchEvent | React.TouchEvent) => {
|
|
496
|
+
const touches = Array.from(event.touches).map(touch => ({
|
|
497
|
+
id: touch.identifier,
|
|
498
|
+
x: touch.clientX,
|
|
499
|
+
y: touch.clientY,
|
|
500
|
+
}));
|
|
501
|
+
|
|
502
|
+
setInteractionState(prev => {
|
|
503
|
+
// Reset states when no touches remain
|
|
504
|
+
if (touches.length === 0) {
|
|
505
|
+
return {
|
|
506
|
+
...prev,
|
|
507
|
+
isDragging: false,
|
|
508
|
+
dragStart: null,
|
|
509
|
+
touchState: {
|
|
510
|
+
...prev.touchState,
|
|
511
|
+
touches: [],
|
|
512
|
+
isPinching: false,
|
|
513
|
+
lastDistance: 0,
|
|
514
|
+
isTouch: false,
|
|
515
|
+
},
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// Single touch remaining - switch from pinch to pan
|
|
520
|
+
if (touches.length === 1 && touches[0] && prev.touchState.isPinching) {
|
|
521
|
+
const rect = (event.target as Element).getBoundingClientRect();
|
|
522
|
+
const x = touches[0].x - rect.left;
|
|
523
|
+
const y = touches[0].y - rect.top;
|
|
524
|
+
|
|
525
|
+
return {
|
|
526
|
+
...prev,
|
|
527
|
+
isDragging: true,
|
|
528
|
+
dragStart: { x, y },
|
|
529
|
+
touchState: {
|
|
530
|
+
...prev.touchState,
|
|
531
|
+
touches,
|
|
532
|
+
isPinching: false,
|
|
533
|
+
lastDistance: 0,
|
|
534
|
+
},
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
return {
|
|
539
|
+
...prev,
|
|
540
|
+
touchState: {
|
|
541
|
+
...prev.touchState,
|
|
542
|
+
touches,
|
|
543
|
+
},
|
|
544
|
+
};
|
|
545
|
+
});
|
|
546
|
+
}, []);
|
|
547
|
+
|
|
548
|
+
const handlePointerDown = useCallback(
|
|
549
|
+
(event: PointerEvent | React.PointerEvent) => {
|
|
550
|
+
const isPen = event.pointerType === 'pen';
|
|
551
|
+
const isTouch = event.pointerType === 'touch';
|
|
552
|
+
|
|
553
|
+
if (isPen) {
|
|
554
|
+
setInteractionState(prev => ({
|
|
555
|
+
...prev,
|
|
556
|
+
penState: {
|
|
557
|
+
isPen: true,
|
|
558
|
+
pressure: event.pressure || 0,
|
|
559
|
+
tiltX: (event as any).tiltX || 0,
|
|
560
|
+
tiltY: (event as any).tiltY || 0,
|
|
561
|
+
},
|
|
562
|
+
isDragging: true,
|
|
563
|
+
dragStart: {
|
|
564
|
+
x: event.clientX - (event.target as Element).getBoundingClientRect().left,
|
|
565
|
+
y: event.clientY - (event.target as Element).getBoundingClientRect().top,
|
|
566
|
+
},
|
|
567
|
+
}));
|
|
568
|
+
} else if (!isTouch) {
|
|
569
|
+
// Regular mouse interaction
|
|
570
|
+
const rect = (event.target as Element).getBoundingClientRect();
|
|
571
|
+
const x = event.clientX - rect.left;
|
|
572
|
+
const y = event.clientY - rect.top;
|
|
573
|
+
handleDragStart(x, y);
|
|
574
|
+
}
|
|
575
|
+
},
|
|
576
|
+
[handleDragStart]
|
|
577
|
+
);
|
|
578
|
+
|
|
579
|
+
const handlePointerMove = useCallback(
|
|
580
|
+
(event: PointerEvent | React.PointerEvent) => {
|
|
581
|
+
const rect = (event.target as Element).getBoundingClientRect();
|
|
582
|
+
const x = event.clientX - rect.left;
|
|
583
|
+
const y = event.clientY - rect.top;
|
|
584
|
+
|
|
585
|
+
if (event.pointerType === 'pen' && interactionState.penState.isPen) {
|
|
586
|
+
setInteractionState(prev => {
|
|
587
|
+
if (prev.isDragging && prev.dragStart) {
|
|
588
|
+
const deltaX = x - prev.dragStart.x;
|
|
589
|
+
const deltaY = y - prev.dragStart.y;
|
|
590
|
+
|
|
591
|
+
// Pen pressure affects pan sensitivity
|
|
592
|
+
const pressureMultiplier = Math.max(0.1, event.pressure || 0.5);
|
|
593
|
+
|
|
594
|
+
return {
|
|
595
|
+
...prev,
|
|
596
|
+
panOffset: {
|
|
597
|
+
x: prev.panOffset.x + deltaX * pressureMultiplier,
|
|
598
|
+
y: prev.panOffset.y + deltaY * pressureMultiplier,
|
|
599
|
+
},
|
|
600
|
+
dragStart: { x, y },
|
|
601
|
+
penState: {
|
|
602
|
+
...prev.penState,
|
|
603
|
+
pressure: event.pressure || 0,
|
|
604
|
+
tiltX: (event as any).tiltX || 0,
|
|
605
|
+
tiltY: (event as any).tiltY || 0,
|
|
606
|
+
},
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
return {
|
|
611
|
+
...prev,
|
|
612
|
+
penState: {
|
|
613
|
+
...prev.penState,
|
|
614
|
+
pressure: event.pressure || 0,
|
|
615
|
+
tiltX: (event as any).tiltX || 0,
|
|
616
|
+
tiltY: (event as any).tiltY || 0,
|
|
617
|
+
},
|
|
618
|
+
};
|
|
619
|
+
});
|
|
620
|
+
} else if (event.pointerType !== 'touch') {
|
|
621
|
+
// Regular mouse move
|
|
622
|
+
handleCrosshair(x, y);
|
|
623
|
+
|
|
624
|
+
if (interactionState.isDragging && interactionState.dragStart) {
|
|
625
|
+
const deltaX = x - interactionState.dragStart.x;
|
|
626
|
+
const deltaY = y - interactionState.dragStart.y;
|
|
627
|
+
handlePan(deltaX, deltaY);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
},
|
|
631
|
+
[interactionState, handleCrosshair, handlePan]
|
|
632
|
+
);
|
|
633
|
+
|
|
634
|
+
const handlePointerUp = useCallback(
|
|
635
|
+
(event: PointerEvent | React.PointerEvent) => {
|
|
636
|
+
if (event.pointerType === 'pen') {
|
|
637
|
+
setInteractionState(prev => ({
|
|
638
|
+
...prev,
|
|
639
|
+
isDragging: false,
|
|
640
|
+
dragStart: null,
|
|
641
|
+
penState: {
|
|
642
|
+
isPen: false,
|
|
643
|
+
pressure: 0,
|
|
644
|
+
tiltX: 0,
|
|
645
|
+
tiltY: 0,
|
|
646
|
+
},
|
|
647
|
+
}));
|
|
648
|
+
} else if (event.pointerType !== 'touch') {
|
|
649
|
+
handleDragEnd();
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
[handleDragEnd]
|
|
653
|
+
);
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* Reset all interactions
|
|
657
|
+
*/
|
|
658
|
+
const resetView = useCallback(() => {
|
|
659
|
+
setInteractionState(prev => ({
|
|
660
|
+
...prev,
|
|
661
|
+
zoomLevel: 1,
|
|
662
|
+
panOffset: { x: 0, y: 0 },
|
|
663
|
+
selectedPoints: [],
|
|
664
|
+
crosshair: null,
|
|
665
|
+
brushSelection: null,
|
|
666
|
+
}));
|
|
667
|
+
}, []);
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Enhanced animation helpers
|
|
671
|
+
*/
|
|
672
|
+
const startAnimation = useCallback((duration: number = 1000) => {
|
|
673
|
+
setInteractionState(prev => ({ ...prev, isAnimating: true }));
|
|
674
|
+
|
|
675
|
+
if (animationFrameRef.current) {
|
|
676
|
+
cancelAnimationFrame(animationFrameRef.current);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
const startTime = Date.now();
|
|
680
|
+
const animate = () => {
|
|
681
|
+
const elapsed = Date.now() - startTime;
|
|
682
|
+
const progress = Math.min(elapsed / duration, 1);
|
|
683
|
+
|
|
684
|
+
if (progress < 1) {
|
|
685
|
+
animationFrameRef.current = requestAnimationFrame(animate);
|
|
686
|
+
} else {
|
|
687
|
+
setInteractionState(prev => ({ ...prev, isAnimating: false }));
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
animationFrameRef.current = requestAnimationFrame(animate);
|
|
692
|
+
}, []);
|
|
693
|
+
|
|
694
|
+
const stopAnimation = useCallback(() => {
|
|
695
|
+
if (animationFrameRef.current) {
|
|
696
|
+
cancelAnimationFrame(animationFrameRef.current);
|
|
697
|
+
animationFrameRef.current = null;
|
|
698
|
+
}
|
|
699
|
+
setInteractionState(prev => ({ ...prev, isAnimating: false }));
|
|
700
|
+
}, []);
|
|
701
|
+
|
|
702
|
+
// Cleanup animation on unmount
|
|
703
|
+
useEffect(() => {
|
|
704
|
+
return () => {
|
|
705
|
+
if (animationFrameRef.current) {
|
|
706
|
+
cancelAnimationFrame(animationFrameRef.current);
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
}, []);
|
|
710
|
+
|
|
711
|
+
return {
|
|
712
|
+
// State
|
|
713
|
+
interactionState,
|
|
714
|
+
hoveredPoint: interactionState.hoveredPoint,
|
|
715
|
+
selectedPoints: interactionState.selectedPoints,
|
|
716
|
+
zoomLevel: interactionState.zoomLevel,
|
|
717
|
+
panOffset: interactionState.panOffset,
|
|
718
|
+
isAnimating: interactionState.isAnimating,
|
|
719
|
+
isDragging: interactionState.isDragging,
|
|
720
|
+
crosshair: interactionState.crosshair,
|
|
721
|
+
brushSelection: interactionState.brushSelection,
|
|
722
|
+
focusedPointIndex: interactionState.focusedPointIndex,
|
|
723
|
+
|
|
724
|
+
// Refs
|
|
725
|
+
containerRef,
|
|
726
|
+
svgRef,
|
|
727
|
+
|
|
728
|
+
// Props and attributes
|
|
729
|
+
defaultProps,
|
|
730
|
+
generateChartClass,
|
|
731
|
+
chartAttributes: generateChartAttributes(initialProps || {}),
|
|
732
|
+
|
|
733
|
+
// Calculations
|
|
734
|
+
calculateScales,
|
|
735
|
+
getChartColors,
|
|
736
|
+
|
|
737
|
+
// Enhanced interactions
|
|
738
|
+
handlePointHover,
|
|
739
|
+
handlePointLeave,
|
|
740
|
+
handlePointClick,
|
|
741
|
+
handleZoom,
|
|
742
|
+
handlePan,
|
|
743
|
+
handleDragStart,
|
|
744
|
+
handleDragEnd,
|
|
745
|
+
handleCrosshair,
|
|
746
|
+
clearCrosshair,
|
|
747
|
+
resetView,
|
|
748
|
+
|
|
749
|
+
// Touch and pointer handlers
|
|
750
|
+
handleTouchStart,
|
|
751
|
+
handleTouchMove,
|
|
752
|
+
handleTouchEnd,
|
|
753
|
+
handlePointerDown,
|
|
754
|
+
handlePointerMove,
|
|
755
|
+
handlePointerUp,
|
|
756
|
+
|
|
757
|
+
// Animation
|
|
758
|
+
startAnimation,
|
|
759
|
+
stopAnimation,
|
|
760
|
+
|
|
761
|
+
// State setters for advanced use cases
|
|
762
|
+
setInteractionState,
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Hook for chart data processing and transformation
|
|
768
|
+
*/
|
|
769
|
+
export function useChartData(
|
|
770
|
+
datasets: ChartDataset[],
|
|
771
|
+
options?: {
|
|
772
|
+
enableDecimation?: boolean;
|
|
773
|
+
maxDataPoints?: number;
|
|
774
|
+
enableRealTime?: boolean;
|
|
775
|
+
realTimeInterval?: number;
|
|
776
|
+
}
|
|
777
|
+
) {
|
|
778
|
+
const [processedData, setProcessedData] = useState(datasets);
|
|
779
|
+
const [isProcessing, setIsProcessing] = useState(false);
|
|
780
|
+
|
|
781
|
+
const {
|
|
782
|
+
enableDecimation = false,
|
|
783
|
+
maxDataPoints = 1000,
|
|
784
|
+
enableRealTime = false,
|
|
785
|
+
realTimeInterval = 1000,
|
|
786
|
+
} = options || {};
|
|
787
|
+
|
|
788
|
+
// Data decimation for performance
|
|
789
|
+
const decimateData = useCallback(
|
|
790
|
+
(data: ChartDataset[], maxPoints: number) => {
|
|
791
|
+
if (!enableDecimation || !data.length) return data;
|
|
792
|
+
|
|
793
|
+
const dataLength = data[0]?.data?.length || 0;
|
|
794
|
+
if (dataLength <= maxPoints) return data;
|
|
795
|
+
|
|
796
|
+
const step = Math.ceil(dataLength / maxPoints);
|
|
797
|
+
return data.map(dataset => ({
|
|
798
|
+
...dataset,
|
|
799
|
+
data: dataset.data?.filter((_, index) => index % step === 0) || [],
|
|
800
|
+
}));
|
|
801
|
+
},
|
|
802
|
+
[enableDecimation]
|
|
803
|
+
);
|
|
804
|
+
|
|
805
|
+
// Moving average calculation
|
|
806
|
+
const calculateMovingAverage = useCallback((values: number[], period: number) => {
|
|
807
|
+
const result: (number | null)[] = [];
|
|
808
|
+
for (let i = 0; i < values.length; i++) {
|
|
809
|
+
if (i < period - 1) {
|
|
810
|
+
result.push(null);
|
|
811
|
+
} else {
|
|
812
|
+
const sum = values.slice(i - period + 1, i + 1).reduce((a, b) => a + b, 0);
|
|
813
|
+
result.push(sum / period);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
return result;
|
|
817
|
+
}, []);
|
|
818
|
+
|
|
819
|
+
// Trend line calculation (linear regression)
|
|
820
|
+
const calculateTrendLine = useCallback((values: number[]): (number | null)[] => {
|
|
821
|
+
const n = values.length;
|
|
822
|
+
if (n < 2) return values.map((): null => null);
|
|
823
|
+
|
|
824
|
+
const xSum = values.reduce((sum, _, i) => sum + i, 0);
|
|
825
|
+
const ySum = values.reduce((sum, val) => sum + val, 0);
|
|
826
|
+
const xySum = values.reduce((sum, val, i) => sum + i * val, 0);
|
|
827
|
+
const x2Sum = values.reduce((sum, _, i) => sum + i * i, 0);
|
|
828
|
+
|
|
829
|
+
const slope = (n * xySum - xSum * ySum) / (n * x2Sum - xSum * xSum);
|
|
830
|
+
const intercept = (ySum - slope * xSum) / n;
|
|
831
|
+
|
|
832
|
+
return values.map((_, i) => slope * i + intercept);
|
|
833
|
+
}, []);
|
|
834
|
+
|
|
835
|
+
// Process data when datasets change
|
|
836
|
+
useEffect(() => {
|
|
837
|
+
setIsProcessing(true);
|
|
838
|
+
|
|
839
|
+
const processData = async () => {
|
|
840
|
+
let processed = [...datasets];
|
|
841
|
+
|
|
842
|
+
if (enableDecimation && maxDataPoints) {
|
|
843
|
+
processed = decimateData(processed, maxDataPoints);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
setProcessedData(processed);
|
|
847
|
+
setIsProcessing(false);
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
processData();
|
|
851
|
+
}, [datasets, decimateData, enableDecimation, maxDataPoints]);
|
|
852
|
+
|
|
853
|
+
// Real-time data updates
|
|
854
|
+
useEffect(() => {
|
|
855
|
+
if (!enableRealTime) return undefined;
|
|
856
|
+
|
|
857
|
+
const interval = setInterval(() => {
|
|
858
|
+
setProcessedData(prev => [...prev]); // Trigger re-render for real-time updates
|
|
859
|
+
}, realTimeInterval);
|
|
860
|
+
|
|
861
|
+
return () => clearInterval(interval);
|
|
862
|
+
}, [enableRealTime, realTimeInterval]);
|
|
863
|
+
|
|
864
|
+
return {
|
|
865
|
+
processedData,
|
|
866
|
+
isProcessing,
|
|
867
|
+
decimateData,
|
|
868
|
+
calculateMovingAverage,
|
|
869
|
+
calculateTrendLine,
|
|
870
|
+
setProcessedData,
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Hook for chart accessibility features
|
|
876
|
+
*/
|
|
877
|
+
export function useChartAccessibility(
|
|
878
|
+
datasets: ChartDataset[],
|
|
879
|
+
options?: {
|
|
880
|
+
enableKeyboardNavigation?: boolean;
|
|
881
|
+
enableScreenReader?: boolean;
|
|
882
|
+
announceDataChanges?: boolean;
|
|
883
|
+
}
|
|
884
|
+
) {
|
|
885
|
+
const {
|
|
886
|
+
enableKeyboardNavigation = true,
|
|
887
|
+
enableScreenReader = true,
|
|
888
|
+
announceDataChanges = true,
|
|
889
|
+
} = options || {};
|
|
890
|
+
|
|
891
|
+
const [focusedPoint, setFocusedPoint] = useState({ datasetIndex: 0, pointIndex: 0 });
|
|
892
|
+
const [announcement, setAnnouncement] = useState('');
|
|
893
|
+
|
|
894
|
+
// Keyboard navigation
|
|
895
|
+
const handleKeyDown = useCallback(
|
|
896
|
+
(event: KeyboardEvent, onPointSelect?: (datasetIndex: number, pointIndex: number) => void) => {
|
|
897
|
+
if (!enableKeyboardNavigation || !datasets.length) return;
|
|
898
|
+
|
|
899
|
+
const maxDatasetIndex = datasets.length - 1;
|
|
900
|
+
const maxPointIndex = (datasets[focusedPoint.datasetIndex]?.data?.length || 1) - 1;
|
|
901
|
+
|
|
902
|
+
switch (event.key) {
|
|
903
|
+
case 'ArrowLeft':
|
|
904
|
+
event.preventDefault();
|
|
905
|
+
setFocusedPoint(prev => ({
|
|
906
|
+
...prev,
|
|
907
|
+
pointIndex: Math.max(0, prev.pointIndex - 1),
|
|
908
|
+
}));
|
|
909
|
+
break;
|
|
910
|
+
case 'ArrowRight':
|
|
911
|
+
event.preventDefault();
|
|
912
|
+
setFocusedPoint(prev => ({
|
|
913
|
+
...prev,
|
|
914
|
+
pointIndex: Math.min(maxPointIndex, prev.pointIndex + 1),
|
|
915
|
+
}));
|
|
916
|
+
break;
|
|
917
|
+
case 'ArrowUp':
|
|
918
|
+
event.preventDefault();
|
|
919
|
+
setFocusedPoint(prev => ({
|
|
920
|
+
...prev,
|
|
921
|
+
datasetIndex: Math.max(0, prev.datasetIndex - 1),
|
|
922
|
+
}));
|
|
923
|
+
break;
|
|
924
|
+
case 'ArrowDown':
|
|
925
|
+
event.preventDefault();
|
|
926
|
+
setFocusedPoint(prev => ({
|
|
927
|
+
...prev,
|
|
928
|
+
datasetIndex: Math.min(maxDatasetIndex, prev.datasetIndex + 1),
|
|
929
|
+
}));
|
|
930
|
+
break;
|
|
931
|
+
case 'Home':
|
|
932
|
+
event.preventDefault();
|
|
933
|
+
setFocusedPoint(prev => ({ ...prev, pointIndex: 0 }));
|
|
934
|
+
break;
|
|
935
|
+
case 'End':
|
|
936
|
+
event.preventDefault();
|
|
937
|
+
setFocusedPoint(prev => ({ ...prev, pointIndex: maxPointIndex }));
|
|
938
|
+
break;
|
|
939
|
+
case 'Enter':
|
|
940
|
+
case ' ':
|
|
941
|
+
event.preventDefault();
|
|
942
|
+
onPointSelect?.(focusedPoint.datasetIndex, focusedPoint.pointIndex);
|
|
943
|
+
break;
|
|
944
|
+
}
|
|
945
|
+
},
|
|
946
|
+
[enableKeyboardNavigation, datasets, focusedPoint]
|
|
947
|
+
);
|
|
948
|
+
|
|
949
|
+
// Screen reader announcements
|
|
950
|
+
const announceData = useCallback(
|
|
951
|
+
(message: string) => {
|
|
952
|
+
if (!enableScreenReader) return;
|
|
953
|
+
|
|
954
|
+
setAnnouncement(message);
|
|
955
|
+
// Clear announcement after a delay to allow screen readers to read it
|
|
956
|
+
setTimeout(() => setAnnouncement(''), 1000);
|
|
957
|
+
},
|
|
958
|
+
[enableScreenReader]
|
|
959
|
+
);
|
|
960
|
+
|
|
961
|
+
// Announce data changes
|
|
962
|
+
useEffect(() => {
|
|
963
|
+
if (!announceDataChanges || !datasets.length) return;
|
|
964
|
+
|
|
965
|
+
const totalDataPoints = datasets.reduce((sum, dataset) => sum + (dataset.data?.length || 0), 0);
|
|
966
|
+
announceData(
|
|
967
|
+
`Chart updated with ${datasets.length} datasets and ${totalDataPoints} data points`
|
|
968
|
+
);
|
|
969
|
+
}, [datasets, announceDataChanges, announceData]);
|
|
970
|
+
|
|
971
|
+
// Generate accessible description
|
|
972
|
+
const getAccessibleDescription = useCallback(() => {
|
|
973
|
+
if (!datasets.length) return 'Empty chart';
|
|
974
|
+
|
|
975
|
+
const datasetDescriptions = datasets
|
|
976
|
+
.map((dataset, i) => {
|
|
977
|
+
const dataCount = dataset.data?.length || 0;
|
|
978
|
+
const values = dataset.data?.map(d => d.value).filter(v => typeof v === 'number') || [];
|
|
979
|
+
const min = Math.min(...values);
|
|
980
|
+
const max = Math.max(...values);
|
|
981
|
+
|
|
982
|
+
return `Dataset ${i + 1}: ${dataset.label}, ${dataCount} points, range ${min} to ${max}`;
|
|
983
|
+
})
|
|
984
|
+
.join('. ');
|
|
985
|
+
|
|
986
|
+
return `Chart with ${datasets.length} datasets. ${datasetDescriptions}`;
|
|
987
|
+
}, [datasets]);
|
|
988
|
+
|
|
989
|
+
return {
|
|
990
|
+
focusedPoint,
|
|
991
|
+
announcement,
|
|
992
|
+
handleKeyDown,
|
|
993
|
+
announceData,
|
|
994
|
+
getAccessibleDescription,
|
|
995
|
+
setFocusedPoint,
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Hook for chart performance optimization
|
|
1001
|
+
*/
|
|
1002
|
+
export function useChartPerformance(
|
|
1003
|
+
datasets: ChartDataset[],
|
|
1004
|
+
options?: {
|
|
1005
|
+
enableVirtualization?: boolean;
|
|
1006
|
+
enableMemoization?: boolean;
|
|
1007
|
+
debounceMs?: number;
|
|
1008
|
+
}
|
|
1009
|
+
) {
|
|
1010
|
+
const {
|
|
1011
|
+
enableVirtualization = false,
|
|
1012
|
+
enableMemoization = true,
|
|
1013
|
+
debounceMs = 100,
|
|
1014
|
+
} = options || {};
|
|
1015
|
+
|
|
1016
|
+
const [isOptimizing, setIsOptimizing] = useState(false);
|
|
1017
|
+
const debounceRef = useRef<NodeJS.Timeout | null>(null);
|
|
1018
|
+
|
|
1019
|
+
// Memoized calculations
|
|
1020
|
+
const memoizedScales = useMemo(() => {
|
|
1021
|
+
if (!enableMemoization) return null;
|
|
1022
|
+
|
|
1023
|
+
// Cache expensive scale calculations
|
|
1024
|
+
return datasets.map(dataset => ({
|
|
1025
|
+
label: dataset.label,
|
|
1026
|
+
dataLength: dataset.data?.length || 0,
|
|
1027
|
+
minValue: Math.min(
|
|
1028
|
+
...(dataset.data?.map(d => d.value).filter(v => typeof v === 'number') || [0])
|
|
1029
|
+
),
|
|
1030
|
+
maxValue: Math.max(
|
|
1031
|
+
...(dataset.data?.map(d => d.value).filter(v => typeof v === 'number') || [0])
|
|
1032
|
+
),
|
|
1033
|
+
}));
|
|
1034
|
+
}, [datasets, enableMemoization]);
|
|
1035
|
+
|
|
1036
|
+
// Debounced updates
|
|
1037
|
+
const debouncedUpdate = useCallback(
|
|
1038
|
+
(callback: () => void) => {
|
|
1039
|
+
if (debounceRef.current) {
|
|
1040
|
+
clearTimeout(debounceRef.current);
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
debounceRef.current = setTimeout(() => {
|
|
1044
|
+
callback();
|
|
1045
|
+
setIsOptimizing(false);
|
|
1046
|
+
}, debounceMs);
|
|
1047
|
+
|
|
1048
|
+
setIsOptimizing(true);
|
|
1049
|
+
},
|
|
1050
|
+
[debounceMs]
|
|
1051
|
+
);
|
|
1052
|
+
|
|
1053
|
+
// Virtualization helpers
|
|
1054
|
+
const getVisibleRange = useCallback(
|
|
1055
|
+
(scrollTop: number, itemHeight: number, containerHeight: number) => {
|
|
1056
|
+
if (!enableVirtualization) return { start: 0, end: datasets[0]?.data?.length || 0 };
|
|
1057
|
+
|
|
1058
|
+
const start = Math.floor(scrollTop / itemHeight);
|
|
1059
|
+
const visibleCount = Math.ceil(containerHeight / itemHeight);
|
|
1060
|
+
const end = Math.min(start + visibleCount + 1, datasets[0]?.data?.length || 0);
|
|
1061
|
+
|
|
1062
|
+
return { start: Math.max(0, start - 1), end };
|
|
1063
|
+
},
|
|
1064
|
+
[enableVirtualization, datasets]
|
|
1065
|
+
);
|
|
1066
|
+
|
|
1067
|
+
// Cleanup
|
|
1068
|
+
useEffect(() => {
|
|
1069
|
+
return () => {
|
|
1070
|
+
if (debounceRef.current) {
|
|
1071
|
+
clearTimeout(debounceRef.current);
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
}, []);
|
|
1075
|
+
|
|
1076
|
+
return {
|
|
1077
|
+
isOptimizing,
|
|
1078
|
+
memoizedScales,
|
|
1079
|
+
debouncedUpdate,
|
|
1080
|
+
getVisibleRange,
|
|
1081
|
+
};
|
|
1082
|
+
}
|