Skip to content

Commit

Permalink
Watch dimension change in useColorVisionEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
susiekims committed Jan 25, 2024
1 parent 04925ca commit 1ff96f2
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/polaris-viz/src/components/DonutChart/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export function Chart({
width && height && isLegendMounted,
);

useColorVisionEvents(shouldUseColorVisionEvents);
useColorVisionEvents({enabled: shouldUseColorVisionEvents});

useWatchColorVisionEvents({
type: COLOR_VISION_SINGLE_ITEM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function Chart({
xAxisOptions,
yAxisOptions,
}: ChartProps) {
useColorVisionEvents(data.length > 1);
useColorVisionEvents({enabled: data.length > 1});

const selectedTheme = useTheme();
const id = useMemo(() => uniqueId('HorizontalBarChart'), []);
Expand Down
2 changes: 1 addition & 1 deletion packages/polaris-viz/src/components/LineChart/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function Chart({
yAxisOptions,
enableHideLegendOverflow = false,
}: ChartProps) {
useColorVisionEvents(data.length > 1);
useColorVisionEvents({enabled: data.length > 1, dimensions});

const selectedTheme = useTheme(theme);
const {isPerformanceImpacted} = useChartContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function Chart({
xAxisOptions,
yAxisOptions,
}: ChartProps) {
useColorVisionEvents(data.length > 1);
useColorVisionEvents({enabled: data.length > 1});

const id = useMemo(() => uniqueId('SimpleBarChart'), []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function Chart({
theme,
yAxisOptions,
}: Props) {
useColorVisionEvents(data.length > 1);
useColorVisionEvents({enabled: data.length > 1});

const selectedTheme = useTheme(theme);
const seriesColors = useThemeSeriesColors(data, selectedTheme);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function Chart({
xAxisOptions,
yAxisOptions,
}: Props) {
useColorVisionEvents(data.length > 1);
useColorVisionEvents({enabled: data.length > 1});

const selectedTheme = useTheme();
const {characterWidths} = useChartContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import {useEffect} from 'react';
import {COLOR_VISION_EVENT, useChartContext} from '@shopify/polaris-viz-core';
import {
BoundingRect,
COLOR_VISION_EVENT,
useChartContext,
} from '@shopify/polaris-viz-core';

import {useExternalHideEvents} from '../ExternalEvents';

import {getDataSetItem, getEventName} from './utilities';

export function useColorVisionEvents(enabled = true) {
export interface Props {
enabled?: boolean;
dimensions?: BoundingRect;
}

export function useColorVisionEvents(props?: Partial<Props>) {
const {enabled = true, dimensions} = props || {};

const {id} = useChartContext();
const {hiddenIndexes} = useExternalHideEvents();

Expand Down Expand Up @@ -70,5 +81,5 @@ export function useColorVisionEvents(enabled = true) {
item.removeEventListener('blur', onMouseLeave);
});
};
}, [id, enabled, hiddenIndexes]);
}, [id, enabled, hiddenIndexes, dimensions]);
}

0 comments on commit 1ff96f2

Please sign in to comment.