Skip to content

Commit 0823548

Browse files
committed
Move global chart context hooks into separate files
1 parent 46cb0fb commit 0823548

21 files changed

+83
-86
lines changed

projects/js-packages/charts/src/components/bar-chart/bar-chart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
GlobalChartsProvider,
1515
useChartId,
1616
useChartRegistration,
17-
useGlobalChartsContext,
17+
useGlobalChartContext,
1818
} from '../../providers/chart-context';
1919
import { GlobalChartsContext } from '../../providers/chart-context/global-charts-provider';
2020
import { attachSubComponents } from '../../utils';
@@ -125,7 +125,7 @@ const BarChartInternal: FC< BarChartProps > = ( {
125125
totalPoints,
126126
} );
127127

128-
const { resolveGroupColor } = useGlobalChartsContext();
128+
const { resolveGroupColor } = useGlobalChartContext();
129129

130130
const getColor = useCallback(
131131
( seriesData: SeriesData, index: number ) =>

projects/js-packages/charts/src/components/conversion-funnel-chart/conversion-funnel-chart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { __experimentalText as Text } from '@wordpress/components'; // eslint-disable-line @wordpress/no-unsafe-wp-apis
22
import clsx from 'clsx';
33
import { type FC, useRef, useMemo, useEffect, useCallback } from 'react';
4-
import { useGlobalChartTheme } from '../../hooks';
4+
import { useGlobalChartTheme } from '../../providers/chart-context';
55
import styles from './conversion-funnel-chart.module.scss';
66
import { useFunnelSelection } from './hooks/use-funnel-selection';
77
import { hexToRgba } from './utils/color-utils';

projects/js-packages/charts/src/components/leaderboard-chart/leaderboard-chart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { Fragment } from '@wordpress/element';
99
import clsx from 'clsx';
1010
import { type FC } from 'react';
11-
import { useGlobalChartTheme } from '../../hooks';
11+
import { useGlobalChartTheme } from '../../providers/chart-context';
1212
import { formatMetricValue } from '../../utils';
1313
import styles from './leaderboard-chart.module.scss';
1414

projects/js-packages/charts/src/components/legend/base-legend.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { LegendItem, LegendLabel, LegendOrdinal, LegendShape } from '@visx/legen
33
import { scaleOrdinal } from '@visx/scale';
44
import clsx from 'clsx';
55
import { forwardRef, useCallback, useMemo, useContext } from 'react';
6-
import { useGlobalChartTheme } from '../../hooks';
7-
import { GlobalChartsContext } from '../../providers/chart-context';
6+
import { useGlobalChartTheme, GlobalChartsContext } from '../../providers/chart-context';
87
import styles from './legend.module.scss';
98
import { valueOrIdentity, valueOrIdentityString, labelTransformFactory } from './utils';
109
import type { BaseLegendProps } from './types';

projects/js-packages/charts/src/components/legend/use-chart-legend-items.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { LineStyles } from '@visx/xychart';
22
import { CSSProperties, useMemo } from 'react';
3-
import { useGlobalChartTheme } from '../../hooks';
3+
import { useGlobalChartTheme } from '../../providers/chart-context';
44
import { getItemShapeStyles, getSeriesStroke } from '../../utils';
55
import type { LegendItemWithGlyph, LegendItemWithoutGlyph } from './types';
66
import type { ChartTheme, SeriesData, DataPointDate, DataPointPercentage } from '../../types';

projects/js-packages/charts/src/components/line-chart/line-chart-annotation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { DataContext } from '@visx/xychart';
1010
import merge from 'deepmerge';
1111
import { useContext, useRef, useEffect, useState, useMemo } from 'react';
12-
import { useGlobalChartTheme } from '../../hooks';
12+
import { useGlobalChartTheme } from '../../providers/chart-context';
1313
import { isSafari } from '../../utils';
1414
import LineChartAnnotationLabelWithPopover, {
1515
POPOVER_BUTTON_SIZE,

projects/js-packages/charts/src/components/line-chart/line-chart.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { __ } from '@wordpress/i18n';
66
import clsx from 'clsx';
77
import { useMemo, useContext, forwardRef, useImperativeHandle, useState, useRef } from 'react';
88
import {
9-
useGlobalChartTheme,
109
useXYChartTheme,
1110
useChartDataTransform,
1211
useChartMargin,
@@ -17,7 +16,8 @@ import {
1716
GlobalChartsContext,
1817
useChartId,
1918
useChartRegistration,
20-
useGlobalChartsContext,
19+
useGlobalChartContext,
20+
useGlobalChartTheme,
2121
} from '../../providers/chart-context';
2222
import { attachSubComponents, getSeriesLineStyles } from '../../utils';
2323
import { DefaultGlyph } from '../default-glyph';
@@ -278,7 +278,7 @@ const LineChartInternal = forwardRef< SingleChartRef, LineChartProps >(
278278
);
279279

280280
const dataSorted = useChartDataTransform( data );
281-
const { resolveGroupColor } = useGlobalChartsContext();
281+
const { resolveGroupColor } = useGlobalChartContext();
282282

283283
// Use the keyboard navigation hook
284284
const { tooltipRef, onChartFocus, onChartBlur, onChartKeyDown } = useKeyboardNavigation( {

projects/js-packages/charts/src/components/line-chart/stories/glyph.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GlyphStar } from '@visx/glyph';
2-
import { useGlobalChartTheme } from '../../../hooks';
2+
import { useGlobalChartTheme } from '../../../providers/chart-context';
33
import { GlobalChartsProvider } from '../../../providers/chart-context/global-charts-provider';
44
import { CHART_THEME_MAP, themeArgTypes } from '../../../stories/theme-config';
55
import LineChart from '../line-chart';

projects/js-packages/charts/src/components/pie-chart/pie-chart.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { Group } from '@visx/group';
22
import { Pie } from '@visx/shape';
33
import clsx from 'clsx';
44
import { useContext, useMemo } from 'react';
5-
import { useChartMouseHandler, useGlobalChartTheme, useElementHeight } from '../../hooks';
5+
import { useChartMouseHandler, useElementHeight } from '../../hooks';
66
import {
77
GlobalChartsProvider,
88
useChartId,
99
useChartRegistration,
10-
useGlobalChartsContext,
10+
useGlobalChartContext,
11+
useGlobalChartTheme,
1112
} from '../../providers/chart-context';
1213
import { GlobalChartsContext } from '../../providers/chart-context/global-charts-provider';
1314
import { attachSubComponents } from '../../utils';
@@ -155,7 +156,7 @@ const PieChartInternal = ( {
155156
metadata: chartMetadata,
156157
} );
157158

158-
const { resolveGroupColor } = useGlobalChartsContext();
159+
const { resolveGroupColor } = useGlobalChartContext();
159160

160161
if ( ! isValid ) {
161162
return (

projects/js-packages/charts/src/components/pie-semi-circle-chart/pie-semi-circle-chart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
GlobalChartsProvider,
1111
useChartId,
1212
useChartRegistration,
13-
useGlobalChartsContext,
13+
useGlobalChartContext,
1414
GlobalChartsContext,
1515
} from '../../providers/chart-context';
1616
import { attachSubComponents } from '../../utils';
@@ -148,7 +148,7 @@ const PieSemiCircleChartInternal: FC< PieSemiCircleChartProps > = ( {
148148
// Validate data first to get validation result
149149
const { isValid, message } = validateData( data );
150150

151-
const { resolveGroupColor } = useGlobalChartsContext();
151+
const { resolveGroupColor } = useGlobalChartContext();
152152

153153
// Define accessors with useMemo to avoid changing dependencies
154154
const accessors = useMemo(

0 commit comments

Comments
 (0)