Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
606679c
start implementing searchPieChart
borys3kk Jan 30, 2026
6782c20
pie chart working on search
borys3kk Jan 30, 2026
6f1cde4
searchPieChart implemented
borys3kk Jan 30, 2026
275d567
npm run prettier
borys3kk Jan 30, 2026
a70b5c1
make barChart/index.tsx react compiler compliant
borys3kk Jan 30, 2026
b9f06cd
make pieChart/index.tsx react compiler compliant
borys3kk Jan 30, 2026
9f54f5f
move ProcessedSlice type to types.ts
borys3kk Jan 30, 2026
08865f6
return to previous const
borys3kk Jan 30, 2026
38e55da
change slice calculation logic
borys3kk Jan 30, 2026
0339b9e
fix prettier
borys3kk Jan 30, 2026
bc08314
Merge branch 'main' of github.com:Expensify/App into add-search-pie-c…
borys3kk Jan 30, 2026
bb73d26
add missing type :)
borys3kk Jan 30, 2026
43ba339
fix prettier :):)
borys3kk Jan 30, 2026
4949699
final typecheck fix?
borys3kk Jan 30, 2026
24293ce
add last missing translations
borys3kk Jan 30, 2026
1075ae1
add translations
borys3kk Jan 30, 2026
72667cf
use already exisitng other tranlsations
borys3kk Jan 30, 2026
6757883
merge main
borys3kk Jan 30, 2026
f23b2ef
fix pretier
borys3kk Jan 30, 2026
6fb44eb
fix tests
borys3kk Jan 30, 2026
e4d4266
fix prettier
borys3kk Jan 30, 2026
b34da1b
merge main
borys3kk Feb 6, 2026
020334d
Merge branch 'main' of github.com:Expensify/App into add-search-pie-c…
borys3kk Feb 9, 2026
f105069
fix merge conflicts, remove other slice, resolve types errors
borys3kk Feb 9, 2026
575bfd1
merge main
borys3kk Feb 9, 2026
c8899cd
fix translations
borys3kk Feb 9, 2026
1b88e83
fix prettier
borys3kk Feb 10, 2026
f0e5574
Resolve conflicts
mateuuszzzzz Feb 17, 2026
5441f87
Fix tooltip after merge of main and cleanup implementationg
mateuuszzzzz Feb 17, 2026
05fbc6d
Remove manual memoization from components touched in this PR
mateuuszzzzz Feb 17, 2026
9004095
Reuse label formatting logic instead of duplicating it for PieChart
mateuuszzzzz Feb 17, 2026
6386e27
Do not store object in state
mateuuszzzzz Feb 17, 2026
940b8b9
Simplify PieChartContent utility functions
mateuuszzzzz Feb 17, 2026
b378b51
Add unit tests for PieChartContent utility functions
mateuuszzzzz Feb 18, 2026
6703ddc
Resolve conflicts and cleanup code after resolving them
mateuuszzzzz Feb 18, 2026
d5a2dfd
Fix isAngleInSlice and add tests covering previous bug
mateuuszzzzz Feb 18, 2026
1a5f00b
Propagate unit position to PieChartContent
mateuuszzzzz Feb 19, 2026
cfeab63
Fix test description and add tests for formatLabel
mateuuszzzzz Feb 23, 2026
ea23c22
Merge branch 'main' into add-search-pie-chart-component
mateuuszzzzz Feb 23, 2026
14adf52
Fix prettier after merging main
mateuuszzzzz Feb 23, 2026
edade67
Address review comments
mateuuszzzzz Feb 23, 2026
f0eb859
Merge branch 'main' into add-search-pie-chart-component
mateuuszzzzz Feb 23, 2026
7b4d824
Remove unused styles
mateuuszzzzz Feb 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7419,6 +7419,7 @@ const CONST = {
TABLE: 'table',
BAR: 'bar',
LINE: 'line',
PIE: 'pie',
},
SYNTAX_FILTER_KEYS: {
TYPE: 'type',
Expand Down
12 changes: 6 additions & 6 deletions src/components/Charts/BarChart/BarChartContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ function BarChartContent({data, title, titleIcon, isLoading, yAxisUnit, yAxisUni
return {...BASE_DOMAIN_PADDING, left: horizontalPadding, right: horizontalPadding};
}, [chartWidth, data.length]);

const {formatXAxisLabel, formatYAxisLabel} = useChartLabelFormats({
const {formatLabel, formatValue} = useChartLabelFormats({
data,
font,
yAxisUnit,
yAxisUnitPosition,
unit: yAxisUnit,
unitPosition: yAxisUnitPosition,
labelSkipInterval,
labelRotation,
truncatedLabels,
Expand Down Expand Up @@ -147,7 +147,7 @@ function BarChartContent({data, title, titleIcon, isLoading, yAxisUnit, yAxisUni
yZero,
});

const tooltipData = useTooltipData(activeDataIndex, data, formatYAxisLabel);
const tooltipData = useTooltipData(activeDataIndex, data, formatValue);

const renderBar = useCallback(
(point: PointsArray[number], chartBounds: ChartBounds, barCount: number) => {
Expand Down Expand Up @@ -219,15 +219,15 @@ function BarChartContent({data, title, titleIcon, isLoading, yAxisUnit, yAxisUni
// Victory-native positions x-axis labels at: chartBounds.bottom + labelOffset + fontSize.
// We subtract descent (fontSize - ascent) so the gap from chart to the ascent line equals AXIS_LABEL_GAP.
labelOffset: AXIS_LABEL_GAP - Math.abs(font?.getMetrics().descent ?? 0),
formatXLabel: formatXAxisLabel,
formatXLabel: formatLabel,
labelRotate: labelRotation,
labelOverflow: 'visible',
}}
yAxis={[
{
font,
labelColor: theme.textSupporting,
formatYLabel: formatYAxisLabel,
formatYLabel: formatValue,
tickCount: Y_AXIS_TICK_COUNT,
lineWidth: Y_AXIS_LINE_WIDTH,
lineColor: theme.border,
Expand Down
3 changes: 2 additions & 1 deletion src/components/Charts/BarChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import ActivityIndicator from '@components/ActivityIndicator';
import useThemeStyles from '@hooks/useThemeStyles';
import type {BarChartProps} from './BarChartContent';

const getBarChartContent = () => import('./BarChartContent');
function BarChart(props: BarChartProps) {
const styles = useThemeStyles();

return (
<WithSkiaWeb
opts={{locateFile: (file: string) => `/${file}`}}
getComponent={() => import('./BarChartContent')}
getComponent={getBarChartContent}
componentProps={props}
fallback={
<View style={[styles.flex1, styles.justifyContentCenter, styles.alignItemsCenter, styles.highlightBG, styles.br4, styles.p5]}>
Expand Down
10 changes: 5 additions & 5 deletions src/components/Charts/LineChart/LineChartContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ function LineChartContent({data, title, titleIcon, isLoading, yAxisUnit, yAxisUn
// Convert hook's degree rotation to radians for Skia rendering
const angleRad = (Math.abs(labelRotation) * Math.PI) / 180;

const {formatYAxisLabel} = useChartLabelFormats({
const {formatValue} = useChartLabelFormats({
data,
font,
yAxisUnit,
yAxisUnitPosition,
unit: yAxisUnit,
unitPosition: yAxisUnitPosition,
});

const checkIsOverDot = useCallback((args: HitTestArgs) => {
Expand All @@ -151,7 +151,7 @@ function LineChartContent({data, title, titleIcon, isLoading, yAxisUnit, yAxisUn
checkIsOver: checkIsOverDot,
});

const tooltipData = useTooltipData(activeDataIndex, data, formatYAxisLabel);
const tooltipData = useTooltipData(activeDataIndex, data, formatValue);

// Custom x-axis labels with hybrid positioning:
// - At 0° (horizontal): center label under the point (like bar chart)
Expand Down Expand Up @@ -264,7 +264,7 @@ function LineChartContent({data, title, titleIcon, isLoading, yAxisUnit, yAxisUn
{
font,
labelColor: theme.textSupporting,
formatYLabel: formatYAxisLabel,
formatYLabel: formatValue,
tickCount: Y_AXIS_TICK_COUNT,
lineWidth: Y_AXIS_LINE_WIDTH,
lineColor: theme.border,
Expand Down
188 changes: 188 additions & 0 deletions src/components/Charts/PieChart/PieChartContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
import React, {useState} from 'react';
import type {LayoutChangeEvent} from 'react-native';
import {View} from 'react-native';
import {Gesture, GestureDetector} from 'react-native-gesture-handler';
import Animated, {useSharedValue} from 'react-native-reanimated';
import {scheduleOnRN} from 'react-native-worklets';
import {Pie, PolarChart} from 'victory-native';
import ActivityIndicator from '@components/ActivityIndicator';
import ChartHeader from '@components/Charts/components/ChartHeader';
import ChartTooltip from '@components/Charts/components/ChartTooltip';
import {PIE_CHART_START_ANGLE} from '@components/Charts/constants';
import {TOOLTIP_BAR_GAP, useChartLabelFormats, useTooltipData} from '@components/Charts/hooks';
import type {ChartDataPoint, ChartProps, PieSlice, UnitPosition} from '@components/Charts/types';
import {findSliceAtPosition, processDataIntoSlices} from '@components/Charts/utils';
import Text from '@components/Text';
import useThemeStyles from '@hooks/useThemeStyles';

type PieChartProps = ChartProps & {
/** Callback when a slice is pressed */
onSlicePress?: (dataPoint: ChartDataPoint, index: number) => void;

/** Symbol/unit for value labels in tooltip (e.g., '$', '€'). */
valueUnit?: string;

/** Position of the unit symbol relative to the value. Defaults to 'left'. */
valueUnitPosition?: UnitPosition;
};

function PieChartContent({data, title, titleIcon, isLoading, valueUnit, valueUnitPosition, onSlicePress}: PieChartProps) {
const styles = useThemeStyles();
const [canvasWidth, setCanvasWidth] = useState(0);
const [canvasHeight, setCanvasHeight] = useState(0);
const [activeSliceIndex, setActiveSliceIndex] = useState(-1);

// Shared values for hover state
const isHovering = useSharedValue(false);
const cursorX = useSharedValue(0);
const cursorY = useSharedValue(0);
const tooltipPosition = useSharedValue({x: 0, y: 0});

const handleLayout = (event: LayoutChangeEvent) => {
setCanvasWidth(event.nativeEvent.layout.width);
setCanvasHeight(event.nativeEvent.layout.height);
};

// Slices are sorted by absolute value (largest first) for color assignment,
// so slice indices don't match the original data array. We map back via
// originalIndex so the tooltip can display the original (possibly negative) value.
const processedSlices = processDataIntoSlices(data, PIE_CHART_START_ANGLE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memoize this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mateuuszzzzz any idea on this?

const activeOriginalDataIndex = activeSliceIndex >= 0 ? (processedSlices.at(activeSliceIndex)?.originalIndex ?? -1) : -1;

const {formatValue} = useChartLabelFormats({data, unit: valueUnit, unitPosition: valueUnitPosition});
const tooltipData = useTooltipData(activeOriginalDataIndex, data, formatValue);

// Calculate pie geometry
const pieGeometry = {radius: Math.min(canvasWidth, canvasHeight) / 2, centerX: canvasWidth / 2, centerY: canvasHeight / 2};

// Handle hover state updates
const updateActiveSlice = (x: number, y: number) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-6 (docs)

This function should be wrapped in useCallback to avoid recreation on every render. It's passed to scheduleOnRN in gesture handlers, so a stable reference is important.

const updateActiveSlice = useCallback((x: number, y: number) => {
    const {radius, centerX, centerY} = pieGeometry;
    const sliceIndex = findSliceAtPosition(x, y, centerX, centerY, radius, 0, processedSlices);
    setActiveSliceIndex(sliceIndex);
}, [pieGeometry, processedSlices]);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah a lot of stuff can be used with useCallback, can we fix every callback in this file?

const {radius, centerX, centerY} = pieGeometry;
const sliceIndex = findSliceAtPosition(x, y, centerX, centerY, radius, 0, processedSlices);
setActiveSliceIndex(sliceIndex);
};

// Handle slice press callback
const handleSlicePress = (sliceIndex: number) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-6 (docs)

This function should be wrapped in useCallback to avoid recreation on every render. It's passed to scheduleOnRN in gesture handlers, so a stable reference is important.

const handleSlicePress = useCallback((sliceIndex: number) => {
    if (sliceIndex < 0 || sliceIndex >= processedSlices.length) {
        return;
    }
    const slice = processedSlices.at(sliceIndex);
    if (!slice || slice.isOther) {
        return;
    }
    const originalDataPoint = data.at(slice.originalIndex);
    if (originalDataPoint && onSlicePress) {
        onSlicePress(originalDataPoint, slice.originalIndex);
    }
}, [processedSlices, data, onSlicePress]);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

if (sliceIndex < 0 || sliceIndex >= processedSlices.length) {
return;
}
const slice = processedSlices.at(sliceIndex);
if (!slice) {
return;
}
const originalDataPoint = data.at(slice.originalIndex);
if (originalDataPoint && onSlicePress) {
onSlicePress(originalDataPoint, slice.originalIndex);
}
};

// Hover gesture
const hoverGesture = () =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-6 (docs)

This gesture handler function should be wrapped in useCallback to avoid recreation on every render. Recreating gesture handlers on every render can cause performance issues and unexpected behavior.

const hoverGesture = useCallback(
    () =>
        Gesture.Hover()
            .onBegin((e) => {
                'worklet';
                isHovering.set(true);
                cursorX.set(e.x);
                cursorY.set(e.y);
                scheduleOnRN(updateActiveSlice, e.x, e.y);
            })
            .onUpdate((e) => {
                'worklet';
                cursorX.set(e.x);
                cursorY.set(e.y);
                scheduleOnRN(updateActiveSlice, e.x, e.y);
            })
            .onEnd(() => {
                'worklet';
                isHovering.set(false);
                scheduleOnRN(setActiveSliceIndex, -1);
            }),
    [updateActiveSlice, isHovering, cursorX, cursorY]
);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Gesture.Hover()
.onBegin((e) => {
'worklet';

isHovering.set(true);
cursorX.set(e.x);
cursorY.set(e.y);
tooltipPosition.set({x: e.x, y: e.y - TOOLTIP_BAR_GAP});
scheduleOnRN(updateActiveSlice, e.x, e.y);
})
.onUpdate((e) => {
'worklet';

cursorX.set(e.x);
cursorY.set(e.y);
tooltipPosition.set({x: e.x, y: e.y - TOOLTIP_BAR_GAP});
scheduleOnRN(updateActiveSlice, e.x, e.y);
})
.onEnd(() => {
'worklet';

isHovering.set(false);
scheduleOnRN(setActiveSliceIndex, -1);
});

// Tap gesture for click/tap navigation
const tapGesture = () =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-6 (docs)

This gesture handler function should be wrapped in useCallback to avoid recreation on every render. Recreating gesture handlers on every render can cause performance issues and unexpected behavior.

const tapGesture = useCallback(
    () =>
        Gesture.Tap().onEnd((e) => {
            'worklet';
            const {radius, centerX, centerY} = pieGeometry;
            const sliceIndex = findSliceAtPosition(e.x, e.y, centerX, centerY, radius, 0, processedSlices);
            if (sliceIndex >= 0) {
                scheduleOnRN(handleSlicePress, sliceIndex);
            }
        }),
    [pieGeometry, processedSlices, handleSlicePress]
);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Gesture.Tap().onEnd((e) => {
'worklet';

const {radius, centerX, centerY} = pieGeometry;
const sliceIndex = findSliceAtPosition(e.x, e.y, centerX, centerY, radius, 0, processedSlices);

if (sliceIndex >= 0) {
scheduleOnRN(handleSlicePress, sliceIndex);
}
});
Comment on lines +80 to +118

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already called out by GH review but we should use useCallback


// Combined gestures - Race allows both hover and tap to work independently
const combinedGesture = Gesture.Race(hoverGesture(), tapGesture());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-6 (docs)

This combined gesture should be wrapped in useMemo to avoid recreation on every render. Creating new gesture combinations on every render impacts performance.

const combinedGesture = useMemo(
    () => Gesture.Race(hoverGesture(), tapGesture()),
    [hoverGesture, tapGesture]
);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.


const renderLegendItem = (slice: PieSlice) => {
return (
<View
key={`legend-${slice.label}`}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include a unique ID as well? Like legend-${slice.originalIndex}-${slice.label}.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still an index, but with a permutation applied, so I don't think we should add it to the key. slice.label should be enough in this case. It's unlikely that those labels will repeat

Comment thread
borys3kk marked this conversation as resolved.
Resolved
style={[styles.flexRow, styles.alignItemsCenter, styles.mr4, styles.mb2]}
>
<View style={[styles.pieChartLegendDot, {backgroundColor: slice.color}]} />
<Text style={[styles.textNormal, styles.ml2]}>{slice.label}</Text>
</View>
);
};

if (isLoading) {
return (
<View style={[styles.pieChartContainer, styles.highlightBG, styles.justifyContentCenter, styles.alignItemsCenter]}>
<ActivityIndicator size="large" />
</View>
);
}

if (data.length === 0) {
return null;
}
Comment on lines +143 to +145

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking if this is expected that we return null here? It seems like when we are loading data, we show a loading spinner. Is a placeholder going to render in this case elsewhere?

@mateuuszzzzz mateuuszzzzz Feb 24, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is more of a defensive condition. In practice, Search will render the EmptySearchView component. However, this is something we might want to revisit once we create the PR for concierge chart embeddings, as we will likely use new lightweight components instead of the main heavy search component.


return (
<View style={[styles.pieChartContainer, styles.highlightBG]}>
<ChartHeader
title={title}
titleIcon={titleIcon}
/>

<GestureDetector gesture={combinedGesture}>
<Animated.View
style={styles.pieChartChartContainer}
onLayout={handleLayout}
>
{processedSlices.length > 0 && (
<PolarChart
data={processedSlices}
labelKey="label"
valueKey="value"
colorKey="color"
>
<Pie.Chart startAngle={PIE_CHART_START_ANGLE} />
</PolarChart>
)}

{/* Tooltip */}
{activeSliceIndex >= 0 && !!tooltipData && (
<ChartTooltip
label={tooltipData.label}
amount={tooltipData.amount}
percentage={tooltipData.percentage}
chartWidth={canvasWidth}
initialTooltipPosition={tooltipPosition}
/>
)}
</Animated.View>
</GestureDetector>
<View style={styles.pieChartLegendContainer}>{processedSlices.map((slice) => renderLegendItem(slice))}</View>
</View>
);
}

export default PieChartContent;
export type {PieChartProps};
12 changes: 12 additions & 0 deletions src/components/Charts/PieChart/index.native.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import type {PieChartProps} from './PieChartContent';
import PieChartContent from './PieChartContent';

function PieChart(props: PieChartProps) {
// eslint-disable-next-line react/jsx-props-no-spreading
return <PieChartContent {...props} />;
}

PieChart.displayName = 'PieChart';

export default PieChart;
29 changes: 29 additions & 0 deletions src/components/Charts/PieChart/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {WithSkiaWeb} from '@shopify/react-native-skia/lib/module/web';
import React from 'react';
import {View} from 'react-native';
import ActivityIndicator from '@components/ActivityIndicator';
import useThemeStyles from '@hooks/useThemeStyles';
import type {PieChartProps} from './PieChartContent';

const getPieChartContent = () => import('./PieChartContent');

function PieChart(props: PieChartProps) {
const styles = useThemeStyles();

return (
<WithSkiaWeb
opts={{locateFile: (file: string) => `/${file}`}}
getComponent={getPieChartContent}
componentProps={props}
fallback={
<View style={[styles.flex1, styles.justifyContentCenter, styles.alignItemsCenter, styles.highlightBG, styles.br4, styles.p5]}>
<ActivityIndicator size="large" />
</View>
}
/>
);
}

PieChart.displayName = 'PieChart';

export default PieChart;
5 changes: 4 additions & 1 deletion src/components/Charts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ const X_AXIS_LINE_WIDTH = 0;
/** Line width for Y-axis grid lines */
const Y_AXIS_LINE_WIDTH = 1;

export {Y_AXIS_TICK_COUNT, AXIS_LABEL_GAP, CHART_PADDING, CHART_CONTENT_MIN_HEIGHT, X_AXIS_LINE_WIDTH, Y_AXIS_LINE_WIDTH};
/** Starting angle for pie chart (0 = 3 o'clock, -90 = 12 o'clock) */
const PIE_CHART_START_ANGLE = -90;

export {Y_AXIS_TICK_COUNT, AXIS_LABEL_GAP, CHART_PADDING, CHART_CONTENT_MIN_HEIGHT, X_AXIS_LINE_WIDTH, Y_AXIS_LINE_WIDTH, PIE_CHART_START_ANGLE};
4 changes: 1 addition & 3 deletions src/components/Charts/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export {useChartInteractionState} from './useChartInteractionState';
export {useChartLabelLayout} from './useChartLabelLayout';
export {useChartInteractions} from './useChartInteractions';
export {useChartInteractions, TOOLTIP_BAR_GAP} from './useChartInteractions';
export type {HitTestArgs} from './useChartInteractions';
export type {ChartInteractionState} from './useChartInteractionState';
export {default as useChartLabelFormats} from './useChartLabelFormats';
export {default as useDynamicYDomain} from './useDynamicYDomain';
export {useTooltipData} from './useTooltipData';
31 changes: 3 additions & 28 deletions src/components/Charts/hooks/useChartInteractions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,8 @@ type CartesianActionsHandle = {
};

/**
* Hook to manage complex chart interactions including hover gestures (web),
* tap gestures (mobile/web), hit-testing, and animated tooltip positioning.
*
* It synchronizes high-frequency interaction data from the UI thread to React state
* for metadata display (like tooltips) and navigation.
*
* @param props - Configuration including press handlers and hit-test logic.
* @returns An object containing refs, gestures, and state for the chart component.
*
* @example
* ```tsx
* const { actionsRef, customGestures, activeDataIndex, isTooltipActive, tooltipStyle } = useChartInteractions({
* handlePress: (index) => console.log("Pressed index:", index),
* checkIsOver: ({ cursorX, targetX, barWidth }) => {
* 'worklet';
* return Math.abs(cursorX - targetX) < barWidth / 2;
* },
* barGeometry: myBarSharedValue,
* });
*
* return (
* <View>
* <CartesianChart customGestures={customGestures} actionsRef={actionsRef} ... />
* {isTooltipActive && <Animated.View style={tooltipStyle}><Tooltip index={activeDataIndex} /></Animated.View>}
* </View>
* );
* ```
* Manages chart interactions (hover, tap, hit-testing) and animated tooltip positioning.
* Synchronizes high-frequency UI thread data to React state for tooltip display and navigation.
*/
function useChartInteractions({handlePress, checkIsOver, chartBottom, yZero}: UseChartInteractionsProps) {
/** Interaction state compatible with Victory Native's internal logic */
Expand Down Expand Up @@ -225,5 +200,5 @@ function useChartInteractions({handlePress, checkIsOver, chartBottom, yZero}: Us
};
}

export {useChartInteractions};
export {useChartInteractions, TOOLTIP_BAR_GAP};
export type {HitTestArgs};
Loading
Loading