diff --git a/.pnpm-patches/@wordpress__dataviews@4.10.0.patch b/.pnpm-patches/@wordpress__dataviews@4.10.0.patch new file mode 100644 index 0000000000000..49656b5f977cc --- /dev/null +++ b/.pnpm-patches/@wordpress__dataviews@4.10.0.patch @@ -0,0 +1,15 @@ +Hack for https://github.com/WordPress/gutenberg/issues/67897 + +diff --git a/package.json b/package.json +index d7af17fea3f59f807a9d7234cf9ce79131538383..c862b012af312c9fc5cf1d2d884ec332ee079d0b 100644 +--- a/package.json ++++ b/package.json +@@ -27,7 +27,7 @@ + "exports": { + ".": { + "types": "./build-types/index.d.ts", +- "import": "./build-module/index.js" ++ "default": "./build/index.js" + }, + "./wp": { + "types": "./build-types/index.d.ts", diff --git a/package.json b/package.json index 605f3c28d9302..c48245d935c8a 100644 --- a/package.json +++ b/package.json @@ -37,5 +37,10 @@ "node": "^22.9.0", "pnpm": "^9.3.0 <9.12.0" }, - "packageManager": "pnpm@9.3.0" + "packageManager": "pnpm@9.3.0", + "pnpm": { + "patchedDependencies": { + "@wordpress/dataviews@4.10.0": ".pnpm-patches/@wordpress__dataviews@4.10.0.patch" + } + } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4f1a0aef04261..d2a2a658b2b2a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,6 +6,11 @@ settings: pnpmfileChecksum: kmseazxfbymwdp5ie53bnph5mq +patchedDependencies: + '@wordpress/dataviews@4.10.0': + hash: of6mtpeubmoicukrgy5ohupf6a + path: .pnpm-patches/@wordpress__dataviews@4.10.0.patch + importers: .: @@ -382,8 +387,8 @@ importers: specifier: 10.14.0 version: 10.14.0(react@18.3.1) '@wordpress/dataviews': - specifier: 4.9.0 - version: 4.9.0(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + specifier: 4.10.0 + version: 4.10.0(patch_hash=of6mtpeubmoicukrgy5ohupf6a)(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/date': specifier: 5.14.0 version: 5.14.0 @@ -1070,8 +1075,8 @@ importers: specifier: 10.14.0 version: 10.14.0(react@18.3.1) '@wordpress/dataviews': - specifier: 4.9.0 - version: 4.9.0(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + specifier: 4.10.0 + version: 4.10.0(patch_hash=of6mtpeubmoicukrgy5ohupf6a)(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/date': specifier: 5.14.0 version: 5.14.0 @@ -8129,8 +8134,8 @@ packages: peerDependencies: react: ^18.0.0 - '@wordpress/dataviews@4.9.0': - resolution: {integrity: sha512-ucAQx1dwlHU8WyhNSfl/OEc8hFNwIy2/XkNAjduelrMqbNiOOue5mfKjO43zqKT/ZFVvju/gUU7gnTX1A98tCA==} + '@wordpress/dataviews@4.10.0': + resolution: {integrity: sha512-Rsp5wUTTGAJlbWdkdFHGXq06LU6F/Kvki6IT9byexu+984h3F+VNIyVCP1BQPqNAWhsUHD4o0gIZKzH17zrCbw==} engines: {node: '>=18.12.0', npm: '>=8.19.2'} peerDependencies: react: ^18.0.0 @@ -19621,7 +19626,7 @@ snapshots: rememo: 4.0.2 use-memo-one: 1.1.3(react@18.3.1) - '@wordpress/dataviews@4.9.0(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@wordpress/dataviews@4.10.0(patch_hash=of6mtpeubmoicukrgy5ohupf6a)(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: '@ariakit/react': 0.4.15(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@babel/runtime': 7.25.7 @@ -19643,7 +19648,7 @@ snapshots: - react-dom - supports-color - '@wordpress/dataviews@4.9.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@wordpress/dataviews@4.10.0(patch_hash=of6mtpeubmoicukrgy5ohupf6a)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: '@ariakit/react': 0.4.15(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@babel/runtime': 7.25.7 @@ -19792,7 +19797,7 @@ snapshots: '@wordpress/compose': 7.14.0(react@18.3.1) '@wordpress/core-data': 7.14.0(@types/react-dom@18.3.1)(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/data': 10.14.0(react@18.3.1) - '@wordpress/dataviews': 4.9.0(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@wordpress/dataviews': 4.10.0(patch_hash=of6mtpeubmoicukrgy5ohupf6a)(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/date': 5.14.0 '@wordpress/deprecated': 4.13.0 '@wordpress/dom': 4.13.0 @@ -19851,7 +19856,7 @@ snapshots: '@wordpress/compose': 7.14.0(react@18.3.1) '@wordpress/core-data': 7.14.0(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/data': 10.14.0(react@18.3.1) - '@wordpress/dataviews': 4.9.0(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@wordpress/dataviews': 4.10.0(patch_hash=of6mtpeubmoicukrgy5ohupf6a)(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/date': 5.14.0 '@wordpress/deprecated': 4.13.0 '@wordpress/dom': 4.13.0 @@ -19910,7 +19915,7 @@ snapshots: '@wordpress/compose': 7.14.0(react@18.3.1) '@wordpress/core-data': 7.14.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/data': 10.14.0(react@18.3.1) - '@wordpress/dataviews': 4.9.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@wordpress/dataviews': 4.10.0(patch_hash=of6mtpeubmoicukrgy5ohupf6a)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/date': 5.14.0 '@wordpress/deprecated': 4.13.0 '@wordpress/dom': 4.13.0 @@ -20006,7 +20011,7 @@ snapshots: '@wordpress/compose': 7.14.0(react@18.3.1) '@wordpress/core-data': 7.14.0(@types/react-dom@18.3.1)(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/data': 10.14.0(react@18.3.1) - '@wordpress/dataviews': 4.9.0(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@wordpress/dataviews': 4.10.0(patch_hash=of6mtpeubmoicukrgy5ohupf6a)(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/date': 5.14.0 '@wordpress/element': 6.14.0 '@wordpress/hooks': 4.14.0 @@ -20045,7 +20050,7 @@ snapshots: '@wordpress/compose': 7.14.0(react@18.3.1) '@wordpress/core-data': 7.14.0(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/data': 10.14.0(react@18.3.1) - '@wordpress/dataviews': 4.9.0(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@wordpress/dataviews': 4.10.0(patch_hash=of6mtpeubmoicukrgy5ohupf6a)(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/date': 5.14.0 '@wordpress/element': 6.14.0 '@wordpress/hooks': 4.14.0 @@ -20084,7 +20089,7 @@ snapshots: '@wordpress/compose': 7.14.0(react@18.3.1) '@wordpress/core-data': 7.14.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/data': 10.14.0(react@18.3.1) - '@wordpress/dataviews': 4.9.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@wordpress/dataviews': 4.10.0(patch_hash=of6mtpeubmoicukrgy5ohupf6a)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/date': 5.14.0 '@wordpress/element': 6.14.0 '@wordpress/hooks': 4.14.0 diff --git a/projects/js-packages/charts/changelog/update-charts-library-tooltip-iteration b/projects/js-packages/charts/changelog/update-charts-library-tooltip-iteration new file mode 100644 index 0000000000000..b95e70a4acf87 --- /dev/null +++ b/projects/js-packages/charts/changelog/update-charts-library-tooltip-iteration @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +Chart Library: Update tooltip component diff --git a/projects/js-packages/charts/src/components/bar-chart/bar-chart.module.scss b/projects/js-packages/charts/src/components/bar-chart/bar-chart.module.scss new file mode 100644 index 0000000000000..ec94022ab4d88 --- /dev/null +++ b/projects/js-packages/charts/src/components/bar-chart/bar-chart.module.scss @@ -0,0 +1,3 @@ +.bar-chart { + position: relative; +} diff --git a/projects/js-packages/charts/src/components/bar-chart/bar-chart.tsx b/projects/js-packages/charts/src/components/bar-chart/bar-chart.tsx new file mode 100644 index 0000000000000..7c6f4976eaa06 --- /dev/null +++ b/projects/js-packages/charts/src/components/bar-chart/bar-chart.tsx @@ -0,0 +1,107 @@ +import { AxisLeft, AxisBottom } from '@visx/axis'; +import { localPoint } from '@visx/event'; +import { Group } from '@visx/group'; +import { scaleBand, scaleLinear } from '@visx/scale'; +import { Bar } from '@visx/shape'; +import { useTooltip } from '@visx/tooltip'; +import clsx from 'clsx'; +import { FC, useCallback, type MouseEvent } from 'react'; +import { useChartTheme } from '../../providers/theme'; +import { BaseTooltip } from '../tooltip'; +import styles from './bar-chart.module.scss'; +import type { BaseChartProps, DataPoint } from '../shared/types'; + +interface BarChartProps extends BaseChartProps { + /** + * Array of data points to display in the chart + */ + data: DataPoint[]; +} + +const BarChart: FC< BarChartProps > = ( { + data, + width, + height, + margin = { top: 20, right: 20, bottom: 40, left: 40 }, + withTooltips = false, + className, +} ) => { + const theme = useChartTheme(); + const { tooltipOpen, tooltipLeft, tooltipTop, tooltipData, hideTooltip, showTooltip } = + useTooltip< DataPoint >(); + + const margins = margin; + const xMax = width - margins.left - margins.right; + const yMax = height - margins.top - margins.bottom; + + const xScale = scaleBand< string >( { + range: [ 0, xMax ], + domain: data.map( d => d.label ), + padding: 0.2, + } ); + + const yScale = scaleLinear< number >( { + range: [ yMax, 0 ], + domain: [ 0, Math.max( ...data.map( d => d.value ) ) ], + } ); + + const handleMouseMove = useCallback( + ( event: MouseEvent< SVGRectElement >, datum: DataPoint ) => { + const coords = localPoint( event ); + if ( ! coords ) return; + + showTooltip( { + tooltipData: datum, + tooltipLeft: coords.x, + tooltipTop: coords.y - 10, + } ); + }, + [ showTooltip ] + ); + + const handleMouseLeave = useCallback( () => { + hideTooltip(); + }, [ hideTooltip ] ); + + return ( +