Skip to content

Commit 4b739f2

Browse files
authored
Merge pull request #735 from shlinkio/dependabot/npm_and_yarn/recharts-3.0.2
Bump recharts from 2.15.4 to 3.x
2 parents 6083b5c + 4805576 commit 4b739f2

9 files changed

Lines changed: 988 additions & 886 deletions

File tree

package-lock.json

Lines changed: 45 additions & 133 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"react-external-link": "^2.5.0",
7474
"react-leaflet": "^5.0",
7575
"react-swipeable": "^7.0.2",
76-
"recharts": "^2.15.4"
76+
"recharts": "^3.1.0"
7777
},
7878
"devDependencies": {
7979
"@shlinkio/eslint-config-js-coding-standard": "~3.5.0",

src/visits/charts/HorizontalBarChart.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type HorizontalBarChartEntry = {
2929
prevAmount: number | null;
3030
};
3131

32-
const isHiddenLabel = (label: string) => label.startsWith('hidden_');
32+
const isHiddenLabel = (label: any) => typeof label !== 'string' || label.startsWith('hidden_');
3333

3434
export const HorizontalBarChart: FC<HorizontalBarChartProps> = (
3535
{ stats, prevStats, highlightedStats, highlightedLabel, max, onClick },
@@ -101,7 +101,7 @@ export const HorizontalBarChart: FC<HorizontalBarChartProps> = (
101101
stackId="main"
102102
cursor="pointer"
103103
fill={brandColor() /* This needs to be set as it is the color used in the tooltip */}
104-
onClick={({ name }: HorizontalBarChartEntry) => onClick?.(name)}
104+
onClick={({ name }) => name && onClick?.(name)}
105105
>
106106
{chartData.map((entry) => (
107107
// Using a Cell, to define a different fill color, without affecting the one used for the tooltip
@@ -114,7 +114,7 @@ export const HorizontalBarChart: FC<HorizontalBarChartProps> = (
114114
stackId="main"
115115
cursor="pointer"
116116
fill={HIGHLIGHTED_COLOR /* This needs to be set as it is the color used in the tooltip */}
117-
onClick={({ name }: HorizontalBarChartEntry) => onClick?.(name)}
117+
onClick={({ name }) => name && onClick?.(name)}
118118
>
119119
{chartData.map((entry) => (
120120
<Cell key={entry.name} fill={HIGHLIGHTED_COLOR_ALPHA} stroke={HIGHLIGHTED_COLOR} strokeWidth={2} />

src/visits/charts/LineChartCard.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
import type { FC } from 'react';
3333
import { useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from 'react';
3434
import { CartesianGrid, Line, LineChart, ReferenceArea, Tooltip, XAxis, YAxis } from 'recharts';
35-
import type { CategoricalChartState } from 'recharts/types/chart/types';
35+
import type { CategoricalChartFunc } from 'recharts/types/chart/types';
3636
import { formatInternational } from '../../utils/dates/helpers/date';
3737
import type { StrictDateRange } from '../../utils/dates/helpers/dateIntervals';
3838
import { rangeOf } from '../../utils/helpers';
@@ -203,9 +203,6 @@ const useActiveDot = (
203203
};
204204
};
205205

206-
const payloadFromChartEvent = (e: CategoricalChartState) =>
207-
e.activePayload?.[0]?.payload as ChartPayloadEntry | undefined;
208-
209206
export type LineChartCardProps = {
210207
visitsGroups: Record<string, VisitsList>;
211208
setSelectedVisits?: (visits: NormalizedVisit[]) => void;
@@ -274,18 +271,18 @@ export const LineChartCard: FC<LineChartCardProps> = (
274271
setSelectionStart(undefined);
275272
setSelectionEnd(undefined);
276273
}, []);
277-
const resolveSelectionStart = useCallback((e: CategoricalChartState, mouseEvent: MouseEvent) => {
278-
const payload = payloadFromChartEvent(e);
279-
if (mouseEvent.button === 0 && payload) {
274+
const resolveSelectionStart: CategoricalChartFunc = useCallback((e, mouseEvent) => {
275+
const payload = e.activeIndex && chartData[e.activeIndex as number];
276+
if ((mouseEvent as unknown as MouseEvent).button === 0 && payload) {
280277
setSelectionStart(payload);
281278
}
282-
}, []);
283-
const resolveSelectionEnd = useCallback((e: CategoricalChartState) => {
284-
const payload = payloadFromChartEvent(e);
279+
}, [chartData]);
280+
const resolveSelectionEnd: CategoricalChartFunc = useCallback((e) => {
281+
const payload = e.activeIndex && chartData[e.activeIndex as number];
285282
if (selectionStart && payload) {
286283
setSelectionEnd(payload);
287284
}
288-
}, [selectionStart]);
285+
}, [chartData, selectionStart]);
289286
const updateDateRange = useCallback(() => {
290287
if (!selectionStart || !selectionEnd) {
291288
return;

0 commit comments

Comments
 (0)