Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a4bb64d
feat: add hover gesture support (enableHover + chartHoverConfig)
adamhari Oct 25, 2026
441e1c2
feat: add pie hover support and hover examples across chart varieties
adamhari Oct 25, 2026
451fffd
docs: hover gesture documentation + more hover examples
adamhari Oct 26, 2026
0d471fd
example: remove dedicated hover-gesture page
adamhari Oct 26, 2026
9ebf07c
example: remove hover-gesture route and docs reference
adamhari Oct 26, 2026
7002bf9
fix: press/click no longer resets hover-driven chart press state
adamhari Oct 26, 2026
d8b884a
example: drive ordinal-data active dot from the shared value
adamhari Oct 26, 2026
7f5d72e
example: drive horizontal-bands-line dot from the shared value
adamhari Oct 26, 2026
b3531cf
example: enable hover on user-facing chart examples
adamhari Oct 27, 2026
ae5e399
example: fix web renderer freeze from font-passing chart wrappers
adamhari Oct 27, 2026
e69f311
chore: trim verbose comments from the hover additions
adamhari Oct 28, 2026
505156a
chore: prune remaining inline comments to exceptional cases only
adamhari Oct 28, 2026
9648ccf
refactor: extract pie hover hit-test into a pure, unit-tested helper
adamhari Oct 30, 2026
cc9e682
fix: clear pie hover state when the chart data changes
adamhari Oct 30, 2026
38aa34c
feat: warn in development when enableHover is set without chartPressS…
adamhari Oct 30, 2026
008aa45
feat: add hoverState prop so hover and press interactions are distinct
adamhari Oct 30, 2026
d9e20a9
docs: document cartesian hoverState for distinct hover and press
adamhari Oct 30, 2026
a9f2001
example: demonstrate distinct hover and press states
adamhari Oct 30, 2026
101b154
fix: restore default press activation in the hover-press example
adamhari Oct 30, 2026
d9da671
feat: add simultaneousWithExternalGesture to chartHoverConfig
adamhari Oct 31, 2026
33a48d0
refactor: rename hoverState prop to chartHoverState for API consistency
adamhari Oct 31, 2026
ab2f1f5
docs: fix polar chart chartHoverState anchor in pie docs cross-link
adamhari Oct 31, 2026
3807bf6
feat: built-in pie hover state and enable hover by default on web
adamhari Nov 1, 2026
5649b95
feat: CartesianChart built-in hover state for full pie API parity
adamhari Nov 2, 2026
6531333
chore: trim inline comments across hover PR code
adamhari Nov 2, 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
11 changes: 11 additions & 0 deletions .changeset/hover-gesture-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"victory-native": minor
---

Add hover gesture support.

Hover is aimed at pointer devices (mouse/trackpad on web or desktop) and is **enabled by default on web**; `enableHover` opts in on other platforms and `enableHover={false}` opts out on web. The hover gesture is composed simultaneously with the press and transform gestures, so touch-only behavior is unchanged.

- `CartesianChart`: hover drives the `chartPressState` values exactly like a press (values and `isActive`), or a separate `chartHoverState` prop (`ChartPressState | ChartPressState[]`) to track hover and press independently. With no states passed at all, the chart maintains a built-in hover state exposed through the render functions' `hoverState` field (`isActive`, `x.value`/`x.position`, `y.<yKey>.value`/`position`), so hover readouts need zero setup — mirroring `PolarChart`.
- `PolarChart`: the hovered-slice index is tracked for you — read it in chart content with the new `usePieHoverState()` hook (`index` is the hovered slice, or `-1` over the donut hole, outside the pie, or off the chart). Pass `chartHoverState={{ index }}` — a Reanimated shared value — only to consume the index outside the chart.
- `chartHoverConfig` (both charts): supports `activeCursor` for cursor styling and `simultaneousWithExternalGesture` to compose the hover gesture with custom gestures built outside the chart.
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ module.exports = {
sourceType: "script",
},
},
{
env: {
node: true,
browser: false,
},
files: ["**/metro.config.js"],
parserOptions: {
sourceType: "script",
},
},
],
parser: "@typescript-eslint/parser",
parserOptions: {
Expand Down
26 changes: 11 additions & 15 deletions example/app/axis-label-renderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ const createBadgeLabelRenderer = (

export default function AxisLabelRenderersPage(props: { segment: string }) {
const description = descriptionForRoute(props.segment);
const font = useFont(inter, 12);
const badgeLabelRenderer = createBadgeLabelRenderer(font);

return (
<SafeAreaView style={styles.safeView}>
Expand All @@ -120,7 +118,7 @@ export default function AxisLabelRenderersPage(props: { segment: string }) {
description="Paragraph labels reserve space for mixed scripts and explicit line breaks on a horizontal category axis."
>
<View style={styles.horizontalChart}>
<MultilingualHorizontalChart font={font} />
<MultilingualHorizontalChart />
</View>
</ChartSection>

Expand All @@ -129,7 +127,7 @@ export default function AxisLabelRenderersPage(props: { segment: string }) {
description="Paragraph labels can constrain width while newline labels keep the numeric axis compact."
>
<View style={styles.verticalChart}>
<ParagraphXAxisChart font={font} />
<ParagraphXAxisChart />
</View>
</ChartSection>

Expand All @@ -138,7 +136,7 @@ export default function AxisLabelRenderersPage(props: { segment: string }) {
description="Custom renderers measure their own label boxes before the chart reserves axis space."
>
<View style={styles.verticalChart}>
<BadgeAxisChart font={font} labelRenderer={badgeLabelRenderer} />
<BadgeAxisChart />
</View>
</ChartSection>
</ScrollView>
Expand Down Expand Up @@ -166,7 +164,8 @@ function ChartSection({
);
}

function MultilingualHorizontalChart({ font }: { font: SkFont | null }) {
function MultilingualHorizontalChart() {
const font = useFont(inter, 12);
return (
<CartesianChart
orientation="horizontal"
Expand Down Expand Up @@ -231,7 +230,8 @@ function MultilingualHorizontalChart({ font }: { font: SkFont | null }) {
);
}

function ParagraphXAxisChart({ font }: { font: SkFont | null }) {
function ParagraphXAxisChart() {
const font = useFont(inter, 12);
return (
<CartesianChart
data={LOCALIZED_PERIODS}
Expand Down Expand Up @@ -293,13 +293,9 @@ function ParagraphXAxisChart({ font }: { font: SkFont | null }) {
);
}

function BadgeAxisChart({
font,
labelRenderer,
}: {
font: SkFont | null;
labelRenderer: AxisLabelRenderer<string>;
}) {
function BadgeAxisChart() {
const font = useFont(inter, 12);
const badgeLabelRenderer = createBadgeLabelRenderer(font);
return (
<CartesianChart
data={BADGE_DATA}
Expand All @@ -312,7 +308,7 @@ function BadgeAxisChart({
tickCount: BADGE_DATA.length,
labelColor: "#155e75",
labelOffset: 8,
labelRenderer,
labelRenderer: badgeLabelRenderer,
title: {
text: "Release phase",
font,
Expand Down
19 changes: 6 additions & 13 deletions example/app/axis-title-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const CATEGORY_DATA = [

export default function AxisTitleLayoutPage(props: { segment: string }) {
const description = descriptionForRoute(props.segment);
const font = useFont(inter, 12);

return (
<SafeAreaView style={styles.safeView}>
Expand All @@ -45,13 +44,13 @@ export default function AxisTitleLayoutPage(props: { segment: string }) {

<ChartSection title="Numeric Y Axes">
<View style={styles.chart}>
<NumericYAxisTitleChart font={font} />
<NumericYAxisTitleChart />
</View>
</ChartSection>

<ChartSection title="Category Y Axes">
<View style={styles.chart}>
<CategoryYAxisTitleChart font={font} />
<CategoryYAxisTitleChart />
</View>
</ChartSection>
</ScrollView>
Expand All @@ -73,11 +72,8 @@ function ChartSection({
);
}

function NumericYAxisTitleChart({
font,
}: {
font: ReturnType<typeof useFont>;
}) {
function NumericYAxisTitleChart() {
const font = useFont(inter, 12);
return (
<CartesianChart
data={NUMERIC_DATA}
Expand Down Expand Up @@ -144,11 +140,8 @@ function NumericYAxisTitleChart({
);
}

function CategoryYAxisTitleChart({
font,
}: {
font: ReturnType<typeof useFont>;
}) {
function CategoryYAxisTitleChart() {
const font = useFont(inter, 12);
return (
<CartesianChart
orientation="horizontal"
Expand Down
51 changes: 51 additions & 0 deletions example/app/bar-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import {
getTransformComponents,
setScale,
setTranslate,
useChartPressState,
useChartTransformState,
} from "victory-native";
import { useDarkMode } from "react-native-dark";
import {
useAnimatedReaction,
useDerivedValue,
useSharedValue,
withTiming,
} from "react-native-reanimated";
Expand All @@ -31,6 +33,7 @@ import { InfoCard } from "../components/InfoCard";
import { descriptionForRoute } from "../consts/routes";
import { InputSegment } from "../components/InputSegment";
import { InputColor } from "../components/InputColor";
import { AnimatedText } from "../components/AnimatedText";

const DATA = (length: number = 10) =>
Array.from({ length }, (_, index) => ({
Expand Down Expand Up @@ -84,9 +87,43 @@ export default function BarChartPage(props: { segment: string }) {
},
);

const { state: pressState, isActive: pressIsActive } = useChartPressState({
x: 0,
y: { listenCount: 0 },
});

const hoveredLabel = useDerivedValue(() => {
if (!pressIsActive) return "Hover the chart!";
const month = pressState.x.value.value;
const date = new Date(2023, month - 1);
return date.toLocaleString("default", { month: "short" });
});
const hoveredValue = useDerivedValue(() => {
if (!pressIsActive) return "";
return `${pressState.y.listenCount.value.value} plays`;
});

return (
<>
<SafeAreaView style={styles.safeView}>
<View style={{ paddingHorizontal: 20, paddingTop: 12, gap: 4 }}>
<AnimatedText
text={hoveredLabel}
defaultValue="Hover the chart!"
style={[
styles.readout,
{ color: isDark ? appColors.text.dark : appColors.text.light },
]}
/>
<AnimatedText
text={hoveredValue}
defaultValue=""
style={[
styles.readoutValue,
{ color: isDark ? appColors.text.dark : appColors.text.light },
]}
/>
</View>
<View style={styles.chart}>
<CartesianChart
transformState={state}
Expand All @@ -95,6 +132,11 @@ export default function BarChartPage(props: { segment: string }) {
yKeys={["listenCount"]}
domainPadding={{ left: 50, right: 50, top: 30 }}
domain={{ y: [0, 100] }}
chartPressState={pressState}
enableHover
chartHoverConfig={{
activeCursor: "pointer",
}}
xAxis={{
font,
tickCount: 5,
Expand Down Expand Up @@ -228,6 +270,15 @@ const styles = StyleSheet.create({
chart: {
flex: 1.5,
},
readout: {
fontSize: 20,
fontWeight: "bold",
},
readoutValue: {
fontSize: 16,
fontWeight: "400",
opacity: 0.75,
},
optionsScrollView: {
flex: 1,
backgroundColor: appColors.cardBackground.light,
Expand Down
1 change: 1 addition & 0 deletions example/app/bar-charts-custom-bars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export default function BarChartCustomBarsPage() {
</Text>
<CartesianChart
chartPressState={state}
enableHover
xKey="month"
padding={5}
yKeys={["listenCount"]}
Expand Down
1 change: 1 addition & 0 deletions example/app/bar-with-tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export default function BarGroupWithTooltipPage(props: { segment: string }) {
labelColor: isDark ? appColors.text.dark : appColors.text.light,
}}
chartPressState={state}
enableHover
onChartBoundsChange={({ bottom, left }) => {
setChartBottom(bottom);
setChartLeft(left);
Expand Down
1 change: 1 addition & 0 deletions example/app/candlestick.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export default function CandlestickPage(props: { segment: string }) {
padding={{ left: 10, right: 10, top: 20, bottom: 10 }}
domainPadding={{ left: 18, right: 18, top: 20, bottom: 12 }}
chartPressState={pressState}
enableHover
xAxis={{
font,
tickValues: MAIN_TICK_VALUES,
Expand Down
1 change: 1 addition & 0 deletions example/app/chart-refs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export default function ChartRefsExample() {
},
}}
chartPressState={state}
enableHover
>
{({ points }) => (
<>
Expand Down
45 changes: 43 additions & 2 deletions example/app/donut-chart.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import React, { useState } from "react";
import { ScrollView, StyleSheet, View } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
import { LinearGradient, vec } from "react-native-skia";
import { Pie, PolarChart } from "victory-native";
import {
LinearGradient,
Text as SkiaText,
useFont,
vec,
} from "react-native-skia";
import { Pie, PolarChart, usePieHoverState } from "victory-native";
import { useDarkMode } from "react-native-dark";
import { useDerivedValue } from "react-native-reanimated";
import { InfoCard } from "example/components/InfoCard";
import { Button } from "example/components/Button";
import { appColors } from "../consts/colors";
import { descriptionForRoute } from "../consts/routes";
import inter from "../assets/inter-medium.ttf";

function calculateGradientPoints(
radius: number,
Expand Down Expand Up @@ -48,6 +56,34 @@ const DATA = (numberPoints = 5) =>
label: `Label ${index + 1}`,
}));

/** Reads the hovered-slice index `PolarChart` maintains internally; no `chartHoverState` prop needed. */
function HoverReadout({
data,
}: {
data: { label: string; value: number; color: string }[];
}) {
const isDark = useDarkMode();
const font = useFont(inter, 14);
const hover = usePieHoverState();
const text = useDerivedValue(() => {
const i = hover.index.value;
const d = i >= 0 && i < data.length ? data[i] : undefined;
return d
? `Label ${i + 1}: ${d.label} — value ${d.value}`
: "Hover the donut!";
});

return (
<SkiaText
x={20}
y={30}
text={text}
font={font}
color={isDark ? appColors.text.dark : appColors.text.light}
/>
);
}

export default function DonutChart(props: { segment: string }) {
const description = descriptionForRoute(props.segment);
const [data, setData] = useState(DATA(5));
Expand All @@ -61,7 +97,12 @@ export default function DonutChart(props: { segment: string }) {
colorKey={"color"}
valueKey={"value"}
labelKey={"label"}
enableHover
chartHoverConfig={{
activeCursor: "pointer",
}}
>
<HoverReadout data={data} />
<Pie.Chart innerRadius={"50%"}>
{({ slice }) => {
const { startX, startY, endX, endY } = calculateGradientPoints(
Expand Down
1 change: 1 addition & 0 deletions example/app/guides/getting-started.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function GettingStartedScreen(props: { segment: string }) {
font,
}}
chartPressState={state}
enableHover
>
{({ points }) => (
<>
Expand Down
Loading